*
* @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);