def test_regionactor(self): # Phosphorylated and unphosphrylated states. phos = State("phosphorylation", True) unphos = State("phosphorylation", False) inters = [] # Phosphorylation with RegionActor as substrate. m = Modification(enzyme=Protoform("P00519"), substrate=RegionActor( Protoform("P00533", regions=[ Region(name='PVPEyINQS', start=280, end=290), Region(name="L receptor", start=57, end=167, states=[phos]) ]), Region(start=1000, end=1500)), target=Residue(aa="Y", loc=1092, state=unphos), value=True) inters.append(m) corpus = KamiCorpus("test") corpus.add_interactions(inters, anatomize=True) print_graph(corpus.get_nugget("test_nugget_1"))
def test_complex_mod_nugget(self): """Complex modification interaction example.""" enzyme_agent = Protoform("P04049") enzyme_region = Region(start=100, end=200, name="lala") enzyme = RegionActor(enzyme_agent, enzyme_region) state = State("phosphorylation", True) reg_residue = Residue("S", 550, state) substrate_region = Region(start=500, end=600, residues=[reg_residue]) substrate_residues = [ Residue("T", 100), Residue("S", 56, State("phosphorylation", True)) ] substrate_state = State("activity", True) next_level_bound = RegionActor(Protoform("P04637"), Region(start=224, end=234)) substrate_bound = Protoform("P12931", bound_to=[next_level_bound]) substrate = Protoform("P00533", regions=[substrate_region], residues=substrate_residues, states=[substrate_state], bound_to=[substrate_bound]) mod_target = Residue("S", "33", State("phosphorylation", False)) mod2 = Modification(enzyme, substrate, mod_target, True) self.corpus.add_interaction(mod2, add_agents=True, anatomize=False)
def test_siteactor(self): """Generate sh2 pY bnd interactions.""" # General phosphorylation state. phos = State("phosphorylation", True) unphos = State("phosphorylation", False) # General SH2 regions. sh2 = Region(name="SH2") sh2n = Region(name="SH2", order=1) sh2c = Region(name="SH2", order=2) inters = [] enz_uniprot = 'P00519' sub_uniprot = 'P00533' rsd = 'Y1092' location = int(rsd[1:]) strt = location - 4 stop = location + 4 site_name = 'b%i' % location m = Modification(enzyme=Protoform(enz_uniprot), substrate=SiteActor(protoform=Protoform(sub_uniprot), site=Site(name=site_name, start=strt, end=stop)), target=Residue(aa="Y", loc=location, state=unphos), value=True) inters.append(m) corpus = KamiCorpus("test") corpus.add_interactions(inters, anatomize=True)
def test_mod_generator(self): """Test generation of a modification nugget graph.""" enzyme_gene = Protoform("A") enzyme_region_actor = RegionActor( protoform=enzyme_gene, region=Region("Pkinase")) enzyme_site_actor = SiteActor( protoform=enzyme_gene, region=Region("Pkinase"), site=Site("tail")) substrate_gene = Protoform("B") substrate_region_actor = RegionActor( protoform=substrate_gene, region=Region("SH2")) substrate_site_actor = SiteActor( protoform=substrate_gene, region=Region("SH2"), site=Site("finger")) residue_mod_target = Residue("Y", 100, State("activity", False)) state_mod_target = State("activity", False) mod1 = Modification( enzyme=enzyme_gene, substrate=substrate_gene, target=state_mod_target ) mod2 = Modification( enzyme=enzyme_region_actor, substrate=substrate_gene, target=state_mod_target ) mod3 = Modification( enzyme=enzyme_site_actor, substrate=substrate_gene, target=state_mod_target ) mod4 = Modification( enzyme=enzyme_site_actor, substrate=substrate_region_actor, target=state_mod_target ) mod5 = Modification( enzyme=enzyme_site_actor, substrate=substrate_site_actor, target=residue_mod_target ) corpus = KamiCorpus("test") identifier = EntityIdentifier( corpus.action_graph, corpus.get_action_graph_typing()) generator = ModGenerator(identifier) n, _, _, _ = generator.generate(mod5) print_graph(n.graph)
def test_region_generator(self): """Test generation of graph components for a Region object.""" kinase_region = Region( name="Pkinase", start=300, end=500, states=[State("activity", True)], residues=[Residue("Y", 1000)], ) nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene try: self.generator.generate_region( nugget, kinase_region, self.default_ag_gene) raise ValueError("Invalid residue was not caught!") except KamiError: pass kinase_region = Region( name="Pkinase", start=300, end=500, states=[State("activity", True)], residues=[Residue("Y", 350, State("phosphorylation", True))], sites=[ # Site(name="bob", residues=[Residue("Y", 350)]), Site(name="alice", start=1000, end=2000) ] ) try: self.generator.generate_region( nugget, kinase_region, self.default_ag_gene) raise ValueError("Invalid site was not caught!") except KamiError: pass nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene kinase_region = Region( name="Pkinase", start=300, end=500, states=[State("activity", True)], residues=[Residue("Y", 350, State("phosphorylation", True))], sites=[ Site(name="alice", start=350, end=450) ] ) kinase_region_id = self.generator.generate_region( nugget, kinase_region, self.default_ag_gene) assert(len(nugget.nodes()) == 5)
def test_identify_state(self): """Test state identification.""" identifier = EntityIdentifier(self.hierarchy.action_graph, self.hierarchy.get_action_graph_typing()) res = identifier.identify_state(State("activity", False), self.residue) assert (res == self.residue_state) res = identifier.identify_state(State("activity", False), self.named_site) assert (res == self.site_state) res = identifier.identify_state(State("activity", False), self.named_region) assert (res == self.region_state) res = identifier.identify_state(State("activity", False), self.gene_id) assert (res == self.gene_state)
def __init__(self): """Initialize with common hierarchy.""" self.hierarchy = KamiCorpus("test") protoform = Protoform("A") self.gene_id = self.hierarchy.add_protoform(protoform) named_region = Region("Kinase") interval_region = Region(start=100, end=200) named_ordered_region1 = Region("SH2", order=1) named_ordered_region2 = Region("SH2", order=2) self.named_region = self.hierarchy.add_region(named_region, self.gene_id) self.interval_region = self.hierarchy.add_region( interval_region, self.gene_id) self.named_ordered_region1 = self.hierarchy.add_region( named_ordered_region1, self.gene_id) self.named_ordered_region2 = self.hierarchy.add_region( named_ordered_region2, self.gene_id) named_site = Site("ATP binding") interval_site = Site(start=100, end=200) named_ordered_site1 = Site("pY", order=1) named_ordered_site2 = Site("pY", order=2) self.named_site = self.hierarchy.add_site(named_site, self.gene_id) self.interval_site = self.hierarchy.add_site(interval_site, self.gene_id) self.named_ordered_site1 = self.hierarchy.add_site( named_ordered_site1, self.gene_id) self.named_ordered_site2 = self.hierarchy.add_site( named_ordered_site2, self.gene_id) residue = Residue("Y", 150) residue_no_loc = Residue("T") self.residue = self.hierarchy.add_residue(residue, self.gene_id) self.residue_no_loc = self.hierarchy.add_residue( residue_no_loc, self.gene_id) residue_state = State("activity", True) site_state = State("activity", True) region_state = State("activity", True) gene_state = State("activity", True) self.residue_state = self.hierarchy.add_state(residue_state, self.residue) self.site_state = self.hierarchy.add_state(site_state, self.named_site) self.region_state = self.hierarchy.add_state(region_state, self.named_region) self.gene_state = self.hierarchy.add_state(gene_state, self.gene_id)
def test_ligandmod_generation(self): """Test generation of a transmodification nugget graph.""" enzyme_gene = Protoform("A") enzyme_region_actor = RegionActor( protoform=enzyme_gene, region=Region("Pkinase")) substrate = Protoform("B") automod = LigandModification( enzyme_region_actor, substrate, Residue("Y", 100, State("phosphorylation", True)), value=True, enzyme_bnd_region=Region("EbndRegion"), substrate_bnd_region=Region("SbndRegion"), substrate_bnd_site=Site("SbndSite")) corpus = KamiCorpus("test") identifier = EntityIdentifier( corpus.action_graph, corpus.get_action_graph_typing()) generator = LigandModGenerator(identifier) n, _, _, _ = generator.generate(automod) print_graph(n.graph) inter = LigandModification( enzyme=RegionActor(protoform=Protoform(uniprotid="P30530", hgnc_symbol="AXL"), region=Region(name="Tyr_kinase", interproid="IPR020635", start=536, end=807)), substrate=SiteActor(protoform=Protoform(uniprotid="P06239", hgnc_symbol="LCK"), site=Site(name="pY394", start=391, end=397)), target=Residue(aa="Y", loc=394, state=State("phosphorylation", False)), value=True, rate=10, enzyme_bnd_region=Region(name="Tyr_kinase", interproid="IPR020635", start=536, end=807), substrate_bnd_site=Site(name='pY394', start=391, end=397) ) corpus = KamiCorpus("test") corpus.add_interaction(inter, anatomize=False) print_graph(corpus.get_nugget('test_nugget_1'))
def test_non_empty_hierarchy(self): """.""" model = KamiCorpus("test") plcg1_pY1253 = Protoform("P19174", synonyms=["PLCG1"], residues=[ Residue("Y", 1253, state=State( "phosphorylation", True)) ]) sh2 = Region(name="SH2") abl1 = Protoform("P00519", synonyms=["ABL1"]) abl1_sh2 = RegionActor(abl1, sh2) bnd = Binding(plcg1_pY1253, abl1_sh2) model.add_interactions([bnd], model) assert (model.empty() is False) model.export_json("test_non_empty_hierarchy.json") new_model = KamiCorpus.load_json("test", "test_non_empty_hierarchy.json") assert (isinstance(new_model, KamiCorpus)) assert (("test_action_graph", "meta_model") in new_model._hierarchy.edges())
def test_complicated_site_actor(self): m = Modification(enzyme=SiteActor(protoform=Protoform( "P00519", sites=[Site(name="bob", start=120, end=150)], regions=[Region(name="alice", start=100, end=200)], residues=[Residue("Y", 122)]), site=Site(name="jack", start=550, end=600, residues=[Residue("T")]), region=Region( name="Pkinase", start=500, end=800, sites=[Site(name="billy")])), substrate=SiteActor(protoform=Protoform("P00533"), site=Site(name="target"), region=Region(name="bla")), target=Residue("Y", 100, State("phosphorylation", False)), value=True) corpus = KamiCorpus("test") corpus.add_interactions([m], anatomize=True) print_graph(corpus.get_nugget("test_nugget_1")) print(ag_to_edge_list(corpus))
def test_multiple_bnd_templates(self): dummy_partner = SiteActor( protoform=Protoform("C"), region=Region(name="C_RegionActor"), site=Site(name="C_SiteActor")) enzyme = SiteActor( protoform=Protoform("A", bound_to=[dummy_partner]), region=Region(name="A_RegionActor", bound_to=[dummy_partner]), site=Site(name="A_SiteActor", bound_to=[dummy_partner])) substrate = SiteActor( protoform=Protoform("B", bound_to=[dummy_partner]), region=Region(name="B_RegionActor", bound_to=[dummy_partner]), site=Site(name="B_SiteActor", bound_to=[dummy_partner])) mod = Modification( enzyme, substrate, target=Residue("Y", 100, State("phosphorylation", False)), value=True) corpus = KamiCorpus("test") identifier = EntityIdentifier( corpus.action_graph, corpus.get_action_graph_typing()) generator = ModGenerator(identifier) n, _, _, _ = generator.generate(mod)
def test_advanced_site_actor(self): # General phosphorylation state. phos = State("phosphorylation", True) unphos = State("phosphorylation", False) # General SH2 regions. sh2 = Region(name="SH2") sh2n = Region(name="SH2", order=1) sh2c = Region(name="SH2", order=2) # Test site. s1 = Site(name="test_site") inters = [] # Modification using SiteActor. m = Modification(enzyme=Protoform("P00519", hgnc_symbol="ABL1"), substrate=SiteActor(protoform=Protoform( "P00519", hgnc_symbol="ABL1"), site=Site(name="site800", start=796, end=804)), target=Residue("Y", 800, State("phosphorylation", False)), value=True) inters.append(m) m = Modification(enzyme=Protoform("P00519", hgnc_symbol="ABL1"), substrate=SiteActor(protoform=Protoform( "P00533", hgnc_symbol="EGFR"), site=Site(name="site800", start=796, end=804)), target=Residue("Y", 800, State("phosphorylation", False)), value=True) inters.append(m) # Binding using SiteActor. b = Binding( SiteActor(protoform=Protoform("P00533", hgnc_symbol="EGFR"), site=Site(name="site800", start=796, end=804)), RegionActor(protoform=Protoform("P62993", hgnc_symbol="GRB2"), region=sh2)) inters.append(b) corpus = KamiCorpus("test") corpus.add_interactions(inters, anatomize=True)
def test_gene_generator(self): """Test generation of graph components for a Protoform object.""" nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene gene1 = Protoform("B") self.generator.generate_gene(nugget, gene1) self.generator.generate_gene( nugget, gene1) nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene gene2 = Protoform( "P00519", synonyms=["ABL1"], states=[State("active", True), State("active", False)], residues=[ Residue("Y", 100, State("phosphorylation", True)), Residue("T", 100, State("phosphorylation", True)), Residue("S", 500), Residue("T") ], sites=[ Site("bob"), Site(start=100, end=300, name="super_site", residues=[Residue("T", 150)]) ], regions=[ Region(name="sh2"), Region( start=0, end=1000, name="big_region", states=[State("activity", True)]) ], bound_to=[gene1], ) gene_id, _ = self.generator.generate_gene(nugget, gene2) # check it is consistent assert(len(nugget.nodes()) == 17) assert(len(nugget.edges()) == 16) assert(gene_id in nugget.graph.nodes()) assert("P00519" in nugget.graph.get_node(gene_id)['uniprotid'])
def __init__(self): """Initialize test class with a model.""" self.model = KamiCorpus("test") egfr = Protoform("P00533") fgfr1 = Protoform("P11362") fgfr1_pysite = SiteActor( Protoform("P11362"), Site("pY", residues=[Residue("Y", 463, State("phosphorylation", True))])) abl1_sh2 = RegionActor(Protoform("P00519"), Region("SH2")) target = Residue("Y", 463, State("phosphorylation", False)) modification = Modification(enzyme=egfr, substrate=fgfr1, target=target) binding = Binding(abl1_sh2, fgfr1_pysite) self.model.add_interactions([modification, binding])
def test_residue_generator(self): """Test generation of graph components for a Residue object.""" t = Residue("T") t100 = Residue("T", 100) y100_phospho = Residue("Y", 100, State("phosphorylation", True)) y100_active = Residue("Y", 100, State("activity", True)) nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene residue1, state1 =\ self.generator.generate_residue( nugget, t, self.default_ag_gene, self.default_ag_gene) assert(state1 is None) assert(residue1 in nugget.nodes()) residue2, _ =\ self.generator.generate_residue( nugget, t, self.default_ag_gene, self.default_ag_gene) residue3, _ =\ self.generator.generate_residue( nugget, t100, self.default_ag_gene, self.default_ag_gene) residue4, state4 =\ self.generator.generate_residue( nugget, y100_phospho, self.default_ag_gene, self.default_ag_gene) assert(state4 is not None) residue5, state5 =\ self.generator.generate_residue( nugget, y100_active, self.default_ag_gene, self.default_ag_gene) assert(len(nugget.nodes()) == 7) assert("T" in nugget.graph.get_node(residue1)["aa"]) assert("T" in nugget.graph.get_node(residue2)["aa"]) assert("T" in nugget.graph.get_node(residue3)["aa"]) assert(nugget.meta_typing[residue1] == "residue") assert(nugget.meta_typing[residue2] == "residue") assert(nugget.meta_typing[residue3] == "residue") assert(nugget.meta_typing[residue4] == "residue") assert(nugget.meta_typing[residue5] == "residue")
def test_simple_mod_nugget(self): """Simple modification interaction example.""" enz_res = Residue("S", 100, State("phospho", True)) enz_reg = Region(start=150, end=170, states=[State("activity", True)]) enzyme_entity = Protoform("P00533", regions=[enz_reg], residues=[enz_res]) sub_bound_1 = Protoform("P28482", states=[State("activity", True)]) sub_bound_2 = Protoform("P28482", states=[State("activity", True)]) substrate_entity = Protoform("P04049", bound_to=[sub_bound_1, sub_bound_2]) mod_state = State("activity", False) value = True mod1 = Modification(enzyme_entity, substrate_entity, mod_state, value) # Create corresponding nugget in the corpus self.corpus.add_interaction(mod1, add_agents=True, anatomize=False)
def test_bookkeeping(self): interactions = [] i1 = LigandModification( RegionActor(Protoform("P00533"), Region(start=712, end=979)), Protoform("P00533"), Residue("Y", 1092, state=State("phosphorylation", False))) interactions.append(i1) i2 = Modification( Protoform("P00519"), Protoform("P00533"), Residue("S", 800, state=State("phosphorylation", False))) interactions.append(i2) i3 = Binding(Protoform("P00424"), SiteActor(Protoform("P00533"), Site(start=799, end=900))) interactions.append(i3) corpus = KamiCorpus("test") corpus.add_interactions(interactions)
def __init__(self): uniprotid = "P00533" simple_region = Region("SH2") regions = [simple_region] sites = [Site("pY")] residues = [ Residue("Y", 100), Residue("S", 155, State("phosphorylation", True)) ] states = [State("activity", True), State("phosphorylation", True)] bounds = [ SiteActor(protoform=Protoform("Q07890"), site=Site("binding_site")), Protoform("P00519") ] self.protoform = Protoform( uniprotid, regions=regions, residues=residues, sites=sites, states=states, bound_to=bounds, hgnc_symbol="EGFR", synonyms=["EGFR", "Epidermal growth factor receptor"]) self.enzyme_gene = Protoform("Q07890") self.enzyme_site_actor = SiteActor(protoform=self.enzyme_gene, region=Region("Pkinase"), site=Site("tail")) self.substrate_gene = Protoform("P00519") self.substrate_region_actor = RegionActor( protoform=self.substrate_gene, region=Region("SH2")) self.residue_mod_target = Residue("Y", 100, State("activity", False))
def test_record_manual_rewrites(self): # Perform a bunch of manual updates self.corpus.add_mod() self.corpus.add_bnd() gene_node = self.corpus.add_protoform(Protoform("P00533")) region_node = self.corpus.add_region( Region("Protein kinase", start=100, end=200), gene_node) self.corpus.add_site(Site("Lala1"), gene_node) site_node = self.corpus.add_site(Site("Lala2"), region_node) residue_node = self.corpus.add_residue(Residue("S", 100), site_node) self.corpus.add_state(State("phosphorylation", True), residue_node)
def test_state_generator(self): """Test generation of graph components for a State object.""" state_true = State("activity", True) state_false = State("activity", False) nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene state1 = self.generator.generate_state( nugget, state_true, self.default_ag_gene) state2 =\ self.generator.generate_state( nugget, state_true, self.default_ag_gene) state3 =\ self.generator.generate_state( nugget, state_false, self.default_ag_gene) state4 =\ self.generator.generate_state( nugget, state_false, self.default_ag_gene) assert(len(nugget.graph.nodes()) == 4) assert("name" in nugget.graph.get_node(state1).keys()) assert("activity" in nugget.graph.get_node(state1)["name"]) assert("name" in nugget.graph.get_node(state2).keys()) assert("activity" in nugget.graph.get_node(state2)["name"]) assert("name" in nugget.graph.get_node(state3).keys()) assert("activity" in nugget.graph.get_node(state3)["name"]) assert("name" in nugget.graph.get_node(state4).keys()) assert("activity" in nugget.graph.get_node(state4)["name"]) assert(nugget.meta_typing[state1] == "state") assert(nugget.meta_typing[state2] == "state") assert(nugget.meta_typing[state3] == "state") assert(nugget.meta_typing[state4] == "state") return
def test_phospho_semantics(self): """Test black box processing using phosphorylation semantics.""" mek1 = Protoform("Q02750") stat3 = Protoform("P40763") mod_state = Residue("S", 727, State("phosphorylation", False)) value = True mod1 = Modification(mek1, stat3, mod_state, value) mod_state_1 = Residue("Y", 705, State("phosphorylation", False)) mod2 = Modification(mek1, stat3, mod_state_1, value) erk1 = Protoform("P27361") mod_state_2 = Residue("T", 201, State("phosphorylation", False)) mod3 = Modification(mek1, erk1, mod_state_2, value) erk2 = Protoform("P28482") mod_state_3 = Residue("T", 182, State("phosphorylation", False)) mod4 = Modification(mek1, erk2, mod_state_3, value) interactions = [mod1, mod2, mod3, mod4] corpus = KamiCorpus("test") corpus.add_interactions(interactions, add_agents=True, anatomize=True) print(corpus.action_graph.nodes()) print( corpus._hierarchy.get_relation("test_action_graph", "semantic_action_graph")) print(corpus) print_graph(corpus.action_graph) print( corpus._hierarchy.get_relation("test_action_graph", "semantic_action_graph"))
def test_site_residue_reconnect(self): sh2 = Region(name="SH2") b = Binding( SiteActor(protoform=Protoform(uniprotid="P00533", hgnc_symbol="EGFR", residues=[ Residue("Y", 1092, state=State( "phosphorylation", True)) ]), site=Site(name="motif1092", start=1088, end=1096)), RegionActor(protoform=Protoform("P62993", hgnc_symbol="GRB2"), region=sh2)) corpus = KamiCorpus("test") corpus.add_interaction(b)
def test_anonymous_mod_generation(self): """Test generation of an anonymous modification nugget graph.""" protoform = Protoform("A") region_actor = RegionActor( protoform=protoform, region=Region("Pkinase")) mod = AnonymousModification( region_actor, Residue("Y", 100, State("phosphorylation", False)), value=True) corpus = KamiCorpus("test") identifier = EntityIdentifier( corpus.action_graph, corpus.get_action_graph_typing()) generator = AnonymousModGenerator(identifier) n, _, _, _ = generator.generate(mod) print_graph(n.graph)
def test_selfmod_generation(self): """Test generation of an automodification nugget graph.""" enzyme_gene = Protoform("A") enzyme_region_actor = RegionActor( protoform=enzyme_gene, region=Region("Pkinase")) automod = SelfModification( enzyme_region_actor, Residue("Y", 100, State("phosphorylation", True)), value=True, substrate_region=Region("Region"), substrate_site=Site("Site")) corpus = KamiCorpus("test") identifier = EntityIdentifier( corpus.action_graph, corpus.get_action_graph_typing()) generator = SelfModGenerator(identifier) n, _, _, _ = generator.generate(automod) print_graph(n.graph)
def test_multiple_sh2(self): """.""" phos = State("phosphorylation", True) sh2n = Region(name="SH2", order=1) sh2c = Region(name="SH2", order=2) pik3r1 = Protoform("P27986", synonyms=["PIK3R1", "PI3K1"]) pik3r1_sh2n = RegionActor(pik3r1, sh2n) pik3r1_sh2c = RegionActor(pik3r1, sh2c) frs2_py196 = Protoform("Q8WU20", synonyms=["FRS2"], residues=[Residue("Y", 196, phos)]) frs2_py349 = Protoform("Q8WU20", synonyms=["FRS2"], residues=[Residue("Y", 349, phos)]) bnds = [] bnds.append(Binding(frs2_py196, pik3r1_sh2n)) bnds.append(Binding(frs2_py349, pik3r1_sh2c)) corpus = KamiCorpus("test") corpus.add_interactions(bnds, anatomize=True)
def test_site_generator(self): """Test generation of graph components for a Site object.""" # Site identification site_bob = Site(name="bob") site100_200 = Site(start=100, end=200) site110_150 = Site(start=110, end=150) site_bob_500_600 = Site(name="bob", start=500, end=600) site_bob_800_1000 = Site(name="bob", start=800, end=1000) site_bob_1 = Site(name="bob", order=1) site_bob_2 = Site(name="bob", order=2) nugget = KamiGraph() nugget.reference_typing[self.default_ag_gene] = self.default_ag_gene site_bob_id_1, _ =\ self.generator.generate_site( nugget, site_bob, self.default_ag_gene, self.default_ag_gene) assert(site_bob_id_1 in nugget.nodes()) site_bob_id_2, _ =\ self.generator.generate_site( nugget, site_bob, self.default_ag_gene, self.default_ag_gene) assert(site_bob_id_2 in nugget.nodes()) # assert(site_bob_id_2 in nugget.reference_typing.keys()) site100_200_id, _ =\ self.generator.generate_site( nugget, site100_200, self.default_ag_gene, self.default_ag_gene) site110_150_id, _ =\ self.generator.generate_site( nugget, site110_150, self.default_ag_gene, self.default_ag_gene) site_bob_500_600_id, _ =\ self.generator.generate_site( nugget, site_bob_500_600, self.default_ag_gene, self.default_ag_gene) site_bob_800_1000_id, _ =\ self.generator.generate_site( nugget, site_bob_800_1000, self.default_ag_gene, self.default_ag_gene) site_bob_1_id, _ =\ self.generator.generate_site( nugget, site_bob_1, self.default_ag_gene, self.default_ag_gene) site_bob_2_id, _ =\ self.generator.generate_site( nugget, site_bob_2, self.default_ag_gene, self.default_ag_gene) assert(len(nugget.nodes()) == 8) # Test generation of the site conditions complex_site = Site( start=500, end=600, states=[State('active', True)], residues=[Residue("Y", 1000, State('phosphorylation', True))], ) try: self.generator.generate_site( nugget, complex_site, self.default_ag_gene, self.default_ag_gene) raise ValueError("Invalid residue was not caught!") except: pass complex_site = Site( start=500, end=600, states=[State('active', True)], residues=[Residue("Y", 505, State('phosphorylation', True))] ) complex_site_id = self.generator.generate_site( nugget, complex_site, self.default_ag_gene, self.default_ag_gene) # assert( # nugget.reference_typing[complex_site_id] == # nugget.reference_typing[site_bob_500_600_id]) assert(len(nugget.nodes()) == 13) assert(len(nugget.edges()) == 3)
def __init__(self): """Initialize tests.""" # Create an empty KAMI corpus self.nxcorpus = KamiCorpus("EGFR_signalling") try: h = Neo4jHierarchy(uri="bolt://localhost:7687", user="******", password="******") h._clear() self.neo4jcorpus = KamiCorpus("egfr", backend="neo4j", uri="bolt://localhost:7687", user="******", password="******") except: warnings.warn("Neo4j is down, skipping Neo4j-related tests") self.neo4jcorpus = None # Create an interaction object egfr = Protoform("P00533") egf = Protoform("P01133") kinase = Region(name="Protein kinase", start=712, end=979, states=[State("activity", True)]) egfr_kinase = RegionActor(protoform=egfr, region=kinase) interaction1 = LigandModification( enzyme=egfr_kinase, substrate=egfr, target=Residue("Y", 1092, state=State("phosphorylation", False)), value=True, rate=1, desc="Phosphorylation of EGFR homodimer") # Aggregate the interaction object to the corpus self.nxcorpus.add_interaction(interaction1) self.neo4jcorpus.add_interaction(interaction1) grb2 = Protoform("P62993", states=[State("activity", True)]) grb2_sh2 = RegionActor(protoform=grb2, region=Region(name="SH2")) shc1 = Protoform("P29353") shc1_pY = SiteActor( protoform=shc1, site=Site( name="pY", residues=[Residue("Y", 317, State("phosphorylation", True))])) interaction1 = Binding(grb2_sh2, shc1_pY) grb2_sh2_with_residues = RegionActor(protoform=grb2, region=Region( name="SH2", residues=[ Residue("S", 90, test=True), Residue("D", 90, test=False) ])) egfr_pY = SiteActor( protoform=egfr, site=Site( name="pY", residues=[Residue("Y", 1092, State("phosphorylation", True))])) interaction2 = Binding(grb2_sh2_with_residues, egfr_pY) axl_PK = RegionActor(protoform=Protoform("P30530", hgnc_symbol="AXL"), region=Region("Protein kinase", start=536, end=807)) interaction3 = SelfModification(axl_PK, target=Residue( "Y", 821, State("phosphorylation", False)), value=True) interaction4 = AnonymousModification(RegionActor(protoform=Protoform( "P30530", hgnc_symbol="AXL", residues=[ Residue("Y", 703, state=State("phosphorylation", True)), Residue("Y", 779, state=State("phosphorylation", True)) ]), region=Region( "Protein kinase", start=536, end=807)), target=State("activity", False), value=True) egf_egfr = Protoform(egfr.uniprotid, bound_to=[egf]) interaction5 = Binding(egf_egfr, egf_egfr) interaction6 = Unbinding(egf_egfr, egf_egfr) interaction7 = LigandModification( egfr_kinase, shc1, target=Residue("Y", 317, State("phosphorylation", False)), value=True, enzyme_bnd_region=Region("egfr_BND"), enzyme_bnd_site=Site("egfr_BND"), substrate_bnd_region=Region("shc1_BND"), substrate_bnd_site=Site("sch1_BND")) interactions = [ interaction1, interaction2, interaction3, interaction4, interaction5, interaction6, interaction7 ] self.nxcorpus.add_interactions(interactions) self.neo4jcorpus.add_interactions(interactions) # Create a protein definition for GRB2 # protoform = Protoform( # "P62993", # regions=[Region( # name="SH2", # residues=[ # Residue("S", 90, test=True), # Residue("D", 90, test=False)])]) # ashl = Product("Ash-L", residues=[Residue("S", 90)]) # s90d = Product("S90D", residues=[Residue("D", 90)]) # grb3 = Product("Grb3", removed_components={"regions": [Region("SH2")]}) # self.grb2_definition = Definition(protoform, [ashl, s90d, grb3]) # self.model = self.nxcorpus.instantiate( # "EGFR_signalling_GRB2", [self.grb2_definition], # default_bnd_rate=0.1, # default_brk_rate=0.1, # default_mod_rate=0.1) self.query1 = (""" MATCH (:protoform)<--(r1:REGION)-->(i:interaction)-*-(n4:protoform) RETURN p1, i, p2; """)
def test_advanced_ligand_mod_generator(self): """Test generation with advanced usage of LigandModification.""" corpus = KamiCorpus("test") identifier = EntityIdentifier( corpus.action_graph, corpus.get_action_graph_typing()) generator = LigandModGenerator(identifier) enzyme = SiteActor( protoform=Protoform("A"), region=Region(name="RegionActor"), site=Site(name="SiteActor")) substrate = SiteActor( protoform=Protoform("B"), region=Region(name="RegionActor"), site=Site(name="SiteActor")) # simple subactors switching subactors = ["protoform", "region", "site"] for ea in subactors: for sa in subactors: mod = LigandModification( enzyme=enzyme, substrate=substrate, target=Residue("Y", 100, State("phosphorylation", True)), value=False, enzyme_bnd_subactor=ea, substrate_bnd_subactor=sa) n, _, _, _ = generator.generate(mod) mod = LigandModification( enzyme=enzyme, substrate=substrate, target=Residue("Y", 100, State("phosphorylation", True)), value=False, enzyme_bnd_region=Region(name="SpecialBindingRegion"), substrate_bnd_region=Region(name="SpecialBindingRegion")) n, _, _, _ = generator.generate(mod) mod = LigandModification( enzyme=enzyme, substrate=substrate, target=Residue("Y", 100, State("phosphorylation", True)), value=False, enzyme_bnd_subactor="region", substrate_bnd_subactor="region", enzyme_bnd_site=Site(name="SpecialBindingSite"), substrate_bnd_site=Site(name="SpecialBindingSite")) n, _, _, _ = generator.generate(mod) mod = LigandModification( enzyme=enzyme, substrate=substrate, target=Residue("Y", 100, State("phosphorylation", True)), value=False, enzyme_bnd_region=Region(name="SpecialBindingRegion"), substrate_bnd_region=Region(name="SpecialBindingRegion"), enzyme_bnd_site=Site(name="SpecialBindingSite"), substrate_bnd_site=Site(name="SpecialBindingSite")) n, _, _, _ = generator.generate(mod) print_graph(n.graph)
def test_sh2_py_semantics(self): """.""" phos = State("phosphorylation", True) dok1_py398 = Protoform("Q99704", synonyms=["DOK1", "p62DOK1"], residues=[Residue("Y", 398, phos)]) abl2 = Protoform("P42684", synonyms=["ABL2"]) sh2 = Region(name="SH2") abl2_sh2 = RegionActor(abl2, sh2) bnd = Binding(dok1_py398, abl2_sh2) corpus = KamiCorpus("test") nugget_id = corpus.add_interaction(bnd) semantic_entities = [ "sh2_domain", "sh2_domain_pY_bnd", "pY_site", "pY_residue", "phosphorylation" ] print(corpus.get_nugget(nugget_id).nodes()) assert ("pY_site" in corpus.get_nugget(nugget_id).nodes()) assert ("pY_residue" in corpus.get_nugget(nugget_id).nodes()) assert ("pY_residue_phospho" in corpus.get_nugget(nugget_id).nodes()) assert ((nugget_id, "sh2_pY_binding_semantic_nugget") in corpus.nugget_relations()) for entity in semantic_entities: assert (entity in corpus._hierarchy.get_relation( "sh2_pY_binding_semantic_nugget", nugget_id).keys()) site_actor_no_residue = SiteActor(Protoform("A"), Site("pY-site", start=100, end=150)) bnd = Binding(abl2_sh2, site_actor_no_residue) nugget_id = corpus.add_interaction(bnd) assert (len(corpus.get_nugget(nugget_id).nodes()) == 7) binding_nodes = [] for n in corpus.action_graph.nodes(): if corpus.get_action_graph_typing()[n] == "bnd": binding_nodes.append(n) assert (len(binding_nodes) == 1) assert ((nugget_id, "sh2_pY_binding_semantic_nugget") in corpus.nugget_relations()) for entity in semantic_entities: assert (entity in corpus._hierarchy.get_relation( "sh2_pY_binding_semantic_nugget", nugget_id).keys()) site_actor_no_phospho = SiteActor( Protoform("A"), Site("pY-site", start=100, end=150, residues=[Residue("Y")])) bnd = Binding(abl2_sh2, site_actor_no_phospho) nugget_id = corpus.add_interaction(bnd) assert (len(corpus.get_nugget(nugget_id).nodes()) == 8) binding_nodes = [] for n in corpus.action_graph.nodes(): if corpus.get_action_graph_typing()[n] == "bnd": binding_nodes.append(n) assert (len(binding_nodes) == 1) assert ((nugget_id, "sh2_pY_binding_semantic_nugget") in corpus.nugget_relations()) for entity in semantic_entities: assert (entity in corpus._hierarchy.get_relation( "sh2_pY_binding_semantic_nugget", nugget_id).keys()) site_actor_with_residue = SiteActor( Protoform("A"), Site("pY-site", start=100, end=150, residues=[ Residue("Y", loc=145, state=State("phosphorylation")) ])) bnd = Binding(abl2_sh2, site_actor_with_residue) nugget_id = corpus.add_interaction(bnd) assert (len(corpus.get_nugget(nugget_id).nodes()) == 7) binding_nodes = [] for n in corpus.action_graph.nodes(): if corpus.get_action_graph_typing()[n] == "bnd": binding_nodes.append(n) assert (len(binding_nodes) == 1) assert ((nugget_id, "sh2_pY_binding_semantic_nugget") in corpus.nugget_relations()) for entity in semantic_entities: assert (entity in corpus._hierarchy.get_relation( "sh2_pY_binding_semantic_nugget", nugget_id).keys()) site_actor_with_residue1 = SiteActor( Protoform("B"), Site("pY-site", residues=[ Residue("Y", loc=145, state=State("phosphorylation")) ])) site_actor_with_residue2 = SiteActor( Protoform("B"), Site("some site", residues=[ Residue("Y", loc=145, state=State("phosphorylation")) ])) bnd1 = Binding(abl2_sh2, site_actor_with_residue1) bnd2 = Binding(abl2_sh2, site_actor_with_residue2) corpus.add_interactions([bnd1, bnd2]) print_graph(corpus.action_graph)