diff --git a/.gitignore b/.gitignore index e0f8f5cf..d6839a13 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ libglpkjni_x64.so # log files jsbml.log +# BiGG models +src/test/resources/bigg/ + diff --git a/.travis.yml b/.travis.yml index 2c4d14a4..f01297de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,10 @@ language: java jdk: - oraclejdk8 +before_install: + # get BiGG models for testing + cd src/test + source ./download_bigg_models.sh + script: - mvn clean install \ No newline at end of file diff --git a/INSTALL.md b/INSTALL.md index b2b3a785..669f5d8c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -11,6 +11,7 @@ http://scpsolver.org/ and add in the library folder according to the `pom.xml`. ### GLPK ``` +sudo apt-get install libglpk-dev sudo apt-get install libglpk-java ``` diff --git a/src/test/download_bigg_models.sh b/src/test/download_bigg_models.sh new file mode 100755 index 00000000..5e379767 --- /dev/null +++ b/src/test/download_bigg_models.sh @@ -0,0 +1,27 @@ +#!/bin/bash +################################################# +# Download bigg models for testing +# +# usage: +# source ./download_bigg_models.sh +################################################# + +TEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +# download and extract the bigg models for testing +mkdir -p resources/bigg +cd resources/bigg +wget https://github.com/matthiaskoenig/bigg-models-fba/raw/master/models/bigg_models_v1.5.tar.gz +tar xzvf bigg_models_v1.5.tar.gz +rm bigg_models_v1.5.tar.gz + +# set environment variable +export BIGG_MODELS_PATH=${TEST_DIR}/resources/bigg + +echo $BIGG_MODELS_PATH + + + + + + diff --git a/src/test/java/org/simulator/TestUtils.java b/src/test/java/org/simulator/TestUtils.java index 97f9c818..442acc89 100644 --- a/src/test/java/org/simulator/TestUtils.java +++ b/src/test/java/org/simulator/TestUtils.java @@ -21,38 +21,22 @@ public class TestUtils { public static String FBA_RESOURCE_PATH = "/fba"; - /** - * Returns location of BiGG test model directory from environment variable. - */ - public static String getBiGGModelPath() { - Map env = System.getenv(); - String key = "BIGG_MODELS"; - String value = null; - if (env.containsKey(key)) { - value = env.get(key); - logger.info(String.format("BiGG models folder found: %s", value)); - } - else { - logger.info(String.format("%s environment variable not set.", key)); - } - return value; - } - - /** * Get an iteratable over the resources in the resourcePath. *

* Resources in the skip set are skipped. * If a filter string is given only the resources matching the filter are returned. */ - public static Iterable findResources(String resourcePath, String extension, String filter, HashSet skip) { - - File currentDir = new File(System.getProperty("user.dir")); - // String rootPath = new File(currentDir, resourcePath).getPath(); - String rootPath = currentDir.getAbsolutePath() + "/src/test/resources" + resourcePath; - - System.out.println("curDir:" + currentDir); - System.out.println("rootPath:" + rootPath); + public static Iterable findResources(String resourcePath, String extension, String filter, HashSet skip, Boolean mvnResource) { + + String rootPath = resourcePath; + if (mvnResource) { + File currentDir = new File(System.getProperty("user.dir")); + System.out.println("curDir: " + currentDir); + // String rootPath = new File(currentDir, resourcePath).getPath(); + rootPath = currentDir.getAbsolutePath() + "/src/test/resources" + resourcePath; + } + System.out.println("rootPath: " + rootPath); // Get SBML files for passed tests LinkedList sbmlPaths = TestUtils.findFiles(rootPath, extension, filter, skip); diff --git a/src/test/java/org/simulator/fba/BiGGTest.java b/src/test/java/org/simulator/fba/BiGGTest.java index 9944a200..233d78f6 100644 --- a/src/test/java/org/simulator/fba/BiGGTest.java +++ b/src/test/java/org/simulator/fba/BiGGTest.java @@ -1,30 +1,58 @@ package org.simulator.fba; +import org.sbml.jsbml.JSBML; +import org.sbml.jsbml.SBMLDocument; +import org.sbml.jsbml.SBMLReader; import org.simulator.TestUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - +import javax.xml.stream.XMLStreamException; +import java.io.*; +import java.util.Arrays; import java.util.HashSet; +import java.util.Map; +import java.util.zip.GZIPInputStream; + +import static org.junit.Assert.assertNotNull; /** * Test cases for the BIGG models. - * bigg_models v1.4 (https://github.com/SBRG/bigg_models/releases) - * - * Models were retrieved on 2017-10-10 from the available database dumps on - * dropbox. + * bigg_models v1.5 (https://github.com/SBRG/bigg_models/releases) */ @RunWith(value = Parameterized.class) public class BiGGTest { private String resource; + private static final Logger logger = LoggerFactory.getLogger(TestUtils.class); @Before public void setUp(){ } - + + /** + * Returns location of BiGG test model directory from environment variable. + */ + public static String getBiGGModelPath() { + Map env = System.getenv(); + String key = "BIGG_MODELS_PATH"; + String version = "v1.5"; + String value = null; + if (env.containsKey(key)) { + value = env.get(key); + value = value + "/" + version; + logger.info(String.format("BiGG models folder found: %s", value)); + } + else { + logger.info(String.format("%s environment variable not set.", key)); + } + return value; + } + public BiGGTest(String resource) { this.resource = resource; } @@ -33,24 +61,45 @@ public BiGGTest(String resource) { public static Iterable data(){ HashSet skip = null; String filter = null; + Boolean mvnResource = false; - // find all BiGG models (FIXME: work on compressed models) + System.out.println("Searching resources"); - String bigg_path = TestUtils.getBiGGModelPath(); - return TestUtils.findResources(bigg_path, ".xml", filter, skip); - } - // TODO: read cobrapy reference values for comparison - /** - @Test - public void testSingle() throws Exception { - TestUtils.testNetwork(taskMonitor, getClass().getName(), resource); + // find all BiGG models (compressed files) + String biggPath = getBiGGModelPath(); + System.out.println("BiGG models path: " + biggPath); + return TestUtils.findResources(biggPath, ".xml.gz", filter, skip, mvnResource); } @Test - public void testSerialization() throws Exception { - TestUtils.testNetworkSerialization(getClass().getName(), resource); - } - */ + public void testFBA() throws Exception { + logger.info("--------------------------------------------------------"); + logger.info(String.format("%s", resource)); + System.out.println("BiGG Resource:" + resource); + + // read SBML + InputStream is = new FileInputStream(resource); + GZIPInputStream gzis = new GZIPInputStream(is); + + SBMLDocument doc = SBMLReader.read(gzis); + logger.info(doc.toString()); + assertNotNull(doc); + + // TODO: solve FBA ( + /* + COBRAsolver solver = new COBRAsolver(doc); + if (solver.solve()) { + System.out.println(resourceName); + System.out.println("Objective value:\t" + solver.getObjetiveValue()); + System.out.println("Fluxes:\t" + Arrays.toString(solver.getValues())); + } else { + logger.error("\nSolver returned null for " + resourceName); + } + */ + + //TODO: check against reference solution + is.close(); + } } \ No newline at end of file diff --git a/src/test/java/org/simulator/fba/CobraSolverTest.java b/src/test/java/org/simulator/fba/CobraSolverTest.java index f7d1a578..aca5431a 100644 --- a/src/test/java/org/simulator/fba/CobraSolverTest.java +++ b/src/test/java/org/simulator/fba/CobraSolverTest.java @@ -20,6 +20,7 @@ public class CobraSolverTest { private static final Logger logger = LoggerFactory.getLogger(CobraSolverTest.class); @Test + @Ignore // breaks on Ubuntu: https://github.com/shalinshah1993/SBSCL/issues/24 public void solveEColiCore() throws ModelOverdeterminedException, XMLStreamException { String resourceName = "fba/e_coli_core.xml";