RNAblueprint-1.3.2
common.h
Go to the documentation of this file.
1 
11 #ifndef COMMON_H
12 #define COMMON_H
13 
14 
15 // include standard library parts
16 #include <string>
17 #include <vector>
18 #include <array>
19 #include <unordered_map>
20 #include <set>
21 #include <list>
22 #include <iostream>
23 #include <utility>
24 #include <exception>
25 #include <random>
26 
27 // include boost components
28 #include <boost/lexical_cast.hpp>
29 #include <boost/config.hpp>
30 #include <boost/graph/adjacency_list.hpp>
31 #include <boost/graph/iteration_macros.hpp>
32 #ifdef LIBGMP
33 #include <boost/multiprecision/gmp.hpp>
34 #include <boost/random.hpp>
35 #endif
36 // modified boost headers
37 #include "uninduced_subgraph.hpp"
38 
39 namespace design {
40 
41  // Typedef for nos values
42  #ifdef LIBGMP
43  typedef boost::multiprecision::mpf_float_50 SolutionSizeType;
44  typedef boost::random::uniform_real_distribution<boost::multiprecision::mpf_float_50> RandomDistType;
45  #else
46  typedef double SolutionSizeType;
47  typedef std::uniform_real_distribution<double> RandomDistType;
48  #endif
49 
50 
51  namespace detail {
52 
53  //Global variables
54  extern bool debug;
55  extern bool * debug_ptr;
56  extern int construction_timeout;
57  extern int * construction_timeout_ptr;
58 
59  // define size of the alphabet
60  #define A_Size 4
61  // Encode Bases to enums
62 
63  /*
64  A = adenine
65  C = cytosine
66  G = guanine
67  T = thymine
68  R = G A (purine)
69  Y = T C (pyrimidine)
70  K = G T (keto)
71  M = A C (amino)
72  S = G C (strong bonds)
73  W = A T (weak bonds)
74  B = G T C (all but A)
75  D = G A T (all but C)
76  H = A C T (all but G)
77  V = G C A (all but T)
78  N = A G C T (any)
79  */
80 
81  // it is important that 0-3 are the basic bases
82 
83  enum bases {
84  A, C, G, U, R, Y, K, M, S, W, B, D, H, V, N
85  };
86 
87  static std::unordered_map<int, std::set<int> > base_conversion ={
88  { A,
89  { A}},
90  { C,
91  { C}},
92  { G,
93  { G}},
94  { U,
95  { U}},
96  { R,
97  { G, A}},
98  { Y,
99  { U, C}},
100  { K,
101  { G, U}},
102  { M,
103  { A, C}},
104  { S,
105  { G, C}},
106  { W,
107  { A, U}},
108  { B,
109  { G, U, C}},
110  { D,
111  { G, A, U}},
112  { H,
113  { A, C, U}},
114  { V,
115  { G, C, A}},
116  { N,
117  { A, G, C, U}}
118  };
119 
120  // Typedef for sequences of enums
121  typedef std::deque< int > Sequence;
122 
123  // remember the probability of the chosen solution as a fraction
124  // numerator is the amount of solutions for the chosen value
125  // denominator is the total amount of solutions for the problem
126  typedef std::pair< SolutionSizeType, SolutionSizeType > ProbabilityFraction;
127 
128  // function to make enum a char again and other way round
129  char enum_to_char(int intletter);
130  int char_to_enum(char charletter);
131 
132  // overload << operator to print vectors with any content
133 
134  template <typename T>
135  std::ostream& operator<<(std::ostream& os, std::vector<T>& vec) {
136  int i = 0;
137  for (auto elem : vec) {
138  os << "(" << i++ << ") " << elem << std::endl;
139  }
140  return os;
141  }
142 
143  // overload << operator to print maps with any content
144 
145  template <typename U, typename V>
146  std::ostream& operator<<(std::ostream& os, std::map<U, V>& m) {
147  for (typename std::map<U, V>::iterator it = m.begin(); it != m.end(); it++) {
148  os << it->first << "," << it->second << std::endl;
149  }
150  return os;
151  }
152 
153  // overload << operator to print sets with any content
154 
155  template <typename W>
156  std::ostream& operator<<(std::ostream& os, std::set<W>& s) {
157  for (auto elem : s) {
158  os << elem << ", ";
159  }
160  return os;
161  }
162 
163  // overload << operator to print deques with sequence information
164  std::ostream& operator<<(std::ostream& os, Sequence& sequence);
165 
166  // matrix template
167  template < class T, size_t ROWS, size_t COLS > using matrix = std::array< std::array< T, COLS >, ROWS >;
168  }
169 }
170 
171 #endif
172 
173 /*
174  * \endcond INTERNAL
175  */
All classes and functions for the RNA design library are under the design namespace.
Definition: RNAblueprint.h:101