RNAblueprint-1.3.2
dependency_graph.h
Go to the documentation of this file.
1 
11 #ifndef DEPENDENCY_GRAPH_H
12 #define DEPENDENCY_GRAPH_H
13 
14 #include "common.h"
15 #include "graphcommon.h"
16 #include "probability_matrix.h"
17 #include "pathcoloring.h"
18 
19 #include <sstream>
20 #include <unordered_set>
21 #include <chrono>
22 #include <iterator>
23 
24 namespace design {
25  namespace detail {
26  // map for storing all probability matrixes
27  typedef std::unordered_map< Graph*, ProbabilityMatrix> ProbabilityMatrixStorage;
28 
29  // actual dependency graph
30  template <typename R>
31  class DependencyGraph {
32  public:
33  DependencyGraph(std::vector<std::string> structures, std::string constraints, R rand);
34  std::string get_graphml();
35  std::string get_graphml(int connected_component_ID);
36  bool is_bipartite() {
37  return bipartite;
38  }
39  SolutionSizeType number_of_sequences();
40  SolutionSizeType number_of_sequences(int connected_component_ID);
41  int number_of_connected_components();
42  std::vector< int > component_vertices(int connected_component_ID);
43  std::vector< int > articulation_vertices();
44  std::vector< int > articulation_vertices(int connected_component_ID);
45  unsigned long set_seed(int seed) {
46  rand.seed(seed);
47  return seed;
48  }
49  unsigned long set_seed();
50  unsigned int max_number_of_dimensions() {
51  return max_dimensions;
52  }
53  Sequence get_sequence();
54  std::string get_sequence_string();
55  SolutionSizeType set_sequence(Sequence sequence);
56  SolutionSizeType set_sequence_string(std::string seq_str);
57  SolutionSizeType sample();
58  // call this function to sample a random subgraph (either a path, if graph_type=-1 or a connected component, if graph_type=1)
59  SolutionSizeType sample_local_global(int graph_type, int min_num_pos, int max_num_pos);
60  SolutionSizeType sample_clocal(int connected_component_ID);
61  SolutionSizeType sample(int position);
62  SolutionSizeType sample(int start, int end);
63  void set_history_size(unsigned int size);
64  bool revert_sequence(unsigned int jump);
65  std::vector< std::string > get_history();
66  private:
67  Graph graph;
68  ProbabilityMatrixStorage pms;
69  bool bipartite; // if dependency graph is bipartite and a therefore a solution exists
70  R rand;
71  std::list<Sequence> history;
72  unsigned int history_size;
73  // remember maximal dimension count for complexity measure
74  unsigned int max_dimensions = 0;
75  void remember_sequence();
76  void calculate_probabilities(Graph& g, std::chrono::steady_clock::time_point& start_time);
77  ProbabilityFraction sample_sequence(Graph& g);
78  void reset_colors(Graph& g);
79  SolutionSizeType sample(Graph& g);
80  Graph* find_path_subgraph(Vertex v_global, Graph& g);
81  // this function fills the subgraphs set with all the sugraphs of the given type (root, cc, bc, path)
82  // if int type= -1, then it returns all subgraphs which are actual paths (gp.is_path == true).
83  // you can specify also a minimal and maximal size of the subgraph
84  void get_subgraphs(Graph& g, std::unordered_set< Graph* >& subgraphs, int type, unsigned int min_size, unsigned int max_size);
85  std::string sequence_to_string(Sequence sequence);
86  };
87 
88 
89  inline void check_timeout(std::chrono::steady_clock::time_point& start_time) {
90  if (*construction_timeout_ptr != 0) {
91  std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start_time);
92  if (time_span.count() > *construction_timeout_ptr) {
93  std::stringstream ss;
94  ss << "Timeout: Construction of the dependency graph took longer than expected!" << std::endl <<
95  "Stopped after " << time_span.count() << " seconds (Timeout: " << *construction_timeout_ptr << " seconds)" << std::endl;
96  throw std::overflow_error( ss.str() );
97  }
98  }
99  }
100  }
101 }
102 #endif /* DEPENDENCY_GRAPH_H */
103 
104 
105 /*
106  * \endcond INTERNAL
107  */
This file holds all global includes, definitions and variables.
This file holds all important information for the dependency graph, its definition and often used fun...
All classes and functions for the RNA design library are under the design namespace.
Definition: RNAblueprint.h:101
This file holds the functions to sample a sequence for a certain path.
This file holds the class definitions for the Probability Matrix.