private MolecularMatrix createMolecularNexmlMatrix(DiscreteMatrix tbMatrix,OTUs xmlOTUs) {
if ( null == xmlOTUs ) {
xmlOTUs = getOTUsById(tbMatrix.getTaxa().getId());
}
String tbDataType = tbMatrix.getDataType().getDescription();
MolecularMatrix xmlMatrix = null;
CharacterStateSet xmlStateSet = null;
// create the matrix and constant (IUPAC) state set
if ( tbDataType.equals(MatrixDataType.MATRIX_DATATYPE_DNA) ) {
xmlMatrix = getDocument().createMolecularMatrix(xmlOTUs, MolecularMatrix.DNA);
xmlStateSet = ((MolecularMatrix)xmlMatrix).getDNACharacterStateSet();
}
else if ( tbDataType.equals(MatrixDataType.MATRIX_DATATYPE_RNA) ) {
xmlMatrix = getDocument().createMolecularMatrix(xmlOTUs, MolecularMatrix.RNA);
xmlStateSet = ((MolecularMatrix)xmlMatrix).getRNACharacterStateSet();
}
else if ( tbDataType.equals(MatrixDataType.MATRIX_DATATYPE_PROTEIN) ) {
xmlMatrix = getDocument().createMolecularMatrix(xmlOTUs, MolecularMatrix.Protein);
xmlStateSet = ((MolecularMatrix)xmlMatrix).getProteinCharacterStateSet();
}
copyMatrixAttributes(tbMatrix,xmlMatrix);
// lookup the equivalent state in tb and attach identifiers
for(StateSet tbStateSet : tbMatrix.getStateSets() ) {
for (DiscreteCharState tbState : tbStateSet.getStates() ) {
String tbSymbol = tbState.getSymbol().toString().toUpperCase();
CharacterState xmlState = xmlStateSet.lookupCharacterStateBySymbol(tbSymbol);
if ( null == xmlState ) {
xmlState = xmlStateSet.createCharacterState(tbSymbol);
}
attachTreeBaseID((Annotatable)xmlState,tbState,DiscreteCharState.class);
}
}
// create columns and attach identifiers
for ( MatrixColumn tbColumn : tbMatrix.getColumnsReadOnly() ) {
org.nexml.model.Character xmlCharacter = xmlMatrix.createCharacter(xmlStateSet);
copyCharacterAttributes(tbColumn, xmlCharacter);
}
return xmlMatrix;
}