Package org.nexml.model

Examples of org.nexml.model.Document


   
    // this is the full study as it is stored by the database
    Study tbStudy = (Study)loadObject(Study.class, studyId);
   
    // this is an object representation of a NeXML document
    Document nexDoc = DocumentFactory.safeCreateDocument();
   
    // the converter populates the NeXML document with the contents of the treebase study
    NexmlDocumentWriter ndc = new NexmlDocumentWriter(tbStudy,getTaxonLabelHome(),nexDoc);
    ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens   
   
    attachAnalysisMetadata(analyzedDataForData, tbStudy, nexDoc);   
   
    // attach analysis step metadata to matrices
    for ( Matrix<?> nexMatrix : nexDoc.getMatrices() ) {
      attachAnalyzedDataMetadata(analyzedDataForData, nexMatrix);
    }
   
    // attach analysis step metadata to trees
    for ( TreeBlock nexTrees : nexDoc.getTreeBlockList() ) {
      int count = nexTrees.getSegmentCount();     
      for ( int i = 0; i < count; i++ ) {
        Network<?> nexTree = nexTrees.getSegment(i);
        attachAnalyzedDataMetadata(analyzedDataForData, nexTree);       
      }
    }
   
    FileWriter fstream = new FileWriter("/Users/rvosa/Desktop/outfile.xml");
    BufferedWriter out = new BufferedWriter(fstream)
    out.write(nexDoc.getXmlString());
    out.close();
  }
View Full Code Here


  private TaxonLabelHome mTaxonLabelHome;

  public void testSerializeStudy() {
    long studyId = 1787;
    Study study = (Study)loadObject(Study.class, studyId);
    Document doc = DocumentFactory.safeCreateDocument();
    NexmlDocumentWriter conv = new NexmlDocumentWriter(study,getTaxonLabelHome(),doc);
    String xml = conv.fromTreeBaseToXml(study).getXmlString();   
    System.out.println(xml);
    Assert.assertNotNull(xml);
  }
View Full Code Here

    Assert.assertNotNull(xml);
  }
 
  public void testSerializeTree() {
    long treeId = 4816;
    Document doc = DocumentFactory.safeCreateDocument();   
    PhyloTree tree = (PhyloTree)loadObject(PhyloTree.class,treeId);
    TaxonLabelSet tls = tree.getTreeBlock().getTaxonLabelSet();
    NexusDataSet nds = new NexusDataSet();
    nds.getTaxonLabelSets().add(tls);
    TreeBlock treeBlock = new TreeBlock();
View Full Code Here

    // these are the character state matrices that are part of the study
    Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices();

    // this is an object representation of a NeXML document
    Document nexDoc = DocumentFactory.safeCreateDocument();
   
    // the converter populates the NeXML document with the contents of the treebase study
    NexmlDocumentWriter ndc = new NexmlDocumentWriter(tbStudy,getTaxonLabelHome(),nexDoc);
    ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens
   
   
    // these are the NeXML matrices that were created from the study     
    List<Matrix<?>> nexMatrices = nexDoc.getMatrices();
   
    // there most be more than zero matrices because every treebase study has at least one matrix
    Assert.assertTrue(nexMatrices.size() != 0 );
   
    // now we're going to match up the NeXML matrices with their equivalent treebase ones
    for ( Matrix<?> nexMatrix : nexMatrices ) {
     
      // the xml id is the same as the primary key of the equivalent matrix stored by treebase
      String nexId = nexMatrix.getId();
      boolean foundEquivalentMatrix = false;

      // iterate over all treebase matrices for the study
      for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) {       
        String tbId = "M" + tbMatrix.getId();
   
        // although there is a class DistanceMatrix, it is my belief that we don't actually have
        // any distance matrices stored, nor can we convert them to NeXML
        Assert.assertTrue("TreeBASE matrix "+tbId+" must be a character matrix, not a distance matrix", tbMatrix instanceof CharacterMatrix);
       
        // if true, the matrices are equivalent
        if ( nexId.equals(tbId) ) {
          foundEquivalentMatrix = true;
          Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses",
              nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix);
         
          // we have to coerce the tbMatrix into a character matrix to get its character sets
          CharacterMatrix tbCharacterMatrix = (CharacterMatrix)tbMatrix;
          Set<CharSet> tbCharSets = tbCharacterMatrix.getCharSets();
         
          // a treebase matrix has zero or more character sets, we must iterate over them
          for ( CharSet tbCharSet : tbCharSets ) {
           
            // the coordinates of the character set are defined by a collection of column ranges that we iterate over
            Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix);
           
            for ( ColumnRange tbColumnRange : tbColumnRanges ) {
             
              // these are the beginning and end of the range
              int start = tbColumnRange.getStartColIndex();
              int stop = tbColumnRange.getEndColIndex();
             
              // this is how we increment from beginning to end. This number is probably either null, for a
              // contiguous range, or perhaps 3 for codon positions
              int inc = 1;
             
              // need to do this to prevent nullpointerexceptions
              if ( null != tbColumnRange.getRepeatInterval() ) {
                inc = tbColumnRange.getRepeatInterval();
              }
             
              // this is how we create the equivalent nexml character set
              // you will need to update CharSet to get the new implementation of getLabel(), which
              // returns the same value as getTitle()
              Subset nexSubset = nexMatrix.createSubset(tbCharSet.getLabel());
             
              // we have to assign character objects to the subset. Here we get the full list
              List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters();
             
              // now we iterate over the coordinates and assign the nexml characters to the set
              for ( int i = start; i <= stop; i += inc ) {
                nexSubset.addThing(nexCharacters.get(i));
              }
            }
          }
        }
      }
      Assert.assertTrue("Searched for equivalent to NeXML matrix "+nexId, foundEquivalentMatrix);
      System.out.println(nexDoc.getXmlString());
    }
  }
View Full Code Here

    // these are the character state matrices that are part of the study
    Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices();
   

    // this is an object representation of a NeXML document
    Document nexDoc = DocumentFactory.safeCreateDocument();
   
    // the converter populates the NeXML document with the contents of the treebase study
    NexmlDocumentWriter ndc = new NexmlDocumentWriter(tbStudy,getTaxonLabelHome(),nexDoc);
   
    ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens
   
   
    // these are the NeXML matrices that were created from the study     
    List<Matrix<?>> nexMatrices = nexDoc.getMatrices();
   
    //returns true if matrix contains no elements
    boolean nexTest = nexMatrices.isEmpty();
   
    //should be false if the matrix contains elements
    Assert.assertFalse(nexTest);
   
    // there most be more than zero matrices because every treebase study has at least one matrix
    Assert.assertTrue(nexMatrices.size() != 0 );

   
    // now we're going to match up the NeXML matrices with their equivalent treebase ones
    for ( Matrix<?> nexMatrix : nexMatrices ) {
     
      // the xml id is the same as the primary key of the equivalent matrix stored by treebase
      String nexId = nexMatrix.getId();
 
     
      for ( org.cipres.treebase.domain.matrix.Matrix tbMatrix : tbMatrices ) {       
        String tbId = "M" + tbMatrix.getId();
        // if true, the matrices are equivalent
        System.out.println(tbId);
        int otuIndex = 0;
        for ( MatrixRow tbRow : ((CharacterMatrix) tbMatrix).getRowsReadOnly() ) {
          OTUs xmlOTUs = nexMatrix.getOTUs();
         
          //need to make an OTU list because getOTUByID cannot be is private
          List<OTU> xmlOTUList = xmlOTUs.getAllOTUs();//getOTUById(xmlOTUs, tbRow.getTaxonLabel().getId());
          OTU xmlOTU = xmlOTUList.get(otuIndex); //get xmlOTUs
          List<org.nexml.model.Character> characterList = nexMatrix.getCharacters();
       
          int charIndex = 0;
          if ( characterList.size() <= MAX_GRANULAR_NCHAR && xmlOTUs.getAllOTUs().size() <= MAX_GRANULAR_NTAX ) {
         
            //tbColumn is not used, but is in the actual NexmlMatrixConverter class.
            //it is necessary so the for loop does not crash
            for ( MatrixColumn tbColumn : ((CharacterMatrix)tbMatrix).getColumns() ) {
             
              //this builds the matrix
              String string = tbRow.buildElementAsString();
              nexMatrix.setSeq(string, xmlOTU);
             
              //in NexmlMatrixConverter attachTreeBASEID would be called here. Not necessary for the test.
            }
          charIndex++;
          otuIndex++;
         
        }
       
        if ( nexId.equals(tbId) ) {
          Assert.assertTrue("NeXML matrix "+nexId+ " is one of the known subclasses",
          nexMatrix instanceof CategoricalMatrix || nexMatrix instanceof MolecularMatrix || nexMatrix instanceof ContinuousMatrix);
          Assert.assertNotNull(nexMatrix);
          Assert.assertNotNull(tbMatrix);
             
        }

        }
      }
    }
    System.out.println(nexDoc.getXmlString());
  }
View Full Code Here

    // these are the character state matrices that are part of the study
    Set<org.cipres.treebase.domain.matrix.Matrix> tbMatrices = tbStudy.getMatrices();

    // this is an object representation of a NeXML document
    Document nexDoc = DocumentFactory.safeCreateDocument();
   
    // the converter populates the NeXML document with the contents of the treebase study
    NexmlDocumentWriter ndc = new NexmlDocumentWriter(tbStudy,getTaxonLabelHome(),nexDoc);
    ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens
   
    // these are the NeXML matrices that were created from the study     
    List<Matrix<?>> nexMatrices = nexDoc.getMatrices();
   
    // there most be more than zero matrices because every treebase study has at least one matrix
    Assert.assertTrue(nexMatrices.size() != 0 );
   
    // now we're going to match up the NeXML matrices with their equivalent treebase ones
View Full Code Here

   
    // this is the full study as it is stored by the database
    Study tbStudy = (Study)loadObject(Study.class, studyId);

    // this becomes an object representation of a NeXML document
    Document nexDoc = DocumentFactory.safeCreateDocument();
   
    // the converter populates the NeXML document with the contents of the treebase study
    NexmlDocumentWriter ndc = new NexmlDocumentWriter(tbStudy,getTaxonLabelHome(),nexDoc);
    ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens
       
    // these are the NeXML tree blocks that were created from the study     
    List<org.nexml.model.TreeBlock> nexTreeBlocks = nexDoc.getTreeBlockList();
   
    // there most be more than zero tree blocks in this study
    Assert.assertTrue(nexTreeBlocks.size() != 0 );
   
    // now we're going to match up the NeXML taxa in trees with their equivalent treebase ones
View Full Code Here

  private Collection<Study> getTestData() {
    return getTestData("S1787");
  }
 
  public void testStudySearchSerialization() {
    Document doc = DocumentFactory.safeCreateDocument();
    NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc);
    ndw.fromTreeBaseToXml(ssr);
    assertNotNull(doc.getXmlString());
  }
View Full Code Here

    ndw.fromTreeBaseToXml(ssr);
    assertNotNull(doc.getXmlString());
  }
 
  public void testTaxonSearchSerialization() {
    Document doc = DocumentFactory.safeCreateDocument();
    NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc);   
    TaxonSearchResults tasr = ssr.convertToTaxa();
    ndw.fromTreeBaseToXml(tasr);
    assertNotNull(doc.getXmlString());
  }
View Full Code Here

    ndw.fromTreeBaseToXml(tasr);
    assertNotNull(doc.getXmlString());
  }
 
  public void testMatrixSearchSerialization() {
    Document doc = DocumentFactory.safeCreateDocument();
    NexmlDocumentWriter ndw = new NexmlDocumentWriter(null, mTaxonLabelHome, doc);   
    MatrixSearchResults msr = ssr.convertToMatrices();
    ndw.fromTreeBaseToXml(msr);
    assertNotNull(doc.getXmlString());
  }
View Full Code Here

TOP

Related Classes of org.nexml.model.Document

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.