FirstDraft

This commit is contained in:
LukasBuecherl 2022-06-24 06:42:38 +02:00
parent b435eb5c87
commit 75911f5931
2 changed files with 138 additions and 3 deletions

View file

@ -427,7 +427,7 @@ public class Converter {
try
{
inputSBMLDoc = SBMLutilities.readSBML(fullInputFileName, null, null);
SBML2PRISM.convertSBML2PRISM(inputSBMLDoc, "First.prism");
SBML2PRISM.convertSBML2PRISM(inputSBMLDoc, fullInputFileName);
}
catch (XMLStreamException e)
{

View file

@ -28,8 +28,10 @@ import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.sbml.jsbml.Compartment;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ModifierSpeciesReference;
import org.sbml.jsbml.Parameter;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLReader;
@ -84,8 +86,9 @@ public class SBML2PRISM {
public static void convertSBML2PRISM(SBMLDocument sbmlDoc, String filename) throws IOException
{
Model model = sbmlDoc.getModel();
File file = new File(filename);
File file = new File(filename.replace(".xml", ".sm"));
/*
System.err.println("Species: ");
for (int i = 0; i < model.getSpeciesCount(); i++)
{
@ -105,13 +108,145 @@ public class SBML2PRISM {
{
System.err.println(SBMLutilities.convertMath2PrismProperty(model.getConstraint(i).getMath()));
}
for (int i = 0; i < model.getParameterCount(); i++)
{
Parameter parameter = model.getParameter(i);
System.err.println(parameter);
}
*/
// Opening and writing preamble to the file
FileWriter out = new FileWriter(file);
out.write("// File generated by SBML-to-PRISM converter\n");
out.write("// Original file: " + filename + "\n");
out.write("// @GeneticLogicLab\n");
out.write("\n");
out.write("ctmc\n");
out.write("\n");
out.write("// const int MAX_AMOUNT = ADD VALUE \n");
out.write("\n");
// Identify compartments and their size
out.write("// Compartment size\n");
for (int i = 0; i < model.getCompartmentCount(); i++)
{
Compartment compartment = model.getCompartment(i);
out.write("const double " + compartment.getId() + " = " + compartment.getSize() + ";\n");
}
out.write("\n");
// Identify model parameters
out.write("// Model parameters\n");
for (int i = 0; i < model.getParameterCount(); i++)
{
Parameter parameter = model.getParameter(i);
out.write("const double "+ parameter.getId() + " = " + parameter.getValue() +"; // " + parameter.getName() + "\n"); // if not null name
}
out.write("\n");
// Identify model species
for (int i = 0; i < model.getSpeciesCount(); i++)
{
Species species = model.getSpecies(i);
out.write("// Species " + species.getId() + "\n");
out.write("// const int " + species.getId() + "_MAX = MAX_AMOUNT;\n");
out.write("module "+ species.getId() + "\n");
out.write("\n");
out.write(" // "+ species.getId() +" : " + "[0.." + species.getId() + "_MAX] init "+ species.getInitialAmount() + ";\n");
out.write(" "+ species.getId() + " : " + "int init " + species.getInitialAmount() + ";\n");
out.write("\n");
for (int j = 0; j < model.getReactionCount(); j++)
{
Reaction reaction = model.getReaction(j);
SpeciesReference reactant = reaction.getReactantForSpecies(species.getId());
SpeciesReference product = reaction.getProductForSpecies(species.getId());
if(reactant != null)
{
out.write(" // " + reaction.getId() + "\n");
out.write(" [" + reaction.getId() + "] " + species.getId() + " > " + (reactant.getStoichiometry() - 1) + " -> (" + species.getId() + "\'=" + species.getId() + "-" + reactant.getStoichiometry() + ");\n");
} else if (product != null)
{
out.write(" // " + reaction.getId() + "\n");
out.write(" [" + reaction.getId() + "] " + species.getId() + " >= " + "0 -> (" + species.getId() + "\'=" + species.getId() + "+" + product.getStoichiometry() + ");\n");
}
}
out.write("\n");
out.write("endmodule\n");
out.write("\n");
}
// math
out.write("// Reaction rates\n");
out.write("module reaction_rates\n");
out.write("\n");
for (int i = 0; i < model.getReactionCount(); i++)
{
Reaction reaction = model.getReaction(i);
out.write(" // " + reaction.getId() + ": -> ");
for(int j = 0; j < reaction.getProductCount(); j++)
{
out.write(reaction.getProduct(j).getSpecies() + " ");
}
out.write("\n");
out.write(" [" + reaction.getId() + "] " + SBMLutilities.convertMath2PrismProperty(reaction.getKineticLaw().getMath()) + " > 0 -> " + "(" + SBMLutilities.convertMath2PrismProperty(reaction.getKineticLaw().getMath()) + ") : true;\n");
out.write("\n");
}
out.write("endmodule\n");
out.write("\n");
out.write("// Reward structures (one per species)");
out.write("\n");
// Identify model species
for (int i = 0; i < model.getSpeciesCount(); i++)
{
Species species = model.getSpecies(i);
out.write("// Reward " + (i+1) + ": " + species.getId() + "\n");
out.write("rewards " + "\"" + species.getId() + "\" true : " + species.getId() + "; endrewards\n");
}
out.close();
// Write Properties File
File property = new File(filename.replace(".xml", ".props"));
FileWriter property_out = new FileWriter(property);
property_out.write("// File generated by SBML-to-PRISM converter\n");
property_out.write("// Original file: " + filename + "\n");
property_out.write("// @GeneticLogicLab\n");
property_out.write("\n");
for (int i = 0; i < model.getConstraintCount(); i++)
{
property_out.write(SBMLutilities.convertMath2PrismProperty(model.getConstraint(i).getMath()));
}
property_out.close();
/*if (s.isConstant()) {
// write const
} else {