Skip to content

Commit

Permalink
Change simulation entity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zakharc committed May 4, 2019
1 parent 9e6b4f6 commit 4b30cb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.jlibsedml.Output;
import org.jlibsedml.SEDMLDocument;
import org.jlibsedml.SedML;
import org.jlibsedml.execution.IProcessedSedMLSimulationResults;
import org.jlibsedml.execution.IRawSedmlSimulationResults;
import org.simulator.math.odes.MultiTable;
import org.simulator.sedml.SedMLSBMLSimulatorExecutor;

public class SEDMLSimulation extends AbstractSimulation {
Expand All @@ -33,13 +33,10 @@ public SimulationResult simulate(String path) throws Exception {
SedMLSBMLSimulatorExecutor exe = new SedMLSBMLSimulatorExecutor(sedml, wanted, sedmlDir);
Map<AbstractTask, List<IRawSedmlSimulationResults>> res = exe.run();
if (res == null || res.isEmpty() || !exe.isExecuted()) {
// XXX: throw Ex. and log
//
} else {
@SuppressWarnings("rawtypes")
Map results = exe.runSimulations();
@SuppressWarnings("unchecked")
MultiTable solution = (MultiTable) exe.processSimulationResults(wanted, results);
return new ResultAdapter(solution).getResult();
IProcessedSedMLSimulationResults results = exe.processSimulationResults(wanted, res);
return new ResultAdapter(results, sedml.getElementName()).getResult();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,51 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;

import javax.xml.stream.XMLStreamException;

import org.insilico.vissim.sbscl.factory.SimulationResult;
import org.insilico.vissim.sbscl.simulation.SimulationType;
import org.jlibsedml.Libsedml;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLReader;
import org.simulator.omex.OMEXArchive;

/**
* Some basic utilities which need to be in helping project (for shifting operations or
* other reasons), which are not toolkit dependent.
* Some basic utilities which need to be in helping project (for shifting
* operations or other reasons), which are not toolkit dependent.
*/
public class Utils {

/**
* Provides the type of corresponding simulation
*
* <p>
* Every simulation is eponymous to the type of the file specified.
* e.g SimulationType.SEDML is a simulation described with SED-ML file.
* Every simulation is eponymous to the type of the file specified. e.g
* SimulationType.SEDML is a simulation described with SED-ML file.
*
* @param path absolute path to the file
* @return {@link SimulationType}
* */
*/
public SimulationType getSimulationType(String path) {
if (Libsedml.isSEDML(new File(path)))
return SimulationType.SEDML;
if (isOMEXArchiv(path)) {
return SimulationType.OMEX;
}
if (isSBML(path)) {
return SimulationType.SBML;
}
if (isSBML(path)) {
return SimulationType.SBML;
}
if (Libsedml.isSEDML(new File(path)))
return SimulationType.SEDML;
if (isOMEXArchiv(path)) {
return SimulationType.OMEX;
}
return SimulationType.UNKNOWN_ENTITY;
}

/**
* Checks if provided file is a OMEXArchiv (combination of SED-ML
* and SBML file with additional data)
* Checks if provided file is a OMEXArchiv (combination of SED-ML and SBML file
* with additional data)
*
* @param path absolute path to the file
* */
*/
private boolean isOMEXArchiv(String path) {
OMEXArchive archive;
try {
Expand All @@ -59,20 +62,21 @@ private boolean isOMEXArchiv(String path) {
return Boolean.FALSE;
}
}

/**
* Checks if provided file is a SBML file
* XXX: more efficient check should be considered
* Checks if provided file is a SBML file XXX: more efficient check should be
* considered
*
* @param path absolute path to the file
* */
*/
private boolean isSBML(String path) {
try {
// this check should be changed
// reading file to define file type is inefficient
SBMLReader.read(path);
SBMLReader reader = new SBMLReader();
assertNotNull(reader.readSBML(path).getModel());
return Boolean.TRUE;
} catch (XMLStreamException e) {
} catch (XMLStreamException | IOException e) {
return Boolean.FALSE;
}
}
Expand Down

0 comments on commit 4b30cb8

Please sign in to comment.