Package org.cipres.treebase.domain.matrix

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


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

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

    // get symbols as one String. need to do conversion:
    buildSymbols(categoricalData, m);

    // first consider the default char based on matrix data type.
    // For standard matrix, we know it has to be discrete char:
    MatrixDataType dataType = getMatrixDataType();
    DiscreteChar defaultChar = (DiscreteChar) dataType.getDefaultCharacter();
    if (defaultChar != null) {
      matrixJDBC.setDefaultCharID(defaultChar.getId());
    }

    List<MatrixColumnJDBC> columnJDBCs = new ArrayList<MatrixColumnJDBC>();

    // add character/column:
    for (int i = 0; i < numChars; i++) {

      // MatrixColumn aColumn = new MatrixColumn();
      MatrixColumnJDBC aColumnJDBC = new MatrixColumnJDBC();

      DiscreteChar tbChar = defaultChar;

      if (tbChar == null) {
        // it is probably a Standard dataType,
        // need to create characters for each column.

        if (!categoricalData.characterHasName(i) && !categoricalData.hasStateNames(i)) {
          // 1. if there is no character name defined and no state names defined,
          // need to use the defined symbol character
          // which is shared for the entire matrix.
          if (symbolChar == null) {

            tbChar = createCharUseSymbols(categoricalData, i);

            symbolChar = tbChar;

          } else {
            tbChar = symbolChar;

//            if (LOGGER.isDebugEnabled()) {
//              LOGGER.debug(" symbolChar reused for column: " + i); //$NON-NLS-1$
//            }
          }

        } else if (!categoricalData.hasStateNames(i)) {
          // 2. if there is character name defined but still no state names,
          // create a new character but need to use symbols as state names.
          tbChar = createCharUseSymbols(categoricalData, i);

          String charName = null;
          if (categoricalData.characterHasName(i)) {
            charName = categoricalData.getCharacterName(i);
          }
          tbChar.setDescription(charName);

        } else {
          // 3. has stateNames defined,
          // create a new character and set defined state names and symbols.
          tbChar = new DiscreteChar();

          String charName = null;
          if (categoricalData.characterHasName(i)) {
            charName = categoricalData.getCharacterName(i);
          }
          tbChar.setDescription(charName);

          int lastState = categoricalData.maxStateWithName(i);

          for (int j = 0; j <= lastState; j++) {
            String stateName = categoricalData.getStateName(i, j);
            String stateNote = categoricalData.getStateNote(i, j);
            char stateSymbol = categoricalData.getSymbol(j);

            DiscreteCharState tbCharState = new DiscreteCharState();
            tbCharState.setDescription(stateName);
            tbCharState.setSymbol(stateSymbol);

            if (!TreebaseUtil.isEmpty(stateNote)) {
              tbCharState.setNotes(stateNote);
            }

            tbChar.addCharState(tbCharState);
          }
        }

        // ////////////////////////////
        // // Need to create a new char. Add states.
View Full Code Here


   * @param pCategoricalData
   * @param pColIndex
   * @return
   */
  private DiscreteChar createCharUseSymbols(CategoricalData pCategoricalData, int pColIndex) {
    DiscreteChar tbChar;
    tbChar = new DiscreteChar();
    // FIXME do we need the symbol boolean property?
    // tbChar.setSymbol(true);

    int lastSymbol = pCategoricalData.getMaxSymbolDefined();

    for (int j = 0; j <= lastSymbol; j++) {
      // String stateSymbolStr = categoricalData.getStateSymbol(i, j);
      String stateNote = pCategoricalData.getStateNote(pColIndex, j);
      char stateSymbol = pCategoricalData.getSymbol(j);

      DiscreteCharState tbCharState = new DiscreteCharState();
      // tbCharState.setDescription(stateSymbolStr);
      tbCharState.setSymbol(stateSymbol);

      if (!TreebaseUtil.isEmpty(stateNote)) {
        tbCharState.setNotes(stateNote);
      }

      tbChar.addCharState(tbCharState);
    }

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(" symbolChar created for column: " + pColIndex); //$NON-NLS-1$
    }
View Full Code Here

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

      // convert the mesquite character state to treebase state:
      long statesLong = categoricalData.getState(colIndex, pRowIndex);

      MatrixElement element = null;
View Full Code Here

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

      // convert the mesquite character state to treebase state:
      long statesLong = categoricalData.getState(colIndex, pRowIndex);

      MatrixElement element = null;
View Full Code Here

    MatrixDataType dnaType = getMatrixDataTypeHome().findByDescription(
      MatrixDataType.MATRIX_DATATYPE_DNA);
    matrix.setDataType(dnaType);

    // add two columns:
    DiscreteChar dnaChar = (DiscreteChar) dnaType.getDefaultCharacter();
    assertTrue("Failed to load dna character", dnaChar != null);

    MatrixColumn c1 = new MatrixColumn();
    c1.setCharacter(dnaChar);
    matrix.addColumn(c1);

    MatrixColumn c2 = new MatrixColumn();
    c2.setCharacter(dnaChar);
    matrix.addColumn(c2);

    // add two rows:
    TaxonLabel taxonLabel = new TaxonLabel();
    taxonLabel.setTaxonLabel(newName);

    // missing symbol is ?
    DiscreteCharState aState = dnaChar.getStateByDescription("" + DiscreteCharState.MISSING_SYMBOL);
    assertTrue("? is not a valid state", aState != null);

    // create one row with 2 elements:
    MatrixRow r1 = new MatrixRow();
    r1.setTaxonLabel(taxonLabel);
View Full Code Here

      PreparedStatement stateBatch = pCon.prepareStatement(stateStr);

      for (MatrixColumnJDBC columnJDBC : columns) {

        stateBatch.clearBatch();
        DiscreteChar phyloChar = (DiscreteChar) columnJDBC.getPhyloChar();

        // Need to test: symbolChar is shared for the matrix.
        if (phyloChar.getId() == null) {
          ps.setString(1, phyloChar.getDescription()); // phylochar description

          // Not apply to discrete phylo character:
          // ps.setDouble(2, phyloChar.getLowerLimit());
          // ps.setDouble(3, phyloChar.getUpperLimit());

          ResultSet rs = ps.executeQuery();
          if (rs != null && rs.next()) {

            long phyloCharId = rs.getLong(1); // phylochar_id
//            if (LOGGER.isDebugEnabled()) {
//              LOGGER.debug("phylocharId =" + phyloCharId);
//            }

            columnJDBC.setPhyloCharID(phyloCharId);

            // insert new states:
            for (DiscreteCharState aState : phyloChar.getCharStates()) {

              // DISCRETECHARSTATE_ID: default
              // Version: 0

              // Not set here:
              // stateSet_id: null
              // ANCESTRALSTATE_ID

              stateBatch.setString(1, aState.getDescription()); // state description
              stateBatch.setString(2, aState.getNotes()); // state notes
              stateBatch.setLong(3, phyloCharId); // phyloChar id
              stateBatch.setString(4, aState.getSymbol().toString()); //symbol
             
              stateBatch.addBatch();

              // IBM JDBC driver has a 32k batch limit:
              // Don't think a char will have 32k states!!
              // if (count > MatrixJDBC.JDBC_BATCH_LIMIT) {
              // count = 0;
              // psBatch.executeBatch();
              // pCon.commit();
              //
              // if (LOGGER.isDebugEnabled()) {
              // LOGGER.debug("committing count=" + count); //$NON-NLS-1$
              // }
              // }
            }

            stateBatch.executeBatch();
            pCon.commit();

//            if (LOGGER.isDebugEnabled()) {
//              LOGGER.debug("committing state batch ="); //$NON-NLS-1$
//            }

          }
          rs.close();

        } else {
          columnJDBC.setPhyloCharID(phyloChar.getId());
        }

      }
      pCon.commit();
      stateBatch.close();
View Full Code Here

    long[] rowIds = matrixJDBC.getRowIDs();   
    List<DiscreteMatrixElementJDBC> elements = new ArrayList<DiscreteMatrixElementJDBC>();
    int colIndex = 0;
    for ( org.nexml.model.Character xmlCharacter : xmlMatrix.getCharacters() ) {
      String charName = xmlCharacter.getLabel();
      DiscreteChar tbChar = new DiscreteChar();
      tbChar.setDescription(charName);
      MatrixColumnJDBC aColumnJDBC = new MatrixColumnJDBC();
      aColumnJDBC.setPhyloChar(tbChar);     
      columnJDBCs.add(aColumnJDBC);
      int rowIndex = 0;
      for ( OTU xmlOTU : xmlMatrix.getOTUs().getAllOTUs() ) {
View Full Code Here

TOP

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

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.