Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmyers committed Nov 27, 2024
2 parents b11268e + bd67035 commit d4d40a9
Show file tree
Hide file tree
Showing 38 changed files with 15,112 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ biology.
##### Video Demo: [Tools Workflow](https://www.youtube.com/watch?v=g4xayzlyC2Q)
##### Contact: Chris Myers (@cjmyers) [email protected]

Contributor(s): Nathan Barker, Pedro Fontanarrosa, Scott Glass, Kevin Jones, Hiroyuki Kuwahara, Curtis Madsen, Nam Nguyen, Tramy Nguyen, Tyler Patterson, Nicholas Roehner, Jason Stevens, Leandro Watanabe, Michael Zhang, Zhen Zhang, and Zach Zundel.
Contributor(s): Nathan Barker, Lukas Buecherl, Pedro Fontanarrosa, Scott Glass, Kevin Jones, Hiroyuki Kuwahara, Curtis Madsen, Nam Nguyen, Tramy Nguyen, Tyler Patterson, Nicholas Roehner, Jason Stevens, Leandro Watanabe, Michael Zhang, Zhen Zhang, and Zach Zundel.

Active Developer(s): Pedro Fontanarrosa, Chris Myers, Tramy Nguyen, Leandro Watanabe.
Active Developer(s): Lukas Buecherl, Pedro Fontanarrosa, Chris Myers.

## Running iBioSim
1. Download the iBioSim tool from the release page [here](https://github.com/MyersResearchGroup/iBioSim/releases):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,6 @@ private int executePrism(String filename) throws IOException, InterruptedExcepti
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", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.lang.reflect.Method;

import javax.xml.stream.XMLStreamException;

import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLException;
import org.sbml.jsbml.SBMLWriter;
Expand All @@ -33,11 +35,13 @@
import org.virtualparts.VPRException;
import org.virtualparts.VPRTripleStoreException;

// import edu.utah.ece.async.ibiosim.analysis.properties.AnalysisProperties;
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.sbol.SBOLUtility;
import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.BioSimException;
import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.SBOLException;
import edu.utah.ece.async.ibiosim.dataModels.util.observe.BioObservable;

import org.sbml.jsbml.ext.comp.CompModelPlugin;
import org.sbml.jsbml.ext.comp.CompSBMLDocumentPlugin;
Expand Down Expand Up @@ -89,7 +93,7 @@ private static void usage()
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");
Expand All @@ -107,7 +111,7 @@ private static void usage()
System.err.println("\t-tmID Set the ID of the top SBML model");
System.exit(1);
}


/**
* The main method.
Expand All @@ -129,6 +133,7 @@ public static void main(String[] args)
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
Expand All @@ -137,7 +142,8 @@ public static void main(String[] args)
boolean isValidation = false; //indicate if only validate SBOL files
boolean topEnvir = false; // determines if there is a topEnvironment model to be instantiated
boolean CelloModel = false; // determines if Cello-based modeling should be done

boolean PrismUnbound = true; // determines if the prism model should be bound or unbound

String compFileResult = ""; //-cf
String compareFile = ""; //-e
String mainFileResult = ""; //-mf
Expand All @@ -151,7 +157,7 @@ public static void main(String[] args)
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

int index = 0;
Expand Down Expand Up @@ -188,6 +194,9 @@ public static void main(String[] args)
case "-t":
typesInURI = true;
break;
case "-bound":
PrismUnbound = false;
break;
case "-s":
if(index+1 >= args.length || args[index+1].equals("-"))
{
Expand Down Expand Up @@ -225,6 +234,11 @@ else if (args[index+1].equals("SBOL2"))
sbolV2out = true;
++index;
}
else if (args[index+1].equals("PRISM"))
{
prismOut = true;
++index;
}
else
{
usage();
Expand Down Expand Up @@ -412,7 +426,51 @@ else if(outputFileName.isEmpty() && !noOutput && !isValidation && !isDiffFile)
boolean isDirectory = file.isDirectory();
if (!isDirectory)
{
if(inputIsSBML)
if(inputIsSBML && prismOut)
{
SBMLDocument inputSBMLDoc;


try
{
// Read in the SBML
inputSBMLDoc = SBMLutilities.readSBML(fullInputFileName, null, null);

// Create BioModel to allow flattening
File path = new File(fullInputFileName);
BioModel bioModel = new BioModel(path.getParent());
bioModel.load(fullInputFileName);

// Check if BioModel is hierarchical by checking the number of submodels
bioModel.createCompPlugin();
if(bioModel.getListOfSubmodels().isEmpty())
{
// Not hierarchical
SBML2PRISM.convertSBML2PRISM(inputSBMLDoc, fullInputFileName, PrismUnbound);
}else {
// hierarchical, therefore flatten model
if (bioModel.flattenModel(true) != null) {
SBMLDocument sbml = bioModel.flattenModel(true);
SBML2PRISM.convertSBML2PRISM(sbml, fullInputFileName, PrismUnbound);
}
}

}
catch (XMLStreamException e)
{
System.err.println("ERROR: Invalid XML file");
e.printStackTrace();
}
catch (IOException e)
{
System.err.println("ERROR: Unable to read or write prism file");
e.printStackTrace();
}
catch (BioSimException e) {
System.err.println("ERROR: Invalid SBML file");
}

}else if(inputIsSBML)
{
SBOLDocument outSBOLDoc = new SBOLDocument();
SBMLDocument inputSBMLDoc;
Expand Down Expand Up @@ -497,13 +555,13 @@ else if(inputIsSBOL)
circuit_name = circuit_name.replace(".xml", "");
circuit_name = circuit_name.replace(".sbol", "");
String vpr_output = circuit_name + "_topModule";

if(!topLevelURIStr.isEmpty())
{
if (doVPR) {
TopLevel top = sbolDoc.getTopLevel(URI.create(topLevelURIStr));
SBOLDocument newSbolDoc = sbolDoc.createRecursiveCopy(top);

try {
newSbolDoc = VPRModelGenerator.generateModel(urlVPR, newSbolDoc, vpr_output);
//newSbolDoc.write("C:\\Users\\elros\\Desktop\\TestingConverter\\VPRoutput.xml");
Expand All @@ -516,18 +574,18 @@ else if(inputIsSBOL)
e.printStackTrace();
}
//generateSBMLFromSBOL(newSbolDoc, outputDir);

for (ModuleDefinition moduleDef : newSbolDoc.getRootModuleDefinitions())
{
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, newSbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}

else {
ModuleDefinition topModuleDef = sbolDoc.getModuleDefinition(URI.create(topLevelURIStr));
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, topModuleDef, sbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
ModuleDefinition topModuleDef = sbolDoc.getModuleDefinition(URI.create(topLevelURIStr));
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, topModuleDef, sbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}
else
Expand All @@ -545,20 +603,19 @@ else if(inputIsSBOL)
e.printStackTrace();
}
}

for (ModuleDefinition moduleDef : sbolDoc.getRootModuleDefinitions())
{
HashMap<String,BioModel> models = SBOL2SBML.generateModel(outputDir, moduleDef, sbolDoc, CelloModel);
SBMLutilities.exportSBMLModels(models, outputDir, outputFileName, noOutput, sbmlOut, singleSBMLOutput);
}
}

if (topModelId != null) {
SBMLDocument topModel = SBMLutilities.readSBML(outputDir + File.separator + vpr_output+ ".xml", null, null);
topModel.getModel().setId(topModelId);
SBMLWriter writer = new SBMLWriter();
try {
//SBMLutilities.removeUnusedNamespaces(sbml);
//SBMLutilities.removeUnusedNamespaces(sbml);
writer.writeSBMLToFile(topModel, outputDir + File.separator + topModelId + ".xml");
}
catch (SBMLException e) {
Expand All @@ -571,26 +628,25 @@ else if(inputIsSBOL)
e.printStackTrace();
}
}

if (doVPR) {
if (topEnvir) {
SBMLDocument topEnvironment = SBMLutilities.readSBML(environment, null, null);


CompSBMLDocumentPlugin docPlugin = (CompSBMLDocumentPlugin) topEnvironment.getPlugin("comp");
ExternalModelDefinition exte = docPlugin.getExternalModelDefinition("TopModel");
exte.setId(vpr_output);
exte.setSource(vpr_output + ".xml");
//exte.setId("topModule");
//exte.setSource("topModule.xml");

CompModelPlugin SBMLplugin = (CompModelPlugin) topEnvironment.getModel().getPlugin("comp");
Submodel top = SBMLplugin.getSubmodel("C1");
top.setModelRef(vpr_output);
//top.setModelRef("topModule");

SBMLWriter writing = new SBMLWriter();

writing.writeSBMLToFile(topEnvironment, outputDir + File.separator + "Simulation_Environment.xml");
}
}
Expand Down
Loading

0 comments on commit d4d40a9

Please sign in to comment.