Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AA.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/chemical/AA.cc
11 /// @brief translation between amino acid enum and string name/one letter char codes
12 /// @author Phil Bradley
13 
14 // Rosetta headers
15 #include <core/chemical/AA.hh>
16 // AUTO-REMOVED #include <basic/Tracer.hh>
17 
18 // Utility headers
19 #include <utility/exit.hh>
20 // AUTO-REMOVED #include <utility/vector1.hh>
21 
22 // C++ headers
23 #include <map>
24 #include <string>
25 
26 #include <utility/vector1_bool.hh>
27 #include <sstream>
28 
29 
30 
31 namespace core {
32 namespace chemical {
33 
34 
35 /* BEGIN: the following functions are local to this file */
36 
37 
38 /// @brief setup the map that converts string name to AA enum
39 std::map< std::string, AA > setup_name2aa() {
40 
41  std::map< std::string, AA > n2aa;
42 
43  n2aa[ "ALA" ] = aa_ala;
44  n2aa[ "CYS" ] = aa_cys;
45  n2aa[ "ASP" ] = aa_asp;
46  n2aa[ "GLU" ] = aa_glu;
47  n2aa[ "PHE" ] = aa_phe;
48  n2aa[ "GLY" ] = aa_gly;
49  n2aa[ "HIS" ] = aa_his;
50  n2aa[ "ILE" ] = aa_ile;
51  n2aa[ "LYS" ] = aa_lys;
52  n2aa[ "LEU" ] = aa_leu;
53  n2aa[ "MET" ] = aa_met;
54  n2aa[ "ASN" ] = aa_asn;
55  n2aa[ "PRO" ] = aa_pro;
56  n2aa[ "GLN" ] = aa_gln;
57  n2aa[ "ARG" ] = aa_arg;
58  n2aa[ "SER" ] = aa_ser;
59  n2aa[ "THR" ] = aa_thr;
60  n2aa[ "VAL" ] = aa_val;
61  n2aa[ "TRP" ] = aa_trp;
62  n2aa[ "TYR" ] = aa_tyr;
63 
64  n2aa[ "ADE" ] = na_ade;
65  n2aa[ "CYT" ] = na_cyt;
66  n2aa[ "GUA" ] = na_gua;
67  n2aa[ "THY" ] = na_thy;
68 
69  n2aa[ "RAD" ] = na_rad;
70  n2aa[ "RCY" ] = na_rcy;
71  n2aa[ "RGU" ] = na_rgu;
72  n2aa[ "URA" ] = na_ura;
73 
74  n2aa[ "VRT" ] = aa_vrt;
75 
76  n2aa[ "UNK" ] = aa_unk;
77 
78  return n2aa;
79 }
80 
81 
82 /// @brief setup the map the converts one letter char to AA enum
83 std::map< char, AA > setup_oneletter2aa() {
84 
85  std::map< char, AA > l2aa;
86 
87  l2aa[ 'A' ] = aa_ala;
88  l2aa[ 'C' ] = aa_cys;
89  l2aa[ 'D' ] = aa_asp;
90  l2aa[ 'E' ] = aa_glu;
91  l2aa[ 'F' ] = aa_phe;
92  l2aa[ 'G' ] = aa_gly;
93  l2aa[ 'H' ] = aa_his;
94  l2aa[ 'I' ] = aa_ile;
95  l2aa[ 'K' ] = aa_lys;
96  l2aa[ 'L' ] = aa_leu;
97  l2aa[ 'M' ] = aa_met;
98  l2aa[ 'N' ] = aa_asn;
99  l2aa[ 'P' ] = aa_pro;
100  l2aa[ 'Q' ] = aa_gln;
101  l2aa[ 'R' ] = aa_arg;
102  l2aa[ 'S' ] = aa_ser;
103  l2aa[ 'T' ] = aa_thr;
104  l2aa[ 'V' ] = aa_val;
105  l2aa[ 'W' ] = aa_trp;
106  l2aa[ 'Y' ] = aa_tyr;
107  l2aa[ 'a' ] = na_ade;
108  l2aa[ 'c' ] = na_cyt;
109  l2aa[ 'g' ] = na_gua;
110  l2aa[ 't' ] = na_thy;
111 
112  //rhiju RNA. Hmmm. The conflict with DNA seems like it could be a serious issue.
113  l2aa[ 'a' ] = na_rad;
114  l2aa[ 'c' ] = na_rcy;
115  l2aa[ 'g' ] = na_rgu;
116  l2aa[ 'u' ] = na_ura;
117 
118  l2aa[ 'Z' ] = aa_unk;
119  l2aa[ 'X' ] = aa_vrt;
120 
121  return l2aa;
122 }
123 
124 
125 /// @brief map that converts string name to AA enum
126 inline
127 std::map< std::string, AA > & name2aa() {
128  // static initialization only happens once
129  static std::map< std::string, AA > * name2aa_ = new std::map< std::string, AA >( setup_name2aa() );
130  return *name2aa_;
131 }
132 
133 
134 /// @brief map that converts one letter char to AA enum
135 inline
136 std::map< char, AA > & oneletter2aa() {
137  // static initialization only happens once
138  static std::map< char, AA > * oneletter2aa_ = new std::map< char, AA >( setup_oneletter2aa() );
139  return *oneletter2aa_;
140 }
141 
142 
143 /// @brief setup the vector that maps AA enum to string name
145 
147 
148  for ( std::map< std::string, AA >::const_iterator iter = name2aa().begin(),
149  iter_end = name2aa().end(); iter != iter_end; ++iter ) {
150  aa2n[ iter->second ] = iter->first;
151  }
152 
153  return aa2n;
154 }
155 
156 
157 /// @brief vector that maps AA enum to string name
158 inline
160  // static initialization only happens once
162  return *aa2name_;
163 }
164 
165 
166 /// @brief setup the vector that maps AA enum to one letter char
168 
170 
171  for ( std::map< char, AA >::const_iterator iter = oneletter2aa().begin(),
172  iter_end = oneletter2aa().end(); iter != iter_end; ++iter ) {
173  aa2l[ iter->second ] = iter->first;
174  }
175 
176  return aa2l;
177 }
178 
179 
180 /// @brief vector that maps AA enum to one letter char
181 inline
183  // static initialization only happens once
184  static utility::vector1< char > * aa2oneletter_ = new utility::vector1< char >( setup_aa2oneletter() );
185  return *aa2oneletter_;
186 }
187 
188 
189 /* END: the following functions are local to this file */
190 
191 
192 AA
193 aa_from_name( std::string const & name )
194 {
195  std::map< std::string, AA >::const_iterator iter = name2aa().find( name );
196  if ( iter == name2aa().end() ) {
197  utility_exit_with_message( "unrecognized aa type " + name );
198  }
199  return iter->second;
200 }
201 
202 
203 ///////////////////////////////////////////////////////////////////////////////
204 /// @brief input operator for AA enum type
205 ///
206 /// @details read in a string name from a file or std::cin and directly convert
207 /// it to an AA enum type, for example, std::cin >> AA. This will first check
208 /// if the lookup map has been set up already. If the string name cannot be
209 /// converted properly, it will flag the input stream as failure
210 /// (e.g., istream.fail() is true) and set AA enum type to aa_unk.
211 ////////////////////////////////////////////////////////////////////////////////
212 std::istream &
214  std::istream & is,
215  AA & aa
216 )
217 {
218  std::string name;
219  is >> name;
220  std::map< std::string, AA >::const_iterator iter = name2aa().find( name );
221  if ( iter == name2aa().end() ) {
222  //std::cout << "aaextract failed: " << name << std::endl;
223  aa = aa_unk;
224  is.setstate( std::ios_base::failbit );
225  } else {
226  //std::cout << "aaextract succeeded " << name << std::endl;
227  aa = iter->second;
228  }
229  return is;
230 }
231 
232 
233 //////////////////////////////////////////////////////////////////////////////
234 /// @brief output operator for AA enum type
235 ///
236 /// @details example usage: std::cout << aa_gly << std::endl;
237 //////////////////////////////////////////////////////////////////////////////
238 std::ostream &
240  std::ostream & os,
241  AA const & aa
242 )
243 {
244  os << name_from_aa( aa );
245  return os;
246 }
247 
248 
251  if( aa > num_aa_types ) return "AAOutOfRange";
252  return aa2name()[ aa ];
253 }
254 
255 
256 char
258  assert( aa <= chemical::num_canonical_aas );
259  return aa2oneletter()[ aa ];
260 }
261 
262 
263 AA
264 aa_from_oneletter_code( char onelettercode )
265 {
266  return oneletter2aa().find( onelettercode )->second;
267 }
268 
269 
270 bool
271 oneletter_code_specifies_aa( char onelettercode ) {
272  return oneletter2aa().find( onelettercode ) != oneletter2aa().end();
273 }
274 
275 
276 } // namespace chemical
277 } // namespace core