Skip to content

Commit

Permalink
First work on #7, parametrized test for FBA
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskoenig committed Jun 11, 2018
1 parent a944252 commit cefc069
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ libglpkjni_x64.so
# log files
jsbml.log

# BiGG models
src/test/resources/bigg/

5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
27 changes: 27 additions & 0 deletions src/test/download_bigg_models.sh
Original file line number Diff line number Diff line change
@@ -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






36 changes: 10 additions & 26 deletions src/test/java/org/simulator/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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.
* <p>
* Resources in the skip set are skipped.
* If a filter string is given only the resources matching the filter are returned.
*/
public static Iterable<Object[]> findResources(String resourcePath, String extension, String filter, HashSet<String> 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<Object[]> findResources(String resourcePath, String extension, String filter, HashSet<String> 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<String> sbmlPaths = TestUtils.findFiles(rootPath, extension, filter, skip);
Expand Down
87 changes: 68 additions & 19 deletions src/test/java/org/simulator/fba/BiGGTest.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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;
}
Expand All @@ -33,24 +61,45 @@ public BiGGTest(String resource) {
public static Iterable<Object[]> data(){
HashSet<String> 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();
}

}
1 change: 1 addition & 0 deletions src/test/java/org/simulator/fba/CobraSolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit cefc069

Please sign in to comment.