use of cbit.util.xml.VCLogger in project vcell by virtualcell.
the class SBMLImporterTest method testImport.
@Test
public void testImport() throws XMLStreamException, IOException {
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);
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")
// };
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, false);
BioModel bioModel = importer.getBioModel();
}
}
use of cbit.util.xml.VCLogger in project vcell by virtualcell.
the class VCellClientTest method startupWithOpen.
private static VCDocument startupWithOpen(String fileName) {
VCDocument initialDocument = null;
try {
Document xmlDoc = XmlUtil.readXML(new File(fileName));
String vcmlString = XmlUtil.xmlToString(xmlDoc, false);
java.awt.Component parent = null;
VCLogger vcLogger = new TranslationLogger(parent);
initialDocument = XmlHelper.XMLToDocument(vcLogger, vcmlString);
} catch (Exception e) {
e.printStackTrace(System.out);
JOptionPane.showMessageDialog(null, e.getMessage(), "vcell startup error", JOptionPane.ERROR_MESSAGE);
}
return initialDocument;
}
use of cbit.util.xml.VCLogger in project vcell by virtualcell.
the class BNGWindowManager method importSbml.
/**
* Comment
*/
public void importSbml(String bngSbmlStr) {
if (bngSbmlStr == null || bngSbmlStr.length() == 0) {
throw new RuntimeException("SBMl string is empty, cannot import into VCell.");
}
//
// 1. Convert SBML string from BNG to SBML model, add unitDefintions to SBML model using VCell sbml compatible unit system
// 2. Import unit modified SBML model into VCell as biomodel
// 3. Enforce "cleaner" (looking) units on this imported biomodel (can use the units added to the sbml model above)
// 4. Convert all LumpedKinetics reactions into DistributedKinetics.
// 4. Convert this biomodel into vcml string and pass it into XMLInfo and then to RequestManager to open document.
//
ModelUnitSystem mus = ModelUnitSystem.createDefaultVCModelUnitSystem();
ModelUnitSystem sbmlCompatibleVCModelUnitSystem = ModelUnitSystem.createSBMLUnitSystem(mus.getVolumeSubstanceUnit(), mus.getVolumeUnit(), mus.getAreaUnit(), mus.getLengthUnit(), mus.getTimeUnit());
// display to user to change units if desired.
UnitSystemSelectionPanel unitSystemSelectionPanel = new UnitSystemSelectionPanel(true);
unitSystemSelectionPanel.initialize(sbmlCompatibleVCModelUnitSystem);
int retcode = DialogUtils.showComponentOKCancelDialog(getBngOutputPanel(), unitSystemSelectionPanel, "Select new unit system to import into VCell");
ModelUnitSystem forcedModelUnitSystem = null;
while (retcode == JOptionPane.OK_OPTION) {
try {
forcedModelUnitSystem = unitSystemSelectionPanel.createModelUnitSystem();
break;
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(getBngOutputPanel(), e.getMessage(), e);
retcode = DialogUtils.showComponentOKCancelDialog(getBngOutputPanel(), unitSystemSelectionPanel, "Select new unit system to import into VCell");
}
}
if (forcedModelUnitSystem == null) {
DialogUtils.showErrorDialog(getBngOutputPanel(), "Units are required for import into Virtual Cell.");
}
try {
// SBMLUnitTranslator.addUnitDefinitionsToSbmlModel(bngSbmlStr, forcedModelUnitSystem);
String modifiedSbmlStr = bngSbmlStr;
// Create a default VCLogger - SBMLImporter needs it
cbit.util.xml.VCLogger logger = new cbit.util.xml.VCLogger() {
@Override
public void sendMessage(Priority p, ErrorType et, String message) throws Exception {
System.err.println("LOGGER: msgLevel=" + p + ", msgType=" + et + ", " + message);
if (p == VCLogger.Priority.HighPriority) {
throw new RuntimeException("Import failed : " + message);
}
}
public void sendAllMessages() {
}
public boolean hasMessages() {
return false;
}
};
// import sbml String into VCell biomodel
File sbmlFile = File.createTempFile("temp", ".xml");
sbmlFile.deleteOnExit();
XmlUtil.writeXMLStringToFile(modifiedSbmlStr, sbmlFile.getAbsolutePath(), true);
org.vcell.sbml.vcell.SBMLImporter sbmlImporter = new SBMLImporter(sbmlFile.getAbsolutePath(), logger, false);
BioModel bioModel = sbmlImporter.getBioModel();
// enforce 'cleaner looking' units on vc biomodel (the process of adding unit defintion to sbml model messes up the units, though they are correct units (eg., 1e-6m for um).
BioModel modifiedBiomodel = ModelUnitConverter.createBioModelWithNewUnitSystem(bioModel, forcedModelUnitSystem);
// convert any reaction that has GeneralLumpedKinetics to GeneralKinetics
for (ReactionStep rs : modifiedBiomodel.getModel().getReactionSteps()) {
Kinetics kinetics = rs.getKinetics();
if (kinetics instanceof LumpedKinetics) {
rs.setKinetics(DistributedKinetics.toDistributedKinetics((LumpedKinetics) kinetics));
}
}
// convert biomodel to vcml string
String vcmlString = XmlHelper.bioModelToXML(modifiedBiomodel);
ExternalDocInfo externalDocInfo = new ExternalDocInfo(vcmlString);
if (externalDocInfo != null) {
getRequestManager().openDocument(externalDocInfo, this, true);
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Cound not convert BNG sbml string to VCell biomodel : ", e);
}
}
use of cbit.util.xml.VCLogger in project vcell by virtualcell.
the class SbmlVcmlConverter method main.
/**
* @param args -import or -export
*/
public static void main(String[] args) {
Logging.init();
ResourceUtil.setNativeLibraryDirectory();
if (args.length < 2 || args.length > 3) {
System.out.println("Usage:\n\t -export path_of_input_file\n\tOR\n\t -import path_of_input_file [-simulate]");
System.exit(1);
}
if (args.length > 2 && args[0].equals("-export")) {
System.out.println("Export cannot have arguments other than input file.");
System.out.println("Usage:\n\t -export path_of_input_file\n\tOR\n\t-import path_of_input_file [-simulate]");
System.exit(1);
}
try {
String pathName = args[1];
// Read xml file (Sbml or Vcml) into stringbuffer, pass the string into VCell's importer/exporter
String xmlString = getXMLString(pathName);
if (args[0].equals("-import")) {
if (args.length > 3 || (args.length == 3 && !args[2].equals("-simulate"))) {
System.out.println(args[2] + " : Unknown arguments for import; please check and re-run import command");
System.out.println("Usage:\n\t -import path_of_input_file [-simulate]");
System.exit(1);
}
boolean bSimulate = false;
if (args.length == 3 && args[2].equals("-simulate")) {
bSimulate = true;
}
// Create a default VCLogger - SBMLImporter needs it
cbit.util.xml.VCLogger logger = new cbit.util.xml.VCLogger() {
@Override
public void sendMessage(Priority p, ErrorType et, String message) {
System.err.println("LOGGER: msgLevel=" + p + ", msgType=" + et + ", " + message);
if (p == VCLogger.Priority.HighPriority) {
throw new RuntimeException("Import failed : " + message);
}
}
public void sendAllMessages() {
}
public boolean hasMessages() {
return false;
}
};
// invoke SBMLImporter, which returns a Biomodel, convert that to VCML using XMLHelper
try {
// import SBML model into VCML, store VCML string in 'fileName.vcml'
// Instantiate an SBMLImporter to get the speciesUnitsHash - to compute the conversion factor from VC->SB species units.
// and import SBML (sbml->bioModel)
org.vcell.sbml.vcell.SBMLImporter sbmlImporter = new org.vcell.sbml.vcell.SBMLImporter(pathName, logger, false);
BioModel bioModel = sbmlImporter.getBioModel();
// Hashtable<String, SBMLImporter.SBVCConcentrationUnits> speciesUnitsHash = sbmlImporter.getSpeciesUnitsHash();
// double timeFactor = sbmlImporter.getSBMLTimeUnitsFactor();
// convert biomodel to vcml and save to file.
String vcmlString = XmlHelper.bioModelToXML(bioModel);
String fileExtensionStr;
if (pathName.endsWith(".xml")) {
fileExtensionStr = ".xml";
} else if (pathName.endsWith(".sbml")) {
fileExtensionStr = ".sbml";
} else {
throw new RuntimeException("Unknown file extension for SBML file name; Exiting SbmlConverter.");
}
String vcmlFileName = pathName.replace(fileExtensionStr, ".vcml");
File vcmlFile = new File(vcmlFileName);
XmlUtil.writeXMLStringToFile(vcmlString, vcmlFile.getAbsolutePath(), true);
// If user doesn't choose to simulate, you are done.
if (!bSimulate) {
return;
}
// Generate math for lone simContext
SimulationContext simContext = (SimulationContext) bioModel.getSimulationContext(0);
MathDescription mathDesc = simContext.createNewMathMapping().getMathDescription();
simContext.setMathDescription(mathDesc);
// Create basic simulation, with IDA solver (set in solve method) and other defaults, and end time 'Te'
org.vcell.util.document.SimulationVersion simVersion = new org.vcell.util.document.SimulationVersion(new KeyValue("12345"), "name", new org.vcell.util.document.User("user", new KeyValue("123")), new org.vcell.util.document.GroupAccessNone(), // versionBranchPointRef
null, // branchID
new java.math.BigDecimal(1.0), new java.util.Date(), org.vcell.util.document.VersionFlag.Archived, "", null);
Simulation sim1 = new Simulation(simVersion, simContext.getMathDescription());
simContext.addSimulation(sim1);
sim1.setName("sim1");
// using a default end time of 10.0 secs, and a forcing default output time step of 0.01.
// If user wants anything different, user can modify the .idaInput file and re-run simulation separately.
// double newEndTime = endTime * timeFactor;
double newEndTime = endTime;
sim1.getSolverTaskDescription().setTimeBounds(new cbit.vcell.solver.TimeBounds(0, newEndTime));
TimeStep timeStep_1 = new TimeStep();
sim1.getSolverTaskDescription().setTimeStep(new TimeStep(timeStep_1.getMinimumTimeStep(), timeStep_1.getDefaultTimeStep(), newEndTime / 10000));
sim1.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec((newEndTime - 0) / numTimeSteps));
sim1.getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-10, 1e-12));
// save the new vcml with generated math and new sim in file named : fileName_IDA_simulation.vcml
String newVcmlString = XmlHelper.bioModelToXML(bioModel);
String newVcmlFileName = vcmlFile.getPath().replace(".vcml", "_IDA_simulation.vcml");
File newVcmlFile = new File(newVcmlFileName);
XmlUtil.writeXMLStringToFile(newVcmlString, newVcmlFile.getAbsolutePath(), true);
// Solve simulation, which also generates and saves the .idainput file and .csv
// SimSpec to get vars to solve and output in .csv
SimSpec simSpec = SimSpec.fromSBML(xmlString);
solveSimulation(new SimulationJob(sim1, 0, null), vcmlFile.getPath(), simSpec);
} catch (Exception e) {
e.printStackTrace(System.err);
// and an annotation saying why it failed.
try {
String fileExtensionStr;
if (pathName.endsWith(".xml")) {
fileExtensionStr = ".xml";
} else if (pathName.endsWith(".sbml")) {
fileExtensionStr = ".sbml";
} else {
throw new RuntimeException("Unknown file extension for SBML file name; Exiting SbmlConverter.");
}
String dummyVcmlFileName = pathName.replace(fileExtensionStr, ".vcml");
File dummyVcmlFile = new File(dummyVcmlFileName);
BioModel dummy_biomodel = new BioModel(null);
String dummyName = dummyVcmlFile.getName().substring(0, dummyVcmlFile.getName().indexOf(".vcml"));
dummy_biomodel.setName(dummyName);
dummy_biomodel.setDescription("SBML Model could not be automatically converted to VCML : " + e.getMessage());
String vcmlString = XmlHelper.bioModelToXML(dummy_biomodel);
XmlUtil.writeXMLStringToFile(vcmlString, dummyVcmlFile.getAbsolutePath(), true);
} catch (Exception e1) {
e.printStackTrace(System.err);
}
}
} else if (args[0].equals("-export")) {
try {
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(xmlString));
for (int i = 0; i < bioModel.getSimulationContexts().length; i++) {
SimulationContext simContext = bioModel.getSimulationContext(i);
if (simContext.getGeometry().getDimension() == 0 && !simContext.isStoch()) {
if (!simContext.getGeometryContext().isAllSizeSpecifiedPositive()) {
Structure structure = simContext.getModel().getStructure(0);
double structureSize = 1.0;
StructureMapping structMapping = simContext.getGeometryContext().getStructureMapping(structure);
StructureSizeSolver.updateAbsoluteStructureSizes(simContext, structure, structureSize, structMapping.getSizeParameter().getUnitDefinition());
}
// Export the application itself, with default overrides
String sbmlString = XmlHelper.exportSBML(bioModel, 2, 4, 0, false, simContext, null);
String filePath = pathName.substring(0, pathName.lastIndexOf("\\") + 1);
String sbmlFileName = TokenMangler.mangleToSName(bioModel.getName() + "_" + i);
File sbmlFile = new File(filePath + sbmlFileName + ".xml");
XmlUtil.writeXMLStringToFile(sbmlString, sbmlFile.getAbsolutePath(), true);
// Now export each simulation in the application that has overrides
Simulation[] simulations = bioModel.getSimulations(simContext);
for (int j = 0; j < simulations.length; j++) {
if (simulations[j].getMathOverrides().hasOverrides()) {
// Check for parameter scan and create simJob to pass into exporter
for (int k = 0; k < simulations[j].getScanCount(); k++) {
SimulationJob simJob = new SimulationJob(simulations[j], k, null);
sbmlString = XmlHelper.exportSBML(bioModel, 2, 4, 0, false, simContext, simJob);
String fileName = TokenMangler.mangleToSName(sbmlFileName + "_" + j + "_" + k);
sbmlFile = new File(filePath + fileName + ".xml");
XmlUtil.writeXMLStringToFile(sbmlString, sbmlFile.getAbsolutePath(), true);
}
}
}
}
}
System.out.println("Successfully translated model : " + pathName);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
System.exit(0);
} catch (IOException e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
use of cbit.util.xml.VCLogger in project vcell by virtualcell.
the class SBMLImporterTest method main.
public static void main(String[] args) {
Logging.init();
try {
VCLogger vcl = new TLogger();
SBMLImporter imp = new SBMLImporter("samp.sbml", vcl, false);
for (; ; ) {
/*
JFileChooser jfc = new JFileChooser( new File(System.getProperty("user.dir")));
int returnVal = jfc.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File f= jfc.getSelectedFile();
BioModel bm = sa.importSBML(f);
System.out.println(bm.getName());
}
*/
BioModel bm = imp.getBioModel();
System.out.println(bm.getName());
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
Aggregations