From c40ef21edde633cdff534134b671137d06eb6eca Mon Sep 17 00:00:00 2001 From: Hemil Panchiwala Date: Fri, 7 Aug 2020 22:08:05 +0530 Subject: [PATCH] BiGGTest updated to verify reference solutions | minor fix in FBA | updated download_bigg_models script --- .gitignore | 2 +- .../simulator/fba/FluxBalanceAnalysis.java | 5 +- src/test/java/org/simulator/fba/BiGGTest.java | 39 +++++---- .../bigg/bigg_reference_solutions.csv | 85 +++++++++++++++++++ src/test/scripts/download_bigg_models.sh | 2 - 5 files changed, 111 insertions(+), 22 deletions(-) create mode 100644 src/test/resources/bigg/bigg_reference_solutions.csv diff --git a/.gitignore b/.gitignore index 7f962a1f..6b0ae662 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/src/main/java/org/simulator/fba/FluxBalanceAnalysis.java b/src/main/java/org/simulator/fba/FluxBalanceAnalysis.java index 3b05b194..82ccacb7 100644 --- a/src/main/java/org/simulator/fba/FluxBalanceAnalysis.java +++ b/src/main/java/org/simulator/fba/FluxBalanceAnalysis.java @@ -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; @@ -235,7 +238,7 @@ public FluxBalanceAnalysis(SBMLDocument doc) for (Pair 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())); } } diff --git a/src/test/java/org/simulator/fba/BiGGTest.java b/src/test/java/org/simulator/fba/BiGGTest.java index 38cab6bd..9f888c69 100644 --- a/src/test/java/org/simulator/fba/BiGGTest.java +++ b/src/test/java/org/simulator/fba/BiGGTest.java @@ -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; @@ -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; @@ -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 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. @@ -51,7 +66,7 @@ public static Iterable 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); } @@ -59,19 +74,6 @@ public static Iterable data(){ 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); @@ -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); + } } diff --git a/src/test/resources/bigg/bigg_reference_solutions.csv b/src/test/resources/bigg/bigg_reference_solutions.csv new file mode 100644 index 00000000..51afbdce --- /dev/null +++ b/src/test/resources/bigg/bigg_reference_solutions.csv @@ -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 diff --git a/src/test/scripts/download_bigg_models.sh b/src/test/scripts/download_bigg_models.sh index 589f0296..30e6e0c9 100755 --- a/src/test/scripts/download_bigg_models.sh +++ b/src/test/scripts/download_bigg_models.sh @@ -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