def test_conversion(): ia = IndraNetAssembler([st8]) ug = ia.make_model(graph_type='multi_graph') assert len(ug.nodes) == 3 assert len(ug.edges) == 2, ug.edges sg = ia.make_model(graph_type='signed') assert len(sg.nodes) == 3 assert len(sg.edges) == 2, sg.edges assert ('PI3K', 'PIP3', 0) in sg.edges, sg.edges assert ('PI3K', 'PIP2', 1) in sg.edges, sg.edges
def test_complex_members(): ia = IndraNetAssembler([st1, st6]) # First assemble with dataframe method g = ia.make_model(method='df', complex_members=4) assert len(g.nodes) == 5 assert len(g.edges) == 13, len(g.edges) assert ('h', 'i', 0) in g.edges assert ('i', 'h', 0) in g.edges # Get same result assembling with preassembly g = ia.make_model(method='preassembly', complex_members=4) assert len(g.nodes) == 5 assert len(g.edges) == 13, len(g.edges) assert ('h', 'i', 0) in g.edges assert ('i', 'h', 0) in g.edges
def test_exclude_stmts(): ia = IndraNetAssembler([st1, st2, st3]) # First assemble with dataframe method g = ia.make_model(method='df', exclude_stmts=['Inhibition']) assert len(g.nodes) == 3 assert len(g.edges) == 2 assert 'c' not in g.nodes assert ('a', 'c', 0) not in g.edges # Get same result assembling with preassembly g = ia.make_model(method='preassembly', exclude_stmts=['Inhibition']) assert len(g.nodes) == 3 assert len(g.edges) == 2 assert 'c' not in g.nodes assert ('a', 'c', 0) not in g.edges
def test_complex_members(): ia = IndraNetAssembler([st1, st6]) g = ia.make_model(complex_members=4) assert len(g.nodes) == 5 assert len(g.edges) == 13, len(g.edges) assert ('h', 'i', 0) in g.edges assert ('i', 'h', 0) in g.edges
def test_exclude_stmts(): ia = IndraNetAssembler([st1, st2, st3]) g = ia.make_model(exclude_stmts=['Inhibition']) assert len(g.nodes) == 3 assert len(g.edges) == 2 assert 'c' not in g.nodes assert ('a', 'c', 0) not in g.edges
def assemble_unsigned_graph(self): """Assemble the model into unsigned graph and return the assembled graph.""" if not self.assembled_stmts: self.run_assembly() ia = IndraNetAssembler(self.assembled_stmts) unsigned_graph = ia.make_model(graph_type='digraph') return unsigned_graph
def assemble_unsigned_graph(self, **kwargs): """Assemble the model into unsigned graph and return the assembled graph.""" if not self.assembled_stmts: self.run_assembly() ia = IndraNetAssembler(self.assembled_stmts) unsigned_graph = ia.make_model(graph_type='digraph', extra_columns=[('internal', is_internal) ]) return unsigned_graph
def test_conversion(): ia = IndraNetAssembler([st8]) # First assemble with dataframe method ug = ia.make_model(method='df', graph_type='multi_graph') assert len(ug.nodes) == 3 assert len(ug.edges) == 2, ug.edges sg = ia.make_model(method='df', graph_type='signed') assert len(sg.nodes) == 3 assert len(sg.edges) == 2, sg.edges assert ('PI3K', 'PIP3', 0) in sg.edges, sg.edges assert ('PI3K', 'PIP2', 1) in sg.edges, sg.edges # Get same result assembling with preassembly ug = ia.make_model(method='preassembly', graph_type='multi_graph') assert len(ug.nodes) == 3 assert len(ug.edges) == 2, ug.edges sg = ia.make_model(method='preassembly', graph_type='signed') assert len(sg.nodes) == 3, sg.nodes assert len(sg.edges) == 2, sg.edges assert ('PI3K', 'PIP3', 0) in sg.edges, sg.edges assert ('PI3K', 'PIP2', 1) in sg.edges, sg.edges
def test_simple_assembly(): ia = IndraNetAssembler([st1, st2, st3, st4, st5, st6, st7]) # First assemble with dataframe method g = ia.make_model(method='df') assert len(g.nodes) == 6 assert len(g.edges) == 9 # Stmt with 1 agent should not be added assert 'e' not in g.nodes # Complex with more than 3 agents should not be added assert ('f', 'g', 0) in g.edges assert ('h', 'i', 0) not in g.edges # Test node attributes assert g.nodes['a']['ns'] == 'HGNC', g.nodes['a']['ns'] assert g.nodes['a']['id'] == '1' # Test edge attributes e = g['a']['c'][0] assert e['stmt_type'] == 'Inhibition' assert e['belief'] == 0.76 assert e['evidence_count'] == 3 assert g['b']['d'][0]['evidence_count'] == 0 # Get same result assembling with preassembly g = ia.make_model(method='preassembly') assert len(g.nodes) == 6 assert len(g.edges) == 9 # Stmt with 1 agent should not be added assert 'e' not in g.nodes # Complex with more than 3 agents should not be added assert ('f', 'g', 0) in g.edges assert ('h', 'i', 0) not in g.edges # Test node attributes assert g.nodes['a']['ns'] == 'HGNC', g.nodes['a']['ns'] assert g.nodes['a']['id'] == '1' # Test edge attributes e = g['a']['c'][0] assert e['stmt_type'] == 'Inhibition' assert e['belief'] == 0.76 assert e['evidence_count'] == 3 assert g['b']['d'][0]['evidence_count'] == 0
def test_getting_started9_10(): # Chunk 9 # pa.export_model('sbml', file_name='model.sbml') # Chunk 10 from indra.assemblers.indranet import IndraNetAssembler indranet_assembler = IndraNetAssembler(statements=gn_stmts) indranet = indranet_assembler.make_model() assert len(indranet.nodes) > 0, 'indranet contains no nodes' assert len(indranet.edges) > 0, 'indranet contains no edges' # Chunk 11 signed_graph = indranet.to_signed_graph() assert len(signed_graph.nodes) > 0, 'signed graph contains no nodes' assert len(signed_graph.edges) > 0, 'signed graph conatins no edges'
def assemble_signed_graph(self, mode='local', bucket=EMMAA_BUCKET_NAME): """Assemble the model into signed graph and return the assembled graph. """ if not self.assembled_stmts: self.run_assembly() ia = IndraNetAssembler(self.assembled_stmts) signed_graph = ia.make_model(graph_type='signed') if mode == 's3' and 'indranet' in self.export_formats: fname = f'indranet_{self.date_str}.tsv' df = ia.make_df() df.to_csv(fname, sep='\t', index=False) logger.info(f'Uploading {fname}') client = get_s3_client(unsigned=False) client.upload_file(fname, bucket, f'exports/{self.name}/{fname}') return signed_graph
def test_initial_signs(): a = Event(Concept('a'), QualitativeDelta(polarity=1)) b = Event(Concept('b'), QualitativeDelta(polarity=1)) c = Event(Concept('c'), QualitativeDelta(polarity=-1)) d = Event(Concept('d'), QualitativeDelta(polarity=-1)) st1 = Influence(a, b) st2 = Influence(b, c) st3 = Influence(c, d) st4 = Influence(b, d) ia = IndraNetAssembler([st1, st2, st3, st4]) sg = ia.make_model(graph_type='signed') assert len(sg.nodes) == 4 assert len(sg.edges) == 4 assert ('a', 'b', 0) in sg.edges assert ('b', 'c', 0) not in sg.edges assert ('b', 'c', 1) in sg.edges assert ('c', 'd', 0) in sg.edges assert ('c', 'd', 1) not in sg.edges assert ('b', 'd', 0) not in sg.edges assert ('b', 'd', 1) in sg.edges
def test_gene_network(): # Chunk 1: this is tested in _get_gene_network_stmts # from indra.tools.gene_network import GeneNetwork # gn = GeneNetwork(['H2AX']) # biopax_stmts = gn.get_biopax_stmts() # bel_stmts = gn.get_bel_stmts() # Chunk 2 from indra import literature pmids = literature.pubmed_client.get_ids_for_gene('H2AX') # Chunk 3 from indra import literature paper_contents = {} for pmid in pmids: content, content_type = literature.get_full_text(pmid, 'pmid') if content_type == 'abstract': paper_contents[pmid] = content if len(paper_contents) == 5: # Is 10 in actual code break # Chunk 4 from indra.sources import reach literature_stmts = [] for pmid, content in paper_contents.items(): rp = reach.process_text(content, url=reach.local_text_url) literature_stmts += rp.statements print('Got %d statements' % len(literature_stmts)) assert literature_stmts # replaces a print statements # Chunk 6 from indra.tools import assemble_corpus as ac # stmts = biopax_stmts + bel_stmts + literature_stmts # tested elsewhere stmts = gn_stmts + literature_stmts # Added instead of above line stmts = ac.map_grounding(stmts) stmts = ac.map_sequence(stmts) stmts = ac.run_preassembly(stmts) assert stmts # Chunk 7 from indra.assemblers.cx import CxAssembler from indra.databases import ndex_client cxa = CxAssembler(stmts) cx_str = cxa.make_model() assert cx_str # Chunk 8 # ndex_cred = {'user': '******', 'password': '******'} # network_id = ndex_client.create_network(cx_str, ndex_cred) # print(network_id) # Chunk 9 from indra.assemblers.indranet import IndraNetAssembler indranet_assembler = IndraNetAssembler(statements=stmts) indranet = indranet_assembler.make_model() assert len(indranet.nodes) > 0, 'indranet conatins no nodes' assert len(indranet.edges) > 0, 'indranet conatins no edges' # Chunk 10 import networkx as nx paths = nx.single_source_shortest_path(G=indranet, source='H2AX', cutoff=1) assert paths # Chunk 11 from indra.assemblers.pysb import PysbAssembler pysb = PysbAssembler(statements=stmts) pysb_model = pysb.make_model() assert pysb_model