faif
EnergyNucleo.h
1 // singleton, pair of dna nucleotides energies
2 // @author Robert Nowak
3 
4 #ifndef ENERGY_NUCLEO_H
5 #define ENERGY_NUCLEO_H
6 
7 #include <utility>
8 #include <map>
9 
10 #include "Nucleotide.h"
11 
12 namespace faif {
13  namespace dna {
14  /** the energy value */
15  typedef int EnergyValue;
16 
17  /** the pair of nucleotides */
18  typedef std::pair<faif::dna::Nucleotide, faif::dna::Nucleotide> Complementary;
19 
20  /** comparison of pair of nucleotides (support) */
22  bool operator()(const Complementary& a, const Complementary& b) const {
23  if(a.first == b.first )
24  return a.second.get() < b.second.get();
25  else
26  return a.first.get() < b.first.get();
27  }
28  };
29 
30  /** the default energy value */
31  static const EnergyValue DEFAULT_NUCLEO_ENERGY = -1000;
32 
33  /** \brief the maps between pair of nucleotides and its energy
34 
35  Gives energy for two nucleotides, used f.e. in secondary structure calculation
36  */
38  {
39  public:
40  /** c-tor */
41  explicit EnergyNucleo(EnergyValue defaultEnergy) : defaultEnergy_(defaultEnergy) {}
42  /** copy c-tor */
43  EnergyNucleo(const EnergyNucleo& energy) : data_(energy.data_), defaultEnergy_(energy.defaultEnergy_) {}
44  ~EnergyNucleo(){}
45  /** \brief return the energy of given pair */
46  EnergyValue getEnergy ( const faif::dna::Nucleotide& a, const faif::dna::Nucleotide& b ) const {
47  EnergyMap::const_iterator it = data_.find( Complementary(a,b) );
48  if( it != data_.end() )
49  return it->second;
50  else
51  return defaultEnergy_;
52  }
53 
54  /** \brief stores the pair and its energy */
55  void addPair( const faif::dna::Nucleotide& a, const faif::dna::Nucleotide& b, const EnergyValue& val) {
56  data_.insert( EnergyMap::value_type( Complementary(a,b), val ) );
57  }
58  private:
59  typedef std::map<Complementary, EnergyValue, lessComplementary > EnergyMap;
60  EnergyMap data_;
61 
62  // default energy - returned when pair is not found
63  const EnergyValue defaultEnergy_;
64 
65  // assignment not allowed
66  EnergyNucleo& operator=(const EnergyNucleo& energy);
67  };
68 
69  /** default energy object: GC pair: energy = 3, AT pair: energy = 2, GT pair: energy = 1,
70  otherwise energy = -1000 */
71  inline EnergyNucleo createDefaultEnergy(EnergyValue defaultEnergy = DEFAULT_NUCLEO_ENERGY) {
72  EnergyNucleo energy(defaultEnergy);
73  energy.addPair( Nucleotide(GUANINE), Nucleotide(CYTOSINE), 3 );
74  energy.addPair( Nucleotide(CYTOSINE), Nucleotide(GUANINE), 3 );
75  energy.addPair( Nucleotide(ADENINE), Nucleotide(THYMINE), 2 );
76  energy.addPair( Nucleotide(THYMINE), Nucleotide(ADENINE), 2 );
77  energy.addPair( Nucleotide(GUANINE), Nucleotide(THYMINE), 1 );
78  energy.addPair( Nucleotide(THYMINE), Nucleotide(GUANINE), 1 );
79  return energy;
80  }
81 
82  } //namespace dna
83 } //namespace faif
84 
85 
86 #endif //ENERGY_NUCLEO
EnergyNucleo(EnergyValue defaultEnergy)
Definition: EnergyNucleo.h:41
Definition: EnergyNucleo.h:21
EnergyNucleo(const EnergyNucleo &energy)
Definition: EnergyNucleo.h:43
void addPair(const faif::dna::Nucleotide &a, const faif::dna::Nucleotide &b, const EnergyValue &val)
stores the pair and its energy
Definition: EnergyNucleo.h:55
Definition: Chain.h:17
the DNA nucleotide
Definition: Nucleotide.h:21
std::pair< faif::dna::Nucleotide, faif::dna::Nucleotide > Complementary
Definition: EnergyNucleo.h:18
int EnergyValue
Definition: EnergyNucleo.h:15
EnergyNucleo createDefaultEnergy(EnergyValue defaultEnergy=DEFAULT_NUCLEO_ENERGY)
Definition: EnergyNucleo.h:71
the maps between pair of nucleotides and its energy
Definition: EnergyNucleo.h:37
EnergyValue getEnergy(const faif::dna::Nucleotide &a, const faif::dna::Nucleotide &b) const
return the energy of given pair
Definition: EnergyNucleo.h:46