diff --git a/src/main.cpp b/src/main.cpp index b3d47e7..1718279 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -216,6 +216,7 @@ int main(int argc, char **argv) { size_t n_poa_threads = num_poa_threads ? args::get(num_poa_threads) : n_threads; std::string smoothed_out_gfa = args::get(smoothed_out); + std::filesystem::path smoothed_out_gfa_path = smoothed_out_gfa; std::vector consensus_path_names; std::vector consensus_specs; bool requires_consensus = !args::get(vanish_consensus); @@ -1024,13 +1025,13 @@ int main(int argc, char **argv) { std::string path_smoothed_gfa; if (current_iter < num_iterations - 1) { consensus_path_names.clear(); // We need this only at the last iteration - const std::string patent_dir = args::get(tmp_base).empty() ? + const std::string parent_dir = args::get(tmp_base).empty() ? filesystem::path(path_input_gfa).parent_path().string() : args::get(tmp_base); - if (patent_dir == "") { - path_smoothed_gfa = prefix + ".smooth." + std::to_string(current_iter) + ".gfa"; + if (parent_dir == "") { + path_smoothed_gfa = prefix + ".smooth." + std::to_string(current_iter) + ".og"; } else { - path_smoothed_gfa = patent_dir + "/" + prefix + ".smooth." + std::to_string(current_iter) + ".gfa"; + path_smoothed_gfa = parent_dir + "/" + prefix + ".smooth." + std::to_string(current_iter) + ".og"; } } else { path_smoothed_gfa = smoothed_out_gfa; @@ -1038,7 +1039,13 @@ int main(int argc, char **argv) { std::cerr << smoothxg_iter << "::main] writing smoothed graph to " << path_smoothed_gfa << std::endl; ofstream out(path_smoothed_gfa.c_str()); - smoothed->to_gfa(out); + // can write to gfa on the final iteration + if (current_iter == num_iterations - 1 && smoothed_out_gfa_path.extension() == ".gfa") { + smoothed->to_gfa(out); + } + else { + smoothed->serialize(out); + } out.close(); delete smoothed; diff --git a/src/prep.cpp b/src/prep.cpp index 7992d8e..14bb918 100644 --- a/src/prep.cpp +++ b/src/prep.cpp @@ -1,4 +1,5 @@ #include "prep.hpp" +#include namespace smoothxg { @@ -19,7 +20,17 @@ void prep( // load it into an odgi odgi::graph_t graph; - odgi::gfa_to_handle(gfa_in, &graph, true, num_threads, true); + + std::filesystem::path graph_path = gfa_in; + std::cerr << smoothxg_iter << "::prep] Loading graph for prep " << gfa_in << std::endl; + + if (graph_path.extension() == ".gfa") { + odgi::gfa_to_handle(gfa_in, &graph, true, num_threads, true); + } else { + ifstream f(gfa_in.c_str()); + graph.deserialize(f); + f.close(); + } graph.set_number_of_threads(num_threads); // sort it using a short sorting pipeline equivalent to `odgi sort -p Ygs` @@ -144,10 +155,15 @@ void prep( odgi::algorithms::chop(graph, max_node_length, num_threads, true); std::cerr << smoothxg_iter << "::prep] writing graph " << gfa_out << std::endl; + + graph_path = gfa_out; std::ofstream f(gfa_out); - graph.to_gfa(f); + if (graph_path.extension() == ".gfa") { + graph.to_gfa(f); + } else { + graph.serialize(f); + } f.close(); - } }