org.sbml.jsbml
public class JSBML extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DUPLICATE_OBJECT_ID |
static java.lang.String |
ILLEGAL_UNIT_EXCEPTION_MSG
Error message for the case that an invalid unit identifier is to be added
to this object.
|
static int |
INDEX_EXCEEDS_SIZE |
static int |
INVALID_ATTRIBUTE_VALUE |
static int |
INVALID_OBJECT |
static int |
INVALID_XML_OPERATION |
private static java.lang.String |
jsbmlVersion
The current version number of JSBML.
|
static int |
LEVEL_MISMATCH |
static int |
OPERATION_FAILED |
static int |
OPERATION_SUCCESS |
static java.lang.String |
UNDEFINED_MODEL_MSG
This indicates that the
Model has not been set properly or that
an element tries to access its containing model but this is not possible. |
static java.lang.String |
UNDEFINED_PARSE_ERROR_MSG
This message indicates that a problem occurred but the current class
cannot give any more precise information about the reasons.
|
static java.lang.String |
UNDEFINED_PARSING_ERROR_MSG
This message indicates that a problem occurred but the current class
cannot give any more precise information about the reasons.
|
static int |
UNEXPECTED_ATTRIBUTE |
static java.lang.String |
URI_PURL_ELEMENTS
URI for the definition of purl elements
|
static java.lang.String |
URI_PURL_TERMS
URI for purl terms.
|
static java.lang.String |
URI_XHTML_DEFINITION
URI for the definition of XHTML.
|
static int |
VERSION_MISMATCH |
Constructor and Description |
---|
JSBML() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addUnitDefinitionIfNotContained(Model model,
UnitDefinition units)
Adds the given
UnitDefinition to the given model or returns the
identifier of an equivalent UnitDefinition that is already part
of the model. |
static java.lang.String |
formulaToString(ASTNode node)
Converts an
ASTNode formula to a text string using a specific
syntax for mathematical formulas. |
static java.lang.String |
getJSBMLDottedVersion()
Returns the JSBML version as a string of the form '1.2.3'.
|
static int |
getJSBMLVersion()
Returns the JSBML version as an integer: version 1.2.3 becomes 123.
|
static java.lang.String |
getJSBMLVersionString()
Returns the JSBML version as a string: version 1.2.3 becomes '123'.
|
static java.lang.String |
getNamespaceFrom(int level,
int version) |
static <T> void |
loadClasses(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Class<? extends T>> whereToPutProperties)
Loads
Properties from a configuration file with the given path
assuming that all values represent class names. |
static ASTNode |
parseFormula(java.lang.String formula)
Parses a text-string mathematical formula and returns a representation as
an Abstract Syntax Tree.
|
static ASTNode |
readMathMLFromString(java.lang.String xml)
Reads the MathML from the given XML string, constructs a corresponding
abstract syntax tree, and returns a pointer to the root of the tree.
|
static SBMLDocument |
readSBML(java.lang.String fileName)
Reads an SBML document from the given file.
|
static SBMLDocument |
readSBMLFromFile(java.lang.String fileName)
Reads an SBML document from the given file.
|
static SBMLDocument |
readSBMLFromString(java.lang.String xml)
Reads an SBML document from a string assumed to be in XML format.
|
static java.lang.String |
writeMathMLToString(ASTNode node)
Writes the given ASTNode (and its children) to a string as MathML, and
returns the string.
|
static void |
writeSBML(SBMLDocument d,
java.lang.String filename)
Writes the XML representation of an SBML document to a file.
|
static java.lang.String |
writeSBMLToString(SBMLDocument d)
Writes the given SBML document to an in-memory string.
|
public static final int DUPLICATE_OBJECT_ID
public static final java.lang.String ILLEGAL_UNIT_EXCEPTION_MSG
public static final int INDEX_EXCEEDS_SIZE
public static final int INVALID_ATTRIBUTE_VALUE
public static final int INVALID_OBJECT
public static final int INVALID_XML_OPERATION
private static final java.lang.String jsbmlVersion
public static final int LEVEL_MISMATCH
public static final int OPERATION_FAILED
public static final int OPERATION_SUCCESS
public static final java.lang.String UNDEFINED_MODEL_MSG
Model
has not been set properly or that
an element tries to access its containing model but this is not possible.public static final java.lang.String UNDEFINED_PARSE_ERROR_MSG
public static final java.lang.String UNDEFINED_PARSING_ERROR_MSG
public static final int UNEXPECTED_ATTRIBUTE
public static final int VERSION_MISMATCH
public static final transient java.lang.String URI_PURL_TERMS
public static final transient java.lang.String URI_PURL_ELEMENTS
public static final transient java.lang.String URI_XHTML_DEFINITION
public static java.lang.String addUnitDefinitionIfNotContained(Model model, UnitDefinition units)
UnitDefinition
to the given model or returns the
identifier of an equivalent UnitDefinition
that is already part
of the model. In case that the given model is null, the return value of
this method will also be null
.model
- The model where to add the given UnitDefinition
units
- The UnitDefinition
to be checked and possibly added to
the given Model
UnitDefinition
if this one
has been added to the given model, the identifier of an
equivalent UnitDefinition
that is already part of the
given model, or null
.public static java.lang.String formulaToString(ASTNode node) throws SBMLException
ASTNode
formula to a text string using a specific
syntax for mathematical formulas.
The text-string form of mathematical formulas produced by
ASTNode.formulaToString(ASTNode)
and read by
ASTNode.parseFormula(String)
are simple C-inspired infix notation
taken from SBML Level 1. A formula in this text-string form therefore
can be handed to a program that understands SBML Level 1 mathematical
expressions, or used as part of a formula translation system. The syntax is
described in detail in the libsbml documentation for ASTNode.
Be careful that the default FormulaCompiler
used produce an output
a bit different than pure SBML level 1 mathematical expressions, in particular
for logical and relational operators. If the default output is not convenient
for you, you can easily extends one of the existing FormulaCompiler and overwrite
the methods where you want a different output.
node
- the root of the ASTNode
formula expression treenull
is returned if the given
argument is null
.SBMLException
- In case the given ASTNode
tree contains invalid nodes.ASTNode.toFormula()
,
ASTNode.toFormula(FormulaCompiler)
,
FormulaCompiler
,
FormulaCompilerLibSBML
,
FormulaCompilerNoPiecewise
public static java.lang.String getJSBMLDottedVersion()
public static int getJSBMLVersion()
public static java.lang.String getJSBMLVersionString()
public static <T> void loadClasses(java.lang.String path, java.util.Map<java.lang.String,java.lang.Class<? extends T>> whereToPutProperties)
Properties
from a configuration file with the given path
assuming that all values represent class names.T
- path
- whereToPutProperties
- public static ASTNode parseFormula(java.lang.String formula) throws ParseException
Support the syntax defined in FormulaParserLL3
which is almost the same syntax as defined in
the LibSBML L3 parser. The things not supported for now are the units associated with numbers.
Parsing of the various MathML functions and constants are all
case-sensitive by default: names such as
'Cos
' and 'COS
' are not parsed as the MathML cosine
operator, '<cos>
'.
As well, if you have an SBML entities (species, parameter, ...) that
has an id identical to one of the supported mathML element, the parser will interpret the String as the
mathML element and not the SBML entity.
You can change this behaviour by using the FormulaParserLL3.setCaseSensitive(boolean)
method and using the ASTNode.parseFormula(String, IFormulaParser)
method instead of this one:
FormulaParserLL3 caseSensitiveParser = new FormulaParserLL3(new StringReader("")); caseInsensitiveParser.setCaseSensitive(false); ASTNode n = ASTNode.parseFormula("Cos(x)", caseInsensitiveParser);
This method has a different behaviour since JSBML-1.0 compare to JSBML-0.8. There is a different
operator precedence, the parsing is now case sensitive for mathML elements and boolean operators are
now differently interpreted: '&&' and '||' are used instead of 'and' and 'or'.
If you want to use the parser used in JSBML-0.8, you can do that by using the FormulaParser
parser class and using the ASTNode.parseFormula(String, IFormulaParser)
method instead of this one:
FormulaParser oldParser = new FormulaParser(new StringReader("")); ASTNode n = ASTNode.parseFormula("x and y", oldParser);
If you are not satisfied with the behaviour of the existing parsers, you can create
your own, you just need to implement the IFormulaParser
interface.
formula
- a text-string mathematical formula.ASTNode
representing the formula.ParseException
- If the given formula is not of valid format or cannot be
parsed for other reasons.ASTNode.parseFormula(String)
,
ASTNode.parseFormula(String, IFormulaParser)
,
FormulaParserLL3
,
FormulaParser
public static ASTNode readMathMLFromString(java.lang.String xml)
xml
- the MathML XML string.ASTNode
public static SBMLDocument readSBML(java.lang.String fileName) throws javax.xml.stream.XMLStreamException, java.io.IOException
fileName
- the file name.SBMLDocument
object.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.java.io.IOException
- if the file does not exist or cannot be read.public static SBMLDocument readSBMLFromFile(java.lang.String fileName) throws javax.xml.stream.XMLStreamException, java.io.IOException
fileName
- the file name.SBMLDocument
object.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.java.io.IOException
- if the file does not exist or cannot be read.public static SBMLDocument readSBMLFromString(java.lang.String xml) throws javax.xml.stream.XMLStreamException
xml
- the SBMLDocument as XML.SBMLDocument
object.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.public static java.lang.String writeMathMLToString(ASTNode node) throws javax.xml.stream.XMLStreamException, SBMLException
node
- the ASTNode
ASTNode
javax.xml.stream.XMLStreamException
SBMLException
public static void writeSBML(SBMLDocument d, java.lang.String filename) throws javax.xml.stream.XMLStreamException, SBMLException, java.io.IOException
d
- the SBMLdocument
filename
- the file namejavax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
java.io.IOException
- if an I/O error occurs.public static java.lang.String writeSBMLToString(SBMLDocument d) throws javax.xml.stream.XMLStreamException, SBMLException
d
- the SBMLDocument
SBMLDocument
as a
String
.javax.xml.stream.XMLStreamException
- if any error occur while creating the XML document.SBMLException
public static java.lang.String getNamespaceFrom(int level, int version)
level
- version
-