Package org.sbml.jsbml

Examples of org.sbml.jsbml.Model


  public void processEndDocument(SBMLDocument sbmlDocument) {

    log4jLogger.debug("SBMLCoreParser: processEndDocument");
   
    if (sbmlDocument.isSetModel()) {
      Model model = sbmlDocument.getModel();

      if (model.isSetAreaUnits() && !model.isSetAreaUnitsInstance()) {
        log4jLogger.warn("No unitDefinition matches the areaUnitsID of Model.");
      }
      if (model.isSetConversionFactor()
          && !model.isSetConversionFactorInstance()) {
        log4jLogger.warn("No parameter matches the conversionFactorID of Model.");
      }
      if (model.isSetExtentUnits() && !model.isSetExtentUnitsInstance()) {
        log4jLogger.warn("No unitDefinition matches the extentUnitsID of Model.");
      }
      if (model.isSetLengthUnits() && !model.isSetLengthUnitsInstance()) {
        log4jLogger.warn("No unitDefinition matches the lengthUnitsID of Model.");
      }
      if (model.isSetSubstanceUnits()
          && !model.isSetSubstanceUnitsInstance()) {
        log4jLogger.warn("No unitDefinition matches the substanceUnitsID of Model.");
      }
      if (model.isSetTimeUnits() && !model.isSetTimeUnitsInstance()) {
        log4jLogger.warn("No unitDefinition matches the timeUnitsID of Model.");
      }
      if (model.isSetVolumeUnits() && !model.isSetVolumeUnitsInstance()) {
        log4jLogger.warn("No unitDefinition matches the volumeUnitsID of Model.");
      }

      if (model.isSetListOfRules()) {
       
        if (model.getLevel() == 1) {

          log4jLogger.debug("Transformed SBMLLevel1Rule: processEndDocument: model is level 1");

          int i = 0;
          for (Rule rule : model.getListOfRules().clone()) {
            if (rule instanceof SBMLLevel1Rule) {
              Rule realRule;
             
              if (((SBMLLevel1Rule) rule).isScalar()) {
                realRule = ((SBMLLevel1Rule) rule).cloneAsAssignmentRule();
                log4jLogger.debug("Transformed SBMLLevel1Rule: " + ((SBMLLevel1Rule) rule).getVariable() + " into AssignmentRule.");
              } else {
                realRule = ((SBMLLevel1Rule) rule).cloneAsRateRule();
                log4jLogger.debug("Transformed SBMLLevel1Rule: " + ((SBMLLevel1Rule) rule).getVariable() + " into RateRule.");
              }
             
              log4jLogger.debug("Transformed SBMLLevel1Rule: realRule = " + realRule);

              model.getListOfRules().remove(i);
              model.getListOfRules().add(i, realRule);
            }
            i++;
          }
        }
       
        for (int i = 0; i < model.getRuleCount(); 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()
                && !rateRule.isSetVariableInstance()) {
              log4jLogger.warn("No Symbol matches the variableID of RateRule.");
            }
          }
        }
      }
      if (model.isSetListOfCompartments()) {
        for (int i = 0; i < model.getCompartmentCount(); i++) {
          Compartment compartment = model.getCompartment(i);
          if (compartment.isSetCompartmentType()
              && !compartment.isSetCompartmentTypeInstance()) {
            log4jLogger.warn("No CompartmentType matches the compartmentTypeID of compartment.");
          }
          if (compartment.isSetOutside()
              && !compartment.isSetOutsideInstance()) {
            log4jLogger.warn("No Compartment matches the outsideID of compartment.");
          }
          if (compartment.isSetUnits()
              && !compartment.isSetUnitsInstance()) {
            log4jLogger.warn("No UnitDefinition matches the unitsID of compartment.");
          }
        }
      }
      if (model.isSetListOfEvents()) {
        for (int i = 0; i < model.getEventCount(); i++) {
          Event event = model.getEvent(i);

          if (event.isSetTimeUnits()
              && !event.isSetTimeUnitsInstance()) {
            log4jLogger.warn("No UnitDefinition matches the timeUnitsID of event.");
          }

          if (event.isSetListOfEventAssignments()) {

            for (int j = 0; j < event.getEventAssignmentCount(); j++) {
              EventAssignment eventAssignment = event
                  .getEventAssignment(j);

              if (eventAssignment.isSetVariable()
                  && !eventAssignment.isSetVariableInstance()) {
                log4jLogger.warn("No Symbol matches the variableID of eventAssignment.");
              }
            }
          }
        }
      }
      if (model.isSetListOfInitialAssignments()) {
        for (int i = 0; i < model.getInitialAssignmentCount(); i++) {
          InitialAssignment initialAssignment = model
              .getInitialAssignment(i);

          if (initialAssignment.isSetVariable()
              && !initialAssignment.isSetVariableInstance()) {
            log4jLogger.warn("No Symbol matches the symbolID of initialAssignment.");
          }
        }
      }
      if (model.isSetListOfReactions()) {
        for (int i = 0; i < model.getReactionCount(); i++) {
          Reaction reaction = model.getReaction(i);
          if (reaction.isSetCompartment()
              && !reaction.isSetCompartmentInstance()) {
            log4jLogger.warn("No Compartment matches the compartmentID of reaction.");
          }

          if (reaction.isSetListOfReactants()) {
            for (int j = 0; j < reaction.getReactantCount(); j++) {
              SpeciesReference speciesReference = reaction
                  .getReactant(j);

              if (speciesReference.isSetSpecies()
                  && !speciesReference.isSetSpeciesInstance()) {
                log4jLogger.warn(String.format("No Species matches the speciesID '%s' of %s.",
                    speciesReference.getId(), speciesReference.getElementName()));
              }
            }
          }
          if (reaction.isSetListOfProducts()) {
            for (int j = 0; j < reaction.getProductCount(); j++) {
              SpeciesReference speciesReference = reaction
                  .getProduct(j);

              if (speciesReference.isSetSpecies()
                  && !speciesReference.isSetSpeciesInstance()) {
                log4jLogger.warn(String.format("No Species matches the speciesID '%s' of %s.",
                    speciesReference.getId(), speciesReference.getElementName()));
              }
            }
          }
          if (reaction.isSetListOfModifiers()) {
            for (int j = 0; j < reaction.getModifierCount(); j++) {
              ModifierSpeciesReference modifierSpeciesReference = reaction
                  .getModifier(j);

              if (modifierSpeciesReference.isSetSpecies()
                  && !modifierSpeciesReference
                      .isSetSpeciesInstance()) {
                log4jLogger.warn(String.format("No Species matches the speciesID '%s' of %s.",
                    modifierSpeciesReference.getId(), modifierSpeciesReference.getElementName()));
              }
            }
          }
          if (reaction.isSetKineticLaw()) {
            KineticLaw kineticLaw = reaction.getKineticLaw();
            if (kineticLaw.isSetTimeUnits()
                && !kineticLaw.isSetTimeUnitsInstance()) {
              log4jLogger.warn("No UnitDefinition matches the timeUnitsID of kineticLaw.");
            }
            if (kineticLaw.isSetSubstanceUnits()
                && !kineticLaw.isSetSubstanceUnitsInstance()) {
              log4jLogger.warn("No UnitDefinition matches the substanceUnitsID of kineticLaw.");
            }
            if (kineticLaw.isSetListOfLocalParameters()) {
              for (int j = 0; j < kineticLaw.getLocalParameterCount(); j++) {
                LocalParameter parameter = kineticLaw
                    .getLocalParameter(j);
                if (parameter.isSetUnits()
                    && !parameter.isSetUnitsInstance()) {
                  log4jLogger.warn(String.format(
                    "No UnitDefinition matches the unitsID '%s'of the parameter %s.",
                    parameter.getUnits(), parameter.getId()));
                }
              }
            }
          }
        }
      }
      if (model.isSetListOfSpecies()) {
        for (int i = 0; i < model.getSpeciesCount(); i++) {
          Species species = model.getSpecies(i);

          if (species.isSetSubstanceUnits()
              && !species.isSetSubstanceUnitsInstance()) {
            log4jLogger.warn("No UnitDefinition matches the subtsanceUnitsID of species.");
          }
          if (species.isSetSpeciesType()
              && !species.isSetSpeciesTypeInstance()) {
            log4jLogger.warn("No SpeciesType matches the speciesTypeID of species.");
          }
          if (species.isSetConversionFactor()
              && !species.isSetConversionFactorInstance()) {
            log4jLogger.warn("No Parameter matches the conversionFactorID of species.");
          }
          if (species.isSetCompartment()
              && !species.isSetCompartmentInstance()) {
            log4jLogger.warn("No Compartment matches the compartmentID of species.");
          }
          if (species.isSetSpatialSizeUnits()
              && !species.isSetSpatialSizeUnitsInstance()) {
            log4jLogger.warn("No UnitDefinition matches the spatialSizeUnitsID of species.");
          }
        }
      }
      if (model.isSetListOfParameters()) {
        for (int i = 0; i < model.getParameterCount(); i++) {
          Parameter parameter = model.getParameter(i);
          if (parameter.isSetUnits()
              && !parameter.isSetUnitsInstance()) {
            log4jLogger.warn("No UnitDefinition matches the unitsID of parameter.");
          }
        }
View Full Code Here


   * @throws java.lang.Exception
   */
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    doc = new SBMLDocument(3, 1);
    Model m = doc.createModel("test_model");
   
    Compartment c = m.createCompartment("default");
    c.setSpatialDimensions(3d);
   
    Species s1 = m.createSpecies("s1", "species1", c);
    Species s2 = m.createSpecies("s2", "species2", c);
    Species s3 = m.createSpecies("s3", "species3", c);
    Species s4 = m.createSpecies("s4", "species4", c);
   
    Reaction r1 = m.createReaction("r1");
    r1.setName("reaction1");
    r1.setCompartment(c);
    SpeciesReference sr1 = r1.createReactant("sr1", s1);
    sr1.setName("reactant1");
    sr1.setStoichiometry(1d);
    SpeciesReference sr2 = r1.createProduct("sr2", s2);
    sr2.setName("product1");
    sr2.setStoichiometry(1d);
    ModifierSpeciesReference msr1 = r1.createModifier("msr1", s3);
    msr1.setName("modifier");
   
    Reaction r2 = m.createReaction("r2");
    r2.setName("reaction2");
    r2.setCompartment(c);
    SpeciesReference sr3 = r2.createReactant("sr3", s1);
    sr3.setName("reactant2");
    sr3.setStoichiometry(2d);
View Full Code Here

  /**
   * Test method for {@link org.sbml.jsbml.AbstractTreeNode#filter(org.sbml.jsbml.util.filters.Filter)}.
   */
  @Test
  public void testFilter() {
    Model m = doc.getModel();
    List<TreeNode> list = new LinkedList<TreeNode>();
    list.add(m.findNamedSBase("msr1"));
    list.add(m.findNamedSBase("msr2"));
    List<? extends TreeNode> result = doc.filter(filter);
    System.out.println("filter result without internals and without pruning:\n  " + result);
    assertTrue(result.equals(list));
  }
View Full Code Here

  /**
   * Test method for {@link org.sbml.jsbml.AbstractTreeNode#filter(org.sbml.jsbml.util.filters.Filter, boolean)}.
   */
  @Test
  public void testFilterBoolean() {
    Model m = doc.getModel();
    List<TreeNode> list = new LinkedList<TreeNode>();
    list.add(doc);
    list.add(m);
    list.add(m.getListOfReactions());
    Reaction r1 = m.getReaction(0);
    list.add(r1);
    list.add(r1.getListOfModifiers());
    list.add(r1.getModifier(0));
    Reaction r2 = m.getReaction(1);
    list.add(r2);
    list.add(r2.getListOfModifiers());
    list.add(r2.getModifier(0));
    List<? extends TreeNode> result = doc.filter(filter, true);
    System.out.println("filter result retain internals without pruning:\n  " + result);
View Full Code Here

  /**
   * Test method for {@link org.sbml.jsbml.AbstractTreeNode#filter(org.sbml.jsbml.util.filters.Filter, boolean, boolean)}.
   */
  @Test
  public void testFilterBooleanBoolean() {
    Model m = doc.getModel();
    List<TreeNode> list = new LinkedList<TreeNode>();
    list.add(doc);
    list.add(m);
    list.add(m.getListOfReactions());
    Reaction r1 = m.getReaction(0);
    list.add(r1);
    list.add(r1.getListOfModifiers());
    list.add(r1.getModifier(0));
    List<? extends TreeNode> result = doc.filter(filter, true, true);
    System.out.println("filter result retain internals with pruning:\n  " + result);
View Full Code Here

          return annotation;
        } else if (contextObject instanceof SBMLDocument) {
          SBMLDocument sbmlDocument = (SBMLDocument) contextObject;
          if (elementName.equals("model")) {
            Model model = (Model) newContextObject;
            model.setLevel(sbmlDocument.getLevel());
            model.setVersion(sbmlDocument.getVersion());
            model.initDefaults();
            sbmlDocument.setModel(model);

            return model;
          }
        } else if (contextObject instanceof Model) {

          Model model = (Model) contextObject;
          if (newContextObject instanceof ListOf<?>) {
            if (elementName.equals("listOfFunctionDefinitions")
                && model.getLevel() > 1) {
              ListOf<FunctionDefinition> listOfFunctionDefinitions = (ListOf<FunctionDefinition>) newContextObject;
              model.setListOfFunctionDefinitions(listOfFunctionDefinitions);

              return listOfFunctionDefinitions;
            } else if (elementName.equals("listOfUnitDefinitions")) {
              ListOf<UnitDefinition> listOfUnitDefinitions = (ListOf<UnitDefinition>) newContextObject;
              model.setListOfUnitDefinitions(listOfUnitDefinitions);

              return listOfUnitDefinitions;
            } else if (elementName.equals("listOfCompartments")) {
              ListOf<Compartment> listOfCompartments = (ListOf<Compartment>) newContextObject;
              model.setListOfCompartments(listOfCompartments);

              return listOfCompartments;
            } else if (elementName.equals("listOfSpecies")) {
              ListOf<Species> listOfSpecies = (ListOf<Species>) newContextObject;
              model.setListOfSpecies(listOfSpecies);

              return listOfSpecies;
            } else if (elementName.equals("listOfParameters")) {
              ListOf<Parameter> listOfParameters = (ListOf<Parameter>) newContextObject;
              model.setListOfParameters(listOfParameters);

              return listOfParameters;
            } else if (elementName.equals("listOfInitialAssignments")
                && ((model.getLevel() == 2 && model.getVersion() > 1)
                    || model.getLevel() >= 3)) {
              ListOf<InitialAssignment> listOfInitialAssignments = (ListOf<InitialAssignment>) newContextObject;
              model.setListOfInitialAssignments(listOfInitialAssignments);

              return listOfInitialAssignments;
            } else if (elementName.equals("listOfRules")) {
              ListOf<Rule> listOfRules = (ListOf<Rule>) newContextObject;
              model.setListOfRules(listOfRules);

              return listOfRules;
            } else if (elementName.equals("listOfConstraints")
                && ((model.getLevel() == 2 && model.getVersion() > 1)
                    || model.getLevel() >= 3)) {
              ListOf<Constraint> listOfConstraints = (ListOf<Constraint>) newContextObject;
              model.setListOfConstraints(listOfConstraints);

              return listOfConstraints;
            } else if (elementName.equals("listOfReactions")) {
              ListOf<Reaction> listOfReactions = (ListOf<Reaction>) newContextObject;
              model.setListOfReactions(listOfReactions);

              return listOfReactions;
            } else if (elementName.equals("listOfEvents")
                && model.getLevel() > 1) {
              ListOf<Event> listOfEvents = (ListOf<Event>) newContextObject;
              model.setListOfEvents(listOfEvents);

              return listOfEvents;
            } else if (elementName.equals("listOfCompartmentTypes")
                && (model.getLevel() == 2 && model.getVersion() > 1)) {
              ListOf<CompartmentType> listOfCompartmentTypes = (ListOf<CompartmentType>) newContextObject;
              model.setListOfCompartmentTypes(listOfCompartmentTypes);

              return listOfCompartmentTypes;
            } else if (elementName.equals("listOfSpeciesTypes")
                && (model.getLevel() == 2 && model.getVersion() > 1)) {
              ListOf<SpeciesType> listOfSpeciesTypes = (ListOf<SpeciesType>) newContextObject;
              model.setListOfSpeciesTypes(listOfSpeciesTypes);

              return listOfSpeciesTypes;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
          } else {
            log4jLogger.warn("The element " + elementName + " is not recognized");
          }
        } else if (contextObject instanceof ListOf<?>) {
          ListOf<?> list = (ListOf<?>) contextObject;
          if (list.getParentSBMLObject() instanceof Model) {

            Model model = (Model) list.getParentSBMLObject();
            if (elementName.equals("functionDefinition")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfFunctionDefinitions)
                && model.getLevel() > 1) {
              FunctionDefinition functionDefinition = (FunctionDefinition) newContextObject;
              model.addFunctionDefinition(functionDefinition);

              return functionDefinition;
            } else if (elementName.equals("unitDefinition")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfUnitDefinitions)) {
              UnitDefinition unitDefinition = (UnitDefinition) newContextObject;
              model.addUnitDefinition(unitDefinition);

              return unitDefinition;
            } else if (elementName.equals("compartment")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfCompartments)) {
              Compartment compartment = (Compartment) newContextObject;
              compartment.initDefaults();
              model.addCompartment(compartment);

              return compartment;
            } else if (elementName.equals("species")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpecies)
                && ((model.getLevel() == 1 && model
                    .getVersion() > 1) || model.getLevel() > 1)) {
              Species species = (Species) newContextObject;
              species.initDefaults();
              model.addSpecies(species);

              return species;
            }
            // level 1: species => specie
            else if (elementName.equals("specie")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpecies)
                && model.getLevel() == 1
                && model.getVersion() == 1) {
              Species species = (Species) newContextObject;
              species.initDefaults();
              model.addSpecies(species);

              return species;
            } else if (elementName.equals("parameter")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfParameters)) {
              Parameter parameter = (Parameter) newContextObject;
              parameter.initDefaults();
              model.addParameter(parameter);

              return parameter;
            } else if (elementName.equals("initialAssignment")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfInitialAssignments)
                && ((model.getLevel() == 2 && model
                    .getVersion() > 1) || model.getLevel() >= 3)) {
              InitialAssignment initialAssignment = (InitialAssignment) newContextObject;
              model.addInitialAssignment(initialAssignment);

              return initialAssignment;
            } else if (elementName.equals("algebraicRule")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)) {
              AlgebraicRule rule = (AlgebraicRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("assignmentRule")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)
                && model.getLevel() > 1) {
              AssignmentRule rule = (AssignmentRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("parameterRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("specieConcentrationRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1
                && model.getVersion() == 1)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("speciesConcentrationRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1
                && model.getVersion() == 2)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("compartmentVolumeRule")
                && list.getSBaseListType().equals(ListOf.Type.listOfRules)
                && model.getLevel() == 1)
            {
              ExplicitRule rule = (ExplicitRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("rateRule")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfRules)) {
              RateRule rule = (RateRule) newContextObject;
              model.addRule(rule);

              return rule;
            } else if (elementName.equals("constraint")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfConstraints)
                && ((model.getLevel() == 2 && model
                    .getVersion() > 1) || model.getLevel() >= 3)) {
              Constraint constraint = (Constraint) newContextObject;
              model.addConstraint(constraint);

              return constraint;
            } else if (elementName.equals("reaction")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfReactions)) {
              Reaction reaction = (Reaction) newContextObject;
              model.addReaction(reaction);
              reaction.initDefaults();

              return reaction;
            } else if (elementName.equals("event")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfEvents)
                && model.getLevel() > 1) {
              Event event = (Event) newContextObject;
              model.addEvent(event);
              event.initDefaults();

              return event;
            } else if (elementName.equals("compartmentType")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfCompartmentTypes)
                && (model.getLevel() == 2 && model.getVersion() > 1)) {
              CompartmentType compartmentType = (CompartmentType) newContextObject;
              model.addCompartmentType(compartmentType);

              return compartmentType;
            } else if (elementName.equals("speciesType")
                && list.getSBaseListType().equals(
                    ListOf.Type.listOfSpeciesTypes)
                && (model.getLevel() == 2 && model.getVersion() > 1)) {
              SpeciesType speciesType = (SpeciesType) newContextObject;
              model.addSpeciesType(speciesType);

              return speciesType;
            } else {
              log4jLogger.warn("The element " + elementName + " is not recognized");
            }
View Full Code Here

   */
  @SuppressWarnings("deprecation")
  @Test
  public void test_read_l1v1_branch() throws XMLStreamException, InvalidPropertiesFormatException, IOException, ClassNotFoundException {
    SBMLDocument d;
    Model m;
    Compartment c;
    KineticLaw kl;
    LocalParameter p;
    Reaction r;
    Species s;
    SpeciesReference sr;
    UnitDefinition ud;
    String filename = DATA_FOLDER + "/libsbml-test-data/l1v1-branch.xml";
    d = new SBMLReader().readSBML(filename);
    if (d == null)
      ;
    {
    }
    assertTrue(d.getLevel() == 1);
    assertTrue(d.getVersion() == 1);
    m = d.getModel();
    assertTrue(m.getName().equals("Branch"));
    assertTrue(m.getCompartmentCount() == 1);
    c = m.getCompartment(0);
    assertTrue(c.getName().equals("compartmentOne"));
    assertTrue(c.getVolume() == 1);
    ud = c.getDerivedUnitDefinition();
    assertTrue(ud.getUnitCount() == 1);

    // assertTrue(ud.getUnit(0).getKind() == Unit.Kind.LITRE); // getDerivedUnitDefinition not working properly
    assertTrue(m.getSpeciesCount() == 4);
    s = m.getSpecies(0);
    assertTrue(s.getName().equals("S1"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == false);

    //    ud = s.getDerivedUnitDefinition(); // getDerivedUnitDefinition not working properly
//    assertTrue(ud.getUnitCount() == 2);
//    assertTrue(ud.getUnit(0).getKind() == Unit.Kind.MOLE);
//    assertTrue(ud.getUnit(0).getExponent() == 1);
//    assertTrue(ud.getUnit(1).getKind() == Unit.Kind.LITRE);
//    assertTrue(ud.getUnit(1).getExponent() == -1);
   
    s = m.getSpecies(1);
    assertTrue(s.getName().equals("X0"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    s = m.getSpecies(2);
    assertTrue(s.getName().equals("X1"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    s = m.getSpecies(3);
    assertTrue(s.getName().equals("X2"));
    assertTrue(s.getCompartment().equals("compartmentOne"));
    assertTrue(s.getInitialAmount() == 0);
    assertTrue(s.getBoundaryCondition() == true);
    assertTrue(m.getReactionCount() == 3);
    r = m.getReaction(0);
    assertTrue(r.getName().equals("reaction_1"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    ud = r.getKineticLaw().getDerivedUnitDefinition();

    //    assertTrue(ud.getUnitCount() == 2);
//    assertTrue(ud.getUnit(0).getKind() == Unit.Kind.MOLE);
//    assertTrue(ud.getUnit(0).getExponent() == 1);
//    assertTrue(ud.getUnit(1).getKind() == Unit.Kind.LITRE);
//    assertTrue(ud.getUnit(1).getExponent() == -1);
   
    assertTrue(r.getKineticLaw().containsUndeclaredUnits() == true);
    r = m.getReaction(1);
    assertTrue(r.getName().equals("reaction_2"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    r = m.getReaction(2);
    assertTrue(r.getName().equals("reaction_3"));
    assertTrue(r.getReversible() == false);
    assertTrue(r.getFast() == false);
    r = m.getReaction(0);
    assertTrue(r.getReactantCount() == 1);
    assertTrue(r.getProductCount() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("X0"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k1*X0")); // We are not putting the same space in the formula
    assertTrue(kl.getLocalParameterCount() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k1"));
    assertTrue(p.getValue() == 0);
    r = m.getReaction(1);
    assertTrue(r.getReactantCount() == 1);
    assertTrue(r.getProductCount() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    sr = r.getProduct(0);
    assertTrue(sr.getSpecies().equals("X1"));
    assertTrue(sr.getStoichiometry() == 1);
    assertTrue(sr.getDenominator() == 1);
    kl = r.getKineticLaw();
    assertTrue(kl.getFormula().equals("k2*S1")); // equals("k2 * S1")
    assertTrue(kl.getLocalParameterCount() == 1);
    p = kl.getParameter(0);
    assertTrue(p.getName().equals("k2"));
    assertTrue(p.getValue() == 0);
    r = m.getReaction(2);
    assertTrue(r.getReactantCount() == 1);
    assertTrue(r.getProductCount() == 1);
    sr = r.getReactant(0);
    assertTrue(sr.getSpecies().equals("S1"));
    assertTrue(sr.getStoichiometry() == 1);
View Full Code Here

   */
  @Test public void read5() throws XMLStreamException, InvalidPropertiesFormatException, IOException, ClassNotFoundException {
    String fileName = DATA_FOLDER + "/l2v3/BIOMD0000000191.xml"; // l2v3
   
    SBMLDocument doc = new SBMLReader().readSBMLFile(fileName);
    Model model = doc.getModel();
   
    assertTrue(doc.getLevel() == 2 && doc.getVersion() == 3);
   
    assertTrue(model.getUnitDefinitionCount() == 4);
   
    UnitDefinition microM = model.getUnitDefinition(2);
    UnitDefinition microMById = model.getUnitDefinition("microM");
   
    assertTrue(microM.equals(microMById));
   
    assertTrue(microM.getUnitCount() == 2);
    assertTrue(microM.getName().equals("microM"));
    assertTrue(microM.getUnit(0).getScale() == -6);
    assertTrue(microM.getUnit(0).getKind().getName().equals("mole"));
   
    int nbSpecies = model.getListOfSpecies().filterList(new Filter() {
     
        /*
         * (non-Javadoc)
         * @see org.sbml.jsbml.util.filters.Filter#accepts(java.lang.Object)
         */
        public boolean accepts(Object o) {
          if (o instanceof Species) {
            return true;
          }
         
          return false;
        }
      }).size();
   
    assertTrue(nbSpecies == model.getNumSpecies());
  }
View Full Code Here

            }
          }
        }
   
        // creating submodel object
        Model subModel = subModelSbmlDocument.createModel(subModelId);
        subModel.setMetaId(subModelId);

        if (!inclComp) {
          compartmentsIds = null;
        }
        if (inclComp && inclSpecies) {
          speciesIds = getRelatedSpecies(model, null, compartmentsIds, speciesIds);
          reactsIds = getRelatedReactions(model, reactsIds, speciesIds);
        } else {
          speciesIds = reactsIds = null;
        }
       
        Set<String> relatedFunctionsIdSet = new HashSet<String>();
        Set<String> allFunctionsIdSet = new HashSet<String>();
        Map<String, UnitDefinition> unitsMap = new HashMap<String, UnitDefinition>();
       
        for (FunctionDefinition functionDefinition : model.getListOfFunctionDefinitions()) {
          allFunctionsIdSet.add(functionDefinition.getId());
        }

        // TODO: the added rules or events can contain some species, compartment or speciesReferences (for L3) that could
        // not be present in the list of included elements !!!

        //
        // Reactions.
        //

        if (reactsIds != null) {
          for (int i = 0; i < reactsIds.length; i++) {
            Reaction relatedReaction = model.getReaction(reactsIds[i]);

            subModel.addReaction(relatedReaction.clone());

            if (relatedReaction.getKineticLaw() != null) {
              // TODO: Parameters!
              getRelatedFunctionsId(relatedFunctionsIdSet, allFunctionsIdSet, relatedReaction.getKineticLaw().getMath());
              processUnitsMap(unitsMap, model, relatedReaction.getKineticLaw());
            }
          }
        }


        //
        // compartments and compartments type
        //

        speciesIds = getRelatedSpecies(model, reactsIds, compartmentsIds, speciesIds);
        compartmentsIds = getRelatedCompartments(model, compartmentsIds, speciesIds);

        if (compartmentsIds != null) {
          for (int i = 0; i < compartmentsIds.length; i++) {
            Compartment relatedCompartment = model.getCompartment(compartmentsIds[i]);

            subModel.addCompartment(relatedCompartment.clone());
            processUnitsMap(unitsMap, model, relatedCompartment.getUnits());

            // check compartment type
            if ((relatedCompartment.getCompartmentTypeInstance() != null)
               && (subModel.getCompartmentType(relatedCompartment.getCompartmentType()) == null)) {
              subModel.addCompartmentType(relatedCompartment.getCompartmentTypeInstance().clone());
            }
          }
        }


        //
        // species and species type
        //

        if (speciesIds != null) {
          for (int i = 0; i < speciesIds.length; i++) {
            Species relatedSpecies = model.getSpecies(speciesIds[i]);
            subModel.addSpecies(relatedSpecies.clone());
            processUnitsMap(unitsMap, model, relatedSpecies.getSubstanceUnits());

            // check species type
            if ((relatedSpecies.getSpeciesTypeInstance() != null)
               && (subModel.getSpeciesType(relatedSpecies.getSpeciesType()) == null)) {
              subModel.addSpeciesType(relatedSpecies.getSpeciesTypeInstance().clone());
            }
          }
        }


        //
        // rules
        //
       
        if (inclRules) {
          rulesIds = getRelatedRules(model, rulesIds, compartmentsIds, speciesIds);

          if ((rulesIds != null) && (rulesIds.length > 0)) {
            for (String ruleId : rulesIds) {
              for (Rule modelRule : model.getListOfRules()) {
                if (modelRule.getMetaId().equals(ruleId)) {
                  subModel.addRule(modelRule.clone());
                  if (modelRule.getMath() != null) {
                    getRelatedFunctionsId(relatedFunctionsIdSet, allFunctionsIdSet, modelRule.getMath());
                    // TODO: analyze the math to add missing Species, ...
                  }
                }
              }
            }
          }
        }

        //
        // events
        //

        if (inclEvents) {
          eventsIds = getRelatedEvents(model, eventsIds, compartmentsIds, speciesIds);

          if ((eventsIds != null) && (eventsIds.length > 0)) {
            for (int i = 0; i < eventsIds.length; i++) {
              for (Event modelEvent : model.getListOfEvents()) {
                if (modelEvent.getMetaId().equals(eventsIds[i])) {
                  subModel.addEvent(modelEvent.clone());
                  if (modelEvent.getTrigger() != null) {
                    getRelatedFunctionsId(relatedFunctionsIdSet, allFunctionsIdSet, modelEvent.getTrigger().getMath());
                  }
                  if (modelEvent.getDelay() != null) {
                    getRelatedFunctionsId(relatedFunctionsIdSet, allFunctionsIdSet, modelEvent.getDelay().getMath());
                  }
                }
              }
            }
          }
        }


        //
        // parameters.
        //

        // TODO: try not to add all the parameters !!
        // When we do getRelatedFunctions, we could search for the related species and parameter !!
       
        for (Parameter parameter : model.getListOfParameters()) {
            subModel.addParameter(parameter.clone());
            processUnitsMap(unitsMap, model, parameter.getUnits());
        }


        //
        // units
        //

        for (UnitDefinition unitDefinition : unitsMap.values()) {
            subModel.addUnitDefinition(unitDefinition.clone());
        }


        //
        // FunctionDefinition
        //
        for (String functionDefinitionId : relatedFunctionsIdSet) {
            FunctionDefinition func = model.getFunctionDefinition(functionDefinitionId);
            getRelatedFunctionsId(relatedFunctionsIdSet, allFunctionsIdSet, func.getMath());
        }
        for (String functionDefinitionId : relatedFunctionsIdSet) {
            subModel.addFunctionDefinition(model.getFunctionDefinition(functionDefinitionId).clone());
        }

        return subModelSbmlDocument;
    }
View Full Code Here

  @SuppressWarnings("deprecation")
@Test public void test_read_l2v1_assignment()
  {
    SBMLReader reader = new SBMLReader();
    SBMLDocument d = null;
    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.getCompartmentCount() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
/*    ud = c.getDerivedUnitDefinition();
    assertTrue( ud.getUnitCount() == 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.getSpeciesCount() == 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.getParameterCount() == 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.getUnitCount() == 0 );
    assertTrue( m.getRuleCount() == 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.getUnitCount() == 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.getReactionCount() == 2 );
    r = m.getReaction(0);
    assertTrue( r != null );
    assertTrue( r.getId().equals( "in") );
    assertTrue( r.getReactantCount() == 1 );
    assertTrue( r.getProductCount() == 1 );
    sr = r.getReactant(0);
    assertTrue( sr != null );
    assertTrue( sr.getSpecies().equals( "X0") );
    sr = r.getProduct(0);
    assertTrue( sr != null );
    assertTrue( sr.getSpecies().equals( "T" ) );
    kl = r.getKineticLaw();
    assertTrue( kl != null );
    assertTrue( kl.getFormula().equals( "k1*X0") );
    assertTrue( kl.getLocalParameterCount() == 1 );
    r1 = (Reaction) kl.getParentSBMLObject();
    assertTrue( r1 != null );
    assertTrue( r1.getId().equals( "in") );
    assertTrue( r1.getReactantCount() == 1 );
    assertTrue( r1.getProductCount() == 1 );
    lp = kl.getLocalParameter(0);
    assertTrue( lp != null );
    assertTrue( lp.getId().equals( "k1") );
    assertTrue( lp.getValue() == 0.1 );
    kl = (KineticLaw) lp.getParentSBMLObject().getParentSBMLObject();
    assertTrue( kl != null );
    assertTrue( kl.getFormula().equals( "k1*X0") );
    assertTrue( kl.getLocalParameterCount() == 1 );
    r = m.getReaction(1);
    assertTrue( r != null );
    assertTrue( r.getId().equals( "out") );
    assertTrue( r.getReactantCount() == 1 );
    assertTrue( r.getProductCount() == 1 );
    sr = r.getReactant(0);
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.Model

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.