Skip to content

Commit

Permalink
Merge pull request #361 from pangenome/step_index_xg_api
Browse files Browse the repository at this point in the history
We can go from an end step to its previous step
  • Loading branch information
subwaystation authored Jan 13, 2022
2 parents 0d7f950 + 246cf20 commit ebc493f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/odgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ step_handle_t graph_t::get_previous_step(const step_handle_t& step_handle) const
if (is_path_front_end(step_handle)) {
return step_handle;
} else if (is_path_end(step_handle)) {
curr_handle = get_handle_of_step(path_back(as_path_handle(as_integers(step_handle)[0])));
return path_back(as_path_handle(as_integers(step_handle)[0]));
// curr_handle = get_handle_of_step(path_back(as_path_handle(as_integers(step_handle)[0])));
} else {
curr_handle = get_handle_of_step(step_handle);
}
Expand Down
16 changes: 16 additions & 0 deletions src/unittest/stepindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ namespace odgi {
}
cur_step_rank++;
});
step_handle_t path_end = graph.path_end(path);
step_handle_t path_back_from_end = graph.get_previous_step(path_end);
REQUIRE(step_index_1.get_position(path_end, graph) == step_index_1.get_path_len(path));
REQUIRE(step_index_1.get_position(path_back_from_end, graph) == step_index_1.get_position(graph.path_back(path), graph));
}

if (cur_path == "query1") {
Expand All @@ -127,6 +131,10 @@ namespace odgi {
}
cur_step_rank++;
});
step_handle_t path_end = graph.path_end(path);
step_handle_t path_back_from_end = graph.get_previous_step(path_end);
REQUIRE(step_index_1.get_position(path_end, graph) == step_index_1.get_path_len(path));
REQUIRE(step_index_1.get_position(path_back_from_end, graph) == step_index_1.get_position(graph.path_back(path), graph));
}

if (cur_path == "query2") {
Expand All @@ -139,6 +147,10 @@ namespace odgi {
}
cur_step_rank++;
});
step_handle_t path_end = graph.path_end(path);
step_handle_t path_back_from_end = graph.get_previous_step(path_end);
REQUIRE(step_index_1.get_position(path_end, graph) == step_index_1.get_path_len(path));
REQUIRE(step_index_1.get_position(path_back_from_end, graph) == step_index_1.get_position(graph.path_back(path), graph));
}

if (cur_path == "query3") {
Expand Down Expand Up @@ -166,6 +178,10 @@ namespace odgi {
}
cur_step_rank++;
});
step_handle_t path_end = graph.path_end(path);
step_handle_t path_back_from_end = graph.get_previous_step(path_end);
REQUIRE(step_index_1.get_position(path_end, graph) == step_index_1.get_path_len(path));
REQUIRE(step_index_1.get_position(path_back_from_end, graph) == step_index_1.get_position(graph.path_back(path), graph));
}
});
}
Expand Down

0 comments on commit ebc493f

Please sign in to comment.