Package org.sbml.jsbml

Examples of org.sbml.jsbml.SBMLDocument


   * @throws SBMLException
   * @throws XMLStreamException
   */
  public static void main(String[] args) throws XMLStreamException,
      SBMLException {
    SBMLDocument doc = new SBMLDocument(2, 4);
    doc.addTreeNodeChangeListener(new SimpleTreeNodeChangeListener());
    Model model = doc.createModel("test_model");
   
    Parameter k1 = model.createParameter("k1");
    Parameter k2 = model.createParameter("k2");

    k1.addCVTerm(new CVTerm(CVTerm.Qualifier.BQB_IS, "test"));
View Full Code Here


* @version $Rev: 1121 $
*/
public class SpeciesAnnotationTest extends SimpleTreeNodeChangeListener {

  public SpeciesAnnotationTest() throws XMLStreamException, SBMLException {
    SBMLDocument doc = new SBMLDocument(2, 4);
    doc.addTreeNodeChangeListener(this);
    Model model = doc.createModel("model_test");
    Species s1 = model.createSpecies("s1", model.createCompartment("c1"));
    s1.setMetaId("meta_" + s1.getId());
    // Not necessary anymore.
    // s1.getAnnotation().addRDFAnnotationNamespace("bqbiol", "",
    // "http://biomodels.net/biology-qualifiers/");
View Full Code Here

      System.exit(0);
    }

    String fileName = args[0];

    SBMLDocument testDocument = new SBMLReader().readSBML(fileName);
   
    System.out.println("Number of namespaces: " + testDocument.getSBMLDocumentNamespaces().size());

    for(String prefix : testDocument.getSBMLDocumentNamespaces().keySet()){
      System.out.println("PREFIX = "+prefix);
      String uri = testDocument.getSBMLDocumentNamespaces().get(prefix);
      System.out.println("URI = "+uri);
    }

    System.out.println("Model NoRDFAnnotation String = \n@" + testDocument.getModel().getAnnotation().getNonRDFannotation() + "@");

    System.out.println("Model Annotation String = \n@" + testDocument.getModel().getAnnotationString() + "@");
   
    for (Species species : testDocument.getModel().getListOfSpecies()) {
      species.getAnnotationString();
    }
   
    new SBMLWriter().write(testDocument, System.out);
   
View Full Code Here

        // necessary ReadingParser instances.
        // Creates an empty SBMLDocument instance and pushes it on
        // the SBMLElements stack.
        if (currentNode.getLocalPart().equals("sbml")) {

          SBMLDocument sbmlDocument = new SBMLDocument();

          // the output of the change listener is activated or not via log4j.properties
          sbmlDocument.addTreeNodeChangeListener(listener == null
            ? new SimpleTreeNodeChangeListener() : listener);

          for (@SuppressWarnings("unchecked")
              Iterator<Attribute> iterator = startElement.getAttributes(); iterator.hasNext();)
          {
            Attribute attr = iterator.next();
            if (attr.getName().toString().equals("level")) {
              level = StringTools.parseSBMLInt(attr.getValue());
              sbmlDocument.setLevel(level);
            } else if (attr.getName().toString().equals("version")) {
              version = StringTools.parseSBMLInt(attr.getValue());
              sbmlDocument.setVersion(version);
            }
          }
          sbmlElements.push(sbmlDocument);
        } else if (lastElement == null) {
          // We put a fake Constraint element in the stack that can take either math, notes or message.
          // This a hack to be able to read some mathMl or notes by themselves.

          if (currentNode.getLocalPart().equals("notes") || currentNode.getLocalPart().equals("message")) {
           
            initializedParsers.put("", new SBMLCoreParser());
           
          } else if (currentNode.getLocalPart().equals("math")) {
           
            initializedParsers.put("", new MathMLStaxParser());
            initializedParsers.put(ASTNode.URI_MATHML_DEFINITION, new MathMLStaxParser());
            currentNode = new QName(ASTNode.URI_MATHML_DEFINITION, "math");
           
          }
         
          // TODO : will not work with arbitrary SBML part
          // TODO : we need to be able, somehow, to set the Model element in the Constraint
          // to be able to have a fully functional parsing. Without it the functionDefinition, for examples, are
          // not properly recognized.
          Constraint constraint = new Constraint(3,1);
          sbmlElements.push(constraint);
         
        } else if (currentNode.getLocalPart().equals("annotation")) {

          // get the sbml namespace as some element can have similar names in different namespaces
          SBMLDocument sbmlDoc = (SBMLDocument) sbmlElements.firstElement();
          String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

          if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
            if (isInsideAnnotation) {
              logger.warn("Starting to read a new annotation element while the previous annotation element is not finished.");
            }
            isInsideAnnotation = true;
            annotationDeepness++;
          }
         
        } else if (isInsideAnnotation) {
          // Count the number of open elements to know how deep we are in the annotation
          // We should only parse the RDF is annotationDeepness == 1 && rdfDescriptionIndex == 0
          annotationDeepness++;
        }
        else if (currentNode.getLocalPart().equals("notes"))
        {
          // get the sbml namespace as some element can have similar names in different namespaces
          SBMLDocument sbmlDoc = (SBMLDocument) sbmlElements.firstElement();
          String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

          if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
            isInsideNotes = true;
          }
        }
       
        // setting isRDFSBMLSpecificAnnotation
        if (currentNode.getLocalPart().equals("RDF") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS) && annotationDeepness == 1) {
          isRDFSBMLSpecificAnnotation = true;
        } else if (currentNode.getLocalPart().equals("RDF") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS)) {
          isRDFSBMLSpecificAnnotation = false;
          rdfDescriptionIndex = -1;
        }

        if (currentNode.getLocalPart().equals("Description") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS) && isRDFSBMLSpecificAnnotation) {
          rdfDescriptionIndex++;
        }

        if (isInsideAnnotation) {
          logger.debug("startElement : local part = " + currentNode.getLocalPart());
          logger.debug("startElement : annotation deepness = " + annotationDeepness);
          logger.debug("startElement : rdf description index = " + rdfDescriptionIndex);
          logger.debug("startElement : isRDFSBMLSpecificAnnotation = " + isRDFSBMLSpecificAnnotation);
        }

        parser = processStartElement(startElement, currentNode, isHTML,  sbmlElements, isInsideAnnotation, isRDFSBMLSpecificAnnotation);
        lastElement = sbmlElements.peek();

      }
      // Characters
      else if (event.isCharacters()) {
        Characters characters = event.asCharacters();

        if (!characters.isWhiteSpace()) {
          isText = true; // the characters are not only 'white spaces'
        }
        if (sbmlElements.peek() instanceof XMLNode || isInsideNotes) {
          isText = true; // We want to keep the whitespace/formatting when reading html block
        }

        // process the text of a XML element.
        if ((parser != null) && !sbmlElements.isEmpty()  && (isText || isInsideAnnotation)) {
         
          if (isInsideNotes) {
            parser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);
          }
//          else if (isInsideAnnotation) {
//            parser = initializedParsers.get("anyAnnotation");
//          }
         
          logger.debug(" Parser = " + parser.getClass().getName());
          logger.debug(" Characters = @" + characters.getData() + "@");
         
          if (currentNode != null) {
           
            // logger.debug("isCharacter : elementName = " + currentNode.getLocalPart());
           
            parser.processCharactersOf(currentNode.getLocalPart(),
                characters.getData(), sbmlElements.peek());
          } else {
            parser.processCharactersOf(null, characters.getData(),
                sbmlElements.peek());
          }
        } else if (isText) {
          logger.warn(String.format("Some characters cannot be read: %s", characters.getData()));
          if (logger.isDebugEnabled()) {
            logger.debug("Parser = " + parser);
            if (sbmlElements.isEmpty()) {
              logger.debug("The Object Stack is empty !!!");
            } else {
              logger.debug("The current Object in the stack is : " + sbmlElements.peek());
            }
          }

         
        }
      }
      // EndElement
      else if (event.isEndElement()) {

        // the method  processEndElement will return null until we arrive at the end of the 'sbml' element.
        lastElement = sbmlElements.peek();

        currentNode = event.asEndElement().getName();
       
        if (currentNode != null) {
         
          boolean isSBMLelement = true;
         
          // get the sbml namespace as some element can have similar names in different namespaces
          if (sbmlElements.firstElement() instanceof SBMLDocument) {
            SBMLDocument sbmlDoc = (SBMLDocument) sbmlElements.firstElement();
            String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");
            if (!currentNode.getNamespaceURI().equals(sbmlNamespace)) {
              isSBMLelement = false;
            }
          }
         
          if (currentNode.getLocalPart().equals("annotation")) {
           
            if (isSBMLelement) {
              isInsideAnnotation = false;
              annotationDeepness = -1;
              rdfDescriptionIndex = -1;
              isRDFSBMLSpecificAnnotation = false;
            }

          } else if (isInsideAnnotation) {
            annotationDeepness--;
          }
          else if (currentNode.getLocalPart().equals("notes") && isSBMLelement)
          {
            isInsideNotes = false;
          }
         
          if (currentNode.getLocalPart().equals("Description")
              && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS))
          {
            rdfDescriptionIndex--;
          }
        }

        SBMLDocument sbmlDocument = processEndElement(currentNode, isNested, isText, isHTML,
            level, version, parser, sbmlElements, isInsideAnnotation, isRDFSBMLSpecificAnnotation);
       
        if (sbmlDocument != null) {
          return sbmlDocument;
        }
View Full Code Here

          logger.debug("event.isEndElement : sbml element found");
         
          // process the end of the document and return
          // the final SBMLDocument
          if (sbmlElements.peek() instanceof SBMLDocument) {
            SBMLDocument sbmlDocument = (SBMLDocument) sbmlElements.peek();
           
            Iterator<Entry<String, ReadingParser>> iterator = initializedParsers.entrySet().iterator();           
            ArrayList<String> readingParserClasses = new ArrayList<String>();

            // Calling endDocument for all parsers           
View Full Code Here

   
  // TODO : transform this file into a proper junit test class that is included in the jsbml standard tests.
  // The junit test file would test uniqueness of metaids and ids in the model. 
   
  // Setup : creating some simple objects
    SBMLDocument doc=new SBMLDocument(2,4);
    Model m=doc.createModel("model1");
    Reaction r = m.createReaction("id1");
    SpeciesReference s = new SpeciesReference();
    s.setMetaId("meta2");
    r.addReactant(s);
    r.setMetaId("meta");
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.getNumCompartments() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
View Full Code Here

   * @throws ParseException
   * @throws XMLStreamException
   * @throws SBMLException
   */
  public EventTest() throws ParseException, XMLStreamException, SBMLException {
    SBMLDocument doc = new SBMLDocument(3, 1);
    doc.addTreeNodeChangeListener(this);
    Model model = doc.createModel("event_model");
    Compartment c = model.createCompartment("compartment");
    model.createSpecies("s1", c);
    model.createSpecies("s2", c);
    Event ev = model.createEvent();
    Trigger trigger = ev.createTrigger(false, true, ASTNode.parseFormula("3 >= 2"));
    trigger.setMath(ASTNode.geq(new ASTNode(ASTNode.Type.NAME_TIME),
        new ASTNode(10)));
    ev.createPriority(ASTNode.parseFormula("25"));
    ev.createDelay(ASTNode.parseFormula("2"));
    ev.createEventAssignment("s1", ASTNode.parseFormula("s2"));
    System.out.println("==================================");
    new SBMLWriter().write(doc, System.out);
    System.out.println("\n==================================");
    doc.setLevelAndVersion(2, 4);
    System.out.println("==================================");
    new SBMLWriter().write(doc, System.out);
  }
View Full Code Here

    // If the namespaces are declared in the sbml node, we need to add the
    // namespace to
    // the 'SBMLDocumentNamespaces' map of the SBMLDocument instance.
    else if (elementName.equals("sbml")
        && contextObject instanceof SBMLDocument) {
      SBMLDocument sbmlDocument = (SBMLDocument) contextObject;
      sbmlDocument.addNamespace(localName, prefix, URI);
    }
  }
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.getNumCompartments() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.SBMLDocument

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.