Updated Files for the Translator

This commit is contained in:
LukasBuecherl 2022-06-02 15:17:02 -06:00
parent 7672cd24b9
commit b435eb5c87
3 changed files with 348 additions and 5 deletions

View file

@ -90,7 +90,7 @@ public class Converter {
System.err.println("\t-esf Export SBML hierarchical models in a single output file.");
System.err.println("\t-f continue after first error");
System.err.println("\t-i allow SBOL document to be incomplete");
System.err.println("\t-l <language> specifies language (SBOL1/SBOL2/GenBank/FASTA/SBML) for output (default=SBOL2). To output FASTA or GenBank, no SBOL default URI prefix is needed.");
System.err.println("\t-l <language> specifies language (SBOL1/SBOL2/GenBank/FASTA/SBML/PRISM) for output (default=SBOL2). To output FASTA or GenBank, no SBOL default URI prefix is needed.");
System.err.println("\t-mf The name of the file that will be produced to hold the result of the main SBOL file, if SBOL file diff was selected.");
System.err.println("\t-n allow non-compliant URIs");
System.err.println("\t-o <outputFile> specifies the full path of the output file produced from the converter");
@ -105,6 +105,8 @@ public class Converter {
System.err.println("\t-r <url> The specified synbiohub repository the user wants VPR model generator to connect to");
System.err.println("\t -env <SBML environment file> is the complete directory path of the environmental file to instantiate to your model. This only works when VPR model generator is used");
System.err.println("\t-Cello This option is for dynamic modeling of Cello parts and parametrization");
System.err.println("\t-tmID Set the ID of the top SBML model");
System.err.println("\t-prism SBOL to PRISM converter");
System.exit(1);
}
@ -129,6 +131,7 @@ public class Converter {
boolean sbolV1out = false; //-l
boolean sbolV2out = false; //-l
boolean sbmlOut = false; //-l
boolean prismOut = false; //-l
boolean compliant = true; //-n
boolean noOutput = false; //-no
boolean typesInURI = false; //-t
@ -150,6 +153,7 @@ public class Converter {
String version = null; //-v
String urlVPR = ""; //The specified synbiohub repository the user wants VPR model generator to connect to.
String environment ="";
String topModelId = null;
HashSet<String> ref_sbolInputFilePath = new HashSet<String>(); //rsbol
@ -224,6 +228,11 @@ public class Converter {
sbolV2out = true;
++index;
}
else if (args[index+1].equals("PRISM"))
{
prismOut = true;
++index;
}
else
{
usage();
@ -309,6 +318,12 @@ public class Converter {
topEnvir = true;
environment = args[++index];
break;
case "-tmID":
if(index+1 >= args.length || (!args[index+1].isEmpty() && args[index+1].charAt(0)=='-'))
{
usage();
}
topModelId = args[++index];
default:
fullInputFileName = args[index];
}
@ -405,7 +420,30 @@ public class Converter {
boolean isDirectory = file.isDirectory();
if (!isDirectory)
{
if(inputIsSBML)
if(inputIsSBML && prismOut)
{
SBMLDocument inputSBMLDoc;
try
{
inputSBMLDoc = SBMLutilities.readSBML(fullInputFileName, null, null);
SBML2PRISM.convertSBML2PRISM(inputSBMLDoc, "First.prism");
}
catch (XMLStreamException e)
{
System.err.println("ERROR: Invalid XML file");
e.printStackTrace();
}
catch (IOException e)
{
System.err.println("ERROR: Unable to read or write file");
e.printStackTrace();
}
catch (BioSimException e) {
System.err.println("ERROR: Invalid SBML file");
}
}else if(inputIsSBML)
{
SBOLDocument outSBOLDoc = new SBOLDocument();
SBMLDocument inputSBMLDoc;
@ -544,7 +582,7 @@ public class Converter {
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}
/* TODO: PEDRO FIX ME
if (topModelId != null) {
SBMLDocument topModel = SBMLutilities.readSBML(vpr_output+".xml", null, null);
topModel.getModel().setId(topModelId);
@ -563,7 +601,7 @@ public class Converter {
e.printStackTrace();
}
}
*/
if (doVPR) {
if (topEnvir) {
SBMLDocument topEnvironment = SBMLutilities.readSBML(environment, null, null);

View file

@ -0,0 +1,305 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.ibiosim.conversion;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ModifierSpeciesReference;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLReader;
import org.sbml.jsbml.Species;
import org.sbml.jsbml.SpeciesReference;
import org.sbml.jsbml.ext.comp.CompModelPlugin;
import org.sbml.jsbml.ext.comp.CompSBMLDocumentPlugin;
import org.sbml.jsbml.ext.comp.CompSBasePlugin;
import org.sbml.jsbml.ext.comp.ExternalModelDefinition;
import org.sbml.jsbml.ext.comp.ReplacedBy;
import org.sbml.jsbml.ext.comp.ReplacedElement;
import org.sbolstandard.core2.AccessType;
import org.sbolstandard.core2.ComponentDefinition;
import org.sbolstandard.core2.DirectionType;
import org.sbolstandard.core2.EDAMOntology;
import org.sbolstandard.core2.FunctionalComponent;
import org.sbolstandard.core2.Interaction;
import org.sbolstandard.core2.Module;
import org.sbolstandard.core2.ModuleDefinition;
import org.sbolstandard.core2.RefinementType;
import org.sbolstandard.core2.SBOLConversionException;
import org.sbolstandard.core2.SBOLDocument;
import org.sbolstandard.core2.SBOLReader;
import org.sbolstandard.core2.SBOLValidationException;
import org.sbolstandard.core2.Sequence;
import org.sbolstandard.core2.SequenceOntology;
import org.sbolstandard.core2.SystemsBiologyOntology;
import org.sbolstandard.core2.TopLevel;
import edu.utah.ece.async.ibiosim.dataModels.biomodel.annotation.AnnotationUtility;
import edu.utah.ece.async.ibiosim.dataModels.biomodel.parser.BioModel;
import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.SBMLutilities;
import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants;
/**
* Perform conversion from SBML to PRISM.
*
* @author Lukas Buecherl
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class SBML2PRISM {
public static void GoodJob() //throws XMLStreamException, IOException, BioSimException
{
System.err.println("Good Job!");
}
public static void convertSBML2PRISM(SBMLDocument sbmlDoc, String filename) throws IOException
{
Model model = sbmlDoc.getModel();
File file = new File(filename);
System.err.println("Species: ");
for (int i = 0; i < model.getSpeciesCount(); i++)
{
Species species = model.getSpecies(i);
System.err.println(species);
}
System.err.println("Reactions: ");
for (int i = 0; i < model.getReactionCount(); i++)
{
Reaction reaction = model.getReaction(i);
System.err.println(reaction);
}
for (int i = 0; i < model.getConstraintCount(); i++)
{
System.err.println(SBMLutilities.convertMath2PrismProperty(model.getConstraint(i).getMath()));
}
FileWriter out = new FileWriter(file);
out.write("ctmc\n");
out.close();
/*if (s.isConstant()) {
// write const
} else {
// write modules
}
*/
}
/*
private int executePrism(String filename) throws IOException, InterruptedException, XMLStreamException, BioSimException {
int exitValue = 255;
String prop = null;
String directory = properties.getDirectory() + File.separator;
String out = properties.getModelFile().replace(".xml", "").replaceAll(".lpn", "").replaceAll(".sbml", "");
LPN lhpnFile = null;
// String root = properties.getRoot();
new File(filename.replace(".gcm", "").replace(".sbml", "").replace(".xml", "") + ".lpn").delete();
ArrayList<String> specs = new ArrayList<>();
ArrayList<Object[]> conLevel = new ArrayList<>();
retrieveSpeciesAndConLevels(specs, conLevel);
BioModel bioModel = BioModel.createBioModel(properties.getDirectory(), this);
bioModel.load(filename);
if (bioModel.flattenModel(true) != null) {
if (properties.getVerificationProperties().getLpnProperty() != null && !properties.getVerificationProperties().getLpnProperty().equals("")) {
prop = properties.getVerificationProperties().getLpnProperty();
} else {
prop = properties.getVerificationProperties().getConstraintProperty();
}
MutableString mutProp = new MutableString(prop);
lhpnFile = LPN.convertToLHPN(specs, conLevel, mutProp, bioModel);
prop = mutProp.getString();
if (lhpnFile == null) {
new File(properties.getDirectory() + File.separator + "running").delete();
return 0;
}
message.setLog("Saving SBML file as PRISM file:\n" + filename.replace(".xml", ".prism"));
this.notifyObservers(message);
message.setLog("Saving PRISM Property file:\n" + filename.replace(".xml", ".pctl"));
this.notifyObservers(message);
// TODO: LUKAS
// bioModel.convertSBML2PRISM(logFile, filename);
LPN.convertLPN2PRISM(logFile, lhpnFile, filename.replace(".xml", ".prism"), bioModel.getSBMLDocument());
Preferences biosimrc = Preferences.userRoot();
String prismCmd = biosimrc.get("biosim.general.prism", "");
if (prismCmd.contains("$prism")) {
prismCmd = prismCmd.replace("$prism", directory + out + ".prism");
} else {
prismCmd = prismCmd + " " + directory + out + ".prism";
}
if (prismCmd.contains("$pctl")) {
prismCmd = prismCmd.replace("$pctl", directory + out + ".pctl");
} else {
prismCmd = prismCmd + " " + directory + out + ".pctl";
}
message.setLog("Executing:\n" + prismCmd);
this.notifyObservers(message);
reb2sac = exec.exec(prismCmd, null, work);
String error = "", result = "";
try {
InputStream reb = reb2sac.getInputStream();
InputStreamReader isr = new InputStreamReader(reb);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith("Result")) {
result = line + '\n';
}
}
InputStream reb2 = reb2sac.getErrorStream();
int read = reb2.read();
while (read != -1) {
error += (char) read;
read = reb2.read();
}
br.close();
isr.close();
reb.close();
reb2.close();
}
catch (Exception e) {
// e.printStackTrace();
}
if (reb2sac != null) {
exitValue = reb2sac.waitFor();
}
if (!error.equals("")) {
message.setLog("Errors:\n" + error + "\n");
this.notifyObservers(message);
} else if (!result.equals("")) {
message.setLog(result);
this.notifyObservers(message);
} else {
throw new BioSimException("Verification Failed!", "Verification could not be executed. Something went wrong.");
}
exitValue = 0;
} else {
new File(directory + File.separator + "running").delete();
logFile.close();
exitValue = 0;
}
}
if (reb2sac != null) {
exitValue = reb2sac.waitFor();
}
return exitValue;
}
*?
// write pctl file using the SBML constraints
/*
File file = new File(filename);
try {
FileWriter out = new FileWriter(file);
out.write("ctmc\n");
for (String var : LPN.getVariables()) {
int i=0;
Place place;
String lastValue="";
while ((place = LPN.getPlace(var+i))!=null) {
Transition inTrans = place.getPreset()[0];
ExprTree assign = inTrans.getAssignTree(var);
lastValue = assign.toString();
i++;
}
Variable variable = LPN.getVariable(var);
String initValue = variable.getInitValue();
initValue = Long.toString((Math.round(Double.valueOf(initValue))));
if (lastValue.equals("")) {
out.write("const int "+var+"="+initValue+";\n");
} else {
out.write("module "+var+"_def\n");
out.write(" "+var+" : "+"[0.."+lastValue+"] init "+initValue+";\n");
i=0;
while ((place = LPN.getPlace(var+i))!=null) {
Transition inTrans = place.getPreset()[0];
ExprTree assign = inTrans.getAssignTree(var);
out.write(" [] "+var+"="+assign.toString()+" -> ");
boolean first = true;
for (Transition outTrans : place.getPostset()) {
assign = outTrans.getAssignTree(var);
ExprTree delay = outTrans.getDelayTree();
String rate = delay.toString("prism");
rate = rate.replace("exponential", "");
if (!first) out.write(" + ");
out.write(rate+":("+var+"'="+assign.toString()+")");
first = false;
}
out.write(";\n");
i++;
}
out.write("endmodule\n");
}
}
out.close();
for (int i = 0; i < sbml.getModel().getConstraintCount(); i++) {
file = new File(filename.replace(".prism", ".pctl"));
out = new FileWriter(file);
out.write(SBMLutilities.convertMath2PrismProperty(sbml.getModel().getConstraint(i).getMath()));
out.close();
}
}
catch (IOException e) {
//TODO: Leandro fix Me
//message.setErrorDialog("Error Writing File", "I/O error when writing PRISM file");
}
*/
}

View file

@ -13,7 +13,7 @@
*******************************************************************************/
package edu.utah.ece.async.ibiosim.dataModels.biomodel.parser;
import java.io.File;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;