SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aminoacid.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef SHORE_GENOME_AMINOACID_HPP__
27 #define SHORE_GENOME_AMINOACID_HPP__
28 
29 #include <algorithm>
30 #include <cctype>
31 #include <string>
32 
34 #include "shore/base/memops.hpp"
35 #include "shore/base/stringops.hpp"
36 
37 namespace shore {
38 
40 class aa
41 {
42  public:
43 
46  {
47  PCK_NONE, // Stop .
48  PCK_ALANINE, // Ala A
49  PCK_ARGININE, // Arg R
50  PCK_ASPARAGINE, // Asn N
51  PCK_ASPARTIC_ACID, // Asp D
52  PCK_CYSTEINE, // Cys C
53  PCK_GLUTAMIC_ACID, // Glu E
54  PCK_GLUTAMINE, // Gln Q
55  PCK_GLYCINE, // Gly G
56  PCK_HISTIDINE, // His H
57  PCK_ISOLEUCINE, // Ile I
58  PCK_LEUCINE, // Leu L
59  PCK_LYSINE, // Lys K
60  PCK_METHIONINE, // Met M
61  PCK_PHENYLALANINE, // Phe F
62  PCK_PROLINE, // Pro P
63  PCK_SERINE, // Ser S
64  PCK_THREONINE, // Thr T
65  PCK_TRYPTOPHAN, // Trp W
66  PCK_TYROSINE, // Tyr Y
67  PCK_VALINE, // Val V
68  PCK_SELENOCYSTEINE, // Sec U
69  PCK_PYRROLYSINE, // Pyl O
70  PCK_ASPARAGINE_OR_ASPARTIC_ACID,// Asx B
71  PCK_GLUTAMINE_OR_GLUTAMIC_ACID, // Glx Z
72  PCK_LEUCINE_OR_ISOLEUCINE, // Xle J
73  PCK_ANY // Xaa X
74  };
76  enum bit_proteinogenic // bitmask
77  { // OUVYWTSPFMKLIHGQECDNRA
78  BIT_NONE=0x00, // 0000000000000000000000 Stop .
79  BIT_ALANINE=0x01, // 0000000000000000000001 Ala A
80  BIT_ARGININE=0x02, // 0000000000000000000010 Arg R
81  BIT_ASPARAGINE=0x04, // 0000000000000000000100 Asn N
82  BIT_ASPARTIC_ACID=0x08, // 0000000000000000001000 Asp D
83  BIT_CYSTEINE=0x10, // 0000000000000000010000 Cys C
84  BIT_GLUTAMIC_ACID=0x20, // 0000000000000000100000 Glu E
85  BIT_GLUTAMINE=0x40, // 0000000000000001000000 Gln Q
86  BIT_GLYCINE=0x80, // 0000000000000010000000 Gly G
87  BIT_HISTIDINE=0x100, // 0000000000000100000000 His H
88  BIT_ISOLEUCINE=0x200, // 0000000000001000000000 Ile I
89  BIT_LEUCINE=0x400, // 0000000000010000000000 Leu L
90  BIT_LYSINE=0x800, // 0000000000100000000000 Lys K
91  BIT_METHIONINE=0x1000, // 0000000001000000000000 Met M
92  BIT_PHENYLALANINE=0x2000, // 0000000010000000000000 Phe F
93  BIT_PROLINE=0x4000, // 0000000100000000000000 Pro P
94  BIT_SERINE=0x8000, // 0000001000000000000000 Ser S
95  BIT_THREONINE=0x10000, // 0000010000000000000000 Thr T
96  BIT_TRYPTOPHAN=0x20000, // 0000100000000000000000 Trp W
97  BIT_TYROSINE=0x40000, // 0001000000000000000000 Tyr Y
98  BIT_VALINE=0x80000, // 0010000000000000000000 Val V
99  BIT_SELENOCYSTEINE=0x100000, // 0100000000000000000000 Sec U
100  BIT_PYRROLYSINE=0x200000, // 1000000000000000000000 Pyl O
101  // Asparagine or aspartic acid 0000000000000000001100 Asx B
102  // Glutamine or glutamic acid 0000000000000001100000 Glx Z
103  // Leucine or Isoleucine 0000000000011000000000 Xle J
104  // Unspecified or unknown amino acid
105  BIT_ANY=0x3FFFFF // 1111111111111111111111 Xaa X
106  };
107 
108  private:
109 
111  struct symdec_tab
112  {
113  packed_proteinogenic data[256];
114 
115  symdec_tab();
116  };
117 
119  static const char m_symenc_tab[28];
121  static const std::string m_mnemenc_tab[27];
123  static const std::string m_nameenc_tab[27];
125  static const symdec_tab m_symdec_tab;
127  static const packed_proteinogenic m_code_std_tab[64];
128 
129  public:
130 
133  {
134  int codix=static_cast<int>(shore::nuc::pack(b3))&3;
135  codix|=((static_cast<int>(shore::nuc::pack(b2))&3)<<2);
136  codix|=((static_cast<int>(shore::nuc::pack(b1))&3)<<4);
137  return m_code_std_tab[codix];
138  }
139 
141  static packed_proteinogenic dec(const char c)
142  {
143  return m_symdec_tab.data[static_cast<uint8_t>(c)];
144  }
145 
147  static char enc(const packed_proteinogenic p)
148  {
149  return m_symenc_tab[static_cast<int>(p)];
150  }
151 
153  static const std::string &mnemonic(const packed_proteinogenic p)
154  {
155  return m_mnemenc_tab[static_cast<int>(p)];
156  }
157 
159  static const std::string &name(const packed_proteinogenic p)
160  {
161  return m_nameenc_tab[static_cast<int>(p)];
162  }
163 };
164 
165 } // namespace shore
166 
167 #endif // SHORE_GENOME_AMINOACID_HPP__
168