Examples of SBMLDocument


Examples of org.sbml.jsbml.SBMLDocument

   * Tries to validate biomodels file with id 025 with all checks on.
   */
  @Test public void checkConsistencyAllChecks() throws IOException, XMLStreamException {
    String fileName = DATA_FOLDER + "/l2v1/BIOMD0000000025.xml";
   
    SBMLDocument doc = new SBMLReader().readSBML(fileName);
   
    doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.UNITS_CONSISTENCY, true);
   
    int nbErrors = doc.checkConsistency();

    int numRealErrors = doc.getErrorLog().getNumFailsWithSeverity(SEVERITY.ERROR);
      if (numRealErrors > 0) {
        System.out.println("# Found " + numRealErrors + " VALIDATION ERRORS !!!");
      }
     
    System.out.println("Found " + nbErrors + " errors/warnings on Biomodels 025 with the unit checking turned on.");
    assertTrue(nbErrors > 0);
   
    assertTrue(doc.getErrorLog().getNumFailsWithSeverity(SEVERITY.ERROR) == 0);
   
    assertTrue(nbErrors == doc.getErrorCount());
    assertTrue(nbErrors == doc.getErrorLog().getValidationErrors().size());
   
  }
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

      writer.writeStartElement("math");
      writer.writeNamespace(null, ASTNode.URI_MATHML_DEFINITION)
     
      if (isSBMLNamespaceNeeded) {
        // writing the SBML namespace
        SBMLDocument doc = null;
        SBase sbase = astNode.getParentSBMLObject();
        String sbmlNamespace = SBMLDocument.URI_NAMESPACE_L3V1Core;
       
        if (sbase != null) {
          doc = sbase.getSBMLDocument();
          sbmlNamespace = doc.getSBMLDocumentNamespaces().get("xmlns");         
        }
        writer.writeNamespace("sbml", sbmlNamespace);
      }
     
      writer.writeCharacters("\n");
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

   * Tries to validate biomodels file with id 228.
   */
  @Test public void checkConsistency228() throws IOException, XMLStreamException {
    String fileName = DATA_FOLDER + "/l2v4/BIOMD0000000228.xml";
   
    SBMLDocument doc = new SBMLReader().readSBML(fileName);
    try {
      int nbErrors = doc.checkConsistency();

      System.out.println("Found " + nbErrors + " errors on Biomodels 228 with the unit checking turned off.");

    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

   * Tries to validate biomodels file with id 228.
   */
  @Test public void checkConsistency025() throws IOException, XMLStreamException {
    String fileName = DATA_FOLDER + "/l2v1/BIOMD0000000025.xml";
   
    SBMLDocument doc = new SBMLReader().readSBML(fileName);
    try {
      int nbErrors = doc.checkConsistency();

      System.out.println("Found " + nbErrors + " errors on Biomodels 025 with the unit checking turned off.");

    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

   *
   */
  public MathMLTest() {
    int level = 3;
    int version = 1;
    SBMLDocument doc = new SBMLDocument(level, 1);
    Model m = doc.createModel("id");
    FunctionDefinition fd = m.createFunctionDefinition("fd");
    ASTNode math = new ASTNode(Type.LAMBDA, fd);
    math.addChild(new ASTNode("x", fd));
    ASTNode pieces = ASTNode.piecewise(new ASTNode(3, fd), ASTNode.lt("x",
        ASTNode.abs(Double.NEGATIVE_INFINITY, fd)), ASTNode.times(
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

   * @param args
   */
  @Test
  public void idTest() {
    int level = 2, version = 4;
    SBMLDocument doc = new SBMLDocument(level, version);
    Model model = doc.createModel("myModel");
    Reaction r1 = model.createReaction("r1");
   
    /*
     * Local Parameters
     */
 
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

      System.exit(0);
    }

    String fileName = args[0];

    SBMLDocument testDocument = new org.sbml.jsbml.SBMLReader().readSBMLFromFile(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() + "@");
   
    int i = 0;
    for (Species species : testDocument.getModel().getListOfSpecies()) {
      // species.getAnnotationString(); // /scratch/rodrigue/src/jsbml/jsbml_trunk/data/yeast_4.02.xml
      System.out.println("SpeciesType Object = " + species.getSpeciesTypeInstance());
      System.out.println("SpeciesType ID = " + species.getSpeciesType());
      if (i++ > 30) {
        break;
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

        // 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 are probably reading some 'free' XML, mathML or HTML
        {
          // 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 the parent container is set in this SBMLReader, we use it instead.
         
          if (currentNode.getLocalPart().equals("notes") || currentNode.getLocalPart().equals("message"))
          {
            initializedParsers.put("", 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.
          if (astNodeParent != null)
          {
            sbmlElements.push(astNodeParent);
          }
          else
          {
            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
          SBase firstElement = (SBase) sbmlElements.firstElement();
         
          if (firstElement instanceof SBMLDocument) {
            SBMLDocument sbmlDoc = (SBMLDocument) firstElement;
            String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

            if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
              isInsideNotes = true;
            }
          } else if (firstElement instanceof Constraint) { // we are reading a partial document from SBMLReader#readNotes for example
            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.isDebugEnabled()) {
          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,
            isInsideNotes, annotationDeepness, 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");
//          }
         
          if (logger.isDebugEnabled()) {
            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(MessageFormat.format("Some characters cannot be read: {0}", 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, isInsideNotes, annotationDeepness,
            isRDFSBMLSpecificAnnotation);
       
        if (sbmlDocument != null) {
          return sbmlDocument;
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

*/
public class TestLocalParameterIdentification {

  public static void main(String[] args) throws IOException, XMLStreamException {
   
    SBMLDocument doc = new SBMLDocument(2, 4);
    Model model = doc.createModel("model_test");
    Compartment c1 = model.createCompartment("c1");
    Species s1 = model.createSpecies("s1", c1);
    s1.setMetaId("meta_" + s1.getId());
   
    Species s2 = model.createSpecies("s2", c1);
    s2.setMetaId("meta_" + s2.getId());
   
    Reaction r = model.createReaction("r1");
    r.createReactant(s1);
    r.createProduct(s2);
   
    model.createParameter("k");
   
    KineticLaw kl = r.createKineticLaw();
    kl.createLocalParameter("k");
    ASTNode node = ASTNode.readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> <apply><times/><ci> k </ci><ci> S1 </ci></apply></math>");
    kl.setMath(node);
   
    if (!(kl.getMath().getChild(0).getVariable() instanceof LocalParameter)) {
      System.out.println("The local parameter k is not found!");
    }
   
   
    doc = new SBMLReader().readSBML("core/files/test-models/00733-sbml-l2v4.xml");
    r = doc.getModel().getReaction("reaction1");
    kl = r.getKineticLaw();
    if (!(kl.getMath().getChild(1).getVariable() instanceof LocalParameter)) {
      System.out.println("The local parameter k is not found!");
    }
  }
View Full Code Here

Examples of org.sbml.jsbml.SBMLDocument

          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();           
            List<String> readingParserClasses = new ArrayList<String>();

            // Calling endDocument for all parsers           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.