Package org.sbml.jsbml

Examples of org.sbml.jsbml.AssignmentRule


  // TODO : API changes, setVariable function is not in the Rule Class.

  @Test
  public void test_Model_getRules() throws ParseException {
    Rule ar = new AlgebraicRule(2, 4);
    AssignmentRule scr = new AssignmentRule(2, 4);
    AssignmentRule cvr = new AssignmentRule(2, 4);
    AssignmentRule pr = new AssignmentRule(2, 4);
    scr.setVariable("r2");
    cvr.setVariable("r3");
    pr.setVariable("r4");
    ar.setFormula("x + 1");
    scr.setFormula("k * t/(1 + k)");
    cvr.setFormula("0.10 * t");
    pr.setFormula("k3/k2");
    M.addRule(ar);
    M.addRule(scr);
    M.addRule(cvr);
    M.addRule(pr);
    assertTrue(M.getNumRules() == 4);
    ar = M.getRule(0);
    scr = (AssignmentRule) M.getRule(1);
    cvr = (AssignmentRule) M.getRule(2);
    pr = (AssignmentRule) M.getRule(3);
    assertTrue(ar.getFormula().equals("x+1")); // .equals("x + 1")
    assertTrue(scr.getFormula().equals("k*t/(1+k)")); // .equals("k * t/(1 + k)"));
    assertTrue(cvr.getFormula().equals("0.1*t")); // .equals("0.10 * t"));
    assertTrue(pr.getFormula().equals("k3/k2"));
  }
 
View Full Code Here


    Model m;
    Compartment c;
    Species s;
    Parameter gp;
    LocalParameter lp;
    AssignmentRule ar;
    Reaction r;
    SpeciesReference sr;
    KineticLaw kl;
    UnitDefinition ud;
    Reaction r1;
    ListOf<Compartment> loc;
    Compartment c1;
    ListOf<Rule> lor;
    AssignmentRule ar1;
    ListOf<Parameter> lop;
    Parameter p1;
    ListOf<Species> los;
    Species s1;
    String filename = new String( DATA_FOLDER + "/libsbml-test-data/" );
    filename += "l2v1-assignment.xml";
    try {
    d = reader.readSBML(filename);
  } catch (IOException e) {
    e.printStackTrace();
    assert(false);
  } catch (XMLStreamException e) {
    e.printStackTrace();
    assert(false);
  }

  System.out.println(" TestReadFromFile 5 : reading done.");
 
  assertTrue( d.getLevel() == 2 );
    assertTrue( d.getVersion() == 1 );
    m = d.getModel();
    assertTrue( m != null );
    assertTrue( m.getNumCompartments() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
/*    ud = c.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 1 );
    assertTrue( ud.getUnit(0).getKind() == Kind.LITRE );
    */
    loc = m.getListOfCompartments();
    c1 = loc.get(0);
    assertTrue( c1.equals(c) );
    c1 = loc.get("cell");
    assertTrue( c1.equals(c) );
    assertTrue( m.getNumSpecies() == 5 );
    s = m.getSpecies(0);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X0"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 1.0 );
    los = m.getListOfSpecies();
    s1 = los.get(0);
    assertTrue( s1.equals(s) );
    s1 = los.get("X0");
    assertTrue( s1.equals(s) );
    s = m.getSpecies(1);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(2);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "T"   ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(3);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(4);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S2"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    assertTrue( m.getNumParameters() == 1 );
    gp = m.getParameter(0);
    assertTrue( gp != null );
    assertTrue( gp.getId().equals( "Keq") );
    assertTrue( gp.getValue() == 2.5 );
    lop = m.getListOfParameters();
    p1 = lop.get(0);
    assertTrue( p1.equals(gp) );
    p1 = lop.get("Keq");
    assertTrue( p1.equals(gp) );
    /*
    ud = gp.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 0 );
    assertTrue( m.getNumRules() == 2 );
    */
    ar = (AssignmentRulem.getRule(0);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S1"           ) );
    assertTrue( ar.getFormula().equals( "T/(1+Keq)") );
    /*
    ud = ar.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 2 );
    assertTrue( ud.getUnit(0).getKind() == Kind.MOLE );
    assertTrue( ud.getUnit(0).getExponent() == 1 );
    assertTrue( ud.getUnit(1).getKind() == Kind.LITRE );
    assertTrue( ud.getUnit(1).getExponent() == -1 );
    */
    assertTrue( ar.containsUndeclaredUnits() == true );
    lor = m.getListOfRules();
    ar1 = (AssignmentRule) lor.get(0);
    assertTrue( ar1.equals(ar) );
    ar1 = (AssignmentRule) lor.get("S1");
    assertTrue( ar1.equals(ar) );
    ar = (AssignmentRulem.getRule(1);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S2"      ) );
    assertTrue( ar.getFormula().equals( "Keq*S1") );
    assertTrue( m.getNumReactions() == 2 );
View Full Code Here

  /**
   *
   * @return
   */
  public AssignmentRule cloneAsAssignmentRule() {
    return new AssignmentRule(this);
  }
View Full Code Here

    Model m;
    Compartment c;
    Species s;
    Parameter gp;
    LocalParameter lp;
    AssignmentRule ar;
    Reaction r;
    SpeciesReference sr;
    KineticLaw kl;
    UnitDefinition ud;
    Reaction r1;
    ListOf<Compartment> loc;
    Compartment c1;
    ListOf<Rule> lor;
    AssignmentRule ar1;
    ListOf<Parameter> lop;
    Parameter p1;
    ListOf<Species> los;
    Species s1;
    String filename = new String( DATA_FOLDER + "/libsbml-test-data/" );
    filename += "l2v1-assignment.xml";
    try {
    d = reader.readSBML(filename);
  } catch (IOException e) {
    e.printStackTrace();
    assert(false);
  } catch (XMLStreamException e) {
    e.printStackTrace();
    assert(false);
  }

  System.out.println(" TestReadFromFile 5 : reading done.");
 
  assertTrue( d.getLevel() == 2 );
    assertTrue( d.getVersion() == 1 );
    m = d.getModel();
    assertTrue( m != null );
    assertTrue( m.getNumCompartments() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
/*    ud = c.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 1 );
    assertTrue( ud.getUnit(0).getKind() == Kind.LITRE );
    */
    loc = m.getListOfCompartments();
    c1 = loc.get(0);
    assertTrue( c1.equals(c) );
    c1 = loc.get("cell");
    assertTrue( c1.equals(c) );
    assertTrue( m.getNumSpecies() == 5 );
    s = m.getSpecies(0);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X0"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 1.0 );
    los = m.getListOfSpecies();
    s1 = los.get(0);
    assertTrue( s1.equals(s) );
    s1 = los.get("X0");
    assertTrue( s1.equals(s) );
    s = m.getSpecies(1);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(2);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "T"   ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(3);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(4);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S2"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    assertTrue( m.getNumParameters() == 1 );
    gp = m.getParameter(0);
    assertTrue( gp != null );
    assertTrue( gp.getId().equals( "Keq") );
    assertTrue( gp.getValue() == 2.5 );
    lop = m.getListOfParameters();
    p1 = lop.get(0);
    assertTrue( p1.equals(gp) );
    p1 = lop.get("Keq");
    assertTrue( p1.equals(gp) );
    /*
    ud = gp.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 0 );
    assertTrue( m.getNumRules() == 2 );
    */
    ar = (AssignmentRulem.getRule(0);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S1"           ) );
    assertTrue( ar.getFormula().equals( "T/(1+Keq)") );
    /*
    ud = ar.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 2 );
    assertTrue( ud.getUnit(0).getKind() == Kind.MOLE );
    assertTrue( ud.getUnit(0).getExponent() == 1 );
    assertTrue( ud.getUnit(1).getKind() == Kind.LITRE );
    assertTrue( ud.getUnit(1).getExponent() == -1 );
    */
    assertTrue( ar.containsUndeclaredUnits() == true );
    lor = m.getListOfRules();
    ar1 = (AssignmentRule) lor.get(0);
    assertTrue( ar1.equals(ar) );
    ar1 = (AssignmentRule) lor.get("S1");
    assertTrue( ar1.equals(ar) );
    ar = (AssignmentRulem.getRule(1);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S2"      ) );
    assertTrue( ar.getFormula().equals( "Keq*S1") );
    assertTrue( m.getNumReactions() == 2 );
View Full Code Here

      if (model.isSetListOfRules()) {
        for (int i = 0; i < model.getNumRules(); i++) {
          Rule rule = model.getRule(i);
          if (rule instanceof AssignmentRule) {
            AssignmentRule assignmentRule = (AssignmentRule) rule;
            setAssignmentRuleVariable(assignmentRule, model);
          } else if (rule instanceof RateRule) {
            RateRule rateRule = (RateRule) rule;
            setRateRuleVariable(rateRule, model);
          }
View Full Code Here

              return rule;
            } else if (elementName.equals("assignmentRule") // TODO : wrong, there are no assignmentRule element, only more specialize rule
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)) {
              AssignmentRule rule = (AssignmentRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("reaction")
                && list.getSBaseListType().equals(
View Full Code Here

        if (sbase.getElementName().equals("species")) {
          xmlObject.setName("specie");
        } else if (sbase.getElementName().equals("speciesReference")) {
          xmlObject.setName("specieReference");
        } else if (sbase.getElementName().equals("assignementRule")) {
          AssignmentRule assignmentRule = (AssignmentRule) sbase;
          Variable variable = assignmentRule.getVariableInstance();

          if (variable instanceof Species) {
            xmlObject.setName("specieConcentrationRule");
          } else if (variable instanceof Compartment) {
            xmlObject.setName("compartmentVolumeRule");
View Full Code Here

  /**
   *
   * @return
   */
  public AssignmentRule cloneAsAssignmentRule() {
    return new AssignmentRule(this);
  }
View Full Code Here

    location.setMath(ASTNode.parseFormula("lambda(x,0)"));
   
    model.createCompartment("cell");
    model.createParameter("P1");
   
    AssignmentRule rule = model.createAssignmentRule();
    rule.setVariable("P1");
    rule.setMath(ASTNode.parseFormula("location(cell)"));
   
    System.out.println(rule.getMathMLString());
   
    System.out.println(rule.getMath().toFormula());
   
    printASTNoteType(rule.getMath());
   
    // System.out.println("\n\nWhole SBML Document as XML :\n\n" + JSBML.writeSBMLToString(document));
   
    System.out.println("PARSING MATHML NOW ----------");
   
    model.createParameter("P2");
   
    rule = model.createAssignmentRule();
    rule.setVariable("P2");
   
   
    String mathML = "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" +
        "  <apply>\n" +
        "    <ci> location </ci>\n" +
        "    <ci> cell </ci>\n" +
        "  </apply>\n" +
        "</math>";

    rule.setMath(ASTNode.readMathMLFromString(mathML));

    System.out.println(rule.getMathMLString());
   
    System.out.println(rule.getMath().toFormula());

    printASTNoteType(rule.getMath());

    String sbmlDocument = JSBML.writeSBMLToString(document);
   
    System.out.println("\n\nWhole SBML Document as XML :\n\n" + sbmlDocument);
   
    SBMLDocument wrongDocument = JSBML.readSBMLFromString(sbmlDocument.replaceFirst("location", "locatoin"));
   
    rule = (AssignmentRule) wrongDocument.getModel().getRule(0);
       
    System.out.println(rule.getMathMLString());
   
    printASTNoteType(rule.getMath());

    System.out.println(rule.getMath().toFormula());
   
  }
View Full Code Here

        }
       
        for (int i = 0; i < model.getNumRules(); i++) {
          Rule rule = model.getRule(i);
          if (rule instanceof AssignmentRule) {
            AssignmentRule assignmentRule = (AssignmentRule) rule;
            if (assignmentRule.isSetVariable()
                && !assignmentRule.isSetVariableInstance()) {
              log4jLogger.warn("No Symbol matches the variableID of AssignmentRule.");
            }
            if (assignmentRule.isSetUnits()
                && !assignmentRule.isSetUnitsInstance()
                && assignmentRule.isParameter()) {
              log4jLogger.warn("No UnitDefinition matches the unitsID of AssignmentRule.");
            }
          } else if (rule instanceof RateRule) {
            RateRule rateRule = (RateRule) rule;
            if (rateRule.isSetVariable()
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.AssignmentRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.