Added comments to SBML2PRISM
This commit is contained in:
parent
5453e5031d
commit
b8cad2fe48
1 changed files with 41 additions and 8 deletions
|
|
@ -135,6 +135,8 @@ public class SBML2PRISM {
|
|||
// Identify model species
|
||||
for (int i = 0; i < model.getSpeciesCount(); i++)
|
||||
{
|
||||
// Write out syntax
|
||||
// For function checkReservedKeywordPrism see below
|
||||
Species species = model.getSpecies(i);
|
||||
out.write("// Species " + checkReservedKeywordPrism(species.getId()) + "\n");
|
||||
out.write("// const int " + checkReservedKeywordPrism(species.getId()) + "_MAX = MAX_AMOUNT;\n");
|
||||
|
|
@ -144,10 +146,12 @@ public class SBML2PRISM {
|
|||
out.write(" "+ checkReservedKeywordPrism(species.getId()) + " : " + "int init " + (int) (species.getInitialAmount()) + ";\n");
|
||||
out.write("\n");
|
||||
|
||||
// Iterate over reactions
|
||||
for (int j = 0; j < model.getReactionCount(); j++)
|
||||
{
|
||||
Reaction reaction = model.getReaction(j);
|
||||
|
||||
// Identify reactants and products
|
||||
SpeciesReference reactant = reaction.getReactantForSpecies(species.getId());
|
||||
SpeciesReference product = reaction.getProductForSpecies(species.getId());
|
||||
|
||||
|
|
@ -169,8 +173,7 @@ public class SBML2PRISM {
|
|||
|
||||
}
|
||||
|
||||
// Identify reaction rates
|
||||
|
||||
// Identify reaction rate
|
||||
out.write("// Reaction rates\n");
|
||||
out.write("module reaction_rates\n");
|
||||
out.write("\n");
|
||||
|
|
@ -178,6 +181,8 @@ public class SBML2PRISM {
|
|||
for (int i = 0; i < model.getReactionCount(); i++)
|
||||
{
|
||||
Reaction reaction = model.getReaction(i);
|
||||
|
||||
// Write state transitions
|
||||
out.write(" // " + checkReservedKeywordPrism(reaction.getId()) + ": -> ");
|
||||
for(int j = 0; j < reaction.getProductCount(); j++)
|
||||
{
|
||||
|
|
@ -185,6 +190,7 @@ public class SBML2PRISM {
|
|||
}
|
||||
out.write("\n");
|
||||
|
||||
// Get the math for the reaction rate
|
||||
out.write(" [" + checkReservedKeywordPrism(reaction.getId()) + "] " + checkReserveKeywordMath(SBMLutilities.convertMath2PrismProperty(reaction.getKineticLaw().getMath()), model) + " > 0 -> " + "(" + checkReserveKeywordMath(SBMLutilities.convertMath2PrismProperty(reaction.getKineticLaw().getMath()), model) + ") : true;\n");
|
||||
out.write("\n");
|
||||
|
||||
|
|
@ -192,11 +198,12 @@ public class SBML2PRISM {
|
|||
out.write("endmodule\n");
|
||||
|
||||
out.write("\n");
|
||||
|
||||
// Identify rewards
|
||||
out.write("// Reward structures (one per species)");
|
||||
out.write("\n");
|
||||
|
||||
|
||||
// Identify rewards
|
||||
for (int i = 0; i < model.getSpeciesCount(); i++)
|
||||
{
|
||||
Species species = model.getSpecies(i);
|
||||
|
|
@ -212,6 +219,7 @@ public class SBML2PRISM {
|
|||
File property = new File(filename.replace(".xml", ".props"));
|
||||
FileWriter property_out = new FileWriter(property);
|
||||
|
||||
// Property preamble
|
||||
property_out.write("// File generated by SBML-to-PRISM converter\n");
|
||||
property_out.write("// Original file: " + filename + "\n");
|
||||
property_out.write("// @GeneticLogicLab\n");
|
||||
|
|
@ -219,7 +227,7 @@ public class SBML2PRISM {
|
|||
|
||||
for (int i = 0; i < model.getConstraintCount(); i++)
|
||||
{
|
||||
System.err.println(checkReserveKeywordMath(SBMLutilities.convertMath2PrismProperty(model.getConstraint(i).getMath()), model));
|
||||
// Get and write translation of constraint
|
||||
property_out.write(checkReserveKeywordMath(SBMLutilities.convertMath2PrismProperty(model.getConstraint(i).getMath()), model));
|
||||
}
|
||||
|
||||
|
|
@ -227,16 +235,24 @@ public class SBML2PRISM {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Check for reserved keywords as species names
|
||||
* Input: (String) NameOfSpecies
|
||||
* Output: (String) _NameOfSpecies
|
||||
*
|
||||
* Function checks if the name of a species is also a reserved keyword in the prism language. If that is the case, the species name is replaced
|
||||
* by the species name lead by an underscore.
|
||||
*/
|
||||
private static String checkReservedKeywordPrism(String speciesname)
|
||||
{
|
||||
|
||||
// List of reserved keywords in the prism language
|
||||
List<String> keywords = Arrays.asList("A", "bool", "clock", "const", "ctmc", "C", "double", "dtmc", "E", "endinit", "endinvariant", "endmodule",
|
||||
"endobservables", "endrewards", "endsystem", "false", "formula", "filter", "func", "F", "global", "G", "init", "invariant", "I", "int", "label",
|
||||
"max", "mdp", "min", "module", "X", "nondeterministic", "observable", "observables", "of", "Pmax", "Pmin", "P", "pomdp", "popta", "probabilistic",
|
||||
"prob", "pta", "rate", "rewards", "Rmax", "Rmin", "R", "S", "stochastic", "system", "true", "U", "W");
|
||||
|
||||
// Check if species name is in the list
|
||||
if (keywords.contains(speciesname))
|
||||
{
|
||||
return "_" + speciesname;
|
||||
|
|
@ -244,16 +260,27 @@ public class SBML2PRISM {
|
|||
return speciesname;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check for reserved keywords as species names in math properties
|
||||
* Input: (String) NameOfSpecies, model sbmlDoc.getModel();
|
||||
* Output: (String) _NameOfSpecies
|
||||
*
|
||||
* Function checks if the name of a species in a math function is also a reserved keyword in the prism language. If that is the case, the species name in the
|
||||
* function is replaced by the species name lead by an underscore.
|
||||
*/
|
||||
private static String checkReserveKeywordMath(String math, Model model) {
|
||||
|
||||
// List of reserved keywords in the prism language
|
||||
List<String> keywords = Arrays.asList("A", "bool", "clock", "const", "ctmc", "C", "double", "dtmc", "E", "endinit", "endinvariant", "endmodule",
|
||||
"endobservables", "endrewards", "endsystem", "false", "formula", "filter", "func", "F", "global", "G", "init", "invariant", "I", "int", "label",
|
||||
"max", "mdp", "min", "module", "X", "nondeterministic", "observable", "observables", "of", "Pmax", "Pmin", "P", "pomdp", "popta", "probabilistic",
|
||||
"prob", "pta", "rate", "rewards", "Rmax", "Rmin", "R", "S", "stochastic", "system", "true", "U", "W");
|
||||
|
||||
// Declaration of new string list
|
||||
ArrayList<String> speciesString = new ArrayList<String>();
|
||||
|
||||
// Iterating over species, if species name is a reserved keyword add it to list speciesString
|
||||
for (int i = 0; i < model.getSpeciesCount(); i++)
|
||||
{
|
||||
Species species = model.getSpecies(i);
|
||||
|
|
@ -267,14 +294,20 @@ public class SBML2PRISM {
|
|||
|
||||
//System.err.println(speciesString);
|
||||
|
||||
// Iterate over list and replace species name
|
||||
for(int i = 0; i < keywords.size(); i++)
|
||||
{
|
||||
if(speciesString.contains(keywords.get(i)))
|
||||
{
|
||||
// Replace species in math equations
|
||||
// In equations species names are lead by a space
|
||||
String Target = " " + keywords.get(i);
|
||||
//System.err.println(Target);
|
||||
math = math.replace(Target, "_" + keywords.get(i));
|
||||
//System.err.println(math);
|
||||
|
||||
// Replace species names in property files
|
||||
// In property files species names are lead by a (
|
||||
String TargetProperty = "(" + keywords.get(i);
|
||||
math = math.replace(TargetProperty, "(_" + keywords.get(i));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue