Skip to content

Commit fe313f2

Browse files
committed
Fixed reading of character state labels for categorical data.
1 parent dfeae3b commit fe313f2

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

src/mesquite/nexml/InterpretNEXML/NexmlReaders/NexmlCharactersBlockReader.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.nexml.model.Annotatable;
2424
import org.nexml.model.CategoricalMatrix;
2525
import org.nexml.model.Character;
26+
import org.nexml.model.CompoundCharacterState;
2627
import org.nexml.model.ContinuousMatrix;
2728
import org.nexml.model.Matrix;
2829
import org.nexml.model.MatrixCell;
@@ -70,7 +71,7 @@ else if ( xmlMatrix instanceof MolecularMatrix ) {
7071
return null;
7172
}
7273
}
73-
74+
7475
/**
7576
*
7677
* @param mesDataType
@@ -90,21 +91,32 @@ private FileElement readMatrix(String mesDataType,Matrix<?> xmlMatrix,MesquiteFi
9091
for ( Character xmlCharacter : xmlCharacterList ) {
9192
CharacterState mesCS = null;
9293
MatrixCell<?> xmlCell = xmlMatrix.getCell(xmlOTU, xmlCharacter);
93-
if ( mesMatrix instanceof ContinuousData ) {
94-
Double xmlDouble = (Double)xmlCell.getValue();
95-
if ( xmlDouble != null ) {
96-
mesCS = new ContinuousState(xmlDouble);
97-
((ContinuousState)mesCS).setNumItems(1); // XXX for multidimensional matrices
98-
}
99-
}
100-
else {
101-
org.nexml.model.CharacterState xmlState = (org.nexml.model.CharacterState)xmlCell.getValue();
102-
if ( xmlState != null ) {
103-
mesCS = new CategoricalState();
104-
String xmlSymbol = xmlState.getSymbol().toString();
105-
mesCS.setValue(xmlSymbol, mesMatrix);
106-
}
107-
}
94+
if ( mesMatrix instanceof ContinuousData ) {
95+
Double xmlDouble = (Double)xmlCell.getValue();
96+
if ( xmlDouble != null ) {
97+
mesCS = new ContinuousState(xmlDouble);
98+
((ContinuousState)mesCS).setNumItems(1); // XXX for multidimensional matrices
99+
}
100+
}
101+
else {
102+
if (xmlMatrix instanceof CategoricalMatrix) {
103+
for (org.nexml.model.CharacterState state : xmlCharacter.getCharacterStateSet().getCharacterStates()) {
104+
if (!(state instanceof CompoundCharacterState)) {
105+
String label = state.getLabel();
106+
if ((null != label) && (!label.equals("")) && (mesMatrix instanceof CategoricalData)) {
107+
int stateIndex = Integer.parseInt(state.getSymbol().toString());
108+
((CategoricalData)mesMatrix).setStateName(mesCharacter, stateIndex, label);
109+
}
110+
}
111+
}
112+
}
113+
org.nexml.model.CharacterState xmlState = (org.nexml.model.CharacterState)xmlCell.getValue();
114+
if ( xmlState != null ) {
115+
mesCS = new CategoricalState();
116+
String xmlSymbol = xmlState.getSymbol().toString();
117+
mesCS.setValue(xmlSymbol, mesMatrix);
118+
}
119+
}
108120
if ( mesCS != null ) {
109121
mesMatrix.setState(mesCharacter, mesTaxon, mesCS);
110122
//can add in character state stuff here

0 commit comments

Comments
 (0)