Skip to content

Commit

Permalink
BiGGTest updated to verify reference solutions | minor fix in FBA | u…
Browse files Browse the repository at this point in the history
…pdated download_bigg_models script
  • Loading branch information
hemilpanchiwala committed Aug 7, 2020
1 parent 9b92496 commit c40ef21
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ liblpsolve55j_x64.so
jsbml.log

# BiGG models
src/test/resources/bigg/
src/test/resources/bigg/v1.5/

# sbml-test-suite
src/test/resources/sbml-test-suite/
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/simulator/fba/FluxBalanceAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
import org.sbml.jsbml.validator.ModelOverdeterminedException;
import org.simulator.sbml.SBMLinterpreter;
import org.simulator.sbml.astnode.ASTNodeValue;
import scpsolver.constraints.LinearBiggerThanEqualsConstraint;
import scpsolver.constraints.LinearConstraint;
import scpsolver.constraints.LinearEqualsConstraint;
import scpsolver.constraints.LinearSmallerThanEqualsConstraint;
import scpsolver.lpsolver.LinearProgramSolver;
import scpsolver.lpsolver.SolverFactory;
import scpsolver.problems.LinearProgram;
Expand Down Expand Up @@ -235,7 +238,7 @@ public FluxBalanceAnalysis(SBMLDocument doc)
for (Pair<String, Double> pair : species2Reaction.get(species.getId())) {
weights[reaction2Index.get(pair.getKey())] = pair.getValue();
}
if (species2Reaction.get(species.getId()).size() > 1) {
if (species.isSetBoundaryCondition() && !species.getBoundaryCondition()) {
problem.addConstraint(new LinearEqualsConstraint(weights, 0.0, "cnstrt_" + species.getId()));
}
}
Expand Down
39 changes: 21 additions & 18 deletions src/test/java/org/simulator/fba/BiGGTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.simulator.fba;

import org.junit.Ignore;
import org.junit.Assert;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLReader;
import org.simulator.TestUtils;
Expand All @@ -13,9 +13,10 @@
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.zip.GZIPInputStream;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -27,10 +28,24 @@
public class BiGGTest {
private String resource;
private static final Logger logger = LoggerFactory.getLogger(TestUtils.class);
private static final double RESULT_DEVIATION = 1E-6d;

/**
* HashMap for storing the reference results with key as the model names.
*/
private Map<String, Double> referenceResults;

@Before
public void setUp(){ }
public void setUp() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(TestUtils.getPathForTestResource("/bigg/bigg_reference_solutions.csv")));
referenceResults = new HashMap<>();
String line;

while ((line = reader.readLine()) != null) {
String[] solution = line.split(",");
referenceResults.put(solution[0], Double.parseDouble(solution[1]));
}
}

/**
* Returns location of BiGG test model directory from environment variable.
Expand All @@ -51,27 +66,14 @@ public static Iterable<Object[]> data(){

// find all BiGG models (compressed .xml.gz files)
String biggPath = getBiGGModelPath();
System.out.println("BiGG models path: " + biggPath);
logger.info("BiGG models path: " + biggPath);
return TestUtils.findResources(biggPath, ".xml", filter, skip, mvnResource);
}

@Test
public void testFBA() throws Exception {
logger.info("--------------------------------------------------------");
logger.info(String.format("%s", resource));
System.out.println("BiGG Resource:" + resource);

if ((resource.endsWith("iAF987.xml") ||
(resource.endsWith("iAF692.xml")))) {
/*
BiGG Resource://home/mkoenig/git/sbscl-shalin/src/test/resources/bigg/v1.5/iAF987.xml.gz
glp_free: memory allocation error
Error detected in file env/alloc.c at line 72
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
*/
return;
}

SBMLDocument doc = SBMLReader.read(new File(resource));
assertNotNull(doc);
Expand All @@ -85,7 +87,8 @@ public void testFBA() throws Exception {
double[] fluxes = solver.getValues();
assertNotNull(fluxes);

//TODO: check against reference solution
Assert.assertEquals(objectiveValue, referenceResults.get(Paths.get(resource).getFileName().toString()), RESULT_DEVIATION);

}

}
85 changes: 85 additions & 0 deletions src/test/resources/bigg/bigg_reference_solutions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
RECON1.xml,0
Recon3D.xml,755.0032156
STM_v1_0.xml,0.4778336608
e_coli_core.xml,0.873921507
iAB_RBC_283.xml,2.935561467
iAF1260.xml,0.7367009389
iAF1260b.xml,0.7367009389
iAF692.xml,0.02678046755
iAF987.xml,0.04732237668
iAPECO1_1312.xml,0.9824784387
iAT_PLT_636.xml,0
iB21_1397.xml,0.9756145116
iBWG_1329.xml,0.9824784387
iCHOv1.xml,0.0323689716
iE2348C_1286.xml,0.9824784387
iEC042_1314.xml,0.9824784387
iEC55989_1330.xml,0.9824784387
iECABU_c1320.xml,0.9824784387
iECBD_1354.xml,0.9756145116
iECB_1328.xml,0.9824784387
iECDH10B_1368.xml,1.037477544
iECDH1ME8569_1439.xml,0.9824784387
iECD_1391.xml,0.9756145116
iECED1_1282.xml,0.9824634434
iECH74115_1262.xml,0.9824784387
iECIAI1_1343.xml,20.52222563
iECIAI39_1322.xml,0.9828409641
iECNA114_1301.xml,0.9824784387
iECO103_1326.xml,0.9824784387
iECO111_1330.xml,0.9824784387
iECO26_1355.xml,0.9824784387
iECOK1_1307.xml,0.9824784387
iECP_1309.xml,0.9824784387
iECS88_1305.xml,0.9824784387
iECSE_1348.xml,0.9824784387
iECSF_1327.xml,0.9824784387
iECSP_1301.xml,0.9824784387
iECUMN_1333.xml,0.9826920128
iECW_1372.xml,0.9824784387
iECs_1301.xml,0.9824784387
iEKO11_1354.xml,0.9824784387
iETEC_1333.xml,0.9824784387
iEcDH1_1363.xml,0.9824784387
iEcE24377_1341.xml,0.9824784387
iEcHS_1320.xml,0.9824784387
iEcSMS35_1347.xml,0.9824784387
iEcolC_1368.xml,0.9824784387
iG2583_1286.xml,0.9824784387
iHN637.xml,0.2244545421
iIT341.xml,0.6928126937
iJB785.xml,0.05390186747
iJN678.xml,0.06314983713
iJN746.xml,1.4
iJO1366.xml,0.9823718127
iJR904.xml,0.9219480951
iLB1027_lipid.xml,0.3596067078
iLF82_1304.xml,0.9824784387
iLJ478.xml,0.228406792
iML1515.xml,0.8769972144
iMM1415.xml,1.363427906
iMM904.xml,0.2878657037
iND750.xml,0.0973233759
iNF517.xml,0.04263460544
iNJ661.xml,0.05254980101
iNRG857_1313.xml,0.9824784387
iPC815.xml,0.2835583812
iRC1080.xml,6.156851476
iSB619.xml,0.1580502916
iSBO_1134.xml,0.3998801249
iSDY_1059.xml,0.9378903141
iSFV_1184.xml,0.8938577496
iSF_1195.xml,0.9145918469
iSFxv_1172.xml,0.8940890262
iSSON_1240.xml,0.9826450753
iS_1188.xml,0.8570768327
iSbBS512_1146.xml,0.9828118164
iUMN146_1321.xml,0.9824784387
iUMNK88_1353.xml,0.9824784387
iUTI89_1310.xml,0.9824784387
iWFL_1372.xml,0.9824784387
iY75_1357.xml,0.9824784387
iYL1228.xml,1.042637498
iYO844.xml,0.1179663893
iZ_1308.xml,0.9824784387
ic_1306.xml,1.03192228
2 changes: 0 additions & 2 deletions src/test/scripts/download_bigg_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ TEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

# download and extract the bigg models for testing
cd $TEST_DIR/../resources/bigg
mkdir -p $TEST_DIR/../resources/bigg
cd $TEST_DIR/../resources/bigg
wget $BIGG_MODELS_BASE_URL/$FILE_NAME
tar xzf $FILE_NAME
rm $FILE_NAME
Expand Down

0 comments on commit c40ef21

Please sign in to comment.