Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
td_subgraph.hpp
1 
2 
3 #ifndef TD_SUBGRAPH_HPP
4 #define TD_SUBGRAPH_HPP
5 
6 #include "utils/filters.hpp"
7 
8 namespace scaffold{
9  using namespace filters;
10 
11  // a subgraph of edges introduced in a subtree of the Tree Decomposition
12  template<class Graph>
14  {
15  public:
18  typedef filtered_graph<Graph, E_Filter, V_Filter> Subgraph;
19  protected:
20  const Graph& super_g;
21  VertexSet<Graph> introduced_vertices;
22  VertexSet<Graph> forgotten_vertices;
23  EdgeSet<Graph> introduced_edges;
24  V_Filter vertex_filter;
25  E_Filter edge_filter;
26  Subgraph g;
27  public:
28  // constructor from a given host graph
29  TD_Subgraph(const Graph& _super_g):
30  super_g(_super_g),
31  introduced_vertices(),
32  forgotten_vertices(),
33  introduced_edges(default_buckets, _super_g),
34  vertex_filter(&introduced_vertices),
35  edge_filter(&introduced_edges),
36  g(Subgraph(super_g, edge_filter, vertex_filter))
37  {}
38  // destructor
39  ~TD_Subgraph() {}
40 
41  // introduce a vertex
42  void introduce_vertex(const Vertex<Graph>& v)
43  {
44  introduced_vertices.emplace(v);
45  }
46  // forget a vertex; note: forget edges whose both vertices have been forgotten!
47  void forget_vertex(const Vertex<Subgraph>& u)
48  {
49  // forget edges incident to v and a forgotten vertex
50  for(OEdgeIterRange<Subgraph> r = out_edges(u, g); r.first != r.second;){
51  const Vertex<Subgraph>& v = target(*r.first, g);
52  // see if v is forgotten
53  const auto i = forgotten_vertices.find(v);
54  if(i != forgotten_vertices.end()){
55  // if v is forgotten, then forget the edge uv, but advance r.first before
56  const OEdgeIter<Subgraph> e = r.first++;
57  introduced_edges.erase(*e);
58  // if the deletion of e isolated v in g, then delete v
59  if(degree(v, g) == 0) {
60  forgotten_vertices.erase(i);
61  introduced_vertices.erase(v);
62  }// if
63  } else ++r.first;
64  }// for
65  // if all edges of u are forgotten, delete u as well, otherwise mark it forgotten
66  if(degree(u, g) == 0) introduced_vertices.erase(u);
67  else forgotten_vertices.emplace(u);
68  }
69 
70  // introduce an edge
71  void introduce_edge(const Edge<Graph>& e)
72  {
73  introduced_edges.emplace(e);
74  }
75 
76  void join(const TD_Subgraph<Graph>& h)
77  {
78  for(const Vertex<Graph>& v : h.introduced_vertices)
79  if(!contains(introduced_vertices, v)) introduce_vertex(v);
80 
81  for(const Vertex<Graph>& v : h.forgotten_vertices)
82  forgotten_vertices.emplace(v);
83 
84  for(const Edge<Graph>& e : h.introduced_edges){
85  assert(!contains(introduced_edges, e));
86  introduce_edge(e);
87  }
88  }
89  };
90 
91 }//namespace
92 
93 #endif
94 
Definition: read_adj_list.hpp:22
filter to work with filtered graphs that is based on a set of vertices, passed to the constructor ...
Definition: filters.hpp:23
Definition: td_subgraph.hpp:13
bool contains(const Set &s, const Element &el)
a more readable containment check
Definition: utils.hpp:171