Package org.sbml.jsbml

Examples of org.sbml.jsbml.Annotation


    // A CreatorParser can only modify a contextObject which is an Annotation instance.
    // The namespace of this parser should be associated with the creator subnode of an annotation.
    // Creates a ModelHistory instance and set the modelHistory of annotation.
    if (elementName.equals("creator") && contextObject instanceof Annotation){
      Annotation annotation = (Annotation) contextObject;
      History modelHistory = new History();
      annotation.setHistory(modelHistory);
     
      return modelHistory;
    }
    else {
      // TODO : !elementName.equals("creator"), SBML syntax error?
View Full Code Here


    }
    // A SBMLCoreParser can modify a contextObject which is an instance of
    // Annotation.
    // Try to read the attributes.
    else if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;
      isAttributeRead = annotation.readAttribute(attributeName, prefix,
          value);
    } else if (contextObject instanceof ASTNode) {
      ASTNode astNode = (ASTNode) contextObject;
     
      try {
View Full Code Here

      }

      log4jLogger.debug("processNamespace : " + prefix + " = " + URI);
    }
    else if (contextObject instanceof Annotation) {
      Annotation sbase = (Annotation) contextObject;
      sbase.addAnnotationNamespace(localName, prefix, URI);
     
      log4jLogger.debug("processNamespace : " + prefix + " = " + URI);
    }
  }
View Full Code Here

          SBase sbase = (SBase) contextObject;
          sbase.setNotes(new XMLNode(new XMLTriple("notes", null, null), new XMLAttributes()));
        } else if (elementName.equals("annotation")
            && (contextObject instanceof SBase)) {
          SBase sbase = (SBase) contextObject;
          Annotation annotation = (Annotation) newContextObject;
          sbase.setAnnotation(annotation);

          return annotation;
        } else if (contextObject instanceof SBMLDocument) {
          SBMLDocument sbmlDocument = (SBMLDocument) contextObject;
View Full Code Here

    boolean isReadAttribute = false;

    // A RDFAnnotationParser can modify a contextObject which is an Annotation instance.
    // The annotation element can contain other attributes. Try to read them.
    if (contextObject instanceof Annotation){
      Annotation modelAnnotation = (Annotation) contextObject;
      isReadAttribute = modelAnnotation.readAttribute(attributeName, prefix, value);
    }
    // A RDFAnnotationParser can modify a contextObject which is an ModelHistory instance.
    // When this parser is parsing the model history, some rdf attributes can appear. Try to
    // read them.
    else if (contextObject instanceof History){
View Full Code Here

      String localName, boolean hasAttributes, boolean isLastNamespace,
      Object contextObject) {

    // Adds the namespace to the RDFAnnotationNamespaces HashMap of annotation.
    if (elementName.equals("RDF") && contextObject instanceof Annotation){
      Annotation annotation = (Annotation) contextObject;
      annotation.addRDFAnnotationNamespace(localName, prefix, URI);;
    }
  }
View Full Code Here

      Model m = doc.createModel("model1");
      Model m2 = new Model("model1", 2, 4);
     
      Species s1 = m.createSpecies("id1");
     
      Annotation annotation = new Annotation();
      CVTerm cvterm = new CVTerm();
      cvterm.addResource("urn.miriam.obo.go#GO%3A1234567");
      cvterm.setQualifierType(Type.BIOLOGICAL_QUALIFIER);
      cvterm.setBiologicalQualifierType(Qualifier.BQB_IS);
     
      annotation.addCVTerm(cvterm);
     
      System.out.println("The Annotation is still empty as there is no metaid defined on the species !!");
      System.out.println("@" + s1.getAnnotationString() + "@");
     
      s1.setMetaId("meta4");
      s1.setAnnotation(annotation);
     
      System.out.println("After adding a metaid on the species, the Annotation String get generated as it should.");
      System.out.println("@" + s1.getAnnotationString() + "@");
     


      String urn_id = "C00001";
     
      Species specie = m2.createSpecies();
      specie.setId("S2");
      specie.setName("S2");
      // specie.setCompartment(compartment);
      specie.setInitialAmount(1);

      annotation = new Annotation();
      CVTerm cvTerm = new CVTerm(Qualifier.BQB_IS);
      cvTerm.setQualifierType(Type.BIOLOGICAL_QUALIFIER);
     
      if(urn_id.startsWith("C"))
      {
      cvTerm.addResource("urn:miriam:kegg.compound:" + urn_id);
      annotation.addCVTerm(cvTerm);
      annotation.appendNoRDFAnnotation("http://www.genome.jp/dbget-bin/www_bget?cpd:"+urn_id);
      }
     
      if(urn_id.startsWith("G"))
      {
      cvTerm.addResource("urn:miriam:kegg.glycan:" + urn_id);
      annotation.addCVTerm(cvTerm);
      annotation.appendNoRDFAnnotation("<myApp:xxx>http://www.genome.jp/dbget-bin/www_bget?gl:"+urn_id + "</myApp:xxx>");
      }
     
      if (urn_id.contains("."))
      {
      cvTerm.addResource("urn:miriam:ec-code:" + urn_id);
      annotation.addCVTerm(cvTerm);
      annotation.appendNoRDFAnnotation("http://www.genome.jp/dbget-bin/www_bget?ec:"+urn_id);
      }

      System.out.println("The Annotation is still empty as there is no metaid defined on the species !!");
      System.out.println("@" + specie.getAnnotationString() + "@");
View Full Code Here

    if (object instanceof SBase) {
      SBase sbase = (SBase) object;
      packageNamespaces = sbase.getNamespaces();
    } else if (object instanceof Annotation) {
      Annotation annotation = (Annotation) object;
      packageNamespaces = annotation.getNamespaces();
    } else {
      logger.warn("getInitializedParsers : I don't know what to do with " + object);
    }
   
    ArrayList<WritingParser> sbmlParsers = new ArrayList<WritingParser>();
View Full Code Here

    // create the sbmlNamespace variable
    String sbmlNamespace = JSBML.getNamespaceFrom(sbase.getLevel(), sbase.getVersion());
    SMNamespace namespace = element.getContext().getNamespace(sbmlNamespace);

    namespace.setPreferredPrefix("");
    Annotation annotation = sbase.getAnnotation();
    SMOutputElement annotationElement;
    String whiteSpaces = createIndentationString(indent);
   
    if (xmlFragment) {
      annotationElement = element.addElement("annotation");
    } else {
      element.addCharacters("\n");
      element.setIndentation(whiteSpaces, indent, indentCount);   
      annotationElement = element.addElement(namespace, "annotation");
    }
    annotationElement.setIndentation(whiteSpaces, indent, indentCount);

    if ((annotation.getNonRDFannotation() != null)
        && (annotation.getNonRDFannotation().length() > 0)) {
      StringBuffer annotationBeginning = StringTools.concat(whiteSpaces,
          "<annotation");

      // Adding the name spaces of the annotation element
      Map<String, String> otherNamespaces = annotation
          .getAnnotationNamespaces();

      for (String namespacePrefix : otherNamespaces.keySet()) {
        StringTools.append(annotationBeginning, " ", namespacePrefix,
            "=\"", otherNamespaces.get(namespacePrefix), "\"");
        annotationElement.addAttribute(namespacePrefix, otherNamespaces.get(namespacePrefix));
      }
           
      boolean allNamespacesDefined = true;
     
      // Adding the name spaces of the sbml element
      if (sbase.getSBMLDocument() != null) {
        Map<String, String> sbmlDocumentNamespaces = sbase.getSBMLDocument().getSBMLDocumentNamespaces();

        for (String namespacePrefix : sbmlDocumentNamespaces.keySet()) {
         
          // Checking if the namespace declaration is not done twice
          // in the SBMLDocument and the annotation element.
          if (otherNamespaces.get(namespacePrefix) == null) {
            StringTools.append(annotationBeginning, " ", namespacePrefix,
                "=\"", sbmlDocumentNamespaces.get(namespacePrefix), "\"");
          }
        }

      } else {       
        // Can happen when displaying the annotation from an SBase object
        // that is not  yet linked to a SBMLDocument.
        allNamespacesDefined = false;
      }
       
      StringTools.append(annotationBeginning, Character.valueOf('>'),
          Character.valueOf('\n'), annotation.getNonRDFannotation(),
          whiteSpaces, "</annotation>", Character.valueOf('\n'));

      DOMConverter converter = new DOMConverter();
     
      String annotationString = annotationBeginning.toString()
          .replaceAll("&", "&amp;");
      // here indent gets lost.
      Document domDocument = null;
      boolean domConversionDone = false;

      try {
        domDocument = JAXPFacade.getInstance().create(
            new BufferedReader(new StringReader(annotationString)),  allNamespacesDefined);
        domConversionDone = true;
      } catch (SAXException e) {
        e.printStackTrace();
        // TODO : log error or send SBMLException

        logger.warn("Cannot parse the following XML\n@" + annotationString + "@");
        logger.warn("NonRDFannotation =\n@" + annotation.getNonRDFannotation() + "@");
       
        // trying to read the XML without namespace awareness as the XML can be wrong and we still want to
        // write it back as it is.
        if (allNamespacesDefined) {
         
          try {
            domDocument = JAXPFacade.getInstance().create(
                new BufferedReader(new StringReader(annotationString))false);
            domConversionDone = true;
          } catch (SAXException e2) {
            e.printStackTrace();
            // TODO : log error or send SBMLException
          }
        }
      } finally {
        if (domConversionDone) {
          converter.writeFragment(domDocument.getFirstChild()
              .getChildNodes(), writer);
        }
      }
    } else {
      writer.writeCharacters("\n");
    }

    // if the given SBase is not a model and the level is smaller than 3,
    // no history can be written.
    // Annotation cannot be written without metaid tag.
    if (sbase.getAnnotation().isSetRDFannotation()) {
      if (sbase.isSetMetaId()) {
        if (!annotation.isSetAbout()) {
          // add required missing tag
          annotation.setAbout("#" + sbase.getMetaId());
        }
        writeRDFAnnotation(annotation, annotationElement, writer, indent
          + indentCount);
      } else {
        /*
 
View Full Code Here

            value);
      } catch (Throwable exc) {
        System.err.println(exc.getMessage());
      }
    } else if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;
      isAttributeRead = annotation.readAttribute(attributeName, prefix,
          value);
    }

    if (!isAttributeRead) {
      // TODO : throw new SBMLException ("The attribute " + attributeName
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.Annotation

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.