Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
write_dimacs_graph.hpp
1 /*
2  Reads coloring problem in DIMACS format.
3  This works, but could use some polishing.
4 */
5 
6 /* ----------------------------------------------------------------- */
7 
8 #ifndef BOOST_GRAPH_WRITE_DIMACS_GRAPH_HPP
9 #define BOOST_GRAPH_WRITE_DIMACS_GRAPH_HPP
10 
11 #include <iostream>
12 
13 #include "utils/graph_typedefs.hpp"
14 #include "utils/instance.hpp"
15 
16 
17 namespace scaffold { namespace io {
18 
19 
20  // write the graph g to the outstream "out"
21  void write_dimacs_graph(std::ostream& out, const Instance& I){
22  // write p line
23  const RawScaffoldGraph& g = I.get_graph();
24  out << "p edge "<<boost::num_vertices(g)<<" "<<boost::num_edges(g)<<std::endl;
25 
26  // write e lines. To this end, iterate over all vertices & print their adjacent vertices one by one
27  for(ScafVIterRange ur = boost::vertices(g); ur.first != ur.second; ++ur.first){
28  const ScafVertex& u = *ur.first;
29  const size_t u_idx = g[u].index;
30  for(ScafAdjIterRange vr = boost::adjacent_vertices(u, g); vr.first != vr.second; ++vr.first){
31  // only output edges from smaller to larger index
32  const ScafVertex& v = *vr.first;
33  const size_t v_idx = g[v].index;
34  if(v_idx < u_idx){
35  // remember to shift the vertex index by one, since boost starts with 0 and DIMACS starts with 1
36  out << "e "<<v_idx + 1<<" "<<u_idx+1<<std::endl;
37  }
38  } // for
39  }
40  } // function
41 }} // namespace
42 
43 #endif
Definition: read_adj_list.hpp:22
Definition: read_phytree.hpp:10