Skip to content

Commit

Permalink
Merge pull request #930 from Hemant27031999/Annotation-dict
Browse files Browse the repository at this point in the history
Check annotation to be of type dict while reading it from the json
  • Loading branch information
Midnighter committed Mar 23, 2020
2 parents 6f25131 + d1270e2 commit f1d5f2f
Show file tree
Hide file tree
Showing 16 changed files with 1,616 additions and 1,396 deletions.
13 changes: 12 additions & 1 deletion cobra/core/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, id=None, name=""):
self.name = name

self.notes = {}
self.annotation = {}
self._annotation = {}

@property
def id(self):
Expand All @@ -40,6 +40,17 @@ def id(self, value):
def _set_id_with_model(self, value):
self._id = value

@property
def annotation(self):
return self._annotation

@annotation.setter
def annotation(self, annotation):
if not isinstance(annotation, dict):
raise TypeError("Annotation must be a dict")
else:
self._annotation = annotation

def __getstate__(self):
"""To prevent excessive replication during deepcopy."""
state = self.__dict__.copy()
Expand Down
Binary file modified cobra/test/data/iJO1366.pickle
Binary file not shown.
24 changes: 24 additions & 0 deletions cobra/test/data/invalid_annotation_format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"metabolites":[
{
"id":"4crsol_c",
"name":"",
"compartment":"c",
"annotation":[
[
"KEGG Compound",
"http://identifiers.org/kegg.compound/C01468"
],
[
"CHEBI",
"http://identifiers.org/chebi/CHEBI:11981"
]
]
}
],
"reactions":[],
"genes":[],
"id":"tesut",
"compartments":{},
"version": 1
}
95 changes: 61 additions & 34 deletions cobra/test/data/mini.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@
"id": "b2926",
"name": "pgk"
},
{
"id": "b2975",
"name": "glcA"
},
{
"id": "b2987",
"name": "pitB"
Expand All @@ -112,10 +108,6 @@
"id": "b3493",
"name": "pitA"
},
{
"id": "b3603",
"name": "lldP"
},
{
"id": "b3612",
"name": "gpmM"
Expand Down Expand Up @@ -252,7 +244,6 @@
"ADP-GROUP"
],
"cas": [
"58-64-0",
"58-64-0"
],
"chebi": [
Expand Down Expand Up @@ -294,7 +285,6 @@
"bigg.metabolite": "atp",
"biocyc": "ATP",
"cas": [
"56-65-5",
"56-65-5"
],
"chebi": [
Expand Down Expand Up @@ -336,7 +326,6 @@
"bigg.metabolite": "dhap",
"biocyc": "DIHYDROXY-ACETONE-PHOSPHATE",
"cas": [
"57-04-5",
"57-04-5"
],
"chebi": [
Expand Down Expand Up @@ -373,7 +362,6 @@
"bigg.metabolite": "f6p",
"biocyc": "FRUCTOSE-6P",
"cas": [
"643-13-0",
"643-13-0"
],
"chebi": [
Expand Down Expand Up @@ -410,7 +398,6 @@
"bigg.metabolite": "fdp",
"biocyc": "FRUCTOSE-16-DIPHOSPHATE",
"cas": [
"488-69-7",
"488-69-7"
],
"chebi": [
Expand Down Expand Up @@ -445,7 +432,6 @@
"annotation": {
"bigg.metabolite": "g3p",
"cas": [
"142-10-9",
"142-10-9"
],
"chebi": [
Expand Down Expand Up @@ -480,7 +466,6 @@
"GLC-6-P"
],
"cas": [
"56-73-5",
"56-73-5"
],
"chebi": [
Expand Down Expand Up @@ -518,7 +503,6 @@
"annotation": {
"bigg.metabolite": "glc__D",
"cas": [
"50-99-7",
"50-99-7"
],
"kegg.compound": "C00031",
Expand All @@ -539,7 +523,6 @@
"OXONIUM"
],
"cas": [
"7732-18-5",
"7732-18-5"
],
"chebi": [
Expand Down Expand Up @@ -625,7 +608,6 @@
"OXONIUM"
],
"cas": [
"7732-18-5",
"7732-18-5"
],
"chebi": [
Expand Down Expand Up @@ -707,7 +689,6 @@
"bigg.metabolite": "h",
"biocyc": "PROTON",
"cas": [
"12408-02-5",
"12408-02-5"
],
"chebi": [
Expand Down Expand Up @@ -754,7 +735,6 @@
"bigg.metabolite": "h",
"biocyc": "PROTON",
"cas": [
"12408-02-5",
"12408-02-5"
],
"chebi": [
Expand Down Expand Up @@ -797,13 +777,53 @@
"name": "H+"
},
{
"annotation": {
"bigg.metabolite": "lac__D",
"biocyc": "META:D-LACTATE",
"chebi": [
"CHEBI:11001",
"CHEBI:16004",
"CHEBI:18684",
"CHEBI:341",
"CHEBI:42105",
"CHEBI:42111",
"CHEBI:43701"
],
"hmdb": [
"HMDB00171",
"HMDB01311"
],
"kegg.compound": "C00256",
"metanetx.chemical": "MNXM285",
"seed.compound": "cpd00221"
},
"charge": -1,
"compartment": "c",
"formula": "C3H5O3",
"id": "lac__D_c",
"name": "D-Lactate"
},
{
"annotation": {
"bigg.metabolite": "lac__D",
"biocyc": "META:D-LACTATE",
"chebi": [
"CHEBI:11001",
"CHEBI:16004",
"CHEBI:18684",
"CHEBI:341",
"CHEBI:42105",
"CHEBI:42111",
"CHEBI:43701"
],
"hmdb": [
"HMDB00171",
"HMDB01311"
],
"kegg.compound": "C00256",
"metanetx.chemical": "MNXM285",
"seed.compound": "cpd00221"
},
"charge": -1,
"compartment": "e",
"formula": "C3H5O3",
Expand All @@ -815,7 +835,6 @@
"bigg.metabolite": "nad",
"biocyc": "NAD",
"cas": [
"53-84-9",
"53-84-9"
],
"chebi": [
Expand Down Expand Up @@ -855,7 +874,6 @@
"bigg.metabolite": "nadh",
"biocyc": "NADH",
"cas": [
"58-68-4",
"58-68-4"
],
"chebi": [
Expand Down Expand Up @@ -890,7 +908,6 @@
"bigg.metabolite": "pep",
"biocyc": "PHOSPHO-ENOL-PYRUVATE",
"cas": [
"138-08-9",
"138-08-9"
],
"chebi": [
Expand Down Expand Up @@ -928,7 +945,6 @@
"CPD0-1421"
],
"cas": [
"14265-44-2",
"14265-44-2"
],
"chebi": [
Expand Down Expand Up @@ -996,7 +1012,6 @@
"CPD0-1421"
],
"cas": [
"14265-44-2",
"14265-44-2"
],
"chebi": [
Expand Down Expand Up @@ -1060,7 +1075,6 @@
"bigg.metabolite": "pyr",
"biocyc": "PYRUVATE",
"cas": [
"127-17-3",
"127-17-3"
],
"chebi": [
Expand Down Expand Up @@ -1111,15 +1125,10 @@
"upper_bound": 1000.0
},
{
"gene_reaction_rule": "b3603 or b2975",
"gene_reaction_rule": "",
"id": "D_LACt2",
"lower_bound": -1000.0,
"metabolites": {
"h_c": 1,
"h_e": -1,
"lac__D_c": 1,
"lac__D_e": -1
},
"metabolites": {},
"name": "",
"upper_bound": 1000.0
},
Expand Down Expand Up @@ -1167,6 +1176,10 @@
"upper_bound": 1000.0
},
{
"annotation": {
"bigg.reaction": "lac__D",
"sbo": "SBO:0000627"
},
"gene_reaction_rule": "",
"id": "EX_lac__D_e",
"lower_bound": 0.0,
Expand Down Expand Up @@ -1213,7 +1226,7 @@
"annotation": {
"bigg.reaction": "GLCpts"
},
"gene_reaction_rule": "( b2417 and b1621 and b2415 and b2416 ) or ( b2417 and b1101 and b2415 and b2416 ) or ( b1817 and b1818 and b1819 and b2415 and b2416 )",
"gene_reaction_rule": "( b2415 and b2417 and b1101 and b2416 ) or ( b2415 and b2417 and b1621 and b2416 ) or ( b2415 and b1818 and b1817 and b1819 and b2416 )",
"id": "GLCpts",
"lower_bound": 0.0,
"metabolites": {
Expand All @@ -1240,6 +1253,20 @@
"upper_bound": 1000.0
},
{
"annotation": {
"bigg.reaction": "LDH_D",
"biocyc": "META:DLACTDEHYDROGNAD-RXN",
"ec-code": "1.1.1.28",
"kegg.reaction": "R00704",
"metanetx.reaction": "MNXR101037",
"rhea": [
"16369",
"16370",
"16371",
"16372"
],
"sbo": "SBO:0000375"
},
"gene_reaction_rule": "b2133 or b1380",
"id": "LDH_D",
"lower_bound": -1000.0,
Expand Down
Binary file modified cobra/test/data/mini.mat
Binary file not shown.
Binary file modified cobra/test/data/mini.pickle
Binary file not shown.
Loading

0 comments on commit f1d5f2f

Please sign in to comment.