Chemical Data Processing Library C++ API - Version 1.4.0
ResidueDictionary.hpp
Go to the documentation of this file.
1 /*
2  * ResidueDictionary.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library 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 GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_BIOMOL_RESIDUEDICTIONARY_HPP
30 #define CDPL_BIOMOL_RESIDUEDICTIONARY_HPP
31 
32 #include <string>
33 #include <unordered_map>
34 #include <memory>
35 #include <functional>
36 
37 #include <boost/iterator/transform_iterator.hpp>
38 
41 
42 
43 namespace CDPL
44 {
45 
46  namespace Biomol
47  {
48 
54  {
55 
56  public:
61  {
62 
63  public:
65  typedef std::function<Chem::MolecularGraph::SharedPointer(const std::string&)> StructureRetrievalFunction;
66 
79  Entry(const std::string& code, const std::string& rep_code, const std::string& rep_by_code, const std::string& parent_code,
80  const std::string& one_letter_code,bool obsolete, const std::string& name, unsigned int type,
81  const StructureRetrievalFunction& struc_ret_func);
82 
86  Entry();
87 
92  const std::string& getCode() const;
93 
98  const std::string& getReplacedCode() const;
99 
104  const std::string& getReplacedByCode() const;
105 
111  const std::string& getParentCode() const;
112 
118  const std::string& getOneLetterCode() const;
119 
124  bool isObsolete() const;
125 
130  const std::string& getName() const;
131 
136  unsigned int getType() const;
137 
143 
144  private:
145  std::string code;
146  std::string replacesCode;
147  std::string replacedByCode;
148  std::string parentCode;
149  std::string oneLetterCode;
150  bool obsolete;
151  std::string name;
152  unsigned int type;
153  StructureRetrievalFunction structRetrievalFunc;
154  };
155 
156  private:
157  struct CIStringHashFunc
158  {
159 
160  std::size_t operator()(const std::string& str) const;
161  };
162 
163  struct CIStringCmpFunc
164  {
165 
166  bool operator()(const std::string& str1, const std::string& str2) const;
167  };
168 
169  typedef std::unordered_map<std::string, Entry, CIStringHashFunc, CIStringCmpFunc> EntryLookupTable;
170 
171  public:
173  typedef std::shared_ptr<ResidueDictionary> SharedPointer;
174 
176  typedef boost::transform_iterator<std::function<const Entry&(const EntryLookupTable::value_type&)>,
177  EntryLookupTable::const_iterator> ConstEntryIterator;
178 
184  static bool isStdResidue(const std::string& code);
185 
190  void addEntry(const Entry& entry);
191 
197  void addEntry(Entry&& entry);
198 
204  bool containsEntry(const std::string& code) const;
205 
210  void removeEntry(const std::string& code);
211 
217  const Entry& getEntry(const std::string& code) const;
218 
222  void clear();
223 
228  std::size_t getNumEntries() const;
229 
235 
241 
247 
253 
259  const std::string& getReplacedCode(const std::string& code) const;
260 
266  const std::string& getReplacedByCode(const std::string& code) const;
267 
274  const std::string& getParentCode(const std::string& code) const;
275 
282  const std::string& getOneLetterCode(const std::string& code) const;
283 
289  bool isObsolete(const std::string& code) const;
290 
296  const std::string& getName(const std::string& code) const;
297 
303  unsigned int getType(const std::string& code) const;
304 
310  Chem::MolecularGraph::SharedPointer getStructure(const std::string& code) const;
311 
315  void loadDefaults();
316 
321  static void set(const SharedPointer& dict);
322 
327  static const SharedPointer& get();
328 
329  private:
330  static SharedPointer defaultDict;
331  EntryLookupTable entries;
332  };
333  } // namespace Biomol
334 } // namespace CDPL
335 
336 #endif // CDPL_BIOMOL_RESIDUEDICTIONARY_HPP
Definition of the preprocessor macro CDPL_BIOMOL_API.
#define CDPL_BIOMOL_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of class CDPL::Chem::MolecularGraph.
A single residue dictionary entry.
Definition: ResidueDictionary.hpp:61
const std::string & getOneLetterCode() const
Returns the one-letter residue code.
const std::string & getName() const
Returns the full residue name.
unsigned int getType() const
Returns the residue type (see Biomol::ResidueType).
bool isObsolete() const
Tells whether the residue type described by this entry is obsolete.
const std::string & getReplacedByCode() const
Returns the TLC of the residue that replaces this one.
const std::string & getReplacedCode() const
Returns the TLC of the residue this entry replaces.
Chem::MolecularGraph::SharedPointer getStructure() const
Retrieves the residue structure via the configured structure-retrieval function.
Entry(const std::string &code, const std::string &rep_code, const std::string &rep_by_code, const std::string &parent_code, const std::string &one_letter_code, bool obsolete, const std::string &name, unsigned int type, const StructureRetrievalFunction &struc_ret_func)
Constructs and initializes an Entry instance with the given data.
const std::string & getParentCode() const
Returns the TLC of the parent residue.
Entry()
Constructs an empty (default-initialized) Entry instance.
const std::string & getCode() const
Returns the three-letter code (TLC) of the residue.
std::function< Chem::MolecularGraph::SharedPointer(const std::string &)> StructureRetrievalFunction
Generic wrapper for storing a user-defined function that retrieves the residue structure for a given ...
Definition: ResidueDictionary.hpp:65
Global dictionary for the lookup of meta-data associated with the residues in biological macromolecul...
Definition: ResidueDictionary.hpp:54
static void set(const SharedPointer &dict)
Replaces the process-wide default dictionary by dict.
const std::string & getReplacedCode(const std::string &code) const
Returns the TLC of the residue replaced by the residue with three-letter code code.
const std::string & getReplacedByCode(const std::string &code) const
Returns the TLC of the residue that replaces the residue with three-letter code code.
std::shared_ptr< ResidueDictionary > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ResidueDictionary instances.
Definition: ResidueDictionary.hpp:173
ConstEntryIterator getEntriesBegin() const
Returns a constant iterator pointing to the beginning of the entry list.
boost::transform_iterator< std::function< const Entry &(const EntryLookupTable::value_type &)>, EntryLookupTable::const_iterator > ConstEntryIterator
A constant iterator over the entries of the dictionary.
Definition: ResidueDictionary.hpp:177
const std::string & getOneLetterCode(const std::string &code) const
Returns the one-letter code of the residue with three-letter code code.
Chem::MolecularGraph::SharedPointer getStructure(const std::string &code) const
Retrieves the structure of the residue with three-letter code code.
void addEntry(const Entry &entry)
Adds (or overwrites) the dictionary entry entry.
const std::string & getParentCode(const std::string &code) const
Returns the TLC of the parent residue of the residue with three-letter code code.
unsigned int getType(const std::string &code) const
Returns the residue type (see Biomol::ResidueType) of the residue with three-letter code code.
const Entry & getEntry(const std::string &code) const
Returns the dictionary entry for the residue with three-letter code code.
static bool isStdResidue(const std::string &code)
Tells whether the residue with three-letter code code is a standard biopolymer residue (amino acid or...
bool containsEntry(const std::string &code) const
Tells whether the dictionary contains an entry for the residue with three-letter code code.
const std::string & getName(const std::string &code) const
Returns the full name of the residue with three-letter code code.
void removeEntry(const std::string &code)
Removes the dictionary entry for the residue with three-letter code code.
void addEntry(Entry &&entry)
Adds (or overwrites) the dictionary entry entry by moving its data.
void clear()
Removes all entries from the dictionary.
ConstEntryIterator begin() const
Returns a constant iterator pointing to the beginning of the entry list (alias of getEntriesBegin()).
static const SharedPointer & get()
Returns the process-wide default dictionary (lazily initialized on first call).
ConstEntryIterator getEntriesEnd() const
Returns a constant iterator pointing one past the last entry.
void loadDefaults()
Loads the built-in default residue dictionary entries.
bool isObsolete(const std::string &code) const
Tells whether the residue type with three-letter code code is obsolete.
ConstEntryIterator end() const
Returns a constant iterator pointing one past the last entry (alias of getEntriesEnd()).
std::size_t getNumEntries() const
Returns the number of entries in the dictionary.
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:63
The namespace of the Chemical Data Processing Library.