| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evolution.datatype; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class TwoStateCovarion extends DataType { |
| 33 |
|
| 34 |
public static final String DESCRIPTION = "twoStateCovarion"; |
| 35 |
public static final int TYPE = COVARION; |
| 36 |
public static final TwoStateCovarion INSTANCE = new TwoStateCovarion(); |
| 37 |
|
| 38 |
private TwoStateCovarion() { |
| 39 |
stateCount = 4; |
| 40 |
ambiguousStateCount = 8; |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public char[] getValidChars() { |
| 45 |
return null; |
| 46 |
} |
| 47 |
|
| 48 |
public int getState(char c) { |
| 49 |
switch (c) { |
| 50 |
case 'a': |
| 51 |
return 0; |
| 52 |
case 'b': |
| 53 |
return 1; |
| 54 |
case 'c': |
| 55 |
return 2; |
| 56 |
case 'd': |
| 57 |
return 3; |
| 58 |
case '0': |
| 59 |
return 4; |
| 60 |
case '1': |
| 61 |
return 5; |
| 62 |
case '?': |
| 63 |
return getUnknownState(); |
| 64 |
case '-': |
| 65 |
return getGapState(); |
| 66 |
} |
| 67 |
throw new IllegalArgumentException("Character " + c + " not recognised in two-state covarion datatype!"); |
| 68 |
} |
| 69 |
|
| 70 |
public char getChar(int state) { |
| 71 |
|
| 72 |
switch (state) { |
| 73 |
case 0: |
| 74 |
return 'a'; |
| 75 |
case 1: |
| 76 |
return 'b'; |
| 77 |
case 2: |
| 78 |
return 'c'; |
| 79 |
case 3: |
| 80 |
return 'd'; |
| 81 |
case 4: |
| 82 |
return '0'; |
| 83 |
case 5: |
| 84 |
return '1'; |
| 85 |
case 6: |
| 86 |
return '?'; |
| 87 |
case 7: |
| 88 |
return '-'; |
| 89 |
} |
| 90 |
throw new IllegalArgumentException("State " + state + " not recognised in two-state covarion datatype!"); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public int[] getStates(int state) { |
| 98 |
|
| 99 |
if (state == 4 || state == 5) { |
| 100 |
int[] states = new int[2]; |
| 101 |
states[0] = state % 2; |
| 102 |
states[1] = state % 2 + 2; |
| 103 |
return states; |
| 104 |
} else throw new IllegalArgumentException(); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public boolean[] getStateSet(int state) { |
| 111 |
|
| 112 |
boolean[] stateSet = new boolean[stateCount]; |
| 113 |
for (int i = 0; i < stateCount; i++) { |
| 114 |
stateSet[i] = false; |
| 115 |
} |
| 116 |
if (!isAmbiguousState(state)) { |
| 117 |
stateSet[state] = true; |
| 118 |
} else if (state == 4 || state == 5) { |
| 119 |
for (int i = 0; i < stateCount; i++) { |
| 120 |
if ((i % 2) == (state % 2)) { |
| 121 |
stateSet[i] = true; |
| 122 |
} |
| 123 |
} |
| 124 |
} else { |
| 125 |
for (int i = 0; i < stateCount; i++) { |
| 126 |
stateSet[i] = true; |
| 127 |
} |
| 128 |
} |
| 129 |
return stateSet; |
| 130 |
} |
| 131 |
|
| 132 |
public int getUnknownState() { |
| 133 |
return stateCount + 2; |
| 134 |
} |
| 135 |
|
| 136 |
public int getGapState() { |
| 137 |
return stateCount + 3; |
| 138 |
} |
| 139 |
|
| 140 |
public boolean isAmbiguousChar(char c) { |
| 141 |
return isAmbiguousState(getState(c)); |
| 142 |
} |
| 143 |
|
| 144 |
public boolean isUnknownChar(char c) { |
| 145 |
return isUnknownState(getState(c)); |
| 146 |
} |
| 147 |
|
| 148 |
public boolean isGapChar(char c) { |
| 149 |
return isGapState(getState(c)); |
| 150 |
} |
| 151 |
|
| 152 |
public boolean isAmbiguousState(int state) { |
| 153 |
return (state >= 4); |
| 154 |
} |
| 155 |
|
| 156 |
public boolean isUnknownState(int state) { |
| 157 |
return (state == getUnknownState()); |
| 158 |
} |
| 159 |
|
| 160 |
public boolean isGapState(int state) { |
| 161 |
return (state == getGapState()); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
public String getDescription() { |
| 166 |
return DESCRIPTION; |
| 167 |
} |
| 168 |
|
| 169 |
public int getType() { |
| 170 |
return TYPE; |
| 171 |
} |
| 172 |
|
| 173 |
} |