7 #include <boost/graph/graph_traits.hpp>
8 #include <boost/graph/graphviz.hpp>
10 #include "utils/graph_typedefs.hpp"
11 #include "utils/scaffolding_typedefs.hpp"
16 #warning TODO: find a better way to read sequence orientations! Currently, we just take the vertex whose name is "smaller"
18 void derive_sequence_orientations_from_vertex_names(
const ScaffoldGraph& sg, SequenceMap& sequences)
20 const RawScaffoldGraph& g = sg.get_graph();
21 for(
auto range = boost::vertices(g); range.first != range.second; ++range.first){
22 const ScafVertex& u = *range.first;
23 const ScafEdge uv = sg.incident_matching_edge(u);
24 const ScafVertex& v = boost::target(uv, g);
25 const VertexName& u_name = sg[u].name;
26 const VertexName& v_name = sg[v].name;
27 const std::string& contig_name = sg[uv].contig_name;
28 std::string& start_vertex = sequences[contig_name].start_vertex;
29 if(start_vertex.empty()){
32 const int u_num = std::stoi(u_name);
33 const int v_num = std::stoi(v_name);
34 start_vertex = (u_num < v_num) ? u_name : v_name;
35 }
catch(std::exception e){
37 start_vertex = (u_name < v_name) ? u_name : v_name;
44 Instance* read_dot(std::istream& in,
45 const unsigned number_paths,
46 const unsigned number_cycles,
47 const unsigned number_objects,
48 SequenceMap& sequences)
50 RawScaffoldGraph* g =
new RawScaffoldGraph();
51 boost::dynamic_properties dp(boost::ignore_other_properties);
53 dp.property(
"node_id", boost::get(&ScafVertexProperty::index, *g));
54 dp.property(
"label", boost::get(&ScafVertexProperty::name, *g));
56 dp.property(
"label", boost::get(&ScafEdgeProperty::weight, *g));
57 dp.property(
"length", boost::get(&ScafEdgeProperty::length, *g));
58 dp.property(
"meandist", boost::get(&ScafEdgeProperty::length, *g));
59 dp.property(
"cname", boost::get(&ScafEdgeProperty::contig_name, *g));
60 dp.property(
"mult", boost::get(&ScafEdgeProperty::multiplicity, *g));
62 typedef boost::unordered_map<RawScaffoldGraph*, unsigned> GraphIntMap;
63 GraphIntMap insert_size_map, sd_map;
64 boost::associative_property_map<GraphIntMap> insert_size_map_wrapper(insert_size_map);
65 boost::associative_property_map<GraphIntMap> sd_map_wrapper(sd_map);
66 dp.property(
"insert_size", insert_size_map_wrapper);
67 dp.property(
"sd", sd_map_wrapper);
71 if(boost::read_graphviz(in, *g, dp)){
73 (*g)[graph_bundle].insert_size = insert_size_map.at(g);
74 (*g)[graph_bundle].standard_deviation = sd_map.at(g);
76 setup_vertex_names(*g);
77 Instance* outI =
new Instance(g, number_paths, number_cycles, number_objects);
79 fix_non_matching_multiplicities(*outI);
81 derive_sequence_orientations_from_vertex_names(*outI, sequences);
82 DEBUG3(std::cout <<
"read instance: "; outI->print_statistics(); std::cout << std::endl);
85 DEBUG3(std::cout <<
"error parsing graphviz file!" << std::endl);
89 }
catch(boost::bad_parallel_edge ex){
90 std::cout <<
"Parallel-edge exception: "<< ex.what() <<std::endl;
93 }
catch(boost::directed_graph_error ex){
94 std::cout <<
"Directed graph exception: "<< ex.what() <<std::endl;
97 }
catch(boost::undirected_graph_error ex){
98 std::cout <<
"Undirected graph exception: "<<ex.what() <<std::endl;
101 }
catch(boost::bad_graphviz_syntax ex){
102 std::cout <<
"Syntax error: "<< ex.what() <<std::endl;
Definition: read_adj_list.hpp:22
Definition: read_phytree.hpp:10