Examples of CategoricalData


Examples of mesquite.categ.lib.CategoricalData

   *
   * @see org.cipres.treebase.domain.nexus.mesquite.MesquiteMatrixConverter#createMatrix(mesquite.lib.characters.CharacterData)
   */
  @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);

View Full Code Here

Examples of mesquite.categ.lib.CategoricalData

   * Not used anymore. Replaced by createColJDBCElements()
   */
  @Deprecated
  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);
      DiscreteChar columnChar = (DiscreteChar) matrixColumn.getCharacter();

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

      MatrixElement element = null;
      if (categoricalData.isInapplicable(colIndex, pRowIndex)) {
        // gap:
        element = createElement(columnChar, gapSymbolStr, 0, matrix);

      } else if (categoricalData.isUnassigned(colIndex, pRowIndex)) {
        // missing
        element = createElement(columnChar, missingSymbolStr, 0, matrix);

      } else {

        int[] states = CategoricalState.expand(statesLong);

        if (states.length > 1) {
          // multiple states, use compound element:
          CompoundMatrixElement compoundElement = new CompoundMatrixElement();
          Set<DiscreteMatrixElement> elements = new HashSet<DiscreteMatrixElement>();

          // pre calculate the compound values and cache it in compoundElement.
          StringBuilder compoundValues = new StringBuilder();
          compoundValues.append('{');

          for (int i = 0; i < states.length; i++) {
            int aState = states[i];
            String stateName = categoricalData.getStateName(colIndex, aState);

            DiscreteMatrixElement anElement = createElement(
              columnChar,
              stateName,
              i,
              matrix);
            anElement.setColumn(matrixColumn);
            elements.add(anElement);

            anElement.appendValue(compoundValues);

            if (i < states.length - 1) {
              compoundValues.append(' ');
            }
          }

          compoundValues.append('}');
          compoundElement.setCompoundValue(compoundValues.toString());

          compoundElement.setElements(elements);
          element = compoundElement;

        } else {
          // single state, use single element:
          String stateName = categoricalData.getStateName(colIndex, states[0]);
          element = createElement(columnChar, stateName, 0, matrix);
        }
      }

      element.setColumn(matrixColumn);
View Full Code Here

Examples of mesquite.categ.lib.CategoricalData

    char pGapSymbol,
    char pMissingSymbol,
    DiscreteMatrixJDBC pMatrixJDBC,
    List<DiscreteMatrixElementJDBC> pElements) {

    CategoricalData categoricalData = (CategoricalData) pMatrixJDBC.getMesquiteCharacterData();

    Map<String, Long> stateSymbolToIdMap = pMatrixJDBC.getStateSymbolToIdMap(pColIndex);
    long[] rowIds = pMatrixJDBC.getRowIDs();
    List<StringBuffer> symbolBufs = pMatrixJDBC.getRowSymbolBufs();

    // add discrete elements for the specified column:
    for (int rowIndex = 0; rowIndex < rowIds.length; rowIndex++) {

      StringBuffer rowSymbols = symbolBufs.get(rowIndex);

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

      DiscreteMatrixElementJDBC element = new DiscreteMatrixElementJDBC();
      if (categoricalData.isInapplicable(pColIndex, rowIndex)) {
        // gap:
        element.setGap((short) 1);
        // symbol = pGapSymbol;
        rowSymbols.append(pGapSymbol);
      } else if (!categoricalData.isUnassigned(pColIndex, rowIndex)) {
        // not missing :
        // element = new DiscreteMatrixElementJDBC();

        int[] states = CategoricalState.expand(statesLong);

        if (states.length > 1) {
          // multiple states, create a compound element.
          // The original single element "element" is still used as a place holder.
          CompoundElementJDBC compoundElement = new CompoundElementJDBC();

          addDiscreteStateIds(
            states,
            pColIndex,
            categoricalData,
            rowSymbols,
            stateSymbolToIdMap,
            compoundElement);

          compoundElement.setColIndex(pColIndex);
          compoundElement.setRowIndex(rowIndex);
          pMatrixJDBC.getCompoundElements().add(compoundElement);

        } else { // XXX: Can the number of states be 0?  If so, we need a guard condition here 20090121 MJD
          // single state, use single element:
          //String stateName = categoricalData.getStateName(pColIndex, states[0]);
          char aSymbol = categoricalData.getSymbol(states[0]);
          rowSymbols.append(aSymbol);

          findDiscreteStateId(
            stateSymbolToIdMap,
            aSymbol,
View Full Code Here

Examples of mesquite.categ.lib.CategoricalData

   */
  @Override
  @Deprecated
  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);
      DiscreteChar columnChar = (DiscreteChar) matrixColumn.getCharacter();

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

      MatrixElement element = null;
      if (categoricalData.isInapplicable(colIndex, pRowIndex)) {
        // gap:
        element = createElement(columnChar, gapSymbolStr, 0, matrix);

      } else if (categoricalData.isUnassigned(colIndex, pRowIndex)) {
        // missing
        element = createElement(columnChar, missingSymbolStr, 0, matrix);

      } else {

        int[] states = CategoricalState.expand(statesLong);

        if (states.length > 1) {
          // multiple states, use compound element:
          CompoundMatrixElement compoundElement = new CompoundMatrixElement();
          Set<DiscreteMatrixElement> elements = new HashSet<DiscreteMatrixElement>();

          // pre calculate the compound values and cache it in compoundElement.
          StringBuilder compoundValues = new StringBuilder();
          compoundValues.append('{');

          for (int i = 0; i < states.length; i++) {
            int aState = states[i];
            String stateName = categoricalData.getStateName(colIndex, aState);

            DiscreteMatrixElement anElement = createElement(
              columnChar,
              stateName,
              i,
              matrix);
            anElement.setColumn(matrixColumn);
            elements.add(anElement);

            anElement.appendValue(compoundValues);

            if (i < states.length - 1) {
              compoundValues.append(' ');
            }
          }

          compoundValues.append('}');
          compoundElement.setCompoundValue(compoundValues.toString());

          compoundElement.setElements(elements);
          element = compoundElement;

        } else {
          // single state, use single element:
          String stateName = categoricalData.getStateName(colIndex, states[0]);
          element = createElement(columnChar, stateName, 0, matrix);
        }
      }

      element.setColumn(matrixColumn);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.