kappa-dev / kami Goto Github PK
View Code? Open in Web Editor NEWBio-curation library for modelling cellular signalling
License: MIT License
Bio-curation library for modelling cellular signalling
License: MIT License
For kinase activity state nodes, I still get {'activity': {True}} instead of {'name': {'activity'}, 'test': {'true'}}
import json
import pickle
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
from kami.interactions import (Binding, Modification)
from kami.hierarchy import (KamiHierarchy)
from kami.export.old_kami import get_studio_v1
from regraph import print_graph
b1 = Binding(
left=SiteActor(gene=Gene(uniprotid="P00533",
hgnc_symbol="EGFR"),
site=Site(name="pY",
residues=[Residue(aa="Y", loc=1092,
state=State("phosphorylation", "true"))],
start=1088, end=1096)),
right=RegionActor(gene=Gene(uniprotid="P62993",
hgnc_symbol="GRB2"),
region=Region(name="SH2"))
)
print(b1)
hierarchy = KamiHierarchy()
hierarchy.add_interaction(b1, anatomize=True)
print_graph(hierarchy.graph['action_graph'])
print('---')
print(hierarchy.graph['action_graph']
.node['P00533_region_Ser-Thr/Tyr_kinase_cat_dom Prot_kinase_'
'dom Tyr_kinase_cat_dom_IPR001245-IPR000719-IPR020635_'
'712_979_Tyr_kinase_activity'])
I want to create interaction: GRB2 binds EGFR through GRB2's Region SH2 and EGFR's Site motif1092 if EGFR Residue Y1092 is phosphorylated. I use the following Kami interaction:
b = Binding(
[SiteActor(gene=Gene(uniprotid="P00533", hgnc_symbol="EGFR",
residues=[Residue("Y", 1092, state=State("phosphorylation", True))]),
site=Site(name="motif1092", start=1088, end=1096))],
[RegionActor(gene=Gene("P62993", hgnc_symbol="GRB2"), region=sh2)]
)
Everything works as expected, except that there is no edge between Residue Y1092 and Site motif1092.
This issue does not happen with Modification and is independent of whether the anatomizer is used or not.
Trying to build an interaction "A binds B if A is bound to C".
import json
import pickle
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
from kami.interactions import (Binding, Modification)
from kami.hierarchy import (KamiHierarchy)
from kami.resolvers.black_box import create_nuggets
rule_list = []
rule_list.append(
Binding(
[Gene("A", bounds=[Gene("C")])],
[Gene("B")]
)
)
for inter in rule_list:
print(inter)
hierarchy = KamiHierarchy()
create_nuggets(rule_list, hierarchy, anatomize=False)
print(hierarchy.graph['kami'].nodes())
When I print the Binding, I get no reference to C.
Left members: A
Right members: B
Direct? True
Strangely, when I print(hierarchy.graph['kami'].nodes()), I see that the test node "A_is_bnd_C" along with its two loci was added at the level of kami instead of the action graph.
I get an error when trying to import Kami Hierarchy. For both Kami and ReGraph, I am on branch master and up to date (as of this posting).
hmedina@Hector-Surface:~$ cd KAMI-python/
hmedina@Hector-Surface:~/KAMI-python$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
hmedina@Hector-Surface:~/KAMI-python$ cd ../ReGraph/
hmedina@Hector-Surface:~/ReGraph$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
hmedina@Hector-Surface:~/ReGraph$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
>>> from kami.interactions import (Binding, Modification)
>>> from kami.hierarchy import (KamiHierarchy)
Traceback (most recent call last):
File "/home/hmedina/ReGraph/regraph/primitives.py", line 75, in add_nodes_from
node_id, node_attrs = n
ValueError: too many values to unpack (expected 2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hmedina/.local/lib/python3.5/site-packages/kami-0.1-py3.5.egg/kami/hierarchy.py", line 13, in <module>
from kami.resources import default_components
File "/home/hmedina/.local/lib/python3.5/site-packages/kami-0.1-py3.5.egg/kami/resources/default_components.py", line 2, in <module>
from kami.resources import (metamodels,
File "/home/hmedina/.local/lib/python3.5/site-packages/kami-0.1-py3.5.egg/kami/resources/metamodels.py", line 20, in <module>
"action"
File "/home/hmedina/ReGraph/regraph/primitives.py", line 78, in add_nodes_from
add_node(graph, n)
File "/home/hmedina/ReGraph/regraph/primitives.py", line 50, in add_node
graph.node[node_id] = new_attrs
TypeError: 'NodeView' object does not support item assignment
>>>
As this is a Kami call, I'm filing it here, even though all the errors arise on ReGraph calls. If this should be posted to the ReGraph issues page, kindly let me know.
With the following script:
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor,
SiteActor)
from kami.interactions import (Binding, Unbinding, Modification,
TransModification, AutoModification,
AnonymousModification)
from kami.hierarchy import (KamiHierarchy)
from regraph import print_graph
inter = AnonymousModification(
substrate=Gene(uniprotid="P06239",
hgnc_symbol="LCK"),
target=Residue(aa="Y", loc=394,
state=State("phosphorylation", True)),
value=False,
rate=0.01
)
print(inter)
hierarchy = KamiHierarchy()
hierarchy.add_interaction(inter, anatomize=False)
print("printing nugget_1")
print_graph(hierarchy.graph['nugget_1'])
i get this error:
AnonymousModification:
Substrate: P06239
Mod target: Y394
Value: False
Rate: 0.01
Traceback (most recent call last):
File "anonymousmod.py", line 21, in <module>
hierarchy.add_interaction(inter, anatomize=False)
File "/home/slegare/ENS/venv_meta_update/lib/python3.6/site-packages/kami-1.2-py3.6.egg/kami/hierarchy.py", line 840, in add_interaction
nugget, nugget_type = generator.generate(interaction)
File "/home/slegare/ENS/venv_meta_update/lib/python3.6/site-packages/kami-1.2-py3.6.egg/kami/aggregation/generators.py", line 456, in generate
nugget, mod.enzyme)
File "/home/slegare/ENS/venv_meta_update/lib/python3.6/site-packages/kami-1.2-py3.6.egg/kami/aggregation/generators.py", line 399, in _generate_actor
"Unkown type of a PPI actor: '%s'" % type(actor)
kami.exceptions.NuggetGenerationError: Unkown type of a PPI actor: '<class 'NoneType'>'
Example with two Binding interactions:
Once I create_nuggets with those interactions, the two beta-propeller regions are merged onto one region with range 16-904.
import json
import pickle
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
from kami.interactions import (Binding, Modification)
from kami.hierarchy import (KamiHierarchy)
from kami.resolvers.black_box import create_nuggets
rule_list = []
rule_list.append(
Binding(
[RegionActor(
gene=Gene(uniprotid="O75581", hgnc_symbol="LRP6"),
region=Region(name="Six-bladed beta-propeller, TolB-like",
interproid="IPR011042", start=16, end=298))],
[Gene(uniprotid="O14905", hgnc_symbol="WNT9A")]))
rule_list.append(
Binding(
[RegionActor(
gene=Gene(uniprotid="O75581", hgnc_symbol="LRP6"),
region=Region(name="Six-bladed beta-propeller, TolB-like",
interproid="IPR011042", start=630, end=904))],
[Gene(uniprotid="P56704", hgnc_symbol="WTN3A")]))
hierarchy = KamiHierarchy()
create_nuggets(rule_list, hierarchy, anatomize=True)
# Print start and end of region.
node_id = "O75581_Region_Six-bladed beta-propeller, TolB-like_IPR011042_16_298"
start = (list(hierarchy.graph['action_graph'].node[node_id]["start"])[0])
end = (list(hierarchy.graph['action_graph'].node[node_id]["end"])[0])
print("start=", start, "end=", end)
# Get the KamiStudio file for visualization.
kstudio = hierarchy.get_studio_v1()
outfile = open('multiregion.json', 'w')
json.dump(kstudio, outfile, indent=4, sort_keys=False)
Any time I wanted to include an Unbinding interaction, I got the error
File "/home/slegare/ENS/venv_meta_update/lib/python3.6/site-packages/kami-1.2-py3.6.egg/kami/hierarchy.py", line 851, in add_interaction
nugget, nugget_type = generate_from_interaction(self, interaction)
TypeError: 'NoneType' object is not iterable
I fixed this by adding the following at line 925 of generators.py
elif isinstance(interaction, Unbinding):
gen = BndGenerator(hierarchy)
return gen.generate(interaction)
It works since BndGenerator already sets the "test" parameter to False if the object is not an instance of Binding.
I am confused why this bug occured, since Unbindings were working properly in the past ?
If this fix is ok with you, I can push it.
I always got the following error when trying to build a KAMI model with add_interaction():
File "intact.py", line 821, in <module>
kami_model.add_interaction(kami_interactions[0], anatomize=False)
File "/home/slegare/ENS/venv_meta_update/lib/python3.6/site-packages/kami-1.2-py3.6.egg/kami/hierarchy.py", line 851, in add_interaction
nugget, nugget_type = generate_from_interaction(interaction)
TypeError: generate_from_interaction() missing 1 required positional argument: 'interaction'
Looking at function generate_from_interaction(), it requires 2 arguments; hierarchy and interaction.
To fix the error, I added "self" to the arguments in line 851 of hierarchy.py:
nugget, nugget_type = generate_from_interaction(self, interaction)
It works, but is it weird to add "self" as argument? If this fix is ok I would push it.
I got this error while installing KAMI meta_update.
Commenting the line "kami/instantiation" in setup.py seems to solve the problem.
Initializing a GeneAnatomy
object with UniProtID raises a warning that there are multiple UniProtIDs associated and then an error, for example:
>> g = GeneAnatomy("P11362")
/home/eugenia/anaconda3/lib/python3.5/site-packages/kami-0.1-py3.5.egg/anatomizer/new_anatomizer.py:414:
AnatomizerWarning: More than one UniProt Accession Number found for 'ENSP00000432972'
ensp, AnatomizerWarning
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-379402b9ab2b> in <module>()
----> 1 g = GeneAnatomy("P11362")
~/anaconda3/lib/python3.5/site-packages/kami-0.1-py3.5.egg/anatomizer/new_anatomizer.py in __init__(self, query, features, merge_features, nest_features, merge_overlap, nest_overlap, nest_level, offline)
1296 if features and self.found:
1297 # feature_list = get_features(self.canonical)
-> 1298 feature_list = get_ipr_features(self.selected_iso, self.canonical)
1299 # construct fragments from features found
1300 fragnum = 0
~/anaconda3/lib/python3.5/site-packages/kami-0.1-py3.5.egg/anatomizer/new_anatomizer.py in get_ipr_features(selected_ac, canon)
567 search_ac = selected_ac
568 entry = ipr_matches_root.find("protein[@id='%s']" % search_ac)
--> 569 matchlist = entry.findall('match')
570 for feature in matchlist:
571 if feature.get('dbname') not in ignorelist:
AttributeError: 'NoneType' object has no attribute 'findall'
Maybe I do not use enzyme_bnd_region and substrate_bnd_region correctly, but when I run the following script:
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
from kami.interactions import (Binding, Unbinding, Modification, TransModification, AutoModification)
from kami.hierarchy import (KamiHierarchy)
from regraph import print_graph
inter = TransModification(
enzyme=RegionActor(gene=Gene(uniprotid="P30530",
hgnc_symbol="AXL"),
region=Region(name="Tyr_kinase",
interproid="IPR020635",
start=536, end=807)),
substrate=SiteActor(gene=Gene(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)
)
hierarchy = KamiHierarchy()
hierarchy.add_interaction(inter, anatomize=False)
print(inter)
print("printing nugget_1")
print_graph(hierarchy.graph['nugget_1'])
I get no bnd node in the nugget:
TransModification:
Enzyme: region_Tyr_kinase_IPR020635_536_807_P30530
Substrate: P06239_[]_site_pY394_391_397
Mod target: Y394
Value: True
Enzyme binding region: region_Tyr_kinase_IPR020635_536_807
Substrate binding site: site_pY394_391_397
Rate: 10
printing nugget_1
Nodes:
P30530 : {'uniprotid': {'P30530'}, 'hgnc_symbol': {'AXL'}}
P30530_region_Tyr_kinase_IPR020635_536_807 : {'interproid': {'IPR020635'}, 'name': {'Tyr_kinase'}}
P06239 : {'uniprotid': {'P06239'}, 'hgnc_symbol': {'LCK'}}
P06239_site_pY394_391_397 : {'name': {'pY394'}}
mod : {'rate': {5}, 'value': {True}}
P06239_site_pY394_391_397_Y394 : {'aa': {'Y'}, 'test': {True}}
P06239_site_pY394_391_397_Y394_phosphorylation : {'name': {'phosphorylation'}, 'test': {False}}
Edges:
P30530_region_Tyr_kinase_IPR020635_536_807 -> P30530 : {'start': {536}, 'end': {807}}
P30530_region_Tyr_kinase_IPR020635_536_807 -> mod : {}
P06239_site_pY394_391_397 -> P06239 : {'start': {391}, 'end': {397}}
mod -> P06239_site_pY394_391_397_Y394_phosphorylation : {}
P06239_site_pY394_391_397_Y394 -> P06239_site_pY394_391_397 : {'loc': {394}}
P06239_site_pY394_391_397_Y394_phosphorylation -> P06239_site_pY394_391_397_Y394 : {}
When enabling the anatomizer, KAMI puts edges like if sites belong to every region of the gene. This happens also when the site is clearly not in the sequence range of the regions.
In this example, I get
Edges:
P00533_site_pY_1088_1096 -> P00533_region_Furin-like_Cys-rich_dom_IPR006211_185_338_Furin_Cys-rich : {'start': {185}, 'end': {338}}
P00533_site_pY_1088_1096 -> P00533_region_Rcpt_L-dom_IPR000494_57_167_Rcpt_L : {'start': {57}, 'end': {167}}
P00533_site_pY_1088_1096 -> P00533_region_Rcpt_L-dom_IPR000494_361_480_Rcpt_L : {'start': {361}, 'end': {480}}
P00533_site_pY_1088_1096 -> P00533_region_Ser-Thr/Tyr_kinase_cat_dom Prot_kinase_dom Tyr_kinase_cat_dom_IPR001245-IPR000719-IPR020635_712_979_Tyr_kinase : {'start': {712}, 'end': {979}}
P00533_site_pY_1088_1096 -> P00533_region_GF_recep_IV_IPR032778_505_636_GF_recep_IV : {'start': {505}, 'end': {636}}
The script that I ran:
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
from kami.interactions import (Binding, Unbinding, Modification, TransModification, AutoModification)
from kami.hierarchy import (KamiHierarchy)
from kami.export.kstudio import to_kamistudio
from regraph import print_graph
inter_list = []
m1 = Modification(
enzyme=RegionActor(gene=Gene(uniprotid="P00519",
hgnc_symbol="ABL1"),
region=Region(name="Tyr_kinase",
interproid="IPR020635")),
substrate=SiteActor(gene=Gene(uniprotid="P00533",
hgnc_symbol="EGFR"),
site=Site(name="pY",
start=1088, end=1096)),
target=Residue(aa="Y", loc=1092,
state=State("phosphorylation", True)),
value=False,
rate=1
)
inter_list.append(m1)
hierarchy = KamiHierarchy()
hierarchy.add_interactions(inter_list, anatomize=True)
print_graph(hierarchy.graph['action_graph'])
In this example, I want to say that GRB2 binds residue Y1092 from EGFR. So I specify the residue in the interaction. But when I add the interactiont to the hierarchy, it adds an other tyrosine instead. Is there something wrong in how I write the interaction?
import json
import pickle
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor, SiteActor)
from kami.interactions import (Binding, Modification)
from kami.hierarchy import (KamiHierarchy)
from kami.export.old_kami import get_studio_v1
from regraph import print_graph
b1 = Binding(
left=SiteActor(gene=Gene(uniprotid="P00533",
hgnc_symbol="EGFR"),
site=Site(name="pY",
residues=[Residue(aa="Y", loc=1092)],
start=1088, end=1096)),
right=RegionActor(gene=Gene(uniprotid="P62993",
hgnc_symbol="GRB2"),
region=Region(name="SH2"))
)
print(b1)
hierarchy = KamiHierarchy()
hierarchy.add_interaction(b1, anatomize=True)
print_graph(hierarchy.graph['action_graph'])
First got
File "kami/hierarchy.py", line 8, in <module>
from regraph import Rule, Hierarchy
ImportError: cannot import name 'Rule'
Changed line 8 in hierarchy.py to
from regraph.rules import Rule
from regraph.hierarchy import Hierarchy
Now I get error
File "regraph/attribute_sets.py", line 34, in <module>
from regraph.exceptions import AttributeSetError
ImportError: cannot import name 'AttributeSetError'
The mod node of AnonymousModification gives:
mod : {'rate': {0.01}, 'value': {(False,)}}
The value of "value" is {(False,)} instead of {False}. This is enough to make KAMIStudio panic.
from kami.entities import (Gene, Region, Site, Residue, State, RegionActor,
SiteActor)
from kami.interactions import (Binding, Unbinding, Modification,
LigandModification, SelfModification,
AnonymousModification)
from kami.hierarchy import (KamiHierarchy)
from regraph import print_graph
inter = AnonymousModification(
substrate=Gene(uniprotid="P06239",
hgnc_symbol="LCK"),
target=Residue(aa="Y", loc=394,
state=State("phosphorylation", True)),
value=False,
rate=0.01
)
print(inter)
hierarchy = KamiHierarchy()
hierarchy.add_interaction(inter, anatomize=False)
print("printing nugget_1")
print_graph(hierarchy.graph['nugget_1'])
SH2 regions have distinct bnd nodes for each target if the anatomizer is not used.
Kinase regions have distinct mod nodes for each target, independently of anatomizer use.
Here is an example and some KamiStudio images that illustrate the issue.
import json
import pickle
from kami.entities import *
from kami.interactions import (Binding, Modification)
from kami.hierarchy import (KamiHierarchy)
from kami.resolvers.black_box import create_nuggetsinters = []
#ABL1 binds BCR on phosphorylated Y246
sh2_gene = Gene("P00519", hgnc_symbol="ABL1")
ptyr_gene = Gene("P11274", hgnc_symbol="BRC")
ptyr_resi = Residue(aa="Y", loc=246, state=State("phosphorylation", True))
b = Binding(
[RegionActor(gene=sh2_gene, region=Region(name="SH2"))],
[SiteActor(gene=ptyr_gene, site=Site(name="Tyr246", start=246, end=246,
residues=[ptyr_resi]))],
)
inters.append(b)#ABL1 binds BCR on phosphorylated Y279
sh2_gene = Gene("P00519", hgnc_symbol="ABL1")
ptyr_gene = Gene("P11274", hgnc_symbol="BRC")
ptyr_resi = Residue(aa="Y", loc=279, state=State("phosphorylation", True))
b = Binding(
[RegionActor(gene=sh2_gene, region=Region(name="SH2"))],
[SiteActor(gene=ptyr_gene, site=Site(name="Tyr279", start=279, end=279,
residues=[ptyr_resi]))],
)
inters.append(b)#ALK phosphorylates PTPN11 on Y546
kin_gene = Gene("Q9UM73", hgnc_symbol="ALK")
ptyr_gene = Gene("Q06124", hgnc_symbol="PTPN11")
ptyr_resi = Residue(aa="Y", loc=546, state=State("phosphorylation", True))
m = Modification(
enzyme = RegionActor(gene=kin_gene, region=Region(name="Tyr_kin")),
substrate = SiteActor(gene=ptyr_gene, site=Site(name="Tyr546", start=546, end=546)),
mod_target = Residue(aa="Y", loc=546, state=State("phosphorylation", False)),
mod_value = True
)
inters.append(m)#ALK phosphorylates PTPN11 on Y584
kin_gene = Gene("Q9UM73", hgnc_symbol="ALK")
ptyr_gene = Gene("Q06124", hgnc_symbol="PTPN11")
ptyr_resi = Residue(aa="Y", loc=584, state=State("phosphorylation", True))
m = Modification(
enzyme = RegionActor(gene=kin_gene, region=Region(name="Tyr_kin")),
substrate = SiteActor(gene=ptyr_gene, site=Site(name="Tyr584", start=584, end=584)),
mod_target = Residue(aa="Y", loc=584, state=State("phosphorylation", False)),
mod_value = True
)
inters.append(m)hierarchy = KamiHierarchy()
create_nuggets(inters, hierarchy, anatomize=False)kstudio = hierarchy.get_studio_v1()
outfile = open('bind-match-noanato.json', 'w')
json.dump(kstudio, outfile, indent=4, sort_keys=False)
Error on calling KamiHierarchy().
h = KamiHierarchy()
Traceback (most recent call last):
File "", line 1, in
File "/home/venv_newregraph/lib/python3.6/site-packages/kami-0.1-py3.6.egg/kami/hierarchy.py", line 163, in init
self.add_typing(s, t, mapping, total=True, attrs=attrs)
TypeError: add_typing() got an unexpected keyword argument 'total'
Argument 'total' is absent from ReGraph/regraph/hierarchy.py.
def add_typing(self, source, target, mapping, attrs=None):
"""Add homomorphism to the hierarchy.
We will eventually need to add attributes that belong to a whole nugget rather than to a specific node.
For example, a nugget with several actions (which we will also need to implement) should have a single rate for the whole nugget. We should not allow multi-action nuggets to have a different rate for each action.
the only way to select the top level (to create a new graph in it) seems to be to reload the page
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.