Package org.nexml.model

Examples of org.nexml.model.CategoricalMatrix


   */
  private CategoricalMatrix createStandardNexmlMatrix(StandardMatrix tbMatrix,OTUs xmlOTUs) {
    if ( null == xmlOTUs ) {
      xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId());
    }
    CategoricalMatrix xmlMatrix = getDocument().createCategoricalMatrix(xmlOTUs);   
    copyMatrixAttributes(tbMatrix,xmlMatrix);
   
    // first flatten the two-dimensional list into a map, we will always only create a single state set
    List<List<DiscreteCharState>> tbStateLabels = tbMatrix.getStateLabels();
    Map<Character,DiscreteCharState> stateForSymbol = new HashMap<Character,DiscreteCharState>();
    CharacterStateSet xmlStateSet = xmlMatrix.createCharacterStateSet();
    for ( int i = 0; i < tbStateLabels.size(); i++ ) {
      for ( int j = 0; j < tbStateLabels.get(i).size(); j++ ) {
        Character symbol = tbStateLabels.get(i).get(j).getSymbol();
        DiscreteCharState state = tbStateLabels.get(i).get(j);
        stateForSymbol.put(symbol, state);     
      }
    }
   
    // then create the single state set out of the map, assigning all non-missing characters to missing
    Set<CharacterState> xmlMissingStates = new HashSet<CharacterState>();
    for ( Character symbol : stateForSymbol.keySet() ) {
      char sym = symbol.charValue();     
      if ( sym != '-' && sym != '?' ) {
        String symString = symbol.toString();
        CharacterState xmlState = xmlStateSet.createCharacterState(symString);
        xmlMissingStates.add(xmlState);
        DiscreteCharState tbState = stateForSymbol.get(symbol);
        xmlState.setLabel(symString);
        attachTreeBaseID((Annotatable)xmlState,tbState,DiscreteCharState.class);       
      }       
    }
   
    // the missing symbol ("?") includes all others, including gap ("-")
    UncertainCharacterState gap = xmlStateSet.createUncertainCharacterState("-", new HashSet<CharacterState>());
    gap.setLabel("-");
    xmlMissingStates.add(gap);
    UncertainCharacterState missing = xmlStateSet.createUncertainCharacterState("?", xmlMissingStates);
    missing.setLabel("?");
   
    // then create the XML characters, assigning them all the same state set
    List<MatrixColumn> tbColumns = tbMatrix.getColumnsReadOnly();
    for ( int i = 0; i < tbColumns.size(); i++ ) {
      MatrixColumn tbColumn = tbColumns.get(i);     
      org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(xmlStateSet);
      copyCharacterAttributes(tbColumn, xmlCharacter);
    }   
    return xmlMatrix;
  }
View Full Code Here

TOP

Related Classes of org.nexml.model.CategoricalMatrix

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.