#ifndef ASSEMBLE_H #define ASSEMBLE_H 1 #include "Common/ContigNode.h" // for ContigIndexMap #include "Common/Iterator.h" // for output_iterator_traits #include "Graph/DepthFirstSearch.h" using boost::graph_traits; /** Return true if this edge is contiguous. */ template bool isContiguous(const Graph &g, typename graph_traits::edge_descriptor e) { return out_degree(source(e, g), g) == 1 && in_degree(target(e, g), g) == 1; } /** Assemble contigous paths. Write the paths to out. */ template class AssembleVisitor : public boost::default_dfs_visitor { public: AssembleVisitor(OutIt it) : m_it(it) { } template void discover_vertex(const Vertex& u, Graph&) { m_path.push_back(u); } template void finish_vertex(const Vertex&, Graph&) { finishContig(); } template void examine_edge(const Edge& e, const Graph& g) { if (!isContiguous(g, e)) finishContig(); } private: void finishContig() { if (m_path.size() > 1) *m_it++ = m_path; m_path.clear(); } OutIt m_it; typename output_iterator_traits::value_type m_path; }; /** Assemble unambiguous paths. Write the paths to out. */ template void assembleDFS(const Graph& g, OutIt out, bool ss = false) { (void)ss; typedef boost::vector_property_map< boost::default_color_type, ContigIndexMap> ColorMap; depthFirstSearch(g, AssembleVisitor(out), ColorMap(num_vertices(g) / 2), ss); } #endif