Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
pp_pendant_match.hpp
1 /*
2  * preprocess a given graph using the pendant matching rule
3 */
4 
5 /* ----------------------------------------------------------------- */
6 
7 #ifndef PP_PENDANT_MATCH_HPP
8 #define PP_PENDANT_MATCH_HPP
9 
10 #include <list>
11 #include <vector>
12 
13 #include "utils/graph_typedefs.hpp"
14 #include "utils/instance.hpp"
15 
16 using namespace boost;
17 
19  //enum{ num = 555 };
20  size_t num;
21  typedef edge_property_tag kind;
22 } edge_component;
23 
24 
25 namespace scaffold{
26  namespace preprocess {
27 
28  // apply the pendant matching rule to a degree-2 vertex u (with non-matching partner w)
29  // return true <=> edges were deleted from g
30  bool pp_matching_pendant(Instance& I, const ScafVertex& u, const ScafVertex& w, Solution<>* S = NULL){
31  bool change = false;
32  const RawScaffoldGraph& g = I.get_graph();
33  assert(boost::degree(u, g) == 2);
34  assert(I.get_matching().at(u) != w);
35 
36  // Step 1: get edges ux incident with u such that x != v and keep track of the heaviest edge uy with deg(y)=2
37  double max_weight = 0.0;
38  ScafOEdgeIter max_edge;
39  for(ScafOEdgeIterRange r = boost::out_edges(w, g); r.first != r.second; ++r.first){
40  const ScafEdge& uv = *r.first;
41  const ScafVertex& v = boost::target(uv, g);
42  if((v != w) && (boost::degree(w, g) == 2)){
43  const unsigned weight = g[uv].weight;
44  if(weight > max_weight) {
45  max_weight = weight;
46  max_edge = r.first;
47  }// if
48  }// if
49  }// for
50  const ScafVertex& max_vertex = boost::target(*max_edge, g);
51 
52  // Step 2: delete all edges ux with weight at most w(uy) such that x != y (unless no vertex y with deg-2 was found!)
53  if(max_weight != 0.0){
54  //std::cout << "largest weight at "<<*uy<<": "<<max_weight<<std::endl;
55  for(ScafOEdgeIterRange r = boost::out_edges(w, g); r.first != r.second;){
56  const ScafEdge& ux = *r.first;
57  const ScafVertex& x = boost::target(ux, g);
58 
59  if(x != max_vertex){
60  const unsigned weight = g[ux].weight;
61  if(weight <= max_weight){
62  // remove *ei (avoid invalidating ei by copying to tmp, advancing tmp and then deleting the edge)
63  DEBUG3(std::cout << "PP: removing "<<I.get_edge_name(ux)<<" of weight "<< g[ux].weight<<std::endl);
64  ScafOEdgeIter tmp = r.first; ++r.first;
65  I.delete_edge(*tmp, S);
66  change = true;
67  } else ++r.first;
68  } else ++r.first;
69  }// for
70  } // else std::cout << "no vertex of deg 2 adjacent to " <<u << std::endl;
71  return change;
72  } // function
73 
74  // preprocess g
75  // return true <=> edges were deleted from g
76  // NOTE: requires edge indices to be set up before
77  bool pp_matching_pendant(Instance& I, Solution<>* S = NULL){
78  const RawScaffoldGraph& g = I.get_graph();
79  const ScafMatching& matching = I.get_matching();
80  bool change = false;
81 
82  // Step 1: apply the edge version to each non-matching edge uw with deg(u)==2 and uw is not on an alternating cycle
83  for(ScafVIterRange r = boost::vertices(g); r.first != r.second; ++r.first) if(boost::degree(*r.first, g) == 2){
84  // Step 1a: find the unique non-matching partner w of u
85  const ScafVertex& u = *r.first;
86  const ScafAdjIter tmp = boost::adjacent_vertices(u, g).first;
87  const ScafVertex w = (matching.at(u) == *tmp) ? *std::next(tmp) : *tmp;
88  DEBUG3(std::cout << "investigating "<<g[u].name<<" unmatched with "<< g[w].name<<std::endl);
89 
90  // Step 1b: find out whether uw is on an alternating cycle
91  const bool apply_reduction = !I.is_on_alternating_cycle(u, w);
92  DEBUG3(std::cout << "found that ("<<g[u].name<<", "<<g[w].name<<") is "<< (apply_reduction?"not":" ")<<" on an alteranting cycle (or we're not looking for any cycles)"<<std::endl);
93 
94  // Step 1c: apply pp_matching_pendant to uw if it's a bridge
95  if(apply_reduction)
96  if(pp_matching_pendant(I, u, w, S))
97  change = true;
98  } // for
99  return change;
100  } // function
101  } // namespace
102 } // namespace
103 
104 #endif
Definition: graph_utils.hpp:18
Definition: read_adj_list.hpp:22
Definition: pp_pendant_match.hpp:18
bool preprocess
bool indicating whether to run preprocessing or not (currently defunct)
Definition: command_line.hpp:41