NCBI C++ ToolKit
Genetic_code_table.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: Genetic_code_table.hpp 78216 2017-06-03 16:46:26Z kans $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the ASN data definition file
34  * 'seqfeat.asn'.
35  */
36 
37 #ifndef OBJECTS_SEQFEAT_GENETIC_CODE_TABLE_HPP
38 #define OBJECTS_SEQFEAT_GENETIC_CODE_TABLE_HPP
39 
40 
41 // generated includes
43 
44 #include <memory> // for auto_ptr<>
45 
46 // generated classes
47 
49 
50 class CObjectIStream;
51 
52 BEGIN_objects_SCOPE // namespace ncbi::objects::
53 
55 
56 
58 {
60 public:
61  // constructor
62  CGenetic_code_table(void);
63  // destructor
64  ~CGenetic_code_table(void);
65 
66 private:
67  // Prohibit copy constructor and assignment operator
70 };
71 
72 
73 
74 /////////////////// CGenetic_code_table inline methods
75 
76 // constructor
77 inline
79 {
80 }
81 
82 
83 /////////////////// end of CGenetic_code_table inline methods
84 
85 
86 // genetic code translation table class
87 
88 // the function CCdregion_translate::TranslateCdregion in
89 // <objects/util/sequence.hpp> obtains the sequence under
90 // a coding region feature location and uses CTrans_table
91 // to do the translation
92 
94 {
95 public:
96  // constructor
98  // destructor
99  ~CTrans_table(void);
100 
101  // translation finite state machine methods
102  static int SetCodonState (unsigned char ch1,
103  unsigned char ch2,
104  unsigned char ch3);
105  static int NextCodonState (int state,
106  unsigned char ch);
107  static int RevCompState (int state);
108 
109  // lookup of amino acid translated for given codon (state)
110  char GetCodonResidue (int state) const;
111  char GetStartResidue (int state) const;
112  char GetStopResidue (int state) const;
113 
114  bool IsOrfStart (int state) const;
115  bool IsAmbigStart (int state) const;
116  bool IsAnyStart (int state) const;
117  bool IsOrfStop (int state) const;
118  bool IsATGStart (int state) const;
119  bool IsAltStart (int state) const;
120 
121 private:
122  // translation tables common to all genetic codes (single copy)
123  static int sm_NextState [4097];
124  static int sm_RvCmpState [4097];
125  static int sm_BaseToIdx [256];
126 
127  // initialize single copy translation tables
128  static void x_InitFsaTable (void);
129 
130  // translation tables specific to each genetic code instance
131  mutable char m_AminoAcid [4097];
132  mutable char m_OrfStart [4097];
133  mutable char m_OrfStop [4097];
134 
135  // initialize genetic code specific translation tables
136  void x_InitFsaTransl (const string *ncbieaa,
137  const string *sncbieaa) const;
138 
139  friend class CGen_code_table_imp;
140 };
141 
142 
143 
144 // public interface for (single instance) genetic code and translation tables
145 
147 {
148 public:
149  // return initialized translation table given genetic code
150  static const CTrans_table& GetTransTable (int id);
151  static const CTrans_table& GetTransTable (const CGenetic_code& gc);
152 
153  // return table of loaded genetic codes for iteration
154  static const CGenetic_code_table& GetCodeTable (void);
155 
156  // Get the ncbieaa string for a specific genetic code.
157  static const string& GetNcbieaa(int id);
158  static const string& GetNcbieaa(const CGenetic_code& gc);
159 
160  // Get the sncbieaa string for a specific genetic code
161  static const string& GetSncbieaa(int id);
162  static const string& GetSncbieaa(const CGenetic_code& gc);
163 
164  // Convert the numeric representation of a codon to a base one.
165  static string IndexToCodon(int index);
166 
167  // Convert the base representation of a codon to a numeric one.
168  static int CodonToIndex(char base1, char base2, char base3);
169  static int CodonToIndex(const string& codon);
170 
171  // Attempt to load a new translation table; if it fails, throw
172  // an exception and continue to use the old one.
173  static void LoadTransTable(CObjectIStream& ois);
174  static void LoadTransTable(const string& path, ESerialDataFormat format);
175 
176 private:
177  // this class uses a singleton internally to manage the specifics
178  // of the genetic code implementation
179  // these are the variables / functions that control the singleton
181 
182  static void x_InitImplementation(void);
183  static CGen_code_table_imp& x_GetImplementation (void);
184 };
185 
186 
187 inline
189 {
190  if ( !sm_Implementation.get() ) {
192  }
193  return *sm_Implementation;
194 }
195 
196 
197 
198 /////////////////// CTrans_table inline methods
199 
200 inline
201 int CTrans_table::SetCodonState (unsigned char ch1,
202  unsigned char ch2,
203  unsigned char ch3)
204 {
205  return (256 * sm_BaseToIdx [(int) ch1] +
206  16 * sm_BaseToIdx [(int) ch2] +
207  sm_BaseToIdx [(int) ch3] + 1);
208 }
209 
210 inline
212  unsigned char ch)
213 {
214  if (state < 0 || state > 4096) return 0;
215  return (sm_NextState [state] + sm_BaseToIdx [(int) ch]);
216 }
217 
218 inline
220 {
221  if (state < 0 || state > 4096) return 0;
222  return (sm_RvCmpState [state]);
223 }
224 
225 inline
227 {
228  if (state < 0 || state > 4096) return 0;
229  return (m_AminoAcid [state]);
230 }
231 
232 inline
234 {
235  if (state < 0 || state > 4096) return 0;
236  return (m_OrfStart [state]);
237 }
238 
239 inline
241 {
242  if (state < 0 || state > 4096) return 0;
243  return (m_OrfStop [state]);
244 }
245 
246 inline
248 {
249  return (GetStartResidue (state) == 'M');
250 }
251 
252 inline
254 {
255  return (GetStartResidue (state) == 'X');
256 }
257 
258 inline
260 {
261  return (GetStartResidue (state) != '-');
262 }
263 
264 inline
266 {
267  return (GetStopResidue (state) == '*');
268 }
269 
270 inline
272 {
273  static const int k_ATG_state = 389; // ATG initiation codon state
274  return (IsOrfStart (state) && state == k_ATG_state);
275 }
276 
277 inline
279 {
280  static const int k_ATG_state = 389; // ATG initiation codon state
281  return (IsOrfStart (state) && state != k_ATG_state);
282 }
283 
284 /////////////////// end of CTrans_table inline methods
285 
286 
287 
288 END_objects_SCOPE // namespace ncbi::objects::
289 
291 
292 #endif // OBJECTS_SEQFEAT_GENETIC_CODE_TABLE_HPP
293 /* Original file checksum: lines: 93, chars: 2557, CRC32: e1e5ca57 */
Data storage class.
static AutoPtr< CGen_code_table_imp > sm_Implementation
static CGen_code_table_imp & x_GetImplementation(void)
static void x_InitImplementation(void)
table of genetic codes
CGenetic_code_table_Base Tparent
CGenetic_code_table(const CGenetic_code_table &value)
CGenetic_code_table & operator=(const CGenetic_code_table &value)
CObjectIStream –.
Definition: objistr.hpp:93
CObject –.
Definition: ncbiobj.hpp:180
bool IsAmbigStart(int state) const
static int RevCompState(int state)
char GetStartResidue(int state) const
bool IsATGStart(int state) const
char GetCodonResidue(int state) const
bool IsAltStart(int state) const
static int sm_NextState[4097]
bool IsOrfStart(int state) const
static int SetCodonState(unsigned char ch1, unsigned char ch2, unsigned char ch3)
bool IsAnyStart(int state) const
static int NextCodonState(int state, unsigned char ch)
static int sm_RvCmpState[4097]
static int sm_BaseToIdx[256]
char m_AminoAcid[4097]
bool IsOrfStop(int state) const
char GetStopResidue(int state) const
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_SEQFEAT_EXPORT
Definition: ncbi_export.h:768
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
static const BitmapCharRec ch3
Definition: ncbi_10x20.c:1809
static const BitmapCharRec ch1
Definition: ncbi_10x20.c:1827
static const BitmapCharRec ch2
Definition: ncbi_10x20.c:1819
static Format format
Definition: njn_ioutil.cpp:53
Modified on Thu Apr 25 08:19:48 2024 by modify_doxy.py rev. 669887