[med-svn] [python-cobra] 01/07: Imported Upstream version 0.4.0+0

Afif Elghraoui afif at moszumanska.debian.org
Wed Mar 9 06:16:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

afif pushed a commit to branch master
in repository python-cobra.

commit c887cfb3f41793d7a5a2f51c38c55af658eec4ab
Author: Afif Elghraoui <afif at ghraoui.name>
Date:   Tue Mar 8 19:30:02 2016 -0800

    Imported Upstream version 0.4.0+0
---
 appveyor.yml                | 26 +++++++++++---------
 appveyor/build_glpk.py      | 59 +++++++++++++++++++++++++++++++++++++++++++++
 cobra/VERSION               |  2 +-
 cobra/core/Reaction.py      |  9 +++++++
 cobra/test/flux_analysis.py |  6 ++---
 cobra/test/unit_tests.py    | 15 ++++++++++++
 6 files changed, 102 insertions(+), 15 deletions(-)

diff --git a/appveyor.yml b/appveyor.yml
index bbd790c..b2cfa53 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -5,41 +5,45 @@ environment:
     # /E:ON and /V:ON options are not enabled in the batch script intepreter
     # See: http://stackoverflow.com/a/13751649/163740
     WITH_COMPILER: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
-    UCRT: " "
 
   matrix:
     - PYTHON: "C:\\Python27"
-      PYTHON_VERSION: "2.7.10"
+      PYTHON_VERSION: "2.7.11"
       PYTHON_ARCH: "32"
 
     - PYTHON: "C:\\Python34"
-      PYTHON_VERSION: "3.4.3"
+      PYTHON_VERSION: "3.4.4"
+      PYTHON_ARCH: "32"
+
+    - PYTHON: "C:\\Python35"
+      PYTHON_VERSION: "3.5.1"
       PYTHON_ARCH: "32"
 
     - PYTHON: "C:\\Python27-x64"
-      PYTHON_VERSION: "2.7.10"
+      PYTHON_VERSION: "2.7.11"
       PYTHON_ARCH: "64"
 
     - PYTHON: "C:\\Python34-x64"
-      PYTHON_VERSION: "3.4.3"
+      PYTHON_VERSION: "3.4.4"
       PYTHON_ARCH: "64"
 
     - PYTHON: "C:\\Python35-x64"
-      PYTHON_VERSION: "3.5.0"
+      PYTHON_VERSION: "3.5.1"
       PYTHON_ARCH: "64"
-      UCRT: "UCRT"
 
 clone_depth: 25
 
 init:
-  - "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH% %UCRT%"
+  - "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%bit"
+
+cache:
+    - glpk_build -> appveyor/build_glpk.py
+
 
 install:
   - "powershell appveyor\\install.ps1"
   - ps: Start-FileDownload 'https://bitbucket.org/gutworth/six/raw/default/six.py'
-  # Download glpk.h and glpk.lib (separate files for 32/64 bit)
-  - ps: Start-FileDownload 'https://opencobra.github.io/pypi_cobrapy_travis/glpk.h'
-  - "appveyor DownloadFile https://opencobra.github.io/pypi_cobrapy_travis/glpk.lib%PYTHON_ARCH%%UCRT% -FileName glpk.lib"
+  - "%WITH_COMPILER% %PYTHON%/python appveyor/build_glpk.py"
   - "%PYTHON%/python -m pip install Cython"
 
 build: off
diff --git a/appveyor/build_glpk.py b/appveyor/build_glpk.py
new file mode 100644
index 0000000..38216ba
--- /dev/null
+++ b/appveyor/build_glpk.py
@@ -0,0 +1,59 @@
+import os
+import sys
+import hashlib
+import tarfile
+import struct
+import shutil
+import setuptools.msvc9_support
+try:
+    import urllib2
+except ImportError:  # python 3
+    import urllib.request as urllib2
+
+# these need to be set to the latest glpk version
+glpk_version = "4.57"
+glpk_md5 = "237531a54f73155842f8defe51aedb0f"
+
+glpk_build_dir = "glpk_build/glpk-%s" % glpk_version
+url = "http://ftp.gnu.org/gnu/glpk/glpk-%s.tar.gz" % glpk_version
+bitness = struct.calcsize("P") * 8
+
+
+def md5(fname):
+    hash = hashlib.md5()
+    with open(fname, "rb") as f:
+        for chunk in iter(lambda: f.read(4096), b""):
+            hash.update(chunk)
+    return hash.hexdigest()
+
+
+def get_vcvarsall_cmd():
+    py_ver = sys.version_info
+    if py_ver.major == 3 and py_ver.minor >= 5:
+        vc_ver = 14
+    elif py_ver.major == 3 and py_ver.minor >= 3:
+        vc_ver = 10
+    else:
+        vc_ver = 9
+    vc_path = setuptools.msvc9_support.find_vcvarsall(vc_ver)
+    assert vc_path is not None
+    return '"%s" %s' % (vc_path, " amd64" if bitness == 64 else "")
+
+
+if not os.path.isdir("glpk_build/"):
+    os.mkdir("glpk_build")
+if not os.path.isdir(glpk_build_dir):
+    response = urllib2.urlopen(url)
+    with open("glpk-download.tar.gz", "wb") as outfile:
+        outfile.write(response.read())
+    assert md5("glpk-download.tar.gz") == glpk_md5
+    with tarfile.open("glpk-download.tar.gz") as infile:
+        infile.extractall("glpk_build")
+
+os.chdir("%s/w%d" % (glpk_build_dir, bitness))
+if not os.path.isfile("glpk.lib"):
+    shutil.copy2("config_VC", "config.h")
+    os.system(get_vcvarsall_cmd() + "& nmake /f Makefile_VC")
+shutil.copy2("glpk.lib", "../../..")
+os.chdir("../../..")
+shutil.copy2(glpk_build_dir + "/src/glpk.h", ".")
diff --git a/cobra/VERSION b/cobra/VERSION
index a9e3532..1d0ba9e 100644
--- a/cobra/VERSION
+++ b/cobra/VERSION
@@ -1 +1 @@
-0.4.0b7
+0.4.0
diff --git a/cobra/core/Reaction.py b/cobra/core/Reaction.py
index d8f80fc..1110599 100644
--- a/cobra/core/Reaction.py
+++ b/cobra/core/Reaction.py
@@ -40,6 +40,8 @@ def _is_positive(n):
 # precompiled regular expressions
 # Matches and/or in a gene reaction rule
 and_or_search = re.compile(r'\(| and| or|\+|\)', re.IGNORECASE)
+uppercase_AND = re.compile(r'\bAND\b')
+uppercase_OR = re.compile(r'\bOR\b')
 gpr_clean = re.compile(' {2,}')
 # This regular expression finds any single letter compartment enclosed in
 # square brackets at the beginning of the string. For example [c] : foo --> bar
@@ -101,6 +103,13 @@ class Reaction(Object):
         try:
             _, gene_names = parse_gpr(self._gene_reaction_rule)
         except (SyntaxError, TypeError) as e:
+            if "AND" in new_rule or "OR" in new_rule:
+                warn("uppercase AND/OR found in rule '%s' for '%s'" %
+                     (new_rule, repr(self)))
+                new_rule = uppercase_AND.sub("and", new_rule)
+                new_rule = uppercase_OR.sub("or", new_rule)
+                self.gene_reaction_rule = new_rule
+                return
             warn("malformed gene_reaction_rule '%s' for %s" %
                  (new_rule, repr(self)))
             tmp_str = and_or_search.sub('', self._gene_reaction_rule)
diff --git a/cobra/test/flux_analysis.py b/cobra/test/flux_analysis.py
index 4103cf0..0ba8cf1 100644
--- a/cobra/test/flux_analysis.py
+++ b/cobra/test/flux_analysis.py
@@ -173,7 +173,7 @@ class TestCobraFluxAnalysis(TestCase):
         try:
             solver = get_solver_name(mip=True)
         except:
-            self.skip("no MILP solver found")
+            self.skipTest("no MILP solver found")
         test_model = Model()
         test_model.add_metabolites(Metabolite("A"))
         test_model.add_metabolites(Metabolite("B"))
@@ -203,7 +203,7 @@ class TestCobraFluxAnalysis(TestCase):
         try:
             solver = get_solver_name(mip=True)
         except:
-            self.skip("no MILP solver found")
+            self.skipTest("no MILP solver found")
         m = Model()
         m.add_metabolites(map(Metabolite, ["a", "b", "c"]))
         r = Reaction("EX_A")
@@ -247,7 +247,7 @@ class TestCobraFluxAnalysis(TestCase):
         self.assertAlmostEqual(data.growth_rates.max(), 1.20898, places=4)
         self.assertAlmostEqual(abs(data.growth_rates[0, :]).max(), 0, places=4)
         if matplotlib is None:
-            self.skip("can't test plots without matplotlib")
+            self.skipTest("can't test plots without matplotlib")
         data.plot()
 
 # make a test suite to run all of the tests
diff --git a/cobra/test/unit_tests.py b/cobra/test/unit_tests.py
index f673d50..eb984e0 100644
--- a/cobra/test/unit_tests.py
+++ b/cobra/test/unit_tests.py
@@ -269,6 +269,21 @@ class TestReactions(CobraTestCase):
         reaction_gene = list(reaction.genes)[0]
         model_gene = model.genes.get_by_id(reaction_gene.id)
         self.assertIs(reaction_gene, model_gene)
+        # test ability to handle uppercase AND/OR
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            reaction.gene_reaction_rule = "(b1 AND b2) OR (b3 and b4)"
+        self.assertEqual(reaction.gene_reaction_rule,
+                         "(b1 and b2) or (b3 and b4)")
+        self.assertEqual(len(reaction.genes), 4)
+        # ensure regular expressions correctly extract genes from malformed
+        # GPR string
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            reaction.gene_reaction_rule = "(a1 or a2"
+            self.assertEqual(len(reaction.genes), 2)
+            reaction.gene_reaction_rule = "(forT or "
+            self.assertEqual(len(reaction.genes), 1)
 
     def testGPR_modification(self):
         model = self.model

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-cobra.git



More information about the debian-med-commit mailing list