Debian Codegraph @

src/dr/evolution/datatype/OldHiddenNucleotides.java

raw symbols SCIP
1 /*
2 * HiddenNucleotides.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 * @author Alexei Drummond
32 * @version $Id: HiddenNucleotides.java,v 1.4 2005/05/24 20:25:56 rambaut Exp $
33 */
34 @Deprecated
35 public class OldHiddenNucleotides extends DataType {
36
37 public static final String DESCRIPTION = "hiddenNucleotide";
38 public static final OldHiddenNucleotides INSTANCE = new OldHiddenNucleotides(2);
39
40 public OldHiddenNucleotides(int numHiddenStates) {
41 hiddenClassCount = numHiddenStates;
42
43 stateCount = 4 * hiddenClassCount;
44 ambiguousStateCount = stateCount + 6;
45 }
46
47 @Override
48 public char[] getValidChars() {
49 return null;
50 }
51
52 /**
53 * Get state corresponding to a character
54 *
55 * @param c character
56 * @return state
57 */
58 public int getState(char c) {
59
60 switch (c) {
61 case'A':
62 case'a':
63 return stateCount;
64 case'C':
65 case'c':
66 return stateCount + 1;
67 case'G':
68 case'g':
69 return stateCount + 2;
70 case'T':
71 case't':
72 case'U':
73 case'u':
74 return stateCount + 3;
75 case'-':
76 case'?':
77 return getGapState();
78 default: {
79 int state = (int) c - '0';
80 if (c > '?') state -= 1;
81 if (c > 'A') state -= 1;
82 if (c > 'C') state -= 1;
83 if (c > 'G') state -= 1;
84 if (c > 'T') state -= 1;
85 if (c > 'U') state -= 1;
86 if (c > 'a') state -= 1;
87 if (c > 'g') state -= 1;
88 if (c > 'c') state -= 1;
89 if (c > 't') state -= 1;
90 if (c > 'u') state -= 1;
91 return state;
92 }
93 }
94
95 }
96
97 /**
98 * Get character corresponding to a given state
99 *
100 * @param state state
101 * <p/>
102 * return corresponding character
103 */
104 public char getChar(int state) {
105
106 if (state >= stateCount) {
107 switch (state - stateCount) {
108 case 0:
109 return 'A';
110 case 1:
111 return 'C';
112 case 2:
113 return 'G';
114 case 3:
115 return 'T';
116 default:
117 return '-';
118 }
119 } else {
120 char c = (char) (state + '0');
121 if (c >= '?') c += 1;
122 if (c >= 'A') c += 1;
123 if (c >= 'C') c += 1;
124 if (c >= 'G') c += 1;
125 if (c >= 'T') c += 1;
126 if (c >= 'U') c += 1;
127 if (c >= 'a') c += 1;
128 if (c >= 'g') c += 1;
129 if (c >= 'c') c += 1;
130 if (c >= 't') c += 1;
131 if (c >= 'u') c += 1;
132 return c;
133 }
134 }
135
136 public int[] getStates(int state) {
137
138 if (state >= stateCount && state <= stateCount + 3) {
139 int[] states = new int[hiddenClassCount];
140 for (int i = 0; i < hiddenClassCount; i++) {
141 states[i] = state % 4 + (i * 4);
142 }
143 return states;
144 } else throw new IllegalArgumentException();
145 }
146
147 /**
148 * returns an array containing the non-ambiguous states that this state represents.
149 */
150 public boolean[] getStateSet(int state) {
151
152 boolean[] stateSet = new boolean[stateCount];
153 for (int i = 0; i < stateCount; i++) {
154 stateSet[i] = false;
155 }
156 if (!isAmbiguousState(state)) {
157 stateSet[state] = true;
158 } else if (state < (stateCount + 4)) {
159 for (int i = 0; i < stateCount; i++) {
160 if ((i % 4) == (state % 4)) {
161 stateSet[i] = true;
162 }
163
164 }
165 } else {
166 for (int i = 0; i < stateCount; i++) {
167 stateSet[i] = true;
168 }
169 }
170
171 return stateSet;
172 }
173
174 /**
175 * Get state corresponding to an unknown
176 *
177 * @return state
178 */
179 public int getUnknownState() {
180 return stateCount + 4;
181 }
182
183 /**
184 * Get state corresponding to a gap
185 *
186 * @return state
187 */
188 public int getGapState() {
189 return stateCount + 5;
190 }
191
192 /**
193 * @return true if this character is an ambiguous state
194 */
195 public boolean isAmbiguousChar(char c) {
196 return isAmbiguousState(getState(c));
197 }
198
199 /**
200 * @return true if this character is a gap
201 */
202 public boolean isUnknownChar(char c) {
203 return isUnknownState(getState(c));
204 }
205
206 /**
207 * @return true if this character is a gap
208 */
209 public boolean isGapChar(char c) {
210 return isGapState(getState(c));
211 }
212
213 /**
214 * returns true if this state is an ambiguous state.
215 */
216 public boolean isAmbiguousState(int state) {
217 return (state >= stateCount);
218 }
219
220 /**
221 * @return true if this state is an unknown state
222 */
223 public boolean isUnknownState(int state) {
224 return (state == getUnknownState());
225 }
226
227 /**
228 * @return true if this state is a gap
229 */
230 public boolean isGapState(int state) {
231 return (state == getGapState());
232 }
233
234 public int getType() {
235 return 999;
236 }
237
238 public String getDescription() {
239 return "Hidden-state Nucleotides";
240 }
241
242 private int hiddenClassCount;
243
244 public int getHiddenClassCount() {
245 return hiddenClassCount;
246 }
247 }