jigcell.xpp
Class SBMLToStochKitTranslator

java.lang.Object
  extended by jigcell.xpp.SBMLToStochKitTranslator
Direct Known Subclasses:
EnsembleLauncher, StochKitLauncher

public class SBMLToStochKitTranslator
extends java.lang.Object

Translate SBML file produced from JigCell into C++ file as input of Stochkit feature history: supports algebaric rule, and assignment rule - mediate variable assignment (seems useless and causes error) * support for pow + support for function * support for safe name check + support for events * adjust rules * clean up the code * assign event number by calculating power in vivo v1.4 * make name c++ safe by edit SymbolTable.makeFortranSafe * special treatment for Vn, should be changed later v1.5 + execute stochkit + add "double t" to eventAction method v1.6 * LOG and SQRT to log and sqrt * eliminate NaN in parameter declaration. * Vector x = x1 in Propensity function * add parameter decalaration in events v1.7 * changed the order of species index to confirm with RunManager v1.8

Author:
wpy last edited: 7-26-2007

Nested Class Summary
private  class SBMLToStochKitTranslator.LocalRule
           
 
Field Summary
private  java.lang.String code
           
private  java.io.File cwd
           
static java.lang.String DEFAULT_LOWER_BOUND
           
protected static java.lang.String DEFAULT_MODEL_NAME
           
static java.lang.String DEFAULT_NML_FILENAME
           
static java.lang.String DEFAULT_UPPER_BOUND
           
private  java.util.Hashtable defaultInitialConditionsContents
           
static java.lang.String EST_TASK
           
private static java.lang.String EXTRACT_PARAMS
           
static java.lang.String INDENT
           
private static int MAX_CHARS_PER_LINE
           
private static int MAX_EXP_NAME_LENGTH
           
private static int MAX_ID_LENGTH
           
private  jigcell.sbml2.Model model
           
private  SymbolTable mySymbol
           
private  int numRuleVars
           
private  int numVars
           
static java.lang.String PRE_RUN
           
(package private)  java.util.Hashtable reactionIndex
           
private  java.util.ArrayList ruleArray
           
private  java.util.Hashtable ruleHash
           
static java.lang.String RUN_PE
           
static java.lang.String SIM_TASK
           
(package private)  java.util.Hashtable speciesIndex
           
static java.lang.String STATUS
           
private  SymbolTable symbolTable
           
(package private)  java.io.File targetFile
           
static java.lang.String TRANSFORM_TASK
           
private static java.lang.String usage
          Allow SBMLTranslator to be run independent from parent programs as a command line tool.
private static java.lang.String VERSION_MESG
           
 
Constructor Summary
SBMLToStochKitTranslator(jigcell.sbml2.Model model)
          Creates a SBMLTranslator instance ready to create C++ code for model.
SBMLToStochKitTranslator(java.io.Reader reader)
          Creates a SBMLTranslator instance ready to create Fortran code from the SBML read from reader.
SBMLToStochKitTranslator(java.lang.String fileName)
          Creates a SBMLTranslator instance ready to create Fortran code from the SBML file fileName.
 
Method Summary
private static java.lang.String appendAndBreak_(java.lang.String s1, java.lang.String s2, boolean addIndent)
          Underlying method for appendAndBreak and appendAndBreakNoIndent.
private static java.lang.String appendAndBreak(java.lang.String s1, java.lang.String s2)
          Returns s1 and s2 appended with line breaks added if the resulting string is longer than MAX_CHARS_PER_LINE characters.
private static java.lang.String appendAndBreakNoIndent(java.lang.String s1, java.lang.String s2)
          Like appendAndBreak but no additional white space is added when the second line is created.
private static java.lang.String breakAFortranString(int maxWidth, java.lang.String prefix, java.lang.String fortranString, java.lang.String suffix, java.lang.String indent)
          Builds a Fortran expression and adds breaks as necessary to keep the maximum line width below maxWidth.
private  SymbolTable buildSymbolTable(jigcell.sbml2.Model model)
          Creates a table of variable assignments to be inserted as Fortran code.
protected  java.util.List computeSelectionList(java.util.List returnData)
          Computes the list of species to return from simulation.
 java.util.Map estimatorStatus(java.lang.String modelName)
          Multithreaded callers of Biopack can call this method to get the status of the current running estimator.
 java.util.Hashtable extractParameters(java.lang.String f90Model, java.lang.String report)
          Extract the parameter values and names from f90Model and report and put them in a Hashtable.
 java.util.List getAvailableSelections()
          A List[String] of tokens for each measurable element in the model.
private static java.lang.String getModelId(jigcell.sbml2.Model model)
           
private static java.lang.String getModelName(jigcell.sbml2.Model model)
           
protected  java.lang.String getProgramDirectory()
          The location where StochKit is installed.
 java.util.List getSettableNames()
          The name or id of every settable quantity.
static void main(java.lang.String[] args)
           
private static void missingArgument(java.lang.String arg)
           
private static jigcell.sbml2.math.Node multiplyByCompartments(java.lang.String id, jigcell.sbml2.math.Node node, java.util.Map compartmentMap, java.util.Map speciesMap)
          Take the math in node and search for all species multiplying each species by the volume of its compartment.
private static jigcell.sbml2.math.Node multiplyTermsByCompartments(java.lang.String id, jigcell.sbml2.math.Node node, java.util.Map compartmentMap, java.util.Map speciesMap)
          Takes each term (separated by + and - signs) and calls multiplyByCompartments.
private  void ruleGenerateCode(java.util.Map compartmentMap, java.util.Map speciesMap)
           
 void setCWD(java.io.File cwd)
          Sets the directory which all sub processes will be started from.
 jigcell.compare.IDataElement simulate(jigcell.simulation.Simulator simulator)
          Performs a simulation using the current model and settings.
protected  jigcell.compare.IDataElement simulate(jigcell.simulation.Simulator simulator, java.io.File targetFile, java.io.File outputFile)
          Performs a simulation using the current model and settings.
private  void translate()
          to translate the SBML into CPP, called by writeCppCode_
private  void writeCppCode_(java.io.PrintWriter out)
           
 void writeCppCode(java.io.PrintWriter out)
          Writes compilable Fortran code to out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MODEL_NAME

protected static final java.lang.String DEFAULT_MODEL_NAME
See Also:
Constant Field Values

DEFAULT_LOWER_BOUND

public static final java.lang.String DEFAULT_LOWER_BOUND
See Also:
Constant Field Values

DEFAULT_NML_FILENAME

public static final java.lang.String DEFAULT_NML_FILENAME
See Also:
Constant Field Values

DEFAULT_UPPER_BOUND

public static final java.lang.String DEFAULT_UPPER_BOUND
See Also:
Constant Field Values

EST_TASK

public static final java.lang.String EST_TASK
See Also:
Constant Field Values

INDENT

public static final java.lang.String INDENT
See Also:
Constant Field Values

EXTRACT_PARAMS

private static final java.lang.String EXTRACT_PARAMS
See Also:
Constant Field Values

MAX_CHARS_PER_LINE

private static final int MAX_CHARS_PER_LINE
See Also:
Constant Field Values

MAX_EXP_NAME_LENGTH

private static final int MAX_EXP_NAME_LENGTH
See Also:
Constant Field Values

MAX_ID_LENGTH

private static final int MAX_ID_LENGTH

PRE_RUN

public static final java.lang.String PRE_RUN
See Also:
Constant Field Values

RUN_PE

public static final java.lang.String RUN_PE
See Also:
Constant Field Values

SIM_TASK

public static final java.lang.String SIM_TASK
See Also:
Constant Field Values

STATUS

public static final java.lang.String STATUS
See Also:
Constant Field Values

TRANSFORM_TASK

public static final java.lang.String TRANSFORM_TASK
See Also:
Constant Field Values

VERSION_MESG

private static final java.lang.String VERSION_MESG
See Also:
Constant Field Values

cwd

private java.io.File cwd

model

private jigcell.sbml2.Model model

symbolTable

private SymbolTable symbolTable

mySymbol

private SymbolTable mySymbol

speciesIndex

java.util.Hashtable speciesIndex

reactionIndex

java.util.Hashtable reactionIndex

defaultInitialConditionsContents

private java.util.Hashtable defaultInitialConditionsContents

numVars

private int numVars

ruleHash

private java.util.Hashtable ruleHash

ruleArray

private java.util.ArrayList ruleArray

numRuleVars

private int numRuleVars

code

private java.lang.String code

targetFile

java.io.File targetFile

usage

private static java.lang.String usage
Allow SBMLTranslator to be run independent from parent programs as a command line tool.

Constructor Detail

SBMLToStochKitTranslator

public SBMLToStochKitTranslator(jigcell.sbml2.Model model)
                         throws java.lang.Exception
Creates a SBMLTranslator instance ready to create C++ code for model. Conforms to the Biopack API 1.0.

Parameters:
model - Create Fortran code for this Model.
Throws:
java.lang.Exception

SBMLToStochKitTranslator

public SBMLToStochKitTranslator(java.lang.String fileName)
                         throws java.lang.Exception
Creates a SBMLTranslator instance ready to create Fortran code from the SBML file fileName. Conforms to the Biopack API 1.0.

Parameters:
fileName - The SBML file containing the model for this SBMLTranslator instance.
Throws:
java.lang.Exception

SBMLToStochKitTranslator

public SBMLToStochKitTranslator(java.io.Reader reader)
                         throws java.lang.Exception
Creates a SBMLTranslator instance ready to create Fortran code from the SBML read from reader. Conforms to the Biopack API 1.0.

Parameters:
reader - A Reader that reads a stream of characters from some source where the characters are the SBML file text.
Throws:
java.lang.Exception
Method Detail

estimatorStatus

public java.util.Map estimatorStatus(java.lang.String modelName)
                              throws java.lang.Exception
Multithreaded callers of Biopack can call this method to get the status of the current running estimator. A Map is returned that contains keys that are strings representing names of attributes of the current running estimator. The values are objects representing the state.

Throws:
java.lang.Exception

extractParameters

public java.util.Hashtable extractParameters(java.lang.String f90Model,
                                             java.lang.String report)
                                      throws java.lang.Exception
Extract the parameter values and names from f90Model and report and put them in a Hashtable. The f90Model file contains the Fortran code written by writeFortranCode. The report file contains the output of ODRPACK. This routine reads the values from the parameter estimation done by ODRPACK and the names from the f90Model file. The names and values are paired up according to their order and stored in the returned Hashtable.

The equivalence statements in the f90Model file must be in the same order as the report file. The order should be the numerical order of the indexes of the MODEL_PARAMS array. Biopack generated f90 files will always have this order.

Throws:
java.lang.Exception

setCWD

public void setCWD(java.io.File cwd)
Sets the directory which all sub processes will be started from.


writeCppCode

public void writeCppCode(java.io.PrintWriter out)
                  throws java.lang.Exception
Writes compilable Fortran code to out. The code is enough to simulate the model represented by this SBMLTranslator instance. If the readComparatorFiles method was successfully called then the code is enough to do parameter estimation.

Throws:
java.lang.Exception

ruleGenerateCode

private void ruleGenerateCode(java.util.Map compartmentMap,
                              java.util.Map speciesMap)
                       throws java.lang.Exception
Throws:
java.lang.Exception

writeCppCode_

private void writeCppCode_(java.io.PrintWriter out)
                    throws java.lang.Exception
Throws:
java.lang.Exception

translate

private void translate()
                throws java.lang.Exception
to translate the SBML into CPP, called by writeCppCode_

Throws:
java.lang.Exception

appendAndBreak

private static java.lang.String appendAndBreak(java.lang.String s1,
                                               java.lang.String s2)
Returns s1 and s2 appended with line breaks added if the resulting string is longer than MAX_CHARS_PER_LINE characters. When a line break is added the indent is copied from the previous line. If the previous line is the only line the indent is expanded by 4 white spaces. An & is appended before the break to make the string a valid Fortran line continuation.


appendAndBreakNoIndent

private static java.lang.String appendAndBreakNoIndent(java.lang.String s1,
                                                       java.lang.String s2)
Like appendAndBreak but no additional white space is added when the second line is created. Normally the second line is indented 4 whitespaces more than the first. In this version the second and first line have the same indent.


appendAndBreak_

private static java.lang.String appendAndBreak_(java.lang.String s1,
                                                java.lang.String s2,
                                                boolean addIndent)
Underlying method for appendAndBreak and appendAndBreakNoIndent.


breakAFortranString

private static java.lang.String breakAFortranString(int maxWidth,
                                                    java.lang.String prefix,
                                                    java.lang.String fortranString,
                                                    java.lang.String suffix,
                                                    java.lang.String indent)
                                             throws java.lang.Exception
Builds a Fortran expression and adds breaks as necessary to keep the maximum line width below maxWidth. The resulting expression (without line breaks) looks like: prefix+'"'+fortranString+'"'+suffix. Breaks are inserted between prefix and suffix but not inside either. Breaks are inserted inside fortranString of the form "&\n"+indent+"&". prefix must be less than maxWidth. suffix must be equal to or less than maxWidth. fortranString must be smaller than the maximum permitted string in Fortran.

Throws:
java.lang.Exception

buildSymbolTable

private SymbolTable buildSymbolTable(jigcell.sbml2.Model model)
                              throws java.lang.Exception
Creates a table of variable assignments to be inserted as Fortran code. The table has the form: <name> <assignmentChar> <value> <delimeter> <name> <assignmentChar> <value> <delimeter> ... Line breaks are inserted before the line exceeds MAX_CHARS_PER_LINE and the columns are lined up on the assignementChar and delimeter with name and value left justified. An example table might look like:
     k1  = 3  ; k2  = 4
     k23 = 3.4; k5  = 6
     
The last delimeter on each line is ommited. All the name widths are the same (even if the name widths are from different columns). All the value widths are the same (even if the value widths are from different columns). The maximum field width is determined by the largest name and largest value. The table is indented by indent.

Throws:
java.lang.Exception

getModelId

private static java.lang.String getModelId(jigcell.sbml2.Model model)

getModelName

private static java.lang.String getModelName(jigcell.sbml2.Model model)

multiplyByCompartments

private static jigcell.sbml2.math.Node multiplyByCompartments(java.lang.String id,
                                                              jigcell.sbml2.math.Node node,
                                                              java.util.Map compartmentMap,
                                                              java.util.Map speciesMap)
                                                       throws java.lang.Exception
Take the math in node and search for all species multiplying each species by the volume of its compartment. Returns the new root node (maybe the same as the old root node). This requires that the "ci" tags in node are SBML ids. id is the target species (left hand side). Appearances of id in the RHS will not be multiplied by the compartment volume. Terms with species other than id will be divided by the compartment volume of id.

Throws:
java.lang.Exception

multiplyTermsByCompartments

private static jigcell.sbml2.math.Node multiplyTermsByCompartments(java.lang.String id,
                                                                   jigcell.sbml2.math.Node node,
                                                                   java.util.Map compartmentMap,
                                                                   java.util.Map speciesMap)
                                                            throws java.lang.Exception
Takes each term (separated by + and - signs) and calls multiplyByCompartments. Takes the root node and pushes it on the nodes stack. Then iterates until the node stack is empty by
  1. pop the node stack
  2. if operator string then
    1. pop children count children off of children stack into an array
    2. create new node
    3. pop children count off of children stack
    4. push result onto children stack
  3. else if addition or subtraction node then
    1. push operator on node stack
    2. push children on node stack
    3. push children count (of parent node) on children stack.
    else if other node
    1. call multiplyByCompartments and push result on children stack.
    2. increment children count
  4. children stack should have one element, return it as the new root node.

Throws:
java.lang.Exception

computeSelectionList

protected java.util.List computeSelectionList(java.util.List returnData)
Computes the list of species to return from simulation.

Parameters:
returnData - List[String] of columns to return when simulating

getAvailableSelections

public java.util.List getAvailableSelections()
A List[String] of tokens for each measurable element in the model.


getSettableNames

public java.util.List getSettableNames()
The name or id of every settable quantity.


getProgramDirectory

protected java.lang.String getProgramDirectory()
                                        throws java.lang.Exception
The location where StochKit is installed.

Throws:
java.lang.Exception

simulate

public jigcell.compare.IDataElement simulate(jigcell.simulation.Simulator simulator)
                                      throws java.lang.Exception
Performs a simulation using the current model and settings.

Parameters:
simulator - Simulator
Throws:
java.lang.Exception

simulate

protected jigcell.compare.IDataElement simulate(jigcell.simulation.Simulator simulator,
                                                java.io.File targetFile,
                                                java.io.File outputFile)
                                         throws java.lang.Exception
Performs a simulation using the current model and settings.

Parameters:
simulator - Simulator
targetFile - SBML file
outputFile - File that will contain the simulator output
Throws:
java.lang.Exception

missingArgument

private static void missingArgument(java.lang.String arg)

main

public static void main(java.lang.String[] args)