Skip to content

Commit 0798f5c

Browse files
authored
Merge pull request #50 from SystemsBioinformatics/dev
0.8.4 py3.9+ compatibility release
2 parents 644bdfc + c8d9555 commit 0798f5c

14 files changed

+188
-89
lines changed

CONTRIBUTORS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Contributors
22

3-
## Release 0.8.2
3+
## Release 0.8.4
4+
Many thanks go to @willigot for their suggestions and code contributions.
45

6+
## Release 0.8.2
57

68
## Release 0.8.1
79

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CBMPy
22
PySCeS Constraint Based Modelling (http://cbmpy.sourceforge.net)
3-
Copyright (C) 2010-2022 Brett G. Olivier, Vrije Universiteit Amsterdam, Amsterdam, The Netherlands
3+
Copyright (C) 2010-2023 Brett G. Olivier, Vrije Universiteit Amsterdam, Amsterdam, The Netherlands
44

55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -75,4 +75,4 @@ Once you have installed CBMPy it can be easily upgraded.
7575
### Anaconda update
7676
`conda update cbmpy`
7777

78-
(c) Brett G. Olivier, Amsterdam, 2014-2022
78+
(c) Brett G. Olivier, Amsterdam, 2014-2023

RELEASES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Release history
22

3-
## Release 0.8.2 (2021)
3+
## Release 0.8.4 (2023)
4+
Primarily a Python 9.x compatability release
45

56

7+
## Release 0.8.2 (2021)
68
## Release 0.8.1 (2021-07-23)
79

810
Primarily a bugfix release to fix the SymPy compatability issues as well as improved requirements handling.

cbmpy/CBCPLEX.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,7 @@ def cplx_FluxVariabilityAnalysis(
19961996
max_oval = numpy.NaN
19971997
else: # other fail
19981998
max_oval = numpy.NaN
1999+
19992000
if debug:
20002001
cplx_writeLPtoLPTfile(
20012002
cpx, '%smax' % R, title='max%s=%s' % (R, max_oval), Dir=debug_dir
@@ -2016,33 +2017,38 @@ def cplx_FluxVariabilityAnalysis(
20162017
OUTPUT_ARRAY[Ridx, 4] = round(abs(max_oval - min_oval), roundoff_span)
20172018
OUTPUT_ARRAY[Ridx, 5] = MIN_STAT
20182019
OUTPUT_ARRAY[Ridx, 6] = MAX_STAT
2020+
20192021
if markupmodel:
20202022
REAC = fba.getReaction(R)
20212023
REAC.setValue(pre_sol[R])
20222024
REAC.fva_min = min_oval
20232025
REAC.fva_max = max_oval
20242026
REAC.fva_status = (MIN_STAT, MAX_STAT)
2025-
# if MAX_STAT == 1:
2026-
# REAC.fva_max = max_oval
2027-
# else:
2028-
# REAC.fva_max = None
2029-
# if MIN_STAT == 1:
2030-
# REAC.fva_min = min_oval
2031-
# else:
2032-
# REAC.fva_min = None
2027+
#if MAX_STAT == 1:
2028+
#REAC.fva_max = max_oval
2029+
#else:
2030+
#REAC.fva_max = None
2031+
#if MIN_STAT == 1:
2032+
#REAC.fva_min = min_oval
2033+
#else:
2034+
#REAC.fva_min = None
20332035
if R in REDUCED_COSTS:
20342036
REAC.reduced_costs = REDUCED_COSTS[R]
2037+
2038+
# TODO backport from CBGLPK line 839
20352039
if not quiet and MAX_STAT > 1 or MIN_STAT > 1:
20362040
print(
20372041
'Solver fail for reaction \"{}\" (MIN_STAT: {} MAX_STAT: {})'.format(
20382042
R, MIN_STAT, MAX_STAT
20392043
)
20402044
)
2045+
# TODO backport from CBGLPK line 857
20412046
cntr += 1
20422047
if cntr == 200:
20432048
tcnt += cntr
20442049
print('FVA has processed {} of {} reactions'.format(tcnt, NUM_FLX))
20452050
cntr = 0
2051+
20462052
if quiet:
20472053
cplx_setOutputStreams(cpx, mode='default')
20482054
del cpx

cbmpy/CBCommon.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,23 @@
7171

7272
chemElementDefs = None
7373
HAVE_PYPARSING = False
74-
try:
75-
from . import pyparsing
7674

75+
try:
76+
import pyparsing
7777
HAVE_PYPARSING = True
78+
print('pyparsing import')
7879
except ImportError:
79-
try:
80-
print('Attempting global PyParsing import')
81-
import pyparsing
80+
print('INFO: please install pyparsing to enable chemical balance checking!')
81+
82+
83+
#if not HAVE_PYPARSING:
84+
#if os.sys.version_info[0] == 3 and os.sys.version_info[1] < 9:
85+
#try:
86+
#from . import pyparsing
8287

83-
HAVE_PYPARSING = True
84-
except ImportError:
85-
print('INFO please install pyparsing to enable chemical balance checking!')
88+
#HAVE_PYPARSING = True
89+
#except ImportError:
90+
#print('INFO please install pyparsing to enable chemical balance checking!')
8691

8792
if HAVE_PYPARSING:
8893
pp_caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

cbmpy/CBGLPK.py

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@
6767
sw.glp_set_prob_name(lp, "sample")
6868
sw.glp_delete_prob(lp)
6969
HAVE_SWIGLPK = True
70-
print('\n\nCBGLPK based on swiglpk: not all methods implimented yet!')
7170
__solver_version__ = '{}.{}'.format(sw.GLP_MAJOR_VERSION, sw.GLP_MINOR_VERSION)
71+
print(
72+
'CBGLPK based on swiglpk: not all methods implimented yet!',
73+
__solver_version__,
74+
)
75+
7276
except:
7377
raise ImportError
7478

@@ -696,6 +700,7 @@ def glpk_FluxVariabilityAnalysis(
696700
except AttributeError:
697701
OUTPUT_ARRAY = numpy.zeros((NUM_FLX, 7))
698702
OUTPUT_NAMES = []
703+
fva_ridx_fails = []
699704
cntr = 0
700705
tcnt = 0
701706
# this is a memory hack --> prevents solver going berserk
@@ -714,8 +719,9 @@ def glpk_FluxVariabilityAnalysis(
714719
# MIN
715720
# TODO: bgoli: see whether this also works with 'minimize'
716721
glpk_setObjective(cpx, 'min%s' % R, [(1, R)], 'min', reset=True)
717-
## cplx_setBounds(c, id, min=None, max=None) # think about this
722+
718723
MIN_STAT = glpk_Solve(cpx, method=method)
724+
719725
if MIN_STAT == 'LPS_OPT':
720726
MIN_STAT = 1
721727
elif MIN_STAT == 'LPS_UNBND':
@@ -724,6 +730,7 @@ def glpk_FluxVariabilityAnalysis(
724730
MIN_STAT = 3
725731
else:
726732
MIN_STAT = 4
733+
727734
if MIN_STAT == 1: # solved
728735
min_oval = cpx.obj.value
729736
elif MIN_STAT == 2: # unbound
@@ -735,17 +742,21 @@ def glpk_FluxVariabilityAnalysis(
735742
min_oval = numpy.NaN
736743
if debug:
737744
cpx.write(cpxlp=os.path.join(debug_dir, '%smin.lp' % R))
738-
if MIN_STAT >= 3:
739-
if gomin_cntr == 0:
740-
cpx.erase()
741-
del cpx
742-
time.sleep(0.1)
743-
cpx = glpk.LPX(mps=mps_filename)
744-
gomin_cntr += 1
745-
else:
746-
GOMIN = False
745+
746+
if MIN_STAT > 3:
747+
print('Mysterious GLPK MIN_STAT > 3: if you see this please contact a developer (not an error).')
748+
#if gomin_cntr == 0:
749+
#cpx.erase()
750+
#del cpx
751+
#time.sleep(0.1)
752+
#cpx = glpk.LPX(mps=mps_filename)
753+
#gomin_cntr += 1
754+
#else:
755+
#GOMIN = False
756+
GOMIN = False
747757
else:
748758
GOMIN = False
759+
749760
if gomin_cntr >= max_error_iter:
750761
GOMIN = False
751762

@@ -765,6 +776,7 @@ def glpk_FluxVariabilityAnalysis(
765776
MAX_STAT = 3
766777
else:
767778
MAX_STAT = 4
779+
768780
if MAX_STAT == 1: # solved
769781
max_oval = cpx.obj.value
770782
elif MAX_STAT == 2: # unbound
@@ -775,24 +787,30 @@ def glpk_FluxVariabilityAnalysis(
775787
else: # other fail
776788
max_oval = numpy.NaN
777789

778-
if MAX_STAT >= 3:
779-
if gomax_cntr == 0:
780-
cpx.erase()
781-
del cpx
782-
time.sleep(0.1)
783-
cpx = glpk.LPX(mps=mps_filename)
784-
gomax_cntr += 1
785-
else:
786-
GOMAX = False
790+
if MAX_STAT > 3:
791+
print('Mysterious GLPK MAX_STAT > 3: if you see this please contact a developer (not an error).')
792+
#if gomax_cntr == 0:
793+
#cpx.erase()
794+
#del cpx
795+
#time.sleep(0.1)
796+
#cpx = glpk.LPX(mps=mps_filename)
797+
#gomax_cntr += 1
798+
#else:
799+
#GOMAX = False
800+
GOMAX = False
787801
else:
788802
GOMAX = False
803+
789804
if gomax_cntr >= max_error_iter:
790805
GOMAX = False
791806

792807
# check for solver going berserk
793-
if MIN_STAT > 1 and MAX_STAT > 1:
794-
print(Ridx)
795-
time.sleep(1)
808+
#if MIN_STAT > 1 and MAX_STAT > 1:
809+
#print(Ridx)
810+
#time.sleep(1)
811+
812+
if debug:
813+
cpx.write(cpxlp=os.path.join(debug_dir, '%smax.lp' % R))
796814

797815
# enables using the default value as a solution if the solver fails
798816
if pre_opt and default_on_fail:
@@ -801,9 +819,6 @@ def glpk_FluxVariabilityAnalysis(
801819
if MIN_STAT > 1 and not MAX_STAT > 1:
802820
min_oval = pre_sol[R]
803821

804-
if debug:
805-
cpx.write(cpxlp=os.path.join(debug_dir, '%smax.lp' % R))
806-
807822
OUTPUT_ARRAY[Ridx, 0] = pre_sol[R]
808823
if R in REDUCED_COSTS:
809824
OUTPUT_ARRAY[Ridx, 1] = REDUCED_COSTS[R]
@@ -820,18 +835,28 @@ def glpk_FluxVariabilityAnalysis(
820835
REAC.fva_status = (MIN_STAT, MAX_STAT)
821836
if R in REDUCED_COSTS:
822837
REAC.reduced_costs = REDUCED_COSTS[R]
823-
if not quiet and MAX_STAT > 1 or MIN_STAT > 1:
824-
print(
825-
'Solver fail for reaction \"{}\" (MIN_STAT: {} MAX_STAT: {})'.format(
826-
R, MIN_STAT, MAX_STAT
827-
)
828-
)
838+
839+
if not quiet:
840+
if MAX_STAT > 1:
841+
fva_ridx_fails.append((R, MAX_STAT))
842+
#print(
843+
#'Solver fail for reaction \"{}\" (MIN_STAT: {} MAX_STAT: {})'.format(
844+
#R, MIN_STAT, MAX_STAT
845+
#)
846+
if MIN_STAT > 1:
847+
fva_ridx_fails.append((R, MIN_STAT))
848+
829849
cntr += 1
830850
if cntr == 200:
831851
tcnt += cntr
832852
print('FVA has processed {} of {} reactions'.format(tcnt, NUM_FLX))
833853
cntr = 0
834854

855+
if len(fva_ridx_fails) > 0:
856+
print('Optimization failed for the following FVA operations. If this is a large list consider adjusting the FVA tolerances.')
857+
print(fva_ridx_fails)
858+
859+
835860
os.remove(mps_filename)
836861

837862
# cpx.write(cpxlp='thefinaldebug.lp')

cbmpy/CBNetDB.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def createDBTable(self, table, sqlcols):
141141
142142
Effectively writes CREATE TABLE "table" (<id> <type>, gene TEXT PRIMARY KEY, aa_seq TEXT, nuc_seq TEXT, aa_len INT, nuc_len INT) % table
143143
"""
144-
SQL = 'CREATE TABLE %s (' % table
144+
SQL = 'CREATE TABLE "{}" ('.format(table)
145145
for c in sqlcols:
146-
SQL += ' %s,' % c
146+
SQL += ' "{}",'.format(c)
147147
SQL = SQL[:-1]
148148
SQL += ' )'
149149
print(SQL)

cbmpy/CBSolver.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131

3232
from .CBConfig import __CBCONFIG__ as __CBCONFIG__
3333

34+
# Force the use of the CPLX solver by defining this envar
35+
import os
36+
37+
if 'CBMPY_USE_CPLX' in os.environ:
38+
__CBCONFIG__['SOLVER_PREF'] = 'CPLX'
39+
if 'CBMPY_USE_GLPK' in os.environ:
40+
__CBCONFIG__['SOLVER_PREF'] = 'GLPK'
41+
del os
42+
3443
__DEBUG__ = __CBCONFIG__['DEBUG']
3544
__version__ = __CBCONFIG__['VERSION']
3645
SOLVER_PREF = __CBCONFIG__['SOLVER_PREF']

cbmpy/CBWrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def writeSBML3FBCV2(
159159
add_cbmpy_annot=True,
160160
add_cobra_annot=False,
161161
validate=False,
162-
compress_bounds=True,
162+
compress_bounds=False,
163163
zip_model=False,
164164
return_model_string=False,
165165
):

0 commit comments

Comments
 (0)