Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Nov 4, 2023
1 parent 203ed08 commit 89254fe
Show file tree
Hide file tree
Showing 20 changed files with 16,153 additions and 116 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 @@ -905,7 +905,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,137 +1,61 @@
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.experimental.categories.Category;
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;
import org.vcell.test.SBML_IT;

@Category(SBML_IT.class)
@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);
}

}
Loading

0 comments on commit 89254fe

Please sign in to comment.