Package org.cipres.treebase.domain.matrix

Examples of org.cipres.treebase.domain.matrix.CharacterMatrix


      warn(pct + "% Matrix M" + m.getId() + " now has nCHAR = " + m.getnChar() + ", nTAX = " + m.getnTax());
   
  }

  public void setMatrixNChar(CharacterMatrix mDetached) {
    CharacterMatrix m = matrixService.findByID(CharacterMatrix.class,
        mDetached.getId());
    int nChar = m.getColumns().size();
    int nTax = m.getRowsReadOnly().size();
    m.setnChar(nChar);
    m.setnTax(nTax);
  }
View Full Code Here


   */
  @Override
  protected MatrixJDBC createMatrix(CharacterData pMesqMatrix) {
    CategoricalData categoricalData = (CategoricalData) pMesqMatrix;

    CharacterMatrix m = new StandardMatrix();
    DiscreteMatrixJDBC matrixJDBC = new DiscreteMatrixJDBC(m, categoricalData, this);

    int numChars = categoricalData.getNumChars();
    DiscreteChar symbolChar = null; // shared phyloChar for symbols.

View Full Code Here

  protected void addJDBCElements(MatrixRow pRow, int pRowIndex, CharacterData pMesqMatrix) {

    CategoricalData categoricalData = (CategoricalData) pMesqMatrix;
    int numChars = categoricalData.getNumChars();

    CharacterMatrix matrix = pRow.getMatrix();
    List<MatrixColumn> columns = matrix.getColumnsReadOnly();
    String gapSymbolStr = "" + matrix.getGapSymbol();
    String missingSymbolStr = "" + matrix.getMissingSymbol();

    // add matrix row elements
    for (int colIndex = 0; colIndex < numChars; colIndex++) {
      // first find mesquite char and treebase char:
      MatrixColumn matrixColumn = columns.get(colIndex);
View Full Code Here

  protected void addRowElements(MatrixRow pRow, int pRowIndex, CharacterData pMesqMatrix) {

    CategoricalData categoricalData = (CategoricalData) pMesqMatrix;
    int numChars = categoricalData.getNumChars();

    CharacterMatrix matrix = pRow.getMatrix();
    List<MatrixColumn> columns = matrix.getColumnsReadOnly();

    String gapSymbolStr = "" + matrix.getGapSymbol();
    String missingSymbolStr = "" + matrix.getMissingSymbol();

    // add matrix row elements
    for (int colIndex = 0; colIndex < numChars; colIndex++) {
      // first find mesquite char and treebase char:
      MatrixColumn matrixColumn = columns.get(colIndex);
View Full Code Here

          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
View Full Code Here

        if ( nexId.equals(tbId) ) {
          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();
         
          // NexmlMatrixConverter must have assigned character objects to zero or more subsets. Here we get the full list of characters
          List<org.nexml.model.Character> nexCharacters = nexMatrix.getCharacters();
          Assert.assertEquals("The number of characters in the NeXML matrix must match that of the TreeBASE matrix", (Integer)tbMatrix.getnChar(), (Integer)nexCharacters.size());
         
          if (tbCharSets.isEmpty() != true) {
            // a treebase matrix has zero or more character sets, we must iterate over them
            for ( CharSet tbCharSet : tbCharSets ) {
             
              // this is how we fetch the equivalent nexml character set
              Subset nexSubset = nexMatrix.getSubset(tbCharSet.getLabel());
              Assert.assertNotNull("If NexmlMatrixConverter works correctly, a Subset is returned", nexSubset);             
           
              //get names of TreeBASE and NeXML character set
              String tbCharSetName = tbCharSet.getLabel();
              String nexCharSetName = nexSubset.getLabel();
             
              //verify that the names are the same
              Assert.assertEquals("The NeXML character set must have copied the label of the TreeBASE character set",tbCharSetName,nexCharSetName);             
             
              // 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 tbStart = tbColumnRange.getStartColIndex();
                int tbStop = 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 tbInc = 1;
                 
                // need to do this to prevent nullpointerexceptions
                if ( null != tbColumnRange.getRepeatInterval()) {
                   
                  tbInc = tbColumnRange.getRepeatInterval();
                }
               
                // The NexmlMatrixConverter should have created a Subset for each tbCharSet
                if ( null != nexSubset ) {                                   
               
                  // now we iterate over the coordinates in this column range
                  //and verify whether correct character objects are returned
                  for ( int i = tbStart; i <= tbStop; i += tbInc ) {
                   
                    // get the nexml character that should have been created
                    org.nexml.model.Character nexCharacter = nexCharacters.get(i);
                    Assert.assertNotNull("The NeXML Character should not be null if there as an index into it in this set", nexCharacter);
                    Assert.assertTrue("The Subset should contain the character at index i", nexSubset.containsThing(nexCharacter));
                   
                    //get the treebase character for the index in this column range
                    PhyloChar tbCharacter = tbCharacterMatrix.getCharacter(i);
                    Assert.assertNotNull("The TreeBASE PhyloChar should not be null if there as an index into it in this set", tbCharacter);                   
                    Assert.assertEquals("If the TreeBASE character has a label, then the NeXML character's label should match it", tbCharacter.getLabel(), nexCharacter.getLabel());
                   
                  }
                }
View Full Code Here

  /**
   *
   * @see org.cipres.treebase.domain.matrix.RowSegmentService#generateRowSegmentTemplateTSV(java.lang.Long)
   */
  public String generateRowSegmentTemplateTSV(Long pMatrixID) {
    CharacterMatrix m = getDomainHome().getPersistedObjectByID(CharacterMatrix.class, pMatrixID);
    if (m == null) {
      return null;
    }
   
    List<MatrixRow> rows = m.getRowsReadOnly();

    StringBuffer rsTxt = new StringBuffer();

    // First add the header info:
    // Remove the field: IGNORE, ROW_SEGMENT_ID
    EnumSet<RowSegmentField> allFields = EnumSet.allOf(RowSegmentField.class);
    allFields.remove(RowSegmentField.IGNORE);
    allFields.remove(RowSegmentField.ROWSEGMENTID);

    for (RowSegmentField rowSegmentField : allFields) {
      rsTxt.append(rowSegmentField.toString()).append('\t');
    }
    rsTxt.append('\n');

    int colCount = m.getColumns().size();
   
    // Now append one row segment for each row:
    for (MatrixRow aRow : rows) {
      // The included properties and their order are defined in RowSegmentServce.RowSegmentField
      //Id field is skipped.
View Full Code Here

    // check whether parsing is successful:
    if (returnVal.isSuccessful()) {
      List<RowSegment> newRS = new ArrayList<RowSegment>();
      List<RowSegment> updateRS = new ArrayList<RowSegment>();
      Study s = getDomainHome().loadPersistedObjectByID(Study.class, pStudyId);
      CharacterMatrix m = getDomainHome().loadPersistedObjectByID(CharacterMatrix.class, pMatrixId);
     
      mapToSegments(s, m, values, pMappedFields, newRS, updateRS, returnVal);

      // Save to database:
      getRowSegmentHome().storeAll(newRS);
View Full Code Here

  public void remapMatrixTaxonLabels(Matrix matrix,
      Map<TaxonLabel, TaxonLabel> canonical) {
    if (! (matrix instanceof CharacterMatrix)) return;
    warn("  Remapping Matrix " + matrix.getId());

    CharacterMatrix m = (CharacterMatrix) matrix;
    for (MatrixRow mr : m.getRowsReadOnly()) {
      if (canonical.containsKey(mr.getTaxonLabel()))
        mr.setTaxonLabel(canonical.get(mr.getTaxonLabel()));
      for (RowSegment rs : mr.getSegmentsReadOnly()) {
        if (! canonical.containsKey(rs.getTaxonLabel())) continue;
        warn("    Remapping segment " + rs.getId() + " in row " + mr.getId());
View Full Code Here

    if (this.isAll()) return new TaxonSearchResults();

    Collection<Taxon> taxa = new HashSet<Taxon> ();
    for (Matrix m : getResults()) {
      if (! m.isCharacterMatrix()) continue;
      CharacterMatrix cm = (CharacterMatrix) m;
      for (TaxonLabel tl : cm.getAllTaxonLabels())
        if (tl.getTaxonVariant() != null && tl.getTaxonVariant().getTaxon() != null)
          taxa.add(tl.getTaxonVariant().getTaxon());
    }
    return new TaxonSearchResults(taxa);
  }
View Full Code Here

TOP

Related Classes of org.cipres.treebase.domain.matrix.CharacterMatrix

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.