| 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 |
public class PairedDataType extends DataType { |
| 36 |
|
| 37 |
public static final String DESCRIPTION = "pairedDataType"; |
| 38 |
public static final PairedDataType PAIRED_NUCLEOTIDES = new PairedDataType(Nucleotides.INSTANCE); |
| 39 |
public static final PairedDataType PAIRED_AMINO_ACIDS = new PairedDataType(AminoAcids.INSTANCE); |
| 40 |
public static final PairedDataType PAIRED_CODONS = new PairedDataType(Codons.UNIVERSAL); |
| 41 |
|
| 42 |
public PairedDataType(DataType baseDataType) { |
| 43 |
this.baseDataType = baseDataType; |
| 44 |
|
| 45 |
stateCount = baseDataType.getStateCount() * baseDataType.getStateCount(); |
| 46 |
ambiguousStateCount = stateCount + 2; |
| 47 |
} |
| 48 |
|
| 49 |
public final int getState(int state1, int state2) { |
| 50 |
if (baseDataType.isAmbiguousState(state1) || baseDataType.isAmbiguousState(state2)) { |
| 51 |
return getUnknownState(); |
| 52 |
} |
| 53 |
return (state1 * baseDataType.getStateCount()) + state2; |
| 54 |
} |
| 55 |
|
| 56 |
public final int getState(char c1, char c2) { |
| 57 |
return getState(baseDataType.getState(c1), baseDataType.getState(c2)); |
| 58 |
} |
| 59 |
|
| 60 |
public final int getFirstState(int state) { |
| 61 |
return state / baseDataType.getStateCount(); |
| 62 |
} |
| 63 |
|
| 64 |
public final int getSecondState(int state) { |
| 65 |
return state % baseDataType.getStateCount(); |
| 66 |
} |
| 67 |
|
| 68 |
@Override |
| 69 |
public char[] getValidChars() { |
| 70 |
return null; |
| 71 |
} |
| 72 |
|
| 73 |
public final int getState(char c) |
| 74 |
{ |
| 75 |
throw new IllegalArgumentException("Paired datatype cannot be expressed as char"); |
| 76 |
} |
| 77 |
|
| 78 |
public int getUnknownState() { |
| 79 |
return stateCount; |
| 80 |
} |
| 81 |
|
| 82 |
public int getGapState() { |
| 83 |
return stateCount + 1; |
| 84 |
} |
| 85 |
|
| 86 |
public final char getChar(int state) { |
| 87 |
throw new IllegalArgumentException("Paired datatype cannot be expressed as char"); |
| 88 |
} |
| 89 |
|
| 90 |
public final String getTriplet(int state) { |
| 91 |
throw new IllegalArgumentException("Paired datatype cannot be expressed as triplets"); |
| 92 |
} |
| 93 |
|
| 94 |
public final int[] getTripletStates(int state) { |
| 95 |
throw new IllegalArgumentException("Paired datatype cannot be expressed as triplets"); |
| 96 |
} |
| 97 |
|
| 98 |
public String getDescription() { |
| 99 |
return DESCRIPTION; |
| 100 |
} |
| 101 |
|
| 102 |
public int getType() { |
| 103 |
return -1; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
private DataType baseDataType; |
| 109 |
|
| 110 |
} |