def test_msa_custom_corpus_stmt_type(): # Create a pickle with a test statement test_corpus = 'test_corpus2.pkl' kras = Agent('KRAS', db_refs={'HGNC': '6407'}) st1 = Phosphorylation(Agent('x'), kras) st2 = Inhibition(Agent('y'), kras) st3 = Activation(Agent('z'), kras) with open(test_corpus, 'wb') as fh: pickle.dump([st1, st2, st3], fh) # Instantiate MSA with that pickle as the corpus msa = MSA(corpus_config='pickle:%s' % test_corpus) # Query the MSA finder = msa.find_mechanisms('to_target', target=kras, verb='activate') # Make sure we got the original statement back res_stmts = finder.get_statements() assert res_stmts[0].__class__.__name__ == 'Activation' assert res_stmts[0].subj.name == 'z' finder = msa.find_mechanisms('to_target', target=kras, verb='phosphorylate') # Make sure we got the original statement back res_stmts = finder.get_statements() assert res_stmts[0].__class__.__name__ == "Phosphorylation" assert res_stmts[0].enz.name == 'x'
def test_statements_from_neo4j(): user = os.environ.get('INDRA_NEO4J_USER') pw = os.environ.get('INDRA_NEO4J_PASSWORD') url = os.environ.get('INDRA_NEO4J_URL') config = 'neo4j:bolt://%s:%s@%s' % (user, pw, url) msa = MSA(corpus_config=config) kras = Agent('KRAS', db_refs={'HGNC': '6407'}) finder = msa.find_mechanisms('to_target', target=kras, verb='activate') res_stmts = finder.get_statements() assert len(res_stmts) > 1000 assert isinstance(res_stmts[0], Activation) finder = msa.find_mechanisms('from_source', source=kras, verb='activate') res_stmts = finder.get_statements() assert len(res_stmts) > 1000 assert isinstance(res_stmts[0], Activation)
def test_valid_keys_no_text(): # We test that an agent with just a PUBCHEM ID can still be queried msa = MSA() ag = Agent('vemurafenib', db_refs={'PUBCHEM': '42611257'}) finder = msa.find_mechanisms('from_source', ag) stmts = finder.get_statements(block=True) assert stmts
def test_get_finder_agents(): msa = MSA() ag = Agent('SOCS1', db_refs={'HGNC': '19383'}) finder = msa.find_mechanisms('to_target', ag, verb='phosphorylate') other_agents = finder.get_other_agents() assert all(isinstance(a, Agent) for a in other_agents) # The other names should be sorted with PIM1 first (most evidence) assert other_agents[0].name == 'PIM1' fixed_agents = finder.get_fixed_agents() assert 'object' in fixed_agents, fixed_agents assert fixed_agents['object'][0].name == 'SOCS1', fixed_agents['target']
def test_msa_custom_corpus(): # Create a pickle with a test statement test_corpus = 'test_corpus.pkl' stmt = Phosphorylation(Agent('XXXX'), Agent('YYYY', db_refs={'HGNC': '1'})) with open(test_corpus, 'wb') as fh: pickle.dump([stmt], fh) # Instantiate MSA with that pickle as the corpus msa = MSA(corpus_config='pickle:%s' % test_corpus) # Query the MSA finder = msa.find_mechanisms('to_target', target=Agent('YYYY', db_refs={'HGNC': '1'})) # Make sure we got the original statement back res_stmts = finder.get_statements() assert res_stmts[0].matches(stmt) # Now try a modified query finder = msa.find_mechanisms('to_target', target=Agent('ERK', db_refs={'FPLX': 'ERK'})) # Make sure we don't get anything res_stmts = finder.get_statements() assert not res_stmts