Skip to content

Commit b4de9aa

Browse files
committed
import/export user constraints
1 parent 73d4b5c commit b4de9aa

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

src/CBConfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: [email protected]
22-
Last edit: $Author: bgoli $ ($Id: CBConfig.py 631 2017-11-03 16:09:23Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBConfig.py 637 2017-12-15 11:34:59Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -37,13 +37,13 @@
3737
# release
3838

3939
try:
40-
STATUS = '$Rev: 631 $'.replace('Rev: ', '').replace('$', '').strip()
40+
STATUS = '$Rev: 637 $'.replace('Rev: ', '').replace('$', '').strip()
4141
except Exception:
4242
STATUS = ''
4343

4444
__CBCONFIG__ = {'VERSION_MAJOR' : 0,
4545
'VERSION_MINOR' : 7,
46-
'VERSION_MICRO' : 19,
46+
'VERSION_MICRO' : 20,
4747
'VERSION_STATUS' : STATUS,
4848
'VERSION' : None,
4949
'DEBUG' : False,

src/CBModel.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: [email protected]
22-
Last edit: $Author: bgoli $ ($Id: CBModel.py 636 2017-12-13 20:05:01Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBModel.py 640 2017-12-18 18:13:40Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -34,7 +34,7 @@
3434
from __future__ import absolute_import
3535
#from __future__ import unicode_literals
3636

37-
import numpy, re, time, weakref, copy, json, ast
37+
import numpy, re, time, weakref, copy, json, ast, os
3838

3939
try:
4040
from urllib2 import quote as urlquote
@@ -2886,6 +2886,33 @@ def exportFVAdata(self):
28862886
# investigate the use of numpy index arrays here
28872887
raise NotImplementedError
28882888

2889+
def importUserConstraints(self, filename):
2890+
"""
2891+
Exports user constraints in json
2892+
2893+
"""
2894+
F = open(filename, 'r')
2895+
#din = json.load(F)
2896+
self.user_constraints = json.load(F)
2897+
#key = os.path.split(self.sourcefile)[-1]
2898+
#F.close()
2899+
#if key in din:
2900+
#self.user_constraints = din[key]
2901+
#else:
2902+
#print('ERROR: constraints refers to file \"{}\" whereas this is file \"{}\"'.format(list(din.keys())[0], key))
2903+
#return False
2904+
return True
2905+
2906+
def exportUserConstraints(self, filename):
2907+
"""
2908+
Exports user constraints in json
2909+
2910+
"""
2911+
F = open(filename, 'w')
2912+
#json.dump({os.path.split(self.sourcefile)[-1] : self.user_constraints}, F, indent=2)
2913+
json.dump(self.user_constraints, F, indent=2)
2914+
F.close()
2915+
28892916
def createGroup(self, gid):
28902917
"""
28912918
Create an empty group with

src/CBXML.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: [email protected]
22-
Last edit: $Author: bgoli $ ($Id: CBXML.py 629 2017-10-24 22:01:14Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBXML.py 640 2017-12-18 18:13:40Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -2553,6 +2553,11 @@ def sbml_writeSBML3FBC(fba, fname, directory=None, sbml_level_version=(3,1), aut
25532553
F.close()
25542554
print('Model exported as: {}'.format(fname))
25552555

2556+
2557+
# bgoli: temporary (until incorporated into FBC stadard) solution to store the constraints in a separate json file
2558+
if fba.user_constraints is not None and len(fba.user_constraints) >= 1:
2559+
fba.exportUserConstraints(fname+'.user_constraints.json')
2560+
25562561
if VALIDATE:
25572562
sbml_setValidationOptions(cs3.doc, level='full')
25582563
print('\nPerforming validation on output SBML ...\n')

src/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Author: Brett G. Olivier
2121
Contact email: [email protected]
22-
Last edit: $Author: bgoli $ ($Id: __init__.py 633 2017-11-06 09:57:54Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: __init__.py 640 2017-12-18 18:13:40Z bgoli $)
2323
2424
"""
2525
#
@@ -94,7 +94,6 @@
9494
SED = PyscesSED.SEDCBMPY
9595

9696
try:
97-
from . import nosetests
9897
__test_dir__ = os.path.join(__CBCONFIG__['CBMPY_DIR'], 'nosetests')
9998
test_set = 1
10099
test_bundle = os.path.join(__test_dir__, 'cbmpy_test_bundle_v{}.zip.py'.format(test_set))
@@ -107,6 +106,7 @@
107106
zfile.close()
108107
#os.remove(test_bundle)
109108
del zipfile, zfile
109+
from . import nosetests
110110
test = nosetests.run
111111
del nosetests, test_bundle, test_file, test_set
112112
except ImportError:

0 commit comments

Comments
 (0)