Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Dec 2, 2022
1 parent 6c181cb commit a5802a0
Show file tree
Hide file tree
Showing 20 changed files with 15,387 additions and 119 deletions.
2 changes: 1 addition & 1 deletion vcell-core/src/main/java/cbit/vcell/model/Kinetics.java
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ private final void cleanupParameters() throws ModelException, ExpressionExceptio
try {
exp.bindExpression(reactionStep);
}catch (ExpressionBindingException e){
logger.error("error binding expression '"+exp.infix()+"': "+e.getMessage(), e);
logger.warn("error binding expression '"+exp.infix()+"': "+e.getMessage());
}
}
}
Expand Down
142 changes: 33 additions & 109 deletions vcell-core/src/test/java/org/vcell/sbml/SBMLImporterTest.java
Original file line number Diff line number Diff line change
@@ -1,134 +1,58 @@
package org.vcell.sbml;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javax.xml.stream.XMLStreamException;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.vcell.sbml.vcell.SBMLImporter;

import cbit.util.xml.VCLogger;
import cbit.vcell.biomodel.BioModel;

@RunWith(Parameterized.class)
public class SBMLImporterTest {

public enum FAULT {
RESERVED_WORD,
DELAY,
NONINTEGER_STOICH,
INCONSISTENT_UNIT_SYSTEM,
EXPRESSION_BINDING_EXCEPTION,
XOR_MISSING,
JSBML_ERROR // seems like a bug in jsbml RenderParser.processEndDocument() ... line 403 ... wrong constant for extension name
};
private String fileName;


@Ignore
@Test
public void testBioModelsCuratedImport() throws Exception{
HashMap<Integer,FAULT> faults = new HashMap();
faults.put(6, FAULT.RESERVED_WORD);
faults.put(15, FAULT.RESERVED_WORD);
faults.put(92, FAULT.RESERVED_WORD);
faults.put(114, FAULT.RESERVED_WORD);
faults.put(115, FAULT.RESERVED_WORD);
faults.put(117, FAULT.RESERVED_WORD);
faults.put(148, FAULT.RESERVED_WORD);
faults.put(154, FAULT.RESERVED_WORD);
faults.put(155, FAULT.RESERVED_WORD);
faults.put(154, FAULT.RESERVED_WORD);
faults.put(155, FAULT.RESERVED_WORD);
faults.put(156, FAULT.RESERVED_WORD);
faults.put(157, FAULT.RESERVED_WORD);
faults.put(158, FAULT.RESERVED_WORD);
faults.put(159, FAULT.RESERVED_WORD);
faults.put(274, FAULT.RESERVED_WORD);
faults.put(279, FAULT.RESERVED_WORD);
faults.put(282, FAULT.RESERVED_WORD);
faults.put(288, FAULT.RESERVED_WORD);
faults.put(346, FAULT.RESERVED_WORD);
faults.put(24, FAULT.DELAY);
faults.put(25, FAULT.DELAY);
faults.put(34, FAULT.DELAY);
faults.put(196, FAULT.DELAY);
faults.put(39, FAULT.NONINTEGER_STOICH);
faults.put(59, FAULT.NONINTEGER_STOICH);
faults.put(63, FAULT.NONINTEGER_STOICH);
faults.put(81, FAULT.NONINTEGER_STOICH);
faults.put(145, FAULT.NONINTEGER_STOICH);
faults.put(151, FAULT.NONINTEGER_STOICH);
faults.put(199, FAULT.NONINTEGER_STOICH);
faults.put(206, FAULT.NONINTEGER_STOICH);
faults.put(232, FAULT.NONINTEGER_STOICH);
faults.put(244, FAULT.NONINTEGER_STOICH);
faults.put(246, FAULT.NONINTEGER_STOICH);
faults.put(110, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(178, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(228, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(245, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(252, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(262, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(263, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(264, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(267, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(283, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(300, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(316, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(317, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(319, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(322, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(323, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(337, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(327, FAULT.EXPRESSION_BINDING_EXCEPTION);
faults.put(340, FAULT.XOR_MISSING);
faults.put(248, FAULT.EXPRESSION_BINDING_EXCEPTION);
faults.put(305, FAULT.EXPRESSION_BINDING_EXCEPTION);
faults.put(353, FAULT.NONINTEGER_STOICH);
faults.put(367, FAULT.RESERVED_WORD);
faults.put(382, FAULT.RESERVED_WORD);
faults.put(383, FAULT.NONINTEGER_STOICH);
faults.put(384, FAULT.NONINTEGER_STOICH);
faults.put(385, FAULT.NONINTEGER_STOICH);
faults.put(386, FAULT.NONINTEGER_STOICH);
faults.put(387, FAULT.NONINTEGER_STOICH);
faults.put(388, FAULT.NONINTEGER_STOICH);
faults.put(392, FAULT.NONINTEGER_STOICH);
faults.put(401, FAULT.NONINTEGER_STOICH);
faults.put(402, FAULT.RESERVED_WORD);
faults.put(403, FAULT.RESERVED_WORD);
faults.put(405, FAULT.INCONSISTENT_UNIT_SYSTEM);
public SBMLImporterTest(String fileName){
this.fileName = fileName;
}


public static Map<String, SBMLTestSuiteImportTest.FAULT> knownFaults() {
HashMap<String, SBMLTestSuiteImportTest.FAULT> faults = new HashMap<>();
// faults.put(6, FAULT.RESERVED_WORD);
return faults;
}

faults.put(539, FAULT.JSBML_ERROR);

File[] sbmlFiles = SBMLUnitTranslatorTest.getBiomodelsCuratedSBMLFiles();
// File[] sbmlFiles = new File[] {
// new File("/Users/schaff/Documents/workspace-maven/BioModels_Database-r30_pub-sbml_files/curated/BIOMD0000000001.xml"),
// new File("/Users/schaff/Documents/workspace-maven/BioModels_Database-r30_pub-sbml_files/curated/BIOMD0000000101.xml"),
// new File("/Users/schaff/Documents/workspace-maven/sbml-test-suite/cases/semantic/00001/00001-sbml-l3v1.xml")
// };
@Parameterized.Parameters
public static Collection<String> testCases() {
// IntPredicate expressionBindingFilter = (t) -> knownFaults().containsKey(t) && knownFaults().get(t) == FAULT.EXPRESSION_BINDING;
Predicate<String> allTestsFilter = (t) -> true;
// IntPredicate allFailures = (t) -> knownFaults().containsKey(t) && skipFilter.test(t);
Predicate<String> oneModelFilter = (t) -> t.equals("");
return Arrays.stream(SBMLTestFiles.allTestFiles).filter(allTestsFilter).collect(Collectors.toList());
}

@Test
public void testBioModelsCuratedImport() throws Exception{
InputStream sbmlInputStream = SBMLTestFiles.getSBMLTestCase(fileName);
System.out.println("testing "+fileName);
VCLogger vcl = new TLogger();
int start = 401;

for (int index=start; index<sbmlFiles.length; index++){
File sbmlFile = sbmlFiles[index];
int sbmlNumber = Integer.parseInt(sbmlFile.getName().substring(6).replace(".xml", ""));

if (faults.containsKey(sbmlNumber)){
System.err.println("skipping this model, "+faults.get(sbmlNumber).name());
continue;
}
System.out.println("testing "+sbmlFile);
SBMLImporter importer = new SBMLImporter(sbmlFile.getAbsolutePath(), vcl, true);
BioModel bioModel = importer.getBioModel();
}

SBMLImporter importer = new SBMLImporter(sbmlInputStream, vcl, true);
BioModel bioModel = importer.getBioModel();
bioModel.updateAll(false);
}

}
44 changes: 44 additions & 0 deletions vcell-core/src/test/java/org/vcell/sbml/SBMLTestFiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.vcell.sbml;

import org.junit.Assert;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Arrays;

public class SBMLTestFiles {

public final static String[] allTestFiles = new String[]{
// sbml-biomodels-db/
"BIOMD0000000734.xml",
};


public static InputStream getSBMLTestCase(String testFile) {
if (!Arrays.stream(allTestFiles).anyMatch(file -> file.equals(testFile))) {
throw new RuntimeException("file not found for VCell Published Test Suite test "+testFile);
}
try {
return getFileFromResourceAsStream("sbml-biomodels-db/"+testFile);
}catch (FileNotFoundException e){
throw new RuntimeException("failed to find test case file '"+testFile+"' in sbml-biomodels-db/: "+e.getMessage(), e);
}
}

private static InputStream getFileFromResourceAsStream(String fileName) throws FileNotFoundException {
InputStream inputStream = VcmlTestSuiteFiles.class.getResourceAsStream(fileName);
if (inputStream == null) {
throw new FileNotFoundException("file not found! " + fileName);
} else {
return inputStream;
}
}

@Test
public void test_read_sbmlFile() {
InputStream inputStream = getSBMLTestCase(allTestFiles[0]);
Assert.assertTrue(inputStream != null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.runners.Parameterized;
import org.vcell.sbml.vcell.SBMLImporter;

import javax.wsdl.Fault;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -36,12 +37,18 @@ public static Collection<Integer> testCases() {
faults.put(48, FAULT.COMPARTMENT_0D);
faults.put(49, FAULT.COMPARTMENT_0D);
faults.put(50, FAULT.COMPARTMENT_0D);
faults.put(51, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(52, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(53, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(96, FAULT.COMPARTMENT_1D);
faults.put(97, FAULT.COMPARTMENT_0D);
faults.put(99, FAULT.COMPARTMENT_1D);
faults.put(100, FAULT.COMPARTMENT_0D);
faults.put(102, FAULT.COMPARTMENT_1D);
faults.put(103, FAULT.COMPARTMENT_0D);
faults.put(104, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(105, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(106, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(153, FAULT.COMPARTMENT_1D);
faults.put(154, FAULT.COMPARTMENT_1D);
faults.put(155, FAULT.COMPARTMENT_0D);
Expand Down Expand Up @@ -197,12 +204,24 @@ public static Collection<Integer> testCases() {
faults.put(780, FAULT.ALGEBRAIC_RULES);
faults.put(844, FAULT.ALGEBRAIC_RULES);
faults.put(876, FAULT.ALGEBRAIC_RULES);
faults.put(901, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(902, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(903, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(904, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(905, FAULT.COMPARTMENT_1D);
faults.put(906, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(907, FAULT.COMPARTMENT_1D);
faults.put(908, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(909, FAULT.COMPARTMENT_1D);
faults.put(910, FAULT.COMPARTMENT_1D);
faults.put(911, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(912, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(913, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(914, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(915, FAULT.COMPARTMENT_1D);
faults.put(916, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(917, FAULT.COMPARTMENT_1D);
faults.put(918, FAULT.MATHGEN_STRUCTURESIZE_VAR); // StructureSize Variable is not supported at this time
faults.put(919, FAULT.COMPARTMENT_1D);
faults.put(937, FAULT.DELAY);
faults.put(938, FAULT.DELAY);
Expand Down Expand Up @@ -340,7 +359,8 @@ public enum FAULT {
INCONSISTENT_UNIT_SYSTEM,
EXPRESSION_BINDING_EXCEPTION,
XOR_MISSING,
JSBML_ERROR
JSBML_ERROR,
MATHGEN_STRUCTURESIZE_VAR
};


Expand All @@ -356,6 +376,7 @@ public void testSbmlTestSuiteImport() throws Exception{
SBMLImporter importer = new SBMLImporter(testFileInputStream, vcl, bValidateSBML);
try {
BioModel bioModel = importer.getBioModel();
bioModel.updateAll(false);
}catch (Exception e){
System.err.println("unexpected exception in test case "+testCase);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

public class SBMLUnitTranslatorTest {

public static File[] getBiomodelsCuratedSBMLFiles(){
File[] sbmlFiles = new File("/Users/schaff/Documents/workspace-maven/BioModels_Database-r30_pub-sbml_files/curated/").listFiles();
return sbmlFiles;
}

final String sbml_prefix =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<sbml xmlns=\"http://www.sbml.org/sbml/level3/version1/core\" level=\"3\" version=\"1\">\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public enum FAULT {
TOO_SLOW,
GEOMETRYSPEC_DIFFERENT,
NULL_POINTER_EXCEPTION,
DUPLICATE_METADATAID,
UNKNOWN_IDENTIFIER,
SBML_IMPORT_FAILURE,
SBML_DUPLICATE_ID,
SBML_STRUCTURE_MAPPING,
DIVIDE_BY_ZERO,
};

Expand Down Expand Up @@ -240,9 +243,9 @@ public static Collection<String> testCases() {
// Predicate<String> outOfMemoryFilter = (t) -> !outOfMemorySet().contains(t);
// Predicate<String> allTestsFilter = (t) -> true;
// Predicate<String> allFailures = (t) -> knownFaults().containsKey(t) && skipFilter.test(t);
Predicate<String> oneModelFilter = (t) -> t.equals("lumped_reaction_no_size_in_rate.vcml");
Predicate<String> oneModelFilter = (t) -> t.equals("biomodel_9171563.vcml");
Predicate<String> skipFilter = (t) -> !outOfMemorySet().contains(t) && !largeFileSet().contains(t);
return Arrays.stream(VcmlTestSuiteFiles.getVcmlTestCases()).filter(skipFilter).collect(Collectors.toList());
return Arrays.stream(VcmlTestSuiteFiles.getVcmlTestCases()).filter(oneModelFilter).collect(Collectors.toList());
}

@Test
Expand Down
24 changes: 23 additions & 1 deletion vcell-core/src/test/java/org/vcell/sbml/VcmlTestSuiteFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,28 @@
public class VcmlTestSuiteFiles {

private final static String[] allTestFiles = new String[]{
// vcml_testmodels/
"lumped_reaction_no_size_in_rate.vcml",
"lumped_reaction_proper_size_in_rate.vcml",
"lumped_reaction_local_size_in_rate.vcml",
"__export_adv_test.vcml",

// vcml_public/
"biomodel_6766041.vcml",
"biomodel_72815317.vcml",
"biomodel_9171563.vcml",
"biomodel_107874947.vcml",
"biomodel_100370227.vcml",
"biomodel_108026026.vcml",
"biomodel_124562627.vcml",
"biomodel_108657991.vcml",
"biomodel_101963252.vcml",
"biomodel_85831268.vcml",
"biomodel_97428682.vcml",
"biomodel_119943459.vcml",


// vcml_published/
"biomodel_100596964.vcml",
"biomodel_100961371.vcml",
"biomodel_101962320.vcml",
Expand Down Expand Up @@ -228,7 +246,11 @@ public static InputStream getVcmlTestCase(String testFile) {
try {
return getFileFromResourceAsStream("vcml_testmodels/"+testFile);
}catch (FileNotFoundException e2){
throw new RuntimeException("failed to find test case file in vcml_published/ and vcml_testmodels/: "+e2.getMessage(), e2);
try {
return getFileFromResourceAsStream("vcml_public/"+testFile);
}catch (FileNotFoundException e3){
throw new RuntimeException("failed to find test case file '"+testFile+"' in vcml_published/, vcml_testmodels/ and vcml_public/: "+e3.getMessage(), e3);
}
}
}
}
Expand Down
Loading

0 comments on commit a5802a0

Please sign in to comment.