Skip to content

Commit c6eda9c

Browse files
Merge pull request ModelSEED#98 from ModelSEED/fungal
Fungal
2 parents 46ed75c + 4257b5f commit c6eda9c

4 files changed

Lines changed: 867222 additions & 21 deletions

File tree

Scripts/TemplateHelper.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import json
33
import os
4+
import re
45
from .Base_Helper import BaseHelper
56
from .Biochem_Helper import BiochemHelper
67

@@ -373,6 +374,23 @@ def readComplexesFile(self, path, includeLinenum=True, noFormat=False):
373374
raise DuplicateComplexError('Complex %s on line %d is a duplicate' %(role['id'], linenum))
374375

375376
return
377+
378+
def _gen_reaction_info(self, reaction):
379+
stoich = []
380+
for prod, part in enumerate(reaction.split(" <=> ")):
381+
for match in re.finditer('\((\d+)\) (\w+)\[(\d)\]', part):
382+
coeff = match.group(1) if prod else "-"+match.group(1)
383+
stoich.append(":".join([coeff, match.group(2), match.group(3), '0', match.group(2)]))
384+
stoich = ";".join(stoich)
385+
return {
386+
'name': 'null',
387+
'deltag': 'null',
388+
'deltagerr': 'null',
389+
'status': 'OK',
390+
'reversibility': '=',
391+
'is_obsolete': 0,
392+
'stoichiometry': stoich
393+
}
376394

377395
def readReactionsFile(self, path, includeLinenum=True, noFormat=False):
378396
''' Read the contents of a reactions file.
@@ -398,8 +416,8 @@ def readReactionsFile(self, path, includeLinenum=True, noFormat=False):
398416
self.numUniversal = 0
399417

400418
# The following fields are required in a reactions file.
401-
required = { 'id', 'compartment', 'direction', 'gfdir', 'type', 'base_cost',
402-
'forward_cost', 'reverse_cost', 'complexes' }
419+
required = {'id', 'compartment', 'direction', 'gfdir', 'type', 'base_cost',
420+
'forward_cost', 'reverse_cost', 'complexes'}
403421

404422
# Read the reactions from the specified file.
405423
with open(path, 'r') as handle:
@@ -425,8 +443,11 @@ def readReactionsFile(self, path, includeLinenum=True, noFormat=False):
425443
reactionId = fields[fieldNames['id']]
426444
try:
427445
masterReaction = self.masterReactions[reactionId]
428-
except:
429-
raise ReactionNotFoundError('Reaction %s not found in master biochemistry' %(reactionId))
446+
except KeyError:
447+
if 'custom_reaction' in fieldNames and fields[fieldNames['custom_reaction']]:
448+
masterReaction = self._gen_reaction_info(fields[fieldNames['custom_reaction']])
449+
else:
450+
raise ReactionNotFoundError('Reaction %s not found in master biochemistry' %(reactionId))
430451

431452
# Check the reaction status.
432453
#if 'OK' not in masterReaction['status']:
@@ -454,6 +475,7 @@ def readReactionsFile(self, path, includeLinenum=True, noFormat=False):
454475

455476
# Make sure all of the compartments are valid.
456477
compartmentIds = fields[fieldNames['compartment']].split('|')
478+
compartmentIds.sort(key=lambda x: ["m", "n", "p", "x", "z", "c", "e"].index(x))
457479
idcomp = compartmentIds[0]
458480
for cindex in range(len(compartmentIds)):
459481
try:
@@ -491,6 +513,8 @@ def readReactionsFile(self, path, includeLinenum=True, noFormat=False):
491513
reaction['deltaG'] = 10000000
492514
if reaction['deltaGErr'] == 'null':
493515
reaction['deltaGErr'] = 10000000
516+
if reaction['name'] == 'null':
517+
reaction['name'] = reaction['id']
494518
if not isinstance(reaction['base_cost'], (int, long, float, complex)):
495519
reaction['base_cost'] = float(reaction['base_cost'])
496520
if not isinstance(reaction['maxforflux'], (int, long, float, complex)):

Scripts/Validation/Validate_Templates.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ def validate_reaction_list(path, rxn_set, complex_set):
6969
file=sys.stderr)
7070
exit_code = 1
7171
if undef_rxns:
72-
print("ERROR-Undefined Reactions: " + ", ".join(undef_rxns),
72+
print("WARNING-Reactions not defined in main biochemistry: " + ", ".join(undef_rxns),
7373
file=sys.stderr)
74-
exit_code = 1
7574
if undef_complex:
7675
print("ERROR-Undefined Complexes: " + ", ".join(undef_complex),
7776
file=sys.stderr)

0 commit comments

Comments
 (0)