Search in sources :

Example 1 with ParseException

use of org.sbml.jsbml.text.parser.ParseException in project vcell by virtualcell.

the class VCellModel method parseValueStringForParameter.

public ASTNode parseValueStringForParameter(Parameter parameter, String value) {
    Model model = sbmlDocument.getModel();
    ExplicitRule rule = model.getRuleByVariable(parameter.getId());
    if (rule != null) {
        try {
            return ASTNode.parseFormula(value);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : ExplicitRule(org.sbml.jsbml.ExplicitRule) Model(org.sbml.jsbml.Model) ParseException(org.sbml.jsbml.text.parser.ParseException)

Example 2 with ParseException

use of org.sbml.jsbml.text.parser.ParseException in project vcell by virtualcell.

the class SBMLExporter method getFormulaFromExpression.

/**
 * 	getFormulaFromExpression :
 *  Expression infix strings are not handled gracefully by libSBML, esp when ligical or inequality operators are used.
 *  This method
 *		converts the expression into MathML using ExpressionMathMLPrinter;
 *		converts that into libSBMl-readable formula using libSBML utilties.
 *		returns the new formula string.
 */
public static ASTNode getFormulaFromExpression(Expression expression, MathType desiredType) {
    // switch to libSBML for non-boolean
    if (!desiredType.equals(MathType.BOOLEAN)) {
        try {
            return ASTNode.parseFormula(expression.infix());
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new RuntimeException(e.toString());
        }
    }
    // Convert expression into MathML string
    String expMathMLStr = null;
    try {
        expMathMLStr = cbit.vcell.parser.ExpressionMathMLPrinter.getMathML(expression, false, desiredType);
    } catch (java.io.IOException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Error converting expression to MathML string :" + e.getMessage());
    } catch (cbit.vcell.parser.ExpressionException e1) {
        e1.printStackTrace(System.out);
        throw new RuntimeException("Error converting expression to MathML string :" + e1.getMessage());
    }
    // Use libSBMl routines to convert MathML string to MathML document and a libSBML-readable formula string
    ASTNode mathNode = ASTNode.readMathMLFromString(expMathMLStr);
    return mathNode;
}
Also used : ASTNode(org.sbml.jsbml.ASTNode) ParseException(org.sbml.jsbml.text.parser.ParseException) XmlParseException(cbit.vcell.xml.XmlParseException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

ParseException (org.sbml.jsbml.text.parser.ParseException)2 ExpressionException (cbit.vcell.parser.ExpressionException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 ASTNode (org.sbml.jsbml.ASTNode)1 ExplicitRule (org.sbml.jsbml.ExplicitRule)1 Model (org.sbml.jsbml.Model)1