*/
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;
}