Debian Codegraph @

src/dr/evolution/datatype/SimpleCodons.java

raw symbols SCIP
1 /*
2 * SimpleCodons.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 codons
30 *
31 * Codons have tree different representations:
32 * State numbers - 0-63 + 64, 65 as unknown and gap
33 * State chars - the above converted into chars, starting at 'A'
34 * and '?' + '-' for unknown and gap
35 * Strings or chars of three nucleotide characters
36 *
37 * @version $Id: SimpleCodons.java,v 1.1 2005/06/28 11:51:50 rambaut Exp $
38 *
39 * @author Andrew Rambaut
40 * @author Alexei Drummond
41 */
42 public class SimpleCodons extends DataType {
43
44 /**
45 * Name of data type. For XML and human reading of data type.
46 */
47 public static final String DESCRIPTION = "simpleCodon";
48 public static final int TYPE = CODONS;
49
50 public static final SimpleCodons UNIVERSAL = new SimpleCodons(GeneticCode.UNIVERSAL);
51 public static final SimpleCodons VERTEBRATE_MT = new SimpleCodons(GeneticCode.VERTEBRATE_MT);
52 public static final SimpleCodons YEAST = new SimpleCodons(GeneticCode.YEAST);
53 public static final SimpleCodons MOLD_PROTOZOAN_MT = new SimpleCodons(GeneticCode.MOLD_PROTOZOAN_MT);
54 public static final SimpleCodons MYCOPLASMA = new SimpleCodons(GeneticCode.MYCOPLASMA);
55 public static final SimpleCodons INVERTEBRATE_MT = new SimpleCodons(GeneticCode.INVERTEBRATE_MT);
56 public static final SimpleCodons CILIATE = new SimpleCodons(GeneticCode.CILIATE);
57 public static final SimpleCodons ECHINODERM_MT = new SimpleCodons(GeneticCode.ECHINODERM_MT);
58 public static final SimpleCodons EUPLOTID_NUC = new SimpleCodons(GeneticCode.EUPLOTID_NUC);
59 public static final SimpleCodons BACTERIAL = new SimpleCodons(GeneticCode.BACTERIAL);
60 public static final SimpleCodons ALT_YEAST = new SimpleCodons(GeneticCode.ALT_YEAST);
61 public static final SimpleCodons ASCIDIAN_MT = new SimpleCodons(GeneticCode.ASCIDIAN_MT);
62 public static final SimpleCodons FLATWORM_MT = new SimpleCodons(GeneticCode.FLATWORM_MT);
63 public static final SimpleCodons BLEPHARISMA_NUC = new SimpleCodons(GeneticCode.BLEPHARISMA_NUC);
64
65 public static final int UNKNOWN_STATE = 64;
66 public static final int GAP_STATE = 65;
67
68 public static final String[] CODON_TRIPLETS = {
69 "AAA", "AAC", "AAG", "AAT", "ACA", "ACC", "ACG","ACT",
70 "AGA", "AGC", "AGG", "AGT", "ATA", "ATC", "ATG","ATT",
71 "CAA", "CAC", "CAG", "CAT", "CCA", "CCC", "CCG","CCT",
72 "CGA", "CGC", "CGG", "CGT", "CTA", "CTC", "CTG","CTT",
73 "GAA", "GAC", "GAG", "GAT", "GCA", "GCC", "GCG","GCT",
74 "GGA", "GGC", "GGG", "GGT", "GTA", "GTC", "GTG","GTT",
75 "TAA", "TAC", "TAG", "TAT", "TCA", "TCC", "TCG","TCT",
76 "TGA", "TGC", "TGG", "TGT", "TTA", "TTC", "TTG","TTT",
77 "???", "---"
78 };
79
80 /**
81 * Private constructor - DEFAULT_INSTANCE provides the only instance
82 */
83 private SimpleCodons(GeneticCode geneticCode) {
84 this.geneticCode = geneticCode;
85
86 stateCount = 64;
87 ambiguousStateCount = 66;
88 }
89
90 @Override
91 public char[] getValidChars() {
92 return null;
93 }
94
95 /**
96 * Get state corresponding to a character
97 *
98 * @param c character
99 *
100 * @return state
101 */
102 public final int getState(char c)
103 {
104 throw new IllegalArgumentException("Codons datatype cannot be expressed as char");
105 }
106
107 /**
108 * Get state corresponding to an unknown
109 *
110 * @return state
111 */
112 public int getUnknownState() {
113 return UNKNOWN_STATE;
114 }
115
116 /**
117 * Get state corresponding to a gap
118 *
119 * @return state
120 */
121 public int getGapState() {
122 return GAP_STATE;
123 }
124
125 /**
126 * Get state corresponding to a nucleotide triplet
127 *
128 * @param nuc1 the codon triplet as chars
129 * @param nuc2 the codon triplet as chars
130 * @param nuc3 the codon triplet as chars
131 *
132 * @return state
133 */
134 public final int getState(char nuc1, char nuc2, char nuc3)
135 {
136 return getState(Nucleotides.INSTANCE.getState(nuc1),
137 Nucleotides.INSTANCE.getState(nuc2),
138 Nucleotides.INSTANCE.getState(nuc3));
139 }
140
141 /**
142 * Get state corresponding to a nucleotide triplet
143 *
144 * @param nuc1 the codon triplet as states
145 * @param nuc2 the codon triplet as states
146 * @param nuc3 the codon triplet as states
147 *
148 * @return state
149 */
150 public final int getState(int nuc1, int nuc2, int nuc3)
151 {
152 if (Nucleotides.INSTANCE.isGapState(nuc1) ||
153 Nucleotides.INSTANCE.isGapState(nuc2) ||
154 Nucleotides.INSTANCE.isGapState(nuc3)) {
155 return GAP_STATE;
156 }
157
158 if (Nucleotides.INSTANCE.isAmbiguousState(nuc1) ||
159 Nucleotides.INSTANCE.isAmbiguousState(nuc2) ||
160 Nucleotides.INSTANCE.isAmbiguousState(nuc3)) {
161 return UNKNOWN_STATE;
162 }
163
164 return (nuc1 * 16) + (nuc2 * 4) + nuc3;
165 }
166
167 /**
168 * Get character corresponding to a given state
169 *
170 * @param state state
171 *
172 * return corresponding character
173 */
174 public final char getChar(int state)
175 {
176 throw new IllegalArgumentException("Codons datatype cannot be expressed as char");
177 }
178
179 /**
180 * Get triplet string corresponding to a given state
181 *
182 * @param state state
183 *
184 * return corresponding triplet string
185 */
186 public final String getTriplet(int state)
187 {
188 return CODON_TRIPLETS[state];
189 }
190
191 /**
192 * Get an array of three nucleotide states making this codon state
193 *
194 * @param state state
195 *
196 * return corresponding triplet string
197 */
198 public final int[] getTripletStates(int state)
199 {
200 int[] triplet = new int[3];
201
202 triplet[0] = Nucleotides.INSTANCE.getState(CODON_TRIPLETS[state].charAt(0));
203 triplet[1] = Nucleotides.INSTANCE.getState(CODON_TRIPLETS[state].charAt(1));
204 triplet[2] = Nucleotides.INSTANCE.getState(CODON_TRIPLETS[state].charAt(2));
205
206 return triplet;
207 }
208
209 /**
210 * description of data type
211 *
212 * @return string describing the data type
213 */
214 public String getDescription() {
215 return DESCRIPTION;
216 }
217
218 /**
219 * type of data type
220 *
221 * @return integer code for the data type
222 */
223 public int getType() {
224 return TYPE;
225 }
226
227 /**
228 * @return the genetic code
229 */
230 public GeneticCode getGeneticCode() {
231 return geneticCode;
232 }
233
234 /**
235 * Takes non-canonical state and returns true if it represents stop codon
236 * @param state
237 * @return true if the given state represents a stop codon
238 */
239 public final boolean isStopCodon(int state) {
240 return geneticCode.isStopCodon(state);
241 }
242
243 // Private members
244
245 private GeneticCode geneticCode;
246
247 }