| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class MutationDeathType extends DataType { |
| 39 |
protected static String DESCRIPTION = "MutationDeathType"; |
| 40 |
|
| 41 |
protected static int UNKNOWN_STATE = 128; |
| 42 |
protected int[][] codes; |
| 43 |
protected char[] stateCodes; |
| 44 |
public int DEATHSTATE; |
| 45 |
|
| 46 |
public MutationDeathType(char deathCode, char extantCode) { |
| 47 |
super(); |
| 48 |
initialize_internals(); |
| 49 |
codes[extantCode] = new int[]{0}; |
| 50 |
stateCodes[0] = extantCode; |
| 51 |
|
| 52 |
codes[deathCode] = new int[]{1}; |
| 53 |
stateCodes[1] = deathCode; |
| 54 |
stateCount = 2; |
| 55 |
DEATHSTATE = 1; |
| 56 |
ambiguousStateCount = 0; |
| 57 |
} |
| 58 |
|
| 59 |
public MutationDeathType(DataType x, char deathCode) { |
| 60 |
super(); |
| 61 |
int i; |
| 62 |
char stateCode; |
| 63 |
|
| 64 |
initialize_internals(); |
| 65 |
for (i = 0; i < x.getStateCount(); ++i) { |
| 66 |
stateCode = x.getCode(i).charAt(0); |
| 67 |
this.codes[stateCode] = new int[]{i}; |
| 68 |
stateCodes[i] = stateCode; |
| 69 |
} |
| 70 |
this.codes[deathCode] = new int[]{i}; |
| 71 |
stateCodes[i] = deathCode; |
| 72 |
DEATHSTATE = i; |
| 73 |
stateCount = i + 1; |
| 74 |
|
| 75 |
for (i = 0; i < 128; ++i) { |
| 76 |
int state = x.getState((char) i); |
| 77 |
if (state > 0 && state < 128 && x.isAmbiguousState(state) && i != deathCode) { |
| 78 |
if (!x.isUnknownState(state)) { |
| 79 |
int[] states = x.getStates(state); |
| 80 |
this.codes[i] = new int[states.length]; |
| 81 |
System.arraycopy(states, 0, this.codes[i], 0, states.length); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
ambiguousStateCount = x.getAmbiguousStateCount() + 1; |
| 87 |
} |
| 88 |
|
| 89 |
public void addAmbiguity(char ambiguityCode, String s) { |
| 90 |
if (s.length() == 0) { |
| 91 |
this.codes[ambiguityCode] = new int[stateCount]; |
| 92 |
for (int i = 0; i < stateCount; ++i) { |
| 93 |
this.codes[ambiguityCode][i] = i; |
| 94 |
} |
| 95 |
} else { |
| 96 |
this.codes[ambiguityCode] = new int[s.length()]; |
| 97 |
for (int i = 0; i < s.length(); ++i) { |
| 98 |
this.codes[ambiguityCode][i] = getState(s.charAt(i)); |
| 99 |
} |
| 100 |
} |
| 101 |
ambiguousStateCount += 1; |
| 102 |
} |
| 103 |
|
| 104 |
private void initialize_internals() { |
| 105 |
this.codes = new int[128][]; |
| 106 |
this.stateCodes = new char[128]; |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
public char[] getValidChars() { |
| 111 |
return null; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public int getState(char c) { |
| 121 |
if (codes[c] != null && codes[c].length == 1) { |
| 122 |
return codes[c][0]; |
| 123 |
} else { |
| 124 |
return c; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public int getUnknownState() { |
| 134 |
return UNKNOWN_STATE; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public char getChar(int state) { |
| 146 |
if (state < stateCount) |
| 147 |
return stateCodes[state]; |
| 148 |
return super.getChar(state); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public int[] getStates(int state) { |
| 155 |
if (state < stateCount) |
| 156 |
return codes[stateCodes[state]]; |
| 157 |
else |
| 158 |
return codes[state]; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public boolean[] getStateSet(int state) { |
| 165 |
boolean[] stateSet = new boolean[stateCount]; |
| 166 |
int states[]; |
| 167 |
int i; |
| 168 |
for (i = 0; i < stateCount; ++i) |
| 169 |
stateSet[i] = false; |
| 170 |
states = getStates(state); |
| 171 |
|
| 172 |
for (i = 0; states != null && i < states.length; ++i) { |
| 173 |
stateSet[states[i]] = true; |
| 174 |
} |
| 175 |
return stateSet; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public boolean isAmbiguousChar(char c) { |
| 182 |
return codes[c] != null && codes[c].length > 1; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public boolean isUnknownChar(char c) { |
| 189 |
return codes[c] == null; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
public boolean isAmbiguousState(int state) { |
| 196 |
return state >= stateCount; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public boolean isUnknownState(int state) { |
| 203 |
return state >= stateCount && codes[state] == null; |
| 204 |
} |
| 205 |
|
| 206 |
public String getDescription() { |
| 207 |
return DESCRIPTION; |
| 208 |
} |
| 209 |
|
| 210 |
public int getType() { |
| 211 |
return 314; |
| 212 |
} |
| 213 |
} |