Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
convert.hpp
Go to the documentation of this file.
1 
7 #ifndef CONVERT_HPP
8 #define CONVERT_HPP
9 
10 #ifdef has_TOL
11 
12 #include <boost/bimap.hpp>
13 #include <boost/bimap/unordered_set_of.hpp>
14 
15 #include "TOL/Graph.h"
16 
17 #include "utils/utils.hpp"
18 #include "utils/graph_typedefs.hpp"
19 
20 namespace TOL{
21 
22  // a hasher for TOL Vertices
23  struct TOL_Vertex_Hash
24  {
25  size_t operator()(const TOL::Graph::Vertex& v) const {
26  return v.index();
27  }
28  };
29 
31  template<class Graph>
32  using VTranslateBoostTOL = boost::bimap< boost::bimaps::unordered_set_of<Vertex<Graph> >, boost::bimaps::unordered_set_of<TOL::Graph::Vertex, TOL_Vertex_Hash> >;
33 
35  template<class Graph>
36  void convert(const Graph& g, TOL::Graph& tg, VTranslateBoostTOL<Graph>* vtranslate = NULL)
37  {
38  typedef typename VTranslateBoostTOL<Graph>::value_type translate_pair;
39 
40  VTranslateBoostTOL<Graph>* vtrans = vtranslate ? vtranslate : new VTranslateBoostTOL<Graph>();
41  // make sure we can access vtranslate and it's empty
42  vtrans->clear();
43 
44  // Step 1: copy vertices
45  size_t index = 0;
46  for(VertexIterRange<Graph> r = vertices(g); r.first != r.second; ++r.first)
47  vtrans->insert(translate_pair((Vertex<Graph>)*r.first, (TOL::Graph::Vertex)tg.new_vertex(index++)));
48 
49  // Step 2: copy edges
50  for(EdgeIterRange<Graph> e = edges(g); e.first != e.second; ++e.first)
51  tg.new_edge(vtrans->left.at(source(*e.first, g)), vtrans->left.at(target(*e.first, g)));
52 
53  // clean up what we allocated
54  if(!vtranslate) delete vtrans;
55  }
56 
57 }
58 #endif // has_TOL
59 
60 #endif // CONVERT_HPP
61