Skip to content

Commit 0480f05

Browse files
committed
Py3 fixes and update to r666
1 parent 28caf52 commit 0480f05

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/CBModel.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: CBModel.py 661 2018-09-24 15:20:05Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBModel.py 665 2018-11-07 14:27:31Z bgoli $)
2323
2424
"""
2525
## gets rid of "invalid variable name" info
@@ -1150,13 +1150,13 @@ def addReaction(self, reaction, create_default_bounds=False, silent=False):
11501150
if not silent:
11511151
print('\nReaction \"{}\" bounds set to: 0 <= {} <= INF'.format(rid, rid))
11521152

1153-
def addUserConstraint(self, pid, fluxes=None, operator='=', rhs=0.0):
1153+
def addUserConstraint(self, pid, fluxes=None, operator='>=', rhs=0.0):
11541154
"""
11551155
Add a user defined constraint to FBA model, this is additional to the automatically determined Stoichiometric constraints.
11561156
11571157
- *pid* user constraint name/id, use `None` for auto-assign
11581158
- *fluxes* a list of (coefficient, reaction id) pairs where coefficient is a float
1159-
- *operator* is one of = > < >= <=
1159+
- *operator* is one of '=', '>=' or '<=' (< and > will be interpreted as >= or <=)
11601160
- *rhs* a float
11611161
11621162
"""

src/CBMultiCore.py

Lines changed: 14 additions & 7 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: CBMultiCore.py 660 2018-09-24 14:57:04Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: CBMultiCore.py 666 2018-11-21 22:02:35Z bgoli $)
2323
2424
"""
2525

@@ -52,9 +52,16 @@
5252

5353
from .CBConfig import __CBCONFIG__ as __CBCONFIG__
5454

55-
def grouper(n, iterable, padvalue=None):
56-
"grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
57-
return itertools.izip_longest(*[iter(iterable)]*n, fillvalue=padvalue)
55+
# this is to deal with itertools 2/3 differences
56+
try:
57+
itertools.__getattribute__('izip_longest')
58+
def grouper(n, iterable, padvalue=None):
59+
"grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
60+
return itertools.izip_longest(*[iter(iterable)]*n, fillvalue=padvalue)
61+
except AttributeError:
62+
def grouper(n, iterable, padvalue=None):
63+
"grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
64+
return itertools.zip_longest(*[iter(iterable)]*n, fillvalue=padvalue)
5865

5966
def runMultiCoreFVA(fba, selected_reactions=None, pre_opt=True, tol=None, objF2constr=True, rhs_sense='lower',\
6067
optPercentage=100.0, work_dir=None, quiet=True, debug=False, oldlpgen=False, markupmodel=True, procs=2):
@@ -73,7 +80,7 @@ def runMultiCoreFVA(fba, selected_reactions=None, pre_opt=True, tol=None, objF2c
7380
fba.serializeToDisk(fN, protocol=-1)
7481
fN = os.path.abspath(fN)
7582
subprocess.call(['python', MULTIFVAFILE, str(procs), fN])
76-
F = file(fN, 'rb')
83+
F = open(fN, 'rb')
7784
res = pickle.load(F)
7885
F.close()
7986
os.remove(fN)
@@ -115,11 +122,11 @@ def runMultiCoreFVA(fba, selected_reactions=None, pre_opt=True, tol=None, objF2c
115122
#MEargs = [fN+'.lp', selected_reactions, tol, rhs_sense, optPercentage, work_dir, debug]
116123
#print(MEargs)
117124
#print(fN)
118-
#F = file(fN, 'wb')
125+
#F = open(fN, 'wb')
119126
#pickle.dump(MEargs, F, protocol=-1)
120127
#F.close()
121128
#subprocess.call(['python', MULTIENVFVAFILE, str(procs), fN])
122-
#F = file(fN, 'rb')
129+
#F = open(fN, 'rb')
123130
#res = pickle.load(F)
124131
#F.close()
125132
#os.remove(fN)

src/_multicorefva.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: _multicorefva.py 660 2018-09-24 14:57:04Z bgoli $)
22+
Last edit: $Author: bgoli $ ($Id: _multicorefva.py 666 2018-11-21 22:02:35Z bgoli $)
2323
2424
"""
2525

@@ -86,14 +86,14 @@ def multiCoreFVA(fvamod, procs=2, timeout=None):
8686
print(os.sys.argv)
8787

8888
cores = int(os.sys.argv[1])
89-
F = file(os.sys.argv[2],'rb')
89+
F = open(os.sys.argv[2],'rb')
9090
cmod = pickle.load(F)
9191
F.close()
9292

9393
cbmpy.CBSolver.analyzeModel(cmod, oldlpgen=False)
9494
res = multiCoreFVA(cmod, procs=cores)
9595

96-
F = file(os.sys.argv[2], 'wb')
96+
F = open(os.sys.argv[2], 'wb')
9797
pickle.dump(res, F, protocol=-1)
9898
F.flush()
9999
F.close()

0 commit comments

Comments
 (0)