| 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 |
public class Nucleotides extends DataType { |
| 37 |
|
| 38 |
public static final String JC = "JC"; |
| 39 |
public static final String F84 = "F84"; |
| 40 |
public static final String HKY = "HKY"; |
| 41 |
public static final String GTR = "GTR"; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static final String DESCRIPTION = "nucleotide"; |
| 47 |
public static final int TYPE = NUCLEOTIDES; |
| 48 |
public static final Nucleotides INSTANCE = new Nucleotides(); |
| 49 |
|
| 50 |
public static final int A_STATE = 0; |
| 51 |
public static final int C_STATE = 1; |
| 52 |
public static final int G_STATE = 2; |
| 53 |
public static final int UT_STATE = 3; |
| 54 |
|
| 55 |
public static final int R_STATE = 5; |
| 56 |
public static final int Y_STATE = 6; |
| 57 |
|
| 58 |
public static final int UNKNOWN_STATE = 16; |
| 59 |
public static final int GAP_STATE = 17; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public static final char[] NUCLEOTIDE_CHARS = |
| 65 |
{ 'A','C','G','T','U','K','M','R','S','W','Y','B','D','H','V','N', UNKNOWN_CHARACTER,GAP_CHARACTER}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public static final int NUCLEOTIDE_STATES[] = { |
| 73 |
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, |
| 74 |
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, |
| 75 |
|
| 76 |
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, |
| 77 |
|
| 78 |
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,16, |
| 79 |
|
| 80 |
17, 0,11, 1,12,16,16, 2,13,16,16,10,16, 7,15,16, |
| 81 |
|
| 82 |
16,16, 5, 9, 3, 3,14, 8,16, 6,16,17,17,17,17,17, |
| 83 |
|
| 84 |
17, 0,11, 1,12,16,16, 2,13,16,16,10,16, 7,15,16, |
| 85 |
|
| 86 |
16,16, 5, 9, 3, 3,14, 8,16, 6,16,17,17,17,17,17 |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public static final String[] NUCLEOTIDE_AMBIGUITIES = { |
| 93 |
|
| 94 |
"A", "C", "G", "T", "T", "AG", "CT", "AC", "AT", "CG", "GT", |
| 95 |
|
| 96 |
"CGT", "AGT", "ACT", "ACG", "ACGT", "ACGT", "ACGT" |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
protected Nucleotides() { |
| 103 |
stateCount = 4; |
| 104 |
ambiguousStateCount = 18; |
| 105 |
} |
| 106 |
|
| 107 |
@Override |
| 108 |
public char[] getValidChars() { |
| 109 |
return NUCLEOTIDE_CHARS; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public int getState(char c) { |
| 120 |
return NUCLEOTIDE_STATES[c]; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public int getUnknownState() { |
| 129 |
return UNKNOWN_STATE; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public int getGapState() { |
| 138 |
return GAP_STATE; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public char getChar(int state) { |
| 149 |
return NUCLEOTIDE_CHARS[state]; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public int[] getStates(int state) { |
| 157 |
|
| 158 |
String stateString = NUCLEOTIDE_AMBIGUITIES[state]; |
| 159 |
int[] states = new int[stateString.length()]; |
| 160 |
for (int i = 0; i < stateString.length(); i++) { |
| 161 |
states[i] = getState(stateString.charAt(i)); |
| 162 |
} |
| 163 |
|
| 164 |
return states; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public boolean[] getStateSet(int state) { |
| 171 |
|
| 172 |
boolean[] stateSet = new boolean[stateCount]; |
| 173 |
for (int i = 0; i < stateCount; i++) |
| 174 |
stateSet[i] = false; |
| 175 |
|
| 176 |
int len = NUCLEOTIDE_AMBIGUITIES[state].length(); |
| 177 |
for (int i = 0; i < len; i++) |
| 178 |
stateSet[getState(NUCLEOTIDE_AMBIGUITIES[state].charAt(i))] = true; |
| 179 |
|
| 180 |
return stateSet; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public String getDescription() { |
| 189 |
return DESCRIPTION; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
public int getType() { |
| 198 |
return TYPE; |
| 199 |
} |
| 200 |
|
| 201 |
} |