2323import org .nexml .model .Annotatable ;
2424import org .nexml .model .CategoricalMatrix ;
2525import org .nexml .model .Character ;
26+ import org .nexml .model .CompoundCharacterState ;
2627import org .nexml .model .ContinuousMatrix ;
2728import org .nexml .model .Matrix ;
2829import 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