Exemplo n.º 1
0
def test_association():
    st = [Association([Event(Concept('a')), Event(Concept('b'))])]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 2
0
def test_inactivation():
    st = [Inhibition(Agent('DUSP4'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 3
0
def test_influence():
    st = [Influence(Event(Concept('a')), Event(Concept('b')))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 4
0
def test_complex():
    st = [Complex([Agent('BRAF'), Agent('RAF1'), Agent('YWAH')])]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 3
    assert len(ga.graph.edges()) == 3
Exemplo n.º 5
0
def test_phosphorylation():
    st = [Phosphorylation(Agent('MAP2K1'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 6
0
def test_dephosphorylation_noenz():
    st = [Dephosphorylation(None, Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 0
    assert len(ga.graph.edges()) == 0
Exemplo n.º 7
0
 def get_pdf_graph(self):
     """Save a graph made with GraphAssembler as pdf, return file name."""
     fname = 'indrabot.pdf'
     ga = GraphAssembler(self.get_statements())
     ga.make_model()
     ga.save_pdf(fname)
     return fname
Exemplo n.º 8
0
def test_phosphorylation():
    st = [Phosphorylation(Agent('MAP2K1'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    model = ga.make_model()
    assert 'MAP2K1' in model
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 9
0
def assemble_graph():
    """Assemble INDRA Statements and return Graphviz graph dot string."""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    stmts_json = body.get('statements')
    stmts = stmts_from_json(stmts_json)
    ga = GraphAssembler(stmts)
    model_str = ga.make_model()
    res = {'model': model_str}
    return res
Exemplo n.º 10
0
def assemble_graph():
    """Assemble INDRA Statements and return Graphviz graph dot string."""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    stmts_json = body.get('statements')
    stmts = stmts_from_json(stmts_json)
    ga = GraphAssembler(stmts)
    model_str = ga.make_model()
    res = {'model': model_str}
    return res
Exemplo n.º 11
0
 def report_paths_graph(self, paths_list):
     from indra.assemblers.graph import GraphAssembler
     from indra.util import flatten
     path_stmts = [stmts_from_json(l) for l in paths_list]
     all_stmts = flatten(path_stmts)
     ga = GraphAssembler(all_stmts)
     ga.make_model()
     resource = get_img_path('qca_paths.png')
     ga.save_pdf(resource)
     content = KQMLList('display-image')
     content.set('type', 'simulation')
     content.sets('path', resource)
     self.tell(content)
Exemplo n.º 12
0
def draw_graph(stmts, fname):
    graphpr = {'rankdir': 'TD'}
    nodepr = {'fontsize': 12, 'shape': 'plaintext', 'margin': '0,0', 'pad': 0}
    ga = GraphAssembler(stmts, graph_properties=graphpr,
                        node_properties=nodepr)
    ga.make_model()
    ga.save_dot('%s.dot' % fname)
    ga.save_pdf('%s.pdf' % fname)
Exemplo n.º 13
0
def test_get_string():
    st = [Phosphorylation(Agent('MAP2K1'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    graph_str = ga.get_string()
    assert graph_str
Exemplo n.º 14
0
Arquivo: api.py Projeto: steppi/indra
    def post(self):
        """Assemble INDRA Statements and return Graphviz graph dot string.

        Parameters
        ----------
        statements : list[indra.statements.Statement.to_json()]
            A list of INDRA Statements to assemble.

        Returns
        -------
        model
            Assembled model string.
        """
        args = request.json
        stmts_json = args.get('statements')
        stmts = stmts_from_json(stmts_json)
        ga = GraphAssembler(stmts)
        model_str = ga.make_model()
        res = {'model': model_str}
        return res
Exemplo n.º 15
0
def test_inactivation():
    st = [Inhibition(Agent('DUSP4'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 16
0
def test_complex():
    st = [Complex([Agent('BRAF'), Agent('RAF1'), Agent('YWAH')])]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 3
    assert len(ga.graph.edges()) == 3
Exemplo n.º 17
0
def test_influence():
    st = [Influence(Concept('a'), Concept('b'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 18
0
def test_dephosphorylation_noenz():
    st = [Dephosphorylation(None, Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 0
    assert len(ga.graph.edges()) == 0
Exemplo n.º 19
0
def test_association():
    st = [Association([Event(Concept('a')), Event(Concept('b'))])]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 20
0
def test_dephosphorylation():
    st = [Dephosphorylation(Agent('DUSP4'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 21
0
 def get_pdf_graph(self):
     """Save a graph made with GraphAssembler as pdf, return file name."""
     fname = 'indrabot.pdf'
     ga = GraphAssembler(self.get_statements())
     ga.make_model()
     ga.save_pdf(fname)
     return fname
Exemplo n.º 22
0
def test_get_string():
    st = [Phosphorylation(Agent('MAP2K1'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    graph_str = ga.get_string()
    assert graph_str
Exemplo n.º 23
0
def test_influence():
    # Add an extra standalone event just to make sure it doesn't error
    st = [Influence(Event(Concept('a')), Event(Concept('b'))),
          Event(Concept('a'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    assert len(ga.graph.nodes()) == 2
    assert len(ga.graph.edges()) == 1
Exemplo n.º 24
0
 def report_paths_graph(self, paths_list):
     from indra.assemblers.graph import GraphAssembler
     from indra.util import flatten
     path_stmts = [stmts_from_json(l) for l in paths_list]
     all_stmts = flatten(path_stmts)
     ga = GraphAssembler(all_stmts)
     ga.make_model()
     resource = get_img_path('qca_paths.png')
     ga.save_pdf(resource)
     content = KQMLList('display-image')
     content.set('type', 'simulation')
     content.sets('path', resource)
     self.tell(content)
Exemplo n.º 25
0
def format_stmts(stmts, output_format, ev_counts=None, source_counts=None):
    if output_format == 'tsv':
        msg = ''
        for stmt in stmts:
            if not stmt.evidence:
                logger.warning('Statement %s without evidence' % stmt.uuid)
                txt = ''
                pmid = ''
            else:
                txt = '"%s"' % stmt.evidence[0].text if \
                    stmt.evidence[0].text else ''
                pmid = stmt.evidence[0].pmid if stmt.evidence[0].pmid else ''
            try:
                ea_txt = EnglishAssembler([stmt]).make_model()
            except Exception as e:
                ea_txt = ''
                logger.error('English assembly failed for %s' % stmt)
                logger.error(e)
            line = '%s\t%s\t%s\tPMID%s\n' % (stmt, ea_txt, txt, pmid)
            msg += line
        return msg
    elif output_format == 'pkl':
        fname = 'indrabot.pkl'
        with open(fname, 'wb') as fh:
            pickle.dump(stmts, fh)
        return fname
    elif output_format == 'pdf':
        fname = 'indrabot.pdf'
        ga = GraphAssembler(stmts)
        ga.make_model()
        ga.save_pdf(fname)
        return fname
    elif output_format == 'json':
        msg = json.dumps(stmts_to_json(stmts), indent=1)
        return msg
    elif output_format == 'html':
        ev_counts = {} if not ev_counts else ev_counts
        ha = HtmlAssembler(stmts, ev_totals=ev_counts,
                           source_counts=source_counts)
        fname = 'indrabot.html'
        ha.save_model(fname)
        return fname
    return None
Exemplo n.º 26
0
def test_save_pdf():
    st = [Phosphorylation(Agent('MAP2K1'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    ga.save_pdf('/dev/null')
Exemplo n.º 27
0
def test_save_pdf():
    st = [Phosphorylation(Agent('MAP2K1'), Agent('MAPK1'))]
    ga = GraphAssembler()
    ga.add_statements(st)
    ga.make_model()
    ga.save_pdf('/dev/null')