Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
phylo_typedefs.hpp
1 
2 #ifndef PHYLO_TYPEDEFS_HPP
3 #define PHYLO_TYPEDEFS_HPP
4 
5 
6 #include "utils.hpp"
7 #include "graph_typedefs.hpp"
8 
9 using namespace boost;
10 
11 namespace phylo{
12 
13  class PhyloNet{
14  public:
15  typedef adjacency_list<hash_setS,
16  listS,
17  bidirectionalS,
18  property<vertex_index_t, size_t,
19  property<vertex_name_t, std::string>
20  >,
21  no_property
22  > InternalNet;
23 
24  InternalNet net;
25 
26 
27  typedef Vertex<InternalNet> InternVertex;
28  typedef VertexPair<InternalNet> InternVertexPair;
29  typedef VertexSet<InternalNet> InternVertexSet;
30  typedef VertexList<InternalNet> InternVertexList;
31  typedef Edge<InternalNet> Arc;
32  typedef boost::graph_traits<InternalNet>::out_edge_iterator OutEdgeIter;
33  typedef std::pair<OutEdgeIter, OutEdgeIter> OutEdgeIterRange;
34  typedef boost::graph_traits<InternalNet>::in_edge_iterator InEdgeIter;
35  typedef std::pair<InEdgeIter, InEdgeIter> InEdgeIterRange;
36  protected:
37  Vertex<InternalNet> root;
38  public:
39 
40  // =======================
41  // querying
42  // =======================
43 
44  const InternVertex& get_root() const
45  {
46  return root;
47  }
48 
49  InternVertexList get_leaves() const{
50  InternVertexList result;
51  for(VertexIterRange<InternalNet> v = boost::vertices(net); v.first != v.second; ++v.first)
52  if(boost::out_degree(*v.first, net) == 0)
53  result.push_back(*v.first);
54  return result;
55  }
56 
57  std::string get_name(const InternVertex& v) const{
58  return boost::get(vertex_name, net, v);
59  }
60 
61  InternVertexList get_parents(const InternVertex& u) const{
62  InternVertexList result;
63  for(InEdgeIterRange e = boost::in_edges(u, net); e.first != e.second; ++e.first)
64  result.push_back(boost::source(*e.first, net));
65  return result;
66  }
67 
68  size_t num_vertices() const{
69  return boost::num_vertices(net);
70  }
71  size_t num_edges() const{
72  return boost::num_edges(net);
73  }
74 
75  const InternalNet get_network() const{
76  return net;
77  }
78  // ==========================
79  // setting
80  // ==========================
81 
82  const InternVertex& set_root(const size_t idx = 0)
83  {
84  //assert(num_vertices() == 0);
85  // add the root
86  root = boost::add_vertex(net);
87  // put its index
88  put(vertex_index, net, root, idx);
89  return root;
90  }
91 
92  const InternVertex& add_vertex(const InternVertex& parent, const size_t idx = 0, const std::string& name = "")
93  {
94  const InternVertex& v = boost::add_vertex(net);
95  boost::put(vertex_index, net, v, idx ? idx : num_vertices());
96  boost::put(vertex_name, net, v, name != "" ? name : std::to_string(idx));
97  boost::add_edge(parent, v, net);
98  return v;
99  }
100 
101  const InternVertex& add_vertex(const std::list<InternVertex>& parents, const size_t idx = 0, const std::string& name = "")
102  {
103  const InternVertex& v = boost::add_vertex(net);
104  boost::put(vertex_index, net, v, idx ? idx : num_vertices());
105  boost::put(vertex_name, net, v, name != "" ? name : std::to_string(idx));
106  for(const InternVertex& p : parents)
107  boost::add_edge(p, v, net);
108  return v;
109  }
110 
111  void make_leaf(const InternVertex& v, const std::string& name){
112  boost::put(vertex_name, net, v, name);
113  }
114 
115  void add_arc(const InternVertexPair& e){
116  boost::add_edge(e.first, e.second, net);
117  }
118  void add_arc(const InternVertex& u, const InternVertex& v){
119  boost::add_edge(u, v, net);
120  }
121 
122  void delete_vertex(const InternVertex& v){
123  boost::clear_vertex(v, net);
124  boost::remove_vertex(v, net);
125  }
126 
127 
128 
129  };
130 
131 } // namespace
132 
133 
134 #endif
Definition: graph_utils.hpp:18
Definition: phylo_typedefs.hpp:13
Definition: read_phytree.hpp:10