Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
phylo_utils.hpp
1 
2 
3 #ifndef PHYLO_UTILS_HPP
4 #define PHYLO_UTILS_HPP
5 
6 
7 #include "phylo_typedefs.hpp"
8 
9 using namespace boost;
10 
11 namespace phylo{
12 
13 
14  // merge each pair of leaves with the same name
15  void merge_leaves_by_name(PhyloNet& N){
16  typedef typename boost::unordered_map<std::string, PhyloNet::InternVertex> Name_to_Vertex_Map;
17  Name_to_Vertex_Map name_to_vertex;
18 
19  // step 0: get the leaves of N
20  PhyloNet::InternVertexList leaves = N.get_leaves();
21  // step 1: go through the leaves, constructing name_to_vertex & merging leaves
22  for(const auto& l : leaves){
23  const std::string lname = N.get_name(l);
24  // step 1a: see if a leaf with this name is already in the map
25  Name_to_Vertex_Map::const_iterator i = name_to_vertex.find(lname);
26  if(i == name_to_vertex.end()){
27  // if no, add the leaf (with hint)
28  name_to_vertex.insert(i, Name_to_Vertex_Map::value_type(lname, l));
29  } else {
30  // otherwise, merge the leaves
31  const PhyloNet::InternVertex cur_l = i->second;
32  PhyloNet::InternVertex parent = *(N.get_parents(l).begin());
33  N.delete_vertex(l);
34  N.add_arc(parent, cur_l);
35  }
36  }
37  }
38 
39 } // namespace
40 
41 #endif
42 
43 
Definition: graph_utils.hpp:18
Definition: read_phytree.hpp:10