Skip to content

Commit 49625c2

Browse files
committed
Code that fixes DeleteMolecule bug for multiple Delete ops
1 parent 2f9785b commit 49625c2

7 files changed

Lines changed: 359 additions & 10 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import bionetgen
2+
3+
parameter = bionetgen.modelapi.structs.Parameter("A0", "10")
4+
print(parameter.gen_string())
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import bionetgen"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"\n",
22+
"begin reaction rules\n",
23+
" R1: Zeta(ITAM1!1).A(State!1,CBL!2).CBL(site!2) -> dead() kdl DeleteMolecules\n",
24+
" R2: Zeta() -> dead() kdl DeleteMolecules\n",
25+
"end reaction rules\n",
26+
"\n"
27+
]
28+
}
29+
],
30+
"source": [
31+
"mname=\"test_deleteMolecules\"\n",
32+
"model= bionetgen.bngmodel(mname+\".bngl\")\n",
33+
"print(model.rules)"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 31,
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"from collections import OrderedDict\n",
43+
"\n",
44+
"d = [OrderedDict([('@id', 'RR1_RP1_M1'), ('@DeleteMolecules', '1')]), OrderedDict([('@id', 'RR1_RP1_M2'), ('@DeleteMolecules', '1')]), OrderedDict([('@id', 'RR1_RP1_M3'), ('@DeleteMolecules', '1')])]\n",
45+
"#d= d + [OrderedDict([('@id', 'RR1_RP1_M1')])]"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"# Use list comprehension to get an array of values"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 51,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"name": "stdout",
62+
"output_type": "stream",
63+
"text": [
64+
"True\n"
65+
]
66+
}
67+
],
68+
"source": [
69+
"vals=[e['@DeleteMolecules'] for e in d]\n",
70+
"if (all(vals)==1):\n",
71+
" print(True)\n"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 58,
77+
"metadata": {},
78+
"outputs": [
79+
{
80+
"name": "stdout",
81+
"output_type": "stream",
82+
"text": [
83+
"False\n"
84+
]
85+
}
86+
],
87+
"source": [
88+
"print(all([0,0,0])==-1)"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": []
97+
}
98+
],
99+
"metadata": {
100+
"kernelspec": {
101+
"display_name": "base",
102+
"language": "python",
103+
"name": "python3"
104+
},
105+
"language_info": {
106+
"codemirror_mode": {
107+
"name": "ipython",
108+
"version": 3
109+
},
110+
"file_extension": ".py",
111+
"mimetype": "text/x-python",
112+
"name": "python",
113+
"nbconvert_exporter": "python",
114+
"pygments_lexer": "ipython3",
115+
"version": "3.9.7"
116+
}
117+
},
118+
"nbformat": 4,
119+
"nbformat_minor": 2
120+
}

Issues/rule_keywords/run_pybng.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
mname="test_deleteMolecules"
44
model= bionetgen.bngmodel(mname+".bngl")
5-
print(model.rules)
5+
print(model)

Issues/rule_keywords/test_DeleteMolecules.bngl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ begin reaction rules
2121
end reaction rules
2222
end model
2323

24-
#writeModel({suffix=>"changed",evaluate_expressions=>1,overwrite=>1})
24+
#writeModel({suffix=>"changed",evaluate_expressions=>1,overwrite=>1})
25+
writeXML()
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Created by BioNetGen 2.9.0 -->
3+
<sbml xmlns="http://www.sbml.org/sbml/level3" level="3" version="1">
4+
<model id="test_DeleteMolecules">
5+
<ListOfParameters>
6+
<Parameter id="kdl" type="Constant" value="0.03" expr="0.03"/>
7+
</ListOfParameters>
8+
<ListOfMoleculeTypes>
9+
<MoleculeType id="A">
10+
<ListOfComponentTypes>
11+
<ComponentType id="State">
12+
<ListOfAllowedStates>
13+
<AllowedState id="UZAP"/>
14+
<AllowedState id="PZAP"/>
15+
<AllowedState id="SHP"/>
16+
<AllowedState id="uSYK"/>
17+
<AllowedState id="pSYK"/>
18+
</ListOfAllowedStates>
19+
</ComponentType>
20+
<ComponentType id="CBL"/>
21+
</ListOfComponentTypes>
22+
</MoleculeType>
23+
<MoleculeType id="CBL">
24+
<ListOfComponentTypes>
25+
<ComponentType id="site"/>
26+
</ListOfComponentTypes>
27+
</MoleculeType>
28+
<MoleculeType id="Zeta">
29+
<ListOfComponentTypes>
30+
<ComponentType id="receptor"/>
31+
<ComponentType id="ITAM1">
32+
<ListOfAllowedStates>
33+
<AllowedState id="U"/>
34+
<AllowedState id="PP"/>
35+
</ListOfAllowedStates>
36+
</ComponentType>
37+
<ComponentType id="ITAM2">
38+
<ListOfAllowedStates>
39+
<AllowedState id="U"/>
40+
<AllowedState id="PP"/>
41+
</ListOfAllowedStates>
42+
</ComponentType>
43+
<ComponentType id="ITAM3">
44+
<ListOfAllowedStates>
45+
<AllowedState id="U"/>
46+
<AllowedState id="PP"/>
47+
</ListOfAllowedStates>
48+
</ComponentType>
49+
<ComponentType id="ITAM4">
50+
<ListOfAllowedStates>
51+
<AllowedState id="U"/>
52+
<AllowedState id="PP"/>
53+
</ListOfAllowedStates>
54+
</ComponentType>
55+
<ComponentType id="ITAM5">
56+
<ListOfAllowedStates>
57+
<AllowedState id="U"/>
58+
<AllowedState id="PP"/>
59+
</ListOfAllowedStates>
60+
</ComponentType>
61+
<ComponentType id="ITAM6">
62+
<ListOfAllowedStates>
63+
<AllowedState id="U"/>
64+
<AllowedState id="PP"/>
65+
</ListOfAllowedStates>
66+
</ComponentType>
67+
</ListOfComponentTypes>
68+
</MoleculeType>
69+
<MoleculeType id="dead"/>
70+
</ListOfMoleculeTypes>
71+
<ListOfCompartments>
72+
</ListOfCompartments>
73+
<ListOfSpecies>
74+
<Species id="S1" concentration="1" name="A(CBL,State~UZAP)">
75+
<ListOfMolecules>
76+
<Molecule id="S1_M1" name="A">
77+
<ListOfComponents>
78+
<Component id="S1_M1_C1" name="CBL" numberOfBonds="0"/>
79+
<Component id="S1_M1_C2" name="State" state="UZAP" numberOfBonds="0"/>
80+
</ListOfComponents>
81+
</Molecule>
82+
</ListOfMolecules>
83+
</Species>
84+
<Species id="S2" concentration="1" name="Zeta(ITAM1~U,ITAM2~U,ITAM3~U,ITAM4~U,ITAM5~U,ITAM6~U,receptor)">
85+
<ListOfMolecules>
86+
<Molecule id="S2_M1" name="Zeta">
87+
<ListOfComponents>
88+
<Component id="S2_M1_C1" name="ITAM1" state="U" numberOfBonds="0"/>
89+
<Component id="S2_M1_C2" name="ITAM2" state="U" numberOfBonds="0"/>
90+
<Component id="S2_M1_C3" name="ITAM3" state="U" numberOfBonds="0"/>
91+
<Component id="S2_M1_C4" name="ITAM4" state="U" numberOfBonds="0"/>
92+
<Component id="S2_M1_C5" name="ITAM5" state="U" numberOfBonds="0"/>
93+
<Component id="S2_M1_C6" name="ITAM6" state="U" numberOfBonds="0"/>
94+
<Component id="S2_M1_C7" name="receptor" numberOfBonds="0"/>
95+
</ListOfComponents>
96+
</Molecule>
97+
</ListOfMolecules>
98+
</Species>
99+
<Species id="S3" concentration="1" name="CBL(site)">
100+
<ListOfMolecules>
101+
<Molecule id="S3_M1" name="CBL">
102+
<ListOfComponents>
103+
<Component id="S3_M1_C1" name="site" numberOfBonds="0"/>
104+
</ListOfComponents>
105+
</Molecule>
106+
</ListOfMolecules>
107+
</Species>
108+
</ListOfSpecies>
109+
<ListOfReactionRules>
110+
<ReactionRule id="RR1" name="R1" symmetry_factor="1">
111+
<ListOfReactantPatterns>
112+
<ReactantPattern id="RR1_RP1">
113+
<ListOfMolecules>
114+
<Molecule id="RR1_RP1_M1" name="Zeta">
115+
<ListOfComponents>
116+
<Component id="RR1_RP1_M1_C1" name="ITAM1" numberOfBonds="1"/>
117+
</ListOfComponents>
118+
</Molecule>
119+
<Molecule id="RR1_RP1_M2" name="A">
120+
<ListOfComponents>
121+
<Component id="RR1_RP1_M2_C1" name="State" numberOfBonds="1"/>
122+
<Component id="RR1_RP1_M2_C2" name="CBL" numberOfBonds="1"/>
123+
</ListOfComponents>
124+
</Molecule>
125+
<Molecule id="RR1_RP1_M3" name="CBL">
126+
<ListOfComponents>
127+
<Component id="RR1_RP1_M3_C1" name="site" numberOfBonds="1"/>
128+
</ListOfComponents>
129+
</Molecule>
130+
</ListOfMolecules>
131+
<ListOfBonds>
132+
<Bond id="RR1_RP1_B1" site1="RR1_RP1_M1_C1" site2="RR1_RP1_M2_C1"/>
133+
<Bond id="RR1_RP1_B2" site1="RR1_RP1_M2_C2" site2="RR1_RP1_M3_C1"/>
134+
</ListOfBonds>
135+
</ReactantPattern>
136+
</ListOfReactantPatterns>
137+
<ListOfProductPatterns>
138+
<ProductPattern id="RR1_PP1">
139+
<ListOfMolecules>
140+
<Molecule id="RR1_PP1_M1" name="dead"/>
141+
</ListOfMolecules>
142+
</ProductPattern>
143+
</ListOfProductPatterns>
144+
<RateLaw id="RR1_RateLaw" type="Ele" totalrate="0">
145+
<ListOfRateConstants>
146+
<RateConstant value="kdl"/>
147+
</ListOfRateConstants>
148+
</RateLaw>
149+
<Map>
150+
<MapItem sourceID="RR1_RP1_M1"/>
151+
<MapItem sourceID="RR1_RP1_M1_C1"/>
152+
<MapItem sourceID="RR1_RP1_M2"/>
153+
<MapItem sourceID="RR1_RP1_M2_C1"/>
154+
<MapItem sourceID="RR1_RP1_M2_C2"/>
155+
<MapItem sourceID="RR1_RP1_M3"/>
156+
<MapItem sourceID="RR1_RP1_M3_C1"/>
157+
</Map>
158+
<ListOfOperations>
159+
<Add id="RR1_PP1_M1"/>
160+
<Delete id="RR1_RP1_M1" DeleteMolecules="1"/>
161+
<Delete id="RR1_RP1_M2" DeleteMolecules="1"/>
162+
<Delete id="RR1_RP1_M3" DeleteMolecules="1"/>
163+
</ListOfOperations>
164+
</ReactionRule>
165+
<ReactionRule id="RR2" name="R2" symmetry_factor="1">
166+
<ListOfReactantPatterns>
167+
<ReactantPattern id="RR2_RP1">
168+
<ListOfMolecules>
169+
<Molecule id="RR2_RP1_M1" name="Zeta"/>
170+
</ListOfMolecules>
171+
</ReactantPattern>
172+
</ListOfReactantPatterns>
173+
<ListOfProductPatterns>
174+
<ProductPattern id="RR2_PP1">
175+
<ListOfMolecules>
176+
<Molecule id="RR2_PP1_M1" name="dead"/>
177+
</ListOfMolecules>
178+
</ProductPattern>
179+
</ListOfProductPatterns>
180+
<RateLaw id="RR2_RateLaw" type="Ele" totalrate="0">
181+
<ListOfRateConstants>
182+
<RateConstant value="kdl"/>
183+
</ListOfRateConstants>
184+
</RateLaw>
185+
<Map>
186+
<MapItem sourceID="RR2_RP1_M1"/>
187+
</Map>
188+
<ListOfOperations>
189+
<Add id="RR2_PP1_M1"/>
190+
<Delete id="RR2_RP1_M1" DeleteMolecules="1"/>
191+
</ListOfOperations>
192+
</ReactionRule>
193+
</ListOfReactionRules>
194+
<ListOfObservables>
195+
</ListOfObservables>
196+
<ListOfFunctions>
197+
</ListOfFunctions>
198+
</model>
199+
</sbml>

bionetgen/modelapi/xmlparsers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -700,15 +700,15 @@ def get_rule_mod(self, xml):
700700
# determine which rule mod is being used, if any
701701
if "Delete" in list_ops:
702702
del_op = list_ops["Delete"]
703-
# check if modifier was called or automatic
704-
# for op in del_op:
705-
# print(op)
706703
if not isinstance(del_op, list):
707-
mod_call = del_op["@DeleteMolecules"]
708-
if mod_call == "1":
709-
# get mod information & add to string
710-
rule_mod.type = "DeleteMolecules"
711-
rule_mod.id = del_op["@id"]
704+
del_op = [del_op] # Make sure del_op is list
705+
dmvals= [op['@DeleteMolecules'] for op in del_op]
706+
# All Delete operations in rule must have DeleteMolecules attribute or
707+
# it does not apply to the whole rule
708+
if (all(dmvals)==1):
709+
rule_mod.type = "DeleteMolecules"
710+
# JRF: I don't believe the id of the specific op rule_mod is currently used
711+
#rule_mod.id = op["@id"]
712712
elif "ChangeCompartment" in list_ops:
713713
move_op = list_ops["ChangeCompartment"]
714714
if not isinstance(move_op, list):
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
begin model
2+
begin parameters
3+
kdl 0.03 #CBL degrades ZAP/SYK
4+
end parameters
5+
begin molecule types
6+
A(State~UZAP~PZAP~SHP~uSYK~pSYK,CBL)
7+
Zeta(receptor,ITAM1~U~PP,ITAM2~U~PP,ITAM3~U~PP,ITAM4~U~PP,ITAM5~U~PP,ITAM6~U~PP)
8+
CBL(site)
9+
dead()
10+
end molecule types
11+
begin seed species
12+
A(State~UZAP,CBL) 1
13+
Zeta(receptor,ITAM1~U,ITAM2~U,ITAM3~U,ITAM4~U,ITAM5~U,ITAM6~U) 1
14+
CBL(site) 1
15+
end seed species
16+
begin reaction rules
17+
# Keyword is dropped here by unfixed version
18+
R1: Zeta(ITAM1!1).A(State!1,CBL!3).CBL(site!3) -> dead() kdl DeleteMolecules
19+
# Keyword is NOT dropped for this rule because only one molecule is deleted
20+
R2: Zeta() -> dead() kdl DeleteMolecules
21+
end reaction rules
22+
end model
23+
24+
#writeModel({suffix=>"changed",evaluate_expressions=>1,overwrite=>1})
25+
writeXML()

0 commit comments

Comments
 (0)