Package org.cipres.treebase.dao.jdbc

Examples of org.cipres.treebase.dao.jdbc.DiscreteMatrixJDBC


  @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.

    // 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.
        // if (categoricalData.hasStateNames(i)) {
        //
        // String charName = null;
        // if (categoricalData.characterHasName(i)) {
        // charName = categoricalData.getCharacterName(i);
        // }
        // tbChar = new DiscreteChar();
        // 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);
        // }
        // } else {
        // // no state name defined. In this case
        // // 1. if there is no character name defined, need to use the defined symbol
        // character
        // // which is shared for the entire matrix.
        // // 2. if there is character name defined, create a new character but need to
        // // use symbol.
        //         
        // if (symbolChar == null) {
        //
        // tbChar = new DiscreteChar();
        // // do we need the symbol boolean property?
        // //tbChar.setSymbol(true);
        //           
        // int lastSymbol = categoricalData.getMaxSymbolDefined();
        //           
        // for (int j = 0; j <= lastSymbol; j++) {
        // //String stateSymbolStr = categoricalData.getStateSymbol(i, j);
        // String stateNote = categoricalData.getStateNote(i, j);
        // char stateSymbol = categoricalData.getSymbol(j);
        //             
        // DiscreteCharState tbCharState = new DiscreteCharState();
        // //tbCharState.setDescription(stateSymbolStr);
        // tbCharState.setSymbol(stateSymbol);
        //             
        // if (!TreebaseUtil.isEmpty(stateNote)) {
        // tbCharState.setNotes(stateNote);
        // }
        //
        // tbChar.addCharState(tbCharState);
        // }
        //
        // symbolChar = tbChar;
        //
        // if (LOGGER.isDebugEnabled()) {
        // LOGGER.debug(" symbolChar created for column: " + i); //$NON-NLS-1$
        // }
        // } else {
        // tbChar = symbolChar;
        //           
        // if (LOGGER.isDebugEnabled()) {
        // LOGGER.debug(" symbolChar reused for column: " + i); //$NON-NLS-1$
        // }
        // }
        // }
      }

      // aColumn.setCharacter(tbChar);
      // m.addColumn(aColumn);
      aColumnJDBC.setPhyloChar(tbChar);
      columnJDBCs.add(aColumnJDBC);
    }

    matrixJDBC.setMatrixColumnJDBCs(columnJDBCs);
    return matrixJDBC;
  }
View Full Code Here


    }

    List<DiscreteMatrixElementJDBC> elements = new ArrayList<DiscreteMatrixElementJDBC>();

    long[] colIds = pMatrixJDBC.getColIDs();
    DiscreteMatrixJDBC discreteMatrixJDBC = (DiscreteMatrixJDBC) pMatrixJDBC;

    char gapSymbol = pMatrixJDBC.getCharacterMatrix().getGapSymbol();
    char missingSymbol = pMatrixJDBC.getCharacterMatrix().getMissingSymbol();

    for (int colIndex = 0; colIndex < colIds.length; colIndex++) {
      long colId = colIds[colIndex];

      createColJDBCElements(
        colId,
        colIndex,
        gapSymbol,
        missingSymbol,
        discreteMatrixJDBC,
        elements);

    }

    discreteMatrixJDBC.batchUpdateRowSymbol(pCon);
    if (!(discreteMatrixJDBC.getCharacterMatrix().getDataType().isSequence())
      && !(discreteMatrixJDBC.getCharacterMatrix().getDataType().isStandard())) {
      DiscreteMatrixElementJDBC.batchDiscreteElements(elements, pCon);
    }
  }
View Full Code Here

   * @param xmlMatrix
   * @return
   */
  private Matrix fromXmlToTreeBase(CategoricalMatrix xmlMatrix) {
    DiscreteMatrix tbMatrix = new DiscreteMatrix();
    DiscreteMatrixJDBC matrixJDBC = new DiscreteMatrixJDBC(tbMatrix, xmlMatrix, this);
    List<MatrixColumnJDBC> columnJDBCs = new ArrayList<MatrixColumnJDBC>();
    long[] colIds = matrixJDBC.getColIDs();
    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();
View Full Code Here

TOP

Related Classes of org.cipres.treebase.dao.jdbc.DiscreteMatrixJDBC

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.