Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
alternating_path.hpp
Go to the documentation of this file.
1 
6 #ifndef ALTERNATING_PATH_HPP
7 #define ALTERNATING_PATH_HPP
8 
9 
10 #include <boost/graph/adjacency_list.hpp>
11 #include <boost/graph/max_cardinality_matching.hpp>
12 
13 #include "utils/utils.hpp"
14 #include "utils/graph_typedefs.hpp"
15 #include "utils/graph_utils.hpp"
16 
17 namespace scaffold{
18 
20 
30  template<class Graph>
31  bool edge_on_alternating_cycle(const Vertex<Graph>& u,
32  const Vertex<Graph>& v,
33  const Graph& g,
34  const Matching<Graph>& match)
35  {
36  Graph h;
37  // assert that g contains the edge uv
38  assert(boost::edge(u, v, g).second);
39  // assert that the matching is spanning g's vertices
40  assert(boost::num_vertices(g) == 2 * match.size());
41 
42  // step 1: copy g
43  Matching<Graph> translate;
44  boost::copy_graph(g, h, orig_to_copy(associative_property_map<Matching<Graph> >(translate)).vertex_index_map(boost::get(&Graph::vertex_bundled::index, g)));
45 
46  Vertex<Graph>& u_in_h = translate.at(u);
47  Vertex<Graph>& v_in_h = translate.at(v);
48  const Edge<Graph> uv_in_h = boost::edge(u_in_h, v_in_h, h).first;
49 
50  // translate the matching of g into a matching in h
51  Matching<Graph> match_in_h;
52  for(const VertexPair<Graph>& uv: match)
53  match_in_h.emplace(VertexPair<Graph>(translate.at(uv.first), translate.at(uv.second)));
54 
55  // step 2: delete the matching edge(s) incident with u & v in h
56  if(match_in_h.at(u_in_h) != v_in_h) {
57  // if uv is not a matching edge itself, delete the vertices u & v and search for an augmenting path in the rest
58  for(const Vertex<Graph>& x: {u_in_h, v_in_h}){
59  remove_matching_pair<Graph>(x, match_in_h);
60  boost::clear_vertex(x, h);
61  }
62  } else boost::remove_edge(uv_in_h, h);
63  // step 3: try to augment the matching of J
64  typedef typename boost::associative_property_map<Matching<Graph> > MateMap;
65  MateMap matching(match_in_h);
66  boost::edmonds_augmenting_path_finder<Graph, MateMap, VertexIndexMap<Graph> >
67  augmentor(h, matching, boost::get(&Graph::vertex_bundled::index, h));
68 
69  // step 4: return whether the matching is augmentable
70  return augmentor.augment_matching();
71  }
72 
73 
74 
75 }// namespace
76 
77 
78 #endif
79 
Definition: read_adj_list.hpp:22