本文整理汇总了Java中org.sbml.jsbml.SBMLReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java SBMLReader.read方法的具体用法?Java SBMLReader.read怎么用?Java SBMLReader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sbml.jsbml.SBMLReader
的用法示例。
在下文中一共展示了SBMLReader.read方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDocument
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
/**
* Gets the document.
*
* @return the document
* @throws NullPointerException the null pointer exception
* @throws XMLStreamException the XML stream exception
*/
protected SBMLDocument getDocument() throws NullPointerException, XMLStreamException{
JFileChooser chooser = new JFileChooser(OpenDialog.getLastDirectory());
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new FileNameExtensionFilter("SBML File(*.xml)", "xml"));
int returnVal = chooser.showOpenDialog(null);
if (returnVal != JFileChooser.APPROVE_OPTION)
throw new NullPointerException();
File f = chooser.getSelectedFile();
return SBMLReader.read(f.getAbsolutePath());
}
示例2: convertToFBCVersion2
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
private static SBMLDocument convertToFBCVersion2(String filename,SBMLDocument document) throws XMLStreamException, IOException, BioSimException
{
if (document.getDeclaredNamespaces().get("xmlns:"+FBCConstants.shortLabel)!=null &&
document.getDeclaredNamespaces().get("xmlns:"+FBCConstants.shortLabel).endsWith("1"))
{
if (!Executables.libsbmlFound)
{
throw new BioSimException("Unable convert FBC model from Version 1 to Version 2.", "Error Opening File");
}
//long numErrors = 0;
org.sbml.libsbml.SBMLReader reader = new org.sbml.libsbml.SBMLReader();
org.sbml.libsbml.SBMLDocument doc = reader.readSBML(filename);
/* create a new conversion properties structure */
ConversionProperties props = new ConversionProperties(new SBMLNamespaces(3, 1));
/* add an option that we want to strip a given package */
boolean strict = false;
props.addOption("convert fbc v1 to fbc v2", true, "convert fbc v1 to fbc v2");
props.addOption("strict", strict, "should the model be a strict one (i.e.: all non-specified bounds will be filled)");
/* perform the conversion */
if (doc.convert(props) != libsbml.LIBSBML_OPERATION_SUCCESS)
{
System.err.println("Conversion failed!");
doc.printErrors();
// System.exit(2);
}
org.sbml.libsbml.SBMLWriter writer = new org.sbml.libsbml.SBMLWriter();
writer.writeSBMLToFile(doc, filename);
document = SBMLReader.read(new File(filename));
} else {
SBMLutilities.getFBCModelPlugin(document.getModel(),true);
}
return document;
}
示例3: isSBML
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
private static boolean isSBML(File file)
{
try
{
SBMLReader.read(file);
}
catch (Exception e)
{
return false;
}
return true;
}
示例4: performModelChanges
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
public void performModelChanges(String stem) {
SEDMLDocument sedmlDoc;
sedmlDoc = biosim.getSEDMLDocument();
SedML sedml = sedmlDoc.getSedMLModel();
String taskId = simName;
if (stem != null && !stem.equals("")) {
taskId = taskId + "__" + stem;
}
AbstractTask task = sedml.getTaskWithId(taskId);
if (task == null)
return;
// Simulation simulation =
// sedml.getSimulation(task.getSimulationReference());
Model model = sedml.getModelWithId(task.getModelReference());
SBMLWriter Xwriter = new SBMLWriter();
try {
SBMLDocument sbmlDoc = SBMLReader
.read(new File(path + File.separator + simName + File.separator + filename));
//createDataGenerators(sbmlDoc.getModel(), sedml, taskId);
//SEDMLutilities.removeDataGeneratorsByTaskId(sedml, taskId);
biosim.writeSEDMLDocument();
if (model.getListOfChanges().size() == 0)
return;
Xwriter.write(applyChanges(sedmlDoc, sbmlDoc, model),
path + File.separator + simName + File.separator + filename);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例5: loadSBMLFromBuffer
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
private void loadSBMLFromBuffer(StringBuffer buffer) {
try {
SBMLDocument doc = SBMLReader.read(buffer.toString());
biomodel.setSBMLDocument(doc);
biomodel.setSBMLLayout(SBMLutilities.getLayoutModelPlugin(doc.getModel()));
biomodel.setSBMLFBC(SBMLutilities.getFBCModelPlugin(doc.getModel(), true));
biomodel.setSBMLComp(SBMLutilities.getCompSBMLDocumentPlugin(doc));
biomodel.setSBMLCompModel(SBMLutilities.getCompModelPlugin(doc.getModel()));
} catch (XMLStreamException e) {
e.printStackTrace();
}
biomodel.loadDefaultEnclosingCompartment();
biomodel.loadGridSize();
grid.createGrid(null);
}
示例6: performAnalysis
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
private void performAnalysis(String modelFileName, String analysisId) throws Exception {
SedML sedml = sedmlDocument.getSedMLModel();
AbstractTask task = sedml.getTaskWithId(analysisId);
if (task == null) return;
org.jlibsedml.Model model = sedml.getModelWithId(task.getModelReference());
SBMLDocument sbmlDoc = SBMLReader.read(new File(root + File.separator + modelFileName));
if (model.getListOfChanges().size() != 0) {
try {
sbmlDoc = applyChanges(sedmlDocument, sbmlDoc, model);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SBMLWriter Xwriter = new SBMLWriter();
Xwriter.write(sbmlDoc, root + File.separator + "_" + modelFileName);
AnalysisProperties properties;
properties = new AnalysisProperties(analysisId, modelFileName, root, false);
properties.addObserver(this);
BioModel biomodel = BioModel.createBioModel(root + File.separator, this);
biomodel.load(root + File.separator + "_" + modelFileName);
SBMLDocument flatten = biomodel.flattenModel(true);
String newFilename = root + File.separator + analysisId + File.separator + modelFileName;
SBMLWriter.write(flatten, newFilename, ' ', (short) 2);
File tempFile = new File(root + File.separator + "_" + modelFileName);
tempFile.delete();
properties.setId(analysisId);
AnalysisPropertiesLoader.loadSEDML(sedmlDocument, "", properties);
AnalysisPropertiesWriter.createProperties(properties);
Run run = new Run(properties);
run.addObserver(this);
run.execute();
}
示例7: readSBML
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
public static SBMLDocument readSBML(String filename, BioObservable observable, BioObserver observer) throws XMLStreamException, IOException, BioSimException
{
SBMLDocument document = null;
document = SBMLReader.read(new File(filename));
if (document.getModel().isSetId())
{
document.getModel().setId(document.getModel().getId().replace(".", "_"));
}
if (document.getLevel() < GlobalConstants.SBML_LEVEL || document.getVersion() < GlobalConstants.SBML_VERSION)
{
if (!Executables.libsbmlFound)
{
ArrayList<SBase> sbmlElements = getListOfAllElements(document);
for (SBase sbase : sbmlElements) {
if (sbase instanceof Reaction) {
Reaction r = (Reaction) sbase;
if (r.isSetFast()) {
r.unsetFast();
}
}
}
document.setLevelAndVersion(GlobalConstants.SBML_LEVEL, GlobalConstants.SBML_VERSION, false);
// SBMLWriter Xwriter = new SBMLWriter();
// Xwriter.writeSBMLToFile(document, filename);
return document;
}
long numErrors = 0;
org.sbml.libsbml.SBMLReader reader = new org.sbml.libsbml.SBMLReader();
org.sbml.libsbml.SBMLDocument doc = reader.readSBML(filename);
numErrors = doc.checkL3v2Compatibility();
if (numErrors > 0)
{
String msg = "Conversion to SBML level " + GlobalConstants.SBML_LEVEL + " version " + GlobalConstants.SBML_VERSION
+ " produced the errors listed below.";
msg += "It is recommended that you fix them before using these models or you may get unexpected results.\n\n";
msg += "--------------------------------------------------------------------------------------\n";
msg += filename;
msg += "\n--------------------------------------------------------------------------------------\n\n";
for (int i = 0; i < numErrors; i++)
{
String error = doc.getError(i).getMessage();
msg += i + ":" + error + "\n";
}
Message message = new Message();
message.setScrollableErrorDialog("SBML Conversion Errors and Warnings", msg);
if(observable != null)
{
observable.notifyObservers(message);
}
if(observer != null)
{
observer.update(message);
}
}
convertToL3(doc);
doc.setLevelAndVersion(GlobalConstants.SBML_LEVEL, GlobalConstants.SBML_VERSION, false);
/*
* for (int i = 0; i < doc.getNumErrors(); i++) {
* System.out.println(doc.getError(i).getMessage()); }
*/
org.sbml.libsbml.SBMLWriter writer = new org.sbml.libsbml.SBMLWriter();
writer.writeSBMLToFile(doc, filename);
document = SBMLReader.read(new File(filename));
}
document = convertToFBCVersion2(filename,document);
return document;
}
示例8: estimate
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
/**
* This function is used to execute parameter estimation from a given SBML file. The input model serves
* as a template and the existing parameters in the model will set the bounds to which parameter estimation will use.
* <p>
* In addition, the SBML file is used for simulation when estimating the values of the parameters.
*
* @param SBMLFileName: the input SBML file
* @param root: the directory where the experimental data is located
* @param parameterList: the list of parameters that needs to have the value estimated.
* @param experiments: data object that holds the experimental data.
* @param speciesCollection: data object that holds the species in the model.
* @return A new SBMLDocument containing the new parameter values.
* @throws IOException - when a file cannot be read or written.
* @throws XMLStreamException - when an SBML file cannot be parsed.
* @throws BioSimException - when simulation encounters a problem.
*/
public static SBMLDocument estimate(String SBMLFileName, String root, List<String> parameterList, Experiments experiments, SpeciesCollection speciesCollection) throws IOException, XMLStreamException, BioSimException
{
int numberofparameters = parameterList.size();
int sp = 0;
int n = experiments.getExperiments().get(0).size() - 1;
double ep = experiments.getExperiments().get(0).get(n).get(0);
double[] lowerbounds = new double[numberofparameters];
double[] upperbounds = new double[numberofparameters];
HierarchicalSimulation sim = new HierarchicalODERKSimulator(SBMLFileName, root, 0);
sim.initialize(randomSeed, 0);
for (int i = 0; i < numberofparameters; i++)
{
lowerbounds[i] = sim.getTopLevelValue(parameterList.get(i)) / 100;
upperbounds[i] = sim.getTopLevelValue(parameterList.get(i)) * 100;
}
Modelsettings M1 = new Modelsettings(experiments.getExperiments().get(0).get(0), speciesCollection.size(), sp, (int) ep, lowerbounds, upperbounds, false);
// Objective objective1 = new ObjectiveSqureError(M1,0.1);
EvolutionMethodSetting EMS = new EvolutionMethodSetting();
ObjectiveSqureError TP = new ObjectiveSqureError(sim, experiments, parameterList, speciesCollection, M1, 0.1);
SRES sres = new SRES(TP, EMS);
SRES.Solution solution = sres.run(200).getBestSolution();
// TODO: report results: take average of error
// TODO: weight mean square error. Add small value
SBMLDocument doc = SBMLReader.read(new File(SBMLFileName));
Model model = doc.getModel();
for(int i = 0; i < parameterList.size(); i++)
{
Parameter parameter = model.getParameter(parameterList.get(i));
if(parameter != null)
{
parameter.setValue(solution.getFeatures()[i]);
}
}
System.out.println(solution.toString());
return doc;
}
示例9: runSEDML
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
private void runSEDML(String sedML, AnalysisProperties properties, Run run, HashMap<String, String> userValues) throws Exception
{
File sedmlFile = new File(sedML);
SEDMLDocument sedmlDoc = Libsedml.readDocument(sedmlFile);
SedML sedml = sedmlDoc.getSedMLModel();
List<AbstractTask> listOfTasks = sedml.getTasks();
String root = properties.getRoot();
for(AbstractTask task : listOfTasks)
{
/* Load from SED-ML */
properties.setId(task.getId());
org.jlibsedml.Model model = sedml.getModelWithId(task.getModelReference());
String modelSource = sedml.getModelWithId(task.getModelReference()).getSource();
while (sedml.getModelWithId(modelSource)!=null) {
modelSource = sedml.getModelWithId(modelSource).getSource();
}
if (modelSource.indexOf("/")!=-1) {
modelSource = modelSource.substring(modelSource.lastIndexOf("/")+1);
}
SBMLDocument sbmlDoc = SBMLReader.read(new File(root + File.separator + modelSource));
if (model.getListOfChanges().size() != 0) {
try {
sbmlDoc = applyChanges(sedmlDoc, sbmlDoc, model);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SBMLWriter Xwriter = new SBMLWriter();
Xwriter.write(sbmlDoc, root + File.separator + modelSource + "_");
properties.setModelFile(modelSource);
AnalysisPropertiesLoader.loadSEDML(sedmlDoc, "", properties);
// File analysisDir = new File(root + File.separator + task.getId());
/* Replace values with properties given by user */
loadUserValues(userValues);
File analysisDir = new File(properties.getDirectory());
if (!analysisDir.exists())
{
new File(properties.getDirectory()).mkdir();
}
/* Flattening happens here */
BioModel biomodel = BioModel.createBioModel(root, this);
biomodel.addObserver(this);
biomodel.load(root + File.separator + modelSource + "_");
SBMLDocument flatten = biomodel.flattenModel(true);
String newFilename = root + File.separator + task.getId() + File.separator + modelSource;
SBMLWriter.write(flatten, newFilename, ' ', (short) 2);
AnalysisPropertiesWriter.createProperties(properties);
run.execute();
}
for (Output output : sedml.getOutputs())
{
if (output.isPlot2d())
{
// GraphData.createTSDGraph(sedmlDoc,GraphData.TSD_DATA_TYPE,root,null,output.getId(),
// root + File.separator + output.getId()+".png",GraphData.PNG_FILE_TYPE,650,400);
GraphData.createTSDGraph(sedmlDoc,properties.getSimulationProperties().getPrinter_id(),root,null,output.getId(),
properties.getDirectory() + File.separator + output.getId()+".png",GraphData.PNG_FILE_TYPE,650,400);
}
else if (output.isReport())
{
// GraphData.createHistogram(sedmlDoc,GraphData.TSD_DATA_TYPE,root,null,output.getId(),
// root + File.separator + output.getId()+".png",GraphData.PNG_FILE_TYPE,650,400);
GraphData.createHistogram(sedmlDoc,properties.getSimulationProperties().getPrinter_id(),root,null,output.getId(),
properties.getDirectory() + File.separator + output.getId()+".png",GraphData.PNG_FILE_TYPE,650,400);
}
}
}
示例10: BaseLayoutConverter
import org.sbml.jsbml.SBMLReader; //导入方法依赖的package包/类
/**
* Instantiates a new base layout converter.
*
* @param file
* the file
* @throws XMLStreamException
* the XML stream exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public BaseLayoutConverter(File file) throws XMLStreamException, IOException {
document = SBMLReader.read(file);
outputFileName = SBMLUtil.createOutputFileName(file);
}