Debian Codegraph @

src/dr/evolution/datatype/GeneticCode.java

raw symbols SCIP
1 /*
2 * GeneticCode.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 * A set of standard genetic codes.
30 *
31 * @author Andrew Rambaut
32 * @author Alexei Drummond
33 *
34 * @version $Id: GeneticCode.java,v 1.11 2005/05/24 20:25:56 rambaut Exp $
35 */
36
37 public final class GeneticCode implements CodonTable {
38
39 public static final String GENETIC_CODE = "geneticCode";
40
41 /**
42 * Constants used to refer to the built in code tables
43 */
44 public static final int UNIVERSAL_ID = 0;
45 public static final int VERTEBRATE_MT_ID = 1;
46 public static final int YEAST_ID = 2;
47 public static final int MOLD_PROTOZOAN_MT_ID = 3;
48 public static final int MYCOPLASMA_ID = 4;
49 public static final int INVERTEBRATE_MT_ID = 5;
50 public static final int CILIATE_ID = 6;
51 public static final int ECHINODERM_MT_ID = 7;
52 public static final int EUPLOTID_NUC_ID = 8;
53 public static final int BACTERIAL_ID = 9;
54 public static final int ALT_YEAST_ID = 10;
55 public static final int ASCIDIAN_MT_ID = 11;
56 public static final int FLATWORM_MT_ID = 12;
57 public static final int BLEPHARISMA_NUC_ID = 13;
58 public static final int NO_STOPS_ID = 14;
59
60 /**
61 * Standard genetic code tables from GENBANK
62 * Nucleotides go A, C, G, T - Note: this is not the order used by the Genbank web site
63 * With the first codon position most significant (i.e. AAA, AAC, AAG, AAT, ACA, etc.).
64 */
65 public static final String[] GENETIC_CODE_TABLES = {
66 // Universal
67 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF",
68 // Vertebrate Mitochondrial
69 "KNKNTTTT*S*SMIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
70 // Yeast
71 "KNKNTTTTRSRSMIMIQHQHPPPPRRRRTTTTEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
72 // Mold Protozoan Mitochondrial
73 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
74 // Mycoplasma
75 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
76 // Invertebrate Mitochondrial
77 "KNKNTTTTSSSSMIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
78 // Ciliate
79 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVVQYQYSSSS*CWCLFLF",
80 // Echinoderm Mitochondrial
81 "NNKNTTTTSSSSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
82 // Euplotid Nuclear
83 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSCCWCLFLF",
84 // Bacterial
85 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF",
86 // Alternative Yeast
87 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLSLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF",
88 // Ascidian Mitochondrial
89 "KNKNTTTTGSGSMIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSSWCWCLFLF",
90 // Flatworm Mitochondrial
91 "NNKNTTTTSSSSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVVYY*YSSSSWCWCLFLF",
92 // Blepharisma Nuclear
93 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*YQYSSSS*CWCLFLF",
94 // No stops
95 "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVVYYQYSSSSWCWCLFLF"
96 };
97
98 /**
99 * Names of the standard genetic code tables from GENBANK
100 */
101 public static final String[] GENETIC_CODE_NAMES = {
102 "universal", "vertebrateMitochondrial", "yeast", "moldProtozoanMitochondrial",
103 "mycoplasma", "invertebrateMitochondrial", "ciliate", "echinodermMitochondrial",
104 "euplotidNuclear", "bacterial", "alternativeYeast", "ascidianMitochondrial",
105 "flatwormMitochondrial", "blepharismaNuclear", "noStops"
106 };
107
108 /**
109 * Descriptions of the standard genetic code tables from GENBANK
110 */
111 public static final String[] GENETIC_CODE_DESCRIPTIONS = {
112 "Universal", "Vertebrate Mitochondrial", "Yeast", "Mold Protozoan Mitochondrial",
113 "Mycoplasma", "Invertebrate Mitochondrial", "Ciliate", "Echinoderm Mitochondrial",
114 "Euplotid Nuclear", "Bacterial", "Alternative Yeast", "Ascidian Mitochondrial",
115 "Flatworm Mitochondrial", "Blepharisma Nuclear", "Test case with no stop codons"
116 };
117
118 public static final GeneticCode UNIVERSAL = new GeneticCode(UNIVERSAL_ID);
119 public static final GeneticCode VERTEBRATE_MT = new GeneticCode(VERTEBRATE_MT_ID);
120 public static final GeneticCode YEAST = new GeneticCode(YEAST_ID);
121 public static final GeneticCode MOLD_PROTOZOAN_MT = new GeneticCode(MOLD_PROTOZOAN_MT_ID);
122 public static final GeneticCode MYCOPLASMA = new GeneticCode(MYCOPLASMA_ID);
123 public static final GeneticCode INVERTEBRATE_MT = new GeneticCode(INVERTEBRATE_MT_ID);
124 public static final GeneticCode CILIATE = new GeneticCode(CILIATE_ID);
125 public static final GeneticCode ECHINODERM_MT = new GeneticCode(ECHINODERM_MT_ID);
126 public static final GeneticCode EUPLOTID_NUC = new GeneticCode(EUPLOTID_NUC_ID);
127 public static final GeneticCode BACTERIAL = new GeneticCode(BACTERIAL_ID);
128 public static final GeneticCode ALT_YEAST = new GeneticCode(ALT_YEAST_ID);
129 public static final GeneticCode ASCIDIAN_MT = new GeneticCode(ASCIDIAN_MT_ID);
130 public static final GeneticCode FLATWORM_MT = new GeneticCode(FLATWORM_MT_ID);
131 public static final GeneticCode BLEPHARISMA_NUC = new GeneticCode(BLEPHARISMA_NUC_ID);
132 public static final GeneticCode NO_STOPS = new GeneticCode(NO_STOPS_ID);
133
134 public static final GeneticCode[] GENETIC_CODES = {
135 UNIVERSAL, VERTEBRATE_MT, YEAST, MOLD_PROTOZOAN_MT, MYCOPLASMA, INVERTEBRATE_MT,
136 CILIATE, ECHINODERM_MT, EUPLOTID_NUC, BACTERIAL, ALT_YEAST, ASCIDIAN_MT,
137 FLATWORM_MT, BLEPHARISMA_NUC, NO_STOPS
138 };
139
140 public GeneticCode(int geneticCode) {
141
142 this.geneticCode = geneticCode;
143 codeTable = GENETIC_CODE_TABLES[geneticCode];
144 }
145
146 /**
147 * Returns the name of the genetic code
148 */
149 public String getName() {
150 return GENETIC_CODE_NAMES[geneticCode];
151 }
152
153 /**
154 * Returns the description of the genetic code
155 */
156 public String getDescription() {
157 return GENETIC_CODE_DESCRIPTIONS[geneticCode];
158 }
159
160 /**
161 * Returns the char associated with AminoAcid represented by codonState.
162 * Note that the char is as defined by AminoAcids.java
163 * @see AminoAcids
164 * @see Codons
165 * @return state for '?' if codon unknown
166 */
167 public char getAminoAcidChar(int codonState) {
168 if (codonState == Codons.UNKNOWN_STATE)
169 return AminoAcids.UNKNOWN_CHARACTER;
170 else if (codonState == Codons.GAP_STATE)
171 return AminoAcids.GAP_CHARACTER;
172
173 return codeTable.charAt(codonState);
174 }
175
176 /**
177 * Returns the state associated with AminoAcid represented by codonState.
178 * Note that the state is the canonical state (generated combinatorially)
179 * @see AminoAcids
180 * @see Codons
181 * @return '?' if codon unknown
182 */
183 public int getAminoAcidState(int codonState) {
184 if (codonState == Codons.UNKNOWN_STATE)
185 return AminoAcids.UNKNOWN_STATE;
186 else if (codonState == Codons.GAP_STATE)
187 return AminoAcids.GAP_STATE;
188
189 return AminoAcids.AMINOACID_STATES[getAminoAcidChar(codonState)];
190 }
191
192 /**
193 * Note that the state is the canonical state (generated combinatorially)
194 * @return whether the codonState is a stop codon
195 */
196 public boolean isStopCodon(int codonState) {
197 return (getAminoAcidState(codonState) == AminoAcids.STOP_STATE);
198 }
199
200 /**
201 * @return all the possible codons for a given amino acid
202 */
203 public char[][] getCodonsFromAminoAcidState(int aminoAcidState) {
204 throw new RuntimeException("not yet implemented");
205 }
206
207 /*
208 * @return all the possible codons for a given amino acid
209 */
210 public char[][] getCodonsFromAminoAcidChar(char aminoAcidChar) {
211 throw new RuntimeException("not yet implemented");
212 }
213
214 /*
215 * @returns three IUPAC states representing the given amino acid
216 * @note The returned array should not be altered, and implementations
217 * should attempt to implement this as efficiently as possible
218 */
219 public int[] getAmbiguousCodonFromAminoAcidState(int aminoAcid) {
220 throw new RuntimeException("not yet implemented");
221 }
222
223 /**
224 * @return the codon states of stop amino acids.
225 */
226 public int[] getStopCodonIndices() {
227
228 int i, j, n = getStopCodonCount();
229 int[] indices = new int[n];
230
231 j = 0;
232 for (i = 0; i < 64; i++) {
233 if (codeTable.charAt(i) == AminoAcids.STOP_CHARACTER) {
234 indices[j] = i;
235 j++;
236 }
237 }
238
239 return indices;
240 }
241
242 /**
243 * Returns the number of terminator amino acids.
244 */
245 public int getStopCodonCount() {
246 int i, count = 0;
247
248 for (i = 0; i < 64; i++) {
249 if (codeTable.charAt(i) == AminoAcids.STOP_CHARACTER)
250 count++;
251 }
252
253 return count;
254 }
255
256 private int geneticCode;
257 private String codeTable;
258
259 }