Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
ambigous_paths.hpp
Go to the documentation of this file.
1 
19 #ifndef AMBIGOUS_PATHS_HPP
20 #define AMBIGOUS_PATHS_HPP
21 
22 #include "utils/scaffolding_typedefs.hpp"
23 #include "utils/predicates.hpp"
24 
25 namespace scaffold{
26 
28 
29  bool maybe_ambigous_path_extremity_local(const ScafVertex& u, const ScaffoldGraph& sg)
30  {
31  const unsigned deg = sg.degree(u);
32  if(deg > 2) return true;
33  if(deg == 1) return false;
34 
35  auto inc_iter = sg.get_incident(u);
36  assert(inc_iter.is_valid());
37  const unsigned mult = sg[*inc_iter].multiplicity;
38  ++inc_iter;
39  assert(inc_iter.is_valid());
40  return (mult != sg[*inc_iter].multiplicity);
41  }
42 
44  std::pair<ScafVertex,bool> is_ambigous_path_extremity(const ScafVertex& _u, const ScaffoldGraph& sg)
45  {
46  ScafVertex u(_u);
47  DEBUG5(std::cout << "checking "<<sg[u].name<<" for being endpoint of an ambigous path"<<std::endl);
48  if(maybe_ambigous_path_extremity_local(u, sg)){
49  const RawScaffoldGraph& g = sg.get_graph();
50 
51  do{
52  DEBUG5(std::cout << "mark1"<<std::endl);
53  const ScafEdge uv = sg.incident_matching_edge(u);
54  const ScafVertex& v = boost::target(uv, g);
55  const unsigned multi = sg[uv].multiplicity;
56  DEBUG5(std::cout << "mark2"<<std::endl);
57  // do the easy checks:
58  // v has >1 non-matching edge? We have an ambigous path!
59  // v has no non-matching edges? The path is not ambigous!
60  if(sg.degree(v) > 2) return std::pair<ScafVertex, bool>(v, true);
61  if(sg.degree(v) == 1) return std::pair<ScafVertex, bool>(v, false);
62 
63  // get the unique non-matching edge incident to v
64  auto inc_iter = sg.get_incident(v);
65  if(sg[*inc_iter].is_matching_edge()) ++inc_iter;
66  DEBUG5(std::cout << "mark3"<<std::endl);
67  // check its multiplicity
68  if(sg[*inc_iter].multiplicity != multi) return std::pair<ScafVertex, bool>(v, true);
69  // advance along the possible ambigous path
70  u = boost::target(*inc_iter, g);
71  } while(true);
72  } else return std::pair<ScafVertex, bool>(u, false);
73  }
74 
76 
77  void kill_ambigous_paths_brutal(ScaffoldGraph& sg)
78  {
79  const RawScaffoldGraph& g = sg.get_graph();
80  for(auto v_range = boost::vertices(g); v_range.first != v_range.second; ++v_range.first){
81  const ScafVertex& u = *v_range.first;
82  // if u is extremity of an ambigous path, kill its non-matching edges
83  const std::pair<ScafVertex,bool> result = is_ambigous_path_extremity(u, sg);
84  if(result.second){
85  DEBUG5(std::cout << "found ambigous path "<<g[u].name<<"-->"<<g[result.first].name<<std::endl;)
86  // delete all non-matching edges incident with u
87  auto inc_iter = sg.get_incident(u, MatchingPredicate<RawScaffoldGraph>(g, true));
88  while(inc_iter.is_valid()) sg.delete_edge(*(inc_iter++));
89  }
90  }
91  }
92 
93 
94 }//namespace
95 
96 #endif
97 
Definition: read_adj_list.hpp:22