@@ -29,7 +29,7 @@ class TemplateReactionType(Enum):
29
29
GAPFILLING = 'gapfilling'
30
30
31
31
32
- class NewModelTemplateCompound :
32
+ class MSTemplateMetabolite :
33
33
34
34
def __init__ (self , cpd_id , formula = None , name = '' , default_charge = None ,
35
35
mass = None , delta_g = None , delta_g_error = None , is_cofactor = False ,
@@ -51,7 +51,7 @@ def __init__(self, cpd_id, formula=None, name='', default_charge=None,
51
51
52
52
@staticmethod
53
53
def from_dict (d ):
54
- return NewModelTemplateCompound (
54
+ return MSTemplateMetabolite (
55
55
d ['id' ], d ['formula' ], d ['name' ],
56
56
d ['defaultCharge' ], d ['mass' ],
57
57
d ['deltaG' ], d ['deltaGErr' ],
@@ -184,7 +184,7 @@ class MSTemplateReaction(Reaction):
184
184
def __init__ (self , rxn_id : str , reference_id : str , name = '' , subsystem = '' , lower_bound = 0.0 , upper_bound = None ,
185
185
reaction_type = TemplateReactionType .CONDITIONAL , gapfill_direction = '=' ,
186
186
base_cost = 1000 , reverse_penalty = 1000 , forward_penalty = 1000 ,
187
- status = 'OK' , delta_g = 0.0 , delta_g_err = 0.0 , reference_reaction_id = None ):
187
+ status = 'OK' , reference_reaction_id = None ):
188
188
"""
189
189
190
190
:param rxn_id:
@@ -199,8 +199,6 @@ def __init__(self, rxn_id: str, reference_id: str, name='', subsystem='', lower_
199
199
:param reverse_penalty:
200
200
:param forward_penalty:
201
201
:param status:
202
- :param delta_g:
203
- :param delta_g_err:
204
202
:param reference_reaction_id: DO NOT USE THIS duplicate of reference_id
205
203
:param template:
206
204
"""
@@ -212,9 +210,7 @@ def __init__(self, rxn_id: str, reference_id: str, name='', subsystem='', lower_
212
210
self .forward_penalty = forward_penalty
213
211
self .status = status
214
212
self .type = reaction_type .value if type (reaction_type ) == TemplateReactionType else reaction_type
215
- self .deltaG = delta_g
216
- self .deltaGErr = delta_g_err
217
- self .reference_reaction_id = reference_reaction_id #TODO: to be removed
213
+ self .reference_reaction_id = reference_reaction_id # TODO: to be removed
218
214
self .complexes = DictList ()
219
215
self .templateReactionReagents = {}
220
216
self ._template = None
@@ -273,8 +269,6 @@ def from_dict(d, template):
273
269
d ['type' ], d ['GapfillDirection' ],
274
270
d ['base_cost' ], d ['reverse_penalty' ], d ['forward_penalty' ],
275
271
d ['status' ] if 'status' in d else None ,
276
- d ['deltaG' ] if 'deltaG' in d else None ,
277
- d ['deltaGErr' ] if 'deltaGErr' in d else None ,
278
272
d ['reaction_ref' ].split ('/' )[- 1 ]
279
273
)
280
274
reaction .add_metabolites (metabolites )
@@ -336,8 +330,6 @@ def get_data(self):
336
330
'base_cost' : self .base_cost ,
337
331
'reverse_penalty' : self .reverse_penalty ,
338
332
'forward_penalty' : self .forward_penalty ,
339
- 'deltaG' : self .deltaG ,
340
- 'deltaGErr' : self .deltaGErr ,
341
333
'upper_bound' : self .upper_bound ,
342
334
'lower_bound' : self .lower_bound ,
343
335
'direction' : get_direction_from_constraints (self .lower_bound , self .upper_bound ),
@@ -347,7 +339,7 @@ def get_data(self):
347
339
'templateReactionReagents' : template_reaction_reagents ,
348
340
'templatecompartment_ref' : '~/compartments/id/' + self .compartment ,
349
341
'templatecomplex_refs' : list (map (lambda x : '~/complexes/id/' + x .id , self .complexes )),
350
- 'status' : self .status ,
342
+ # 'status': self.status,
351
343
'type' : self .type
352
344
}
353
345
@@ -523,16 +515,40 @@ def _repr_html_(self):
523
515
self .roles .items ()), 200 ))
524
516
525
517
518
+ class MSTemplateCompartment :
519
+
520
+ def __init__ (self , compartment_id : str , name : str , ph : float , hierarchy = 0 , aliases = None ):
521
+ self .id = compartment_id
522
+ self .name = name
523
+ self .ph = ph
524
+ self .hierarchy = hierarchy
525
+ self .aliases = [] if aliases is None else list (aliases )
526
+ self ._template = None
527
+
528
+ @staticmethod
529
+ def from_dict (d ):
530
+ return MSTemplateCompartment (d ['id' ], d ['name' ], d ['pH' ], d ['hierarchy' ], d ['aliases' ])
531
+
532
+ def get_data (self ):
533
+ return {
534
+ 'id' : self .id ,
535
+ 'name' : self .name ,
536
+ 'pH' : self .ph ,
537
+ 'aliases' : self .aliases ,
538
+ 'hierarchy' : self .hierarchy
539
+ }
540
+
541
+
526
542
class MSTemplate :
527
543
528
544
def __init__ (self , template_id , name = '' , domain = '' , template_type = '' , version = 1 , info = None , args = None ):
529
545
self .id = template_id
530
- self .__VERSION__ = version
531
546
self .name = name
532
547
self .domain = domain
533
- self .biochemistry_ref = ''
534
548
self .template_type = template_type
535
- self .compartments = {}
549
+ self .__VERSION__ = version
550
+ self .biochemistry_ref = ''
551
+ self .compartments = DictList ()
536
552
self .biomasses = DictList ()
537
553
self .reactions = DictList ()
538
554
self .compounds = DictList ()
@@ -541,7 +557,21 @@ def __init__(self, template_id, name='', domain='', template_type='', version=1,
541
557
self .complexes = DictList ()
542
558
self .pathways = DictList ()
543
559
self .subsystems = DictList ()
544
- #self.info = info if info else KBaseObjectInfo(object_type='KBaseFBA.NewModelTemplate')
560
+
561
+ def add_compartments (self , compartments : list ):
562
+ """
563
+
564
+ :param compartments:
565
+ :return:
566
+ """
567
+ duplicates = list (filter (lambda x : x .id in self .compartments , compartments ))
568
+ if len (duplicates ) > 0 :
569
+ logger .error ("unable to add compartments [%s] already present in the template" , duplicates )
570
+ return None
571
+
572
+ for x in compartments :
573
+ x ._template = self
574
+ self .compartments += compartments
545
575
546
576
def add_roles (self , roles : list ):
547
577
"""
@@ -693,32 +723,38 @@ def get_role(self, id):
693
723
# return super()._to_object(key, data)
694
724
695
725
def get_data (self ):
696
- compartments = []
726
+ """
727
+ typedef structure {
728
+ modeltemplate_id id;
729
+ string name;
730
+ string type;
731
+ string domain;
732
+ Biochemistry_ref biochemistry_ref;
733
+ list < TemplateRole > roles;
734
+ list < TemplateComplex > complexes;
735
+ list < TemplateCompound > compounds;
736
+ list < TemplateCompCompound > compcompounds;
737
+ list < TemplateCompartment > compartments;
738
+ list < NewTemplateReaction > reactions;
739
+ list < NewTemplateBiomass > biomasses;
740
+ list < TemplatePathway > pathways;
741
+ } NewModelTemplate;
742
+ """
743
+
697
744
return {
698
745
'__VERSION__' : self .__VERSION__ ,
699
746
'id' : self .id ,
700
747
'name' : self .name ,
701
748
'domain' : self .domain ,
702
749
'biochemistry_ref' : self .biochemistry_ref ,
703
750
'type' : 'Test' ,
704
- 'biomasses' : [],
705
- 'compartments' : [{'aliases' : [],
706
- 'hierarchy' : 3 ,
707
- 'id' : 'c' ,
708
- 'index' : '0' ,
709
- 'name' : 'Cytosol' ,
710
- 'pH' : 7 },
711
- {'aliases' : [],
712
- 'hierarchy' : 0 ,
713
- 'id' : 'e' ,
714
- 'index' : '1' ,
715
- 'name' : 'Extracellular' ,
716
- 'pH' : 7 }],
751
+ 'compartments' : list (map (lambda x : x .get_data (), self .compartments )),
717
752
'compcompounds' : list (map (lambda x : x .get_data (), self .compcompounds )),
718
753
'compounds' : list (map (lambda x : x .get_data (), self .compounds )),
719
754
'roles' : list (map (lambda x : x .get_data (), self .roles )),
720
755
'complexes' : list (map (lambda x : x .get_data (), self .complexes )),
721
756
'reactions' : list (map (lambda x : x .get_data (), self .reactions )),
757
+ 'biomasses' : list (self .biomasses ),
722
758
'pathways' : [],
723
759
'subsystems' : [],
724
760
}
@@ -786,7 +822,7 @@ def __init__(self, template_id, name='', domain='', template_type='', version=1,
786
822
self .biochemistry_ref = None
787
823
788
824
@staticmethod
789
- def from_dict (d ):
825
+ def from_dict (d , info = None , args = None ):
790
826
"""
791
827
792
828
:param d:
@@ -873,26 +909,9 @@ def with_compartment(self, cmp_id, name, ph=7, index='0'):
873
909
return self
874
910
875
911
def build (self ):
876
- base = {
877
- '__VERSION__' : '' ,
878
- 'biochemistry_ref' : '' ,
879
- 'biomasses' : [],
880
- 'compartments' : self .compartments ,
881
- 'compcompounds' : [],
882
- 'complexes' : [],
883
- 'compounds' : [],
884
- 'domain' : '' ,
885
- 'id' : '' ,
886
- 'name' : '' ,
887
- 'pathways' : [],
888
- 'reactions' : [],
889
- 'roles' : [],
890
- 'subsystems' : [],
891
- 'type' : ''
892
- }
893
-
894
912
template = MSTemplate (self .id , self .name , self .domain , self .template_type , self .version )
895
- template .add_compounds (list (map (lambda x : NewModelTemplateCompound .from_dict (x ), self .compounds )))
913
+ template .add_compartments (list (map (lambda x : MSTemplateCompartment .from_dict (x ), self .compartments )))
914
+ template .add_compounds (list (map (lambda x : MSTemplateMetabolite .from_dict (x ), self .compounds )))
896
915
template .add_comp_compounds (
897
916
list (map (lambda x : MSTemplateSpecies .from_dict (x ), self .compartment_compounds )))
898
917
template .add_roles (list (map (lambda x : NewModelTemplateRole .from_dict (x ), self .roles )))
0 commit comments