@@ -185,5 +185,99 @@ TEST_CASE("Graph simplification reduces a graph with a self inverting -/+ loop",
185185 }
186186}
187187
188+ TEST_CASE (" Graph simplification reduces a graph with a self inverting -/+ loop with paths" , " [simplify]" ) {
189+ graph_t graph;
190+ handle_t n1 = graph.create_handle (" CAAATAAG" );
191+ handle_t n2 = graph.create_handle (" A" );
192+ handle_t n3 = graph.create_handle (" G" );
193+ handle_t n4 = graph.create_handle (" T" );
194+ handle_t n5 = graph.create_handle (" C" );
195+ handle_t n6 = graph.create_handle (" TTG" );
196+ graph.create_edge (n1, n2);
197+ graph.create_edge (n2, n3);
198+ graph.create_edge (graph.flip (n3), n3);
199+ graph.create_edge (n3, n4);
200+ graph.create_edge (n4, n5);
201+ graph.create_edge (n5, n6);
202+ path_handle_t p_x = graph.create_path_handle (" x" );
203+ path_handle_t p_y = graph.create_path_handle (" y" );
204+ for (auto & p : { p_x, p_y }) {
205+ for (auto & h : { n1, n2, n3, n4, n5, n6 }) {
206+ graph.append_step (p, h);
207+ }
208+ }
209+ path_handle_t q_y = graph.create_path_handle (" q" );
210+ for (auto & p : { q_y }) {
211+ for (auto & h : { n6, n5, n4, n3, n2, n1 }) {
212+ graph.append_step (p, graph.flip (h));
213+ }
214+ }
215+
216+ algorithms::unchop (graph);
217+
218+ uint64_t seen_steps = 0 ;
219+ for (auto & p : { p_x, p_y, q_y }) {
220+ step_handle_t begin = graph.path_begin (p);
221+ step_handle_t end = graph.path_end (p);
222+ for (step_handle_t step = begin;
223+ step != end;
224+ step = graph.get_next_step (step)) {
225+ handle_t h = graph.get_handle_of_step (step);
226+ ++seen_steps;
227+ }
228+ }
229+
230+ // sort the graph
231+ graph.apply_ordering (algorithms::topological_order (&graph), true );
232+
233+ // check that iteration still works
234+ uint64_t seen_steps_after_sort = 0 ;
235+ for (auto & p : { p_x, p_y, q_y }) {
236+ step_handle_t begin = graph.path_begin (p);
237+ step_handle_t end = graph.path_end (p);
238+ for (step_handle_t step = begin;
239+ step != end;
240+ step = graph.get_next_step (step)) {
241+ handle_t h = graph.get_handle_of_step (step);
242+ ++seen_steps_after_sort;
243+ }
244+ }
245+
246+ SECTION (" The graph is as expected" ) {
247+ REQUIRE (seen_steps == 6 );
248+ REQUIRE (seen_steps == seen_steps_after_sort);
249+ REQUIRE (graph.get_sequence (graph.get_handle (1 )) == " CAAATAAGA" );
250+ REQUIRE (graph.get_sequence (graph.get_handle (2 )) == " GTCTTG" );
251+ REQUIRE (graph.has_edge (graph.get_handle (1 ), graph.get_handle (2 )));
252+ REQUIRE (graph.has_edge (graph.flip (graph.get_handle (2 )), graph.get_handle (2 )));
253+ }
254+
255+ // sort the graph
256+ auto order = algorithms::topological_order (&graph);
257+ std::reverse (order.begin (), order.end ());
258+ graph.apply_ordering (order, true );
259+ // graph.optimize(); // breaks!!
260+
261+ // check that iteration still works
262+ uint64_t seen_steps_after_rev = 0 ;
263+ for (auto & p : { p_x, p_y, q_y }) {
264+ step_handle_t begin = graph.path_begin (p);
265+ step_handle_t end = graph.path_end (p);
266+ for (step_handle_t step = begin;
267+ step != end;
268+ step = graph.get_next_step (step)) {
269+ handle_t h = graph.get_handle_of_step (step);
270+ ++seen_steps_after_rev;
271+ }
272+ }
273+
274+ SECTION (" The graph is as expected after reverse sorting" ) {
275+ REQUIRE (seen_steps == seen_steps_after_rev);
276+ REQUIRE (graph.get_sequence (graph.get_handle (2 )) == " CAAATAAGA" );
277+ REQUIRE (graph.get_sequence (graph.get_handle (1 )) == " GTCTTG" );
278+ }
279+
280+ }
281+
188282}
189283}
0 commit comments