| 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.evomodel.substmodel; |
| 27 |
|
| 28 |
import dr.evolution.datatype.Codons; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public enum CodonLabeling { |
| 42 |
SYN("S"), |
| 43 |
NON_SYN("N"); |
| 44 |
|
| 45 |
CodonLabeling(String text) { |
| 46 |
this.text = text; |
| 47 |
} |
| 48 |
|
| 49 |
public String getText() { |
| 50 |
return text; |
| 51 |
} |
| 52 |
|
| 53 |
public static double[] getRegisterMatrix(CodonLabeling labeling, Codons codonDataType) { |
| 54 |
return getRegisterMatrix(labeling, codonDataType, false); |
| 55 |
} |
| 56 |
|
| 57 |
public static double[] getRegisterMatrix(CodonLabeling labeling, Codons codonDataType, boolean base64) { |
| 58 |
final int stateCount = codonDataType.getStateCount(); |
| 59 |
final int rateCount = ((stateCount - 1) * stateCount) / 2; |
| 60 |
|
| 61 |
byte[] rateMap = Codons.constructRateMap( |
| 62 |
rateCount, |
| 63 |
stateCount, |
| 64 |
codonDataType, |
| 65 |
codonDataType.getGeneticCode()); |
| 66 |
|
| 67 |
double[] registerMatrix = new double[stateCount * stateCount]; |
| 68 |
|
| 69 |
int index = 0; |
| 70 |
for (int i = 0; i < stateCount; i++) { |
| 71 |
for (int j = i + 1; j < stateCount; j++) { |
| 72 |
byte b = rateMap[index]; |
| 73 |
if ( |
| 74 |
(labeling == SYN && (b == 1 || b == 2)) || |
| 75 |
(labeling == NON_SYN && (b == 3 || b == 4)) |
| 76 |
) { |
| 77 |
registerMatrix[j * stateCount + i] = registerMatrix[i * stateCount + j] = 1.0; |
| 78 |
} |
| 79 |
index++; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if (base64) { |
| 84 |
double[] oldRegisterMatrix = registerMatrix; |
| 85 |
registerMatrix = new double[64 * 64]; |
| 86 |
for (int i = 0; i < stateCount; i++) { |
| 87 |
for (int j = 0; j < stateCount; j++) { |
| 88 |
if (oldRegisterMatrix[i * stateCount + j] == 1) { |
| 89 |
registerMatrix[codonDataType.getCanonicalState(i) * 64 |
| 90 |
+ codonDataType.getCanonicalState(j)] = 1; |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
return registerMatrix; |
| 96 |
} |
| 97 |
|
| 98 |
private final String text; |
| 99 |
|
| 100 |
public static CodonLabeling parseFromString(String text) { |
| 101 |
for (CodonLabeling scheme : CodonLabeling.values()) { |
| 102 |
if (scheme.getText().compareToIgnoreCase(text) == 0) |
| 103 |
return scheme; |
| 104 |
} |
| 105 |
return null; |
| 106 |
} |
| 107 |
} |