Debian Codegraph @

src/dr/evolution/datatype/PairedDataType.java

raw symbols SCIP
1 /*
2 * PairedDataType.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evolution.datatype;
27
28 /**
29 * implements DataType for nucleotides with hidden state(s)
30 *
31 * @version $Id: PairedDataType.java,v 1.6 2005/06/30 09:54:51 rambaut Exp $
32 *
33 * @author Alexei Drummond
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 // Private members
107
108 private DataType baseDataType;
109
110 }