| 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 |
|
| 33 |
|
| 34 |
@Deprecated |
| 35 |
public class OldHiddenNucleotides extends DataType { |
| 36 |
|
| 37 |
public static final String DESCRIPTION = "hiddenNucleotide"; |
| 38 |
public static final OldHiddenNucleotides INSTANCE = new OldHiddenNucleotides(2); |
| 39 |
|
| 40 |
public OldHiddenNucleotides(int numHiddenStates) { |
| 41 |
hiddenClassCount = numHiddenStates; |
| 42 |
|
| 43 |
stateCount = 4 * hiddenClassCount; |
| 44 |
ambiguousStateCount = stateCount + 6; |
| 45 |
} |
| 46 |
|
| 47 |
@Override |
| 48 |
public char[] getValidChars() { |
| 49 |
return null; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public int getState(char c) { |
| 59 |
|
| 60 |
switch (c) { |
| 61 |
case'A': |
| 62 |
case'a': |
| 63 |
return stateCount; |
| 64 |
case'C': |
| 65 |
case'c': |
| 66 |
return stateCount + 1; |
| 67 |
case'G': |
| 68 |
case'g': |
| 69 |
return stateCount + 2; |
| 70 |
case'T': |
| 71 |
case't': |
| 72 |
case'U': |
| 73 |
case'u': |
| 74 |
return stateCount + 3; |
| 75 |
case'-': |
| 76 |
case'?': |
| 77 |
return getGapState(); |
| 78 |
default: { |
| 79 |
int state = (int) c - '0'; |
| 80 |
if (c > '?') state -= 1; |
| 81 |
if (c > 'A') state -= 1; |
| 82 |
if (c > 'C') state -= 1; |
| 83 |
if (c > 'G') state -= 1; |
| 84 |
if (c > 'T') state -= 1; |
| 85 |
if (c > 'U') state -= 1; |
| 86 |
if (c > 'a') state -= 1; |
| 87 |
if (c > 'g') state -= 1; |
| 88 |
if (c > 'c') state -= 1; |
| 89 |
if (c > 't') state -= 1; |
| 90 |
if (c > 'u') state -= 1; |
| 91 |
return state; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public char getChar(int state) { |
| 105 |
|
| 106 |
if (state >= stateCount) { |
| 107 |
switch (state - stateCount) { |
| 108 |
case 0: |
| 109 |
return 'A'; |
| 110 |
case 1: |
| 111 |
return 'C'; |
| 112 |
case 2: |
| 113 |
return 'G'; |
| 114 |
case 3: |
| 115 |
return 'T'; |
| 116 |
default: |
| 117 |
return '-'; |
| 118 |
} |
| 119 |
} else { |
| 120 |
char c = (char) (state + '0'); |
| 121 |
if (c >= '?') c += 1; |
| 122 |
if (c >= 'A') c += 1; |
| 123 |
if (c >= 'C') c += 1; |
| 124 |
if (c >= 'G') c += 1; |
| 125 |
if (c >= 'T') c += 1; |
| 126 |
if (c >= 'U') c += 1; |
| 127 |
if (c >= 'a') c += 1; |
| 128 |
if (c >= 'g') c += 1; |
| 129 |
if (c >= 'c') c += 1; |
| 130 |
if (c >= 't') c += 1; |
| 131 |
if (c >= 'u') c += 1; |
| 132 |
return c; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
public int[] getStates(int state) { |
| 137 |
|
| 138 |
if (state >= stateCount && state <= stateCount + 3) { |
| 139 |
int[] states = new int[hiddenClassCount]; |
| 140 |
for (int i = 0; i < hiddenClassCount; i++) { |
| 141 |
states[i] = state % 4 + (i * 4); |
| 142 |
} |
| 143 |
return states; |
| 144 |
} else throw new IllegalArgumentException(); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public boolean[] getStateSet(int state) { |
| 151 |
|
| 152 |
boolean[] stateSet = new boolean[stateCount]; |
| 153 |
for (int i = 0; i < stateCount; i++) { |
| 154 |
stateSet[i] = false; |
| 155 |
} |
| 156 |
if (!isAmbiguousState(state)) { |
| 157 |
stateSet[state] = true; |
| 158 |
} else if (state < (stateCount + 4)) { |
| 159 |
for (int i = 0; i < stateCount; i++) { |
| 160 |
if ((i % 4) == (state % 4)) { |
| 161 |
stateSet[i] = true; |
| 162 |
} |
| 163 |
|
| 164 |
} |
| 165 |
} else { |
| 166 |
for (int i = 0; i < stateCount; i++) { |
| 167 |
stateSet[i] = true; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
return stateSet; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
public int getUnknownState() { |
| 180 |
return stateCount + 4; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public int getGapState() { |
| 189 |
return stateCount + 5; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
public boolean isAmbiguousChar(char c) { |
| 196 |
return isAmbiguousState(getState(c)); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public boolean isUnknownChar(char c) { |
| 203 |
return isUnknownState(getState(c)); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public boolean isGapChar(char c) { |
| 210 |
return isGapState(getState(c)); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public boolean isAmbiguousState(int state) { |
| 217 |
return (state >= stateCount); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
public boolean isUnknownState(int state) { |
| 224 |
return (state == getUnknownState()); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
public boolean isGapState(int state) { |
| 231 |
return (state == getGapState()); |
| 232 |
} |
| 233 |
|
| 234 |
public int getType() { |
| 235 |
return 999; |
| 236 |
} |
| 237 |
|
| 238 |
public String getDescription() { |
| 239 |
return "Hidden-state Nucleotides"; |
| 240 |
} |
| 241 |
|
| 242 |
private int hiddenClassCount; |
| 243 |
|
| 244 |
public int getHiddenClassCount() { |
| 245 |
return hiddenClassCount; |
| 246 |
} |
| 247 |
} |