Skip to content

Commit fef7b7f

Browse files
committed
auto-magically import GFAz when a user provides a graph
1 parent 4fac0c0 commit fef7b7f

5 files changed

Lines changed: 814 additions & 719 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ debug_main.cpp
5151
/*.fa
5252
/*.gfa
5353
.vscode/*
54+
.cache/*

src/algorithms/gfa_to_handle.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "gfa_to_handle.hpp"
2+
#include "gfaz_to_handle.hpp"
23
#include "../path.hpp"
4+
#include "../utility.hpp"
35

46
#include <gbwtgraph/utils.h>
57

@@ -325,19 +327,23 @@ static void add_path_listeners(GFAParser& parser, MutablePathMutableHandleGraph*
325327
}
326328

327329
void gfa_to_handle_graph(const string& filename, MutableHandleGraph* graph,
328-
GFAIDMapInfo* translation) {
330+
GFAIDMapInfo* translation, int num_threads) {
331+
if (filename != "-" && ends_with(filename, ".gfaz")) {
332+
gfaz_to_handle_graph(filename, graph, translation, num_threads);
333+
return;
334+
}
329335

330336
get_input_file(filename, [&](istream& in) {
331337
gfa_to_handle_graph(in, graph, translation);
332338
});
333339
}
334340

335341
void gfa_to_handle_graph(const string& filename, MutableHandleGraph* graph,
336-
const string& translation_filename) {
342+
const string& translation_filename, int num_threads) {
337343

338344

339345
GFAIDMapInfo id_map_info;
340-
gfa_to_handle_graph(filename, graph, &id_map_info);
346+
gfa_to_handle_graph(filename, graph, &id_map_info, num_threads);
341347
write_gfa_translation(id_map_info, translation_filename);
342348
}
343349

@@ -357,19 +363,23 @@ void gfa_to_handle_graph(istream& in, MutableHandleGraph* graph,
357363

358364
void gfa_to_path_handle_graph(const string& filename, MutablePathMutableHandleGraph* graph,
359365
GFAIDMapInfo* translation, int64_t max_rgfa_rank,
360-
unordered_set<PathSense>* ignore_sense) {
366+
unordered_set<PathSense>* ignore_sense, int num_threads) {
367+
if (filename != "-" && ends_with(filename, ".gfaz")) {
368+
gfaz_to_path_handle_graph(filename, graph, translation, max_rgfa_rank, ignore_sense, num_threads);
369+
return;
370+
}
361371

362372
get_input_file(filename, [&](istream& in) {
363-
gfa_to_path_handle_graph(in, graph, translation, max_rgfa_rank);
373+
gfa_to_path_handle_graph(in, graph, translation, max_rgfa_rank, ignore_sense);
364374
});
365375
}
366376

367377
void gfa_to_path_handle_graph(const string& filename, MutablePathMutableHandleGraph* graph,
368378
int64_t max_rgfa_rank, const string& translation_filename,
369-
unordered_set<PathSense>* ignore_sense) {
379+
unordered_set<PathSense>* ignore_sense, int num_threads) {
370380

371381
GFAIDMapInfo id_map_info;
372-
gfa_to_path_handle_graph(filename, graph, &id_map_info, max_rgfa_rank);
382+
gfa_to_path_handle_graph(filename, graph, &id_map_info, max_rgfa_rank, ignore_sense, num_threads);
373383
write_gfa_translation(id_map_info, translation_filename);
374384

375385
}

src/algorithms/gfa_to_handle.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,39 @@ struct GFAIDMapInfo : public NamedNodeBackTranslation {
6060
/// std::ios_base::failure if an IO operation fails. Throws invalid_argument if
6161
/// otherwise misused.
6262
/// Does not give max ID hints, and so might be very slow when loading into an ODGI graph.
63+
/// num_threads currently only affects GFAZ input, and is ignored for plain GFA.
6364
void gfa_to_handle_graph(const string& filename,
6465
MutableHandleGraph* graph,
65-
GFAIDMapInfo* translation = nullptr);
66+
GFAIDMapInfo* translation = nullptr,
67+
int num_threads = 0);
6668

6769
/// Overload which serializes its translation to a file internally.
6870
void gfa_to_handle_graph(const string& filename,
6971
MutableHandleGraph* graph,
70-
const string& translation_filename);
72+
const string& translation_filename,
73+
int num_threads = 0);
7174

7275
/// Load a GFA from a stream (assumed not to be seekable or reopenable) into a HandleGraph.
7376
void gfa_to_handle_graph(istream& in,
7477
MutableHandleGraph* graph,
7578
GFAIDMapInfo* translation = nullptr);
7679

7780
/// Same as gfa_to_handle_graph but also adds path elements from the GFA to the graph.
81+
/// num_threads currently only affects GFAZ input, and is ignored for plain GFA.
7882
void gfa_to_path_handle_graph(const string& filename,
7983
MutablePathMutableHandleGraph* graph,
8084
GFAIDMapInfo* translation = nullptr,
8185
int64_t max_rgfa_rank = numeric_limits<int64_t>::max(),
82-
unordered_set<PathSense>* ignore_sense = nullptr);
86+
unordered_set<PathSense>* ignore_sense = nullptr,
87+
int num_threads = 0);
8388

8489
/// Overload which serializes its translation to a file internally.
8590
void gfa_to_path_handle_graph(const string& filename,
8691
MutablePathMutableHandleGraph* graph,
8792
int64_t max_rgfa_rank,
8893
const string& translation_filename,
89-
unordered_set<PathSense>* ignore_sense = nullptr);
94+
unordered_set<PathSense>* ignore_sense = nullptr,
95+
int num_threads = 0);
9096

9197
/// Load a GFA from a stream (assumed not to be seekable or reopenable) into a PathHandleGraph.
9298
void gfa_to_path_handle_graph(istream& in,

src/algorithms/gfaz_to_handle.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ parse_reference_samples(const GfaGraph &gfaz_graph) {
205205
gbwtgraph::REFERENCE_SAMPLE_LIST_GFA_TAG.end(),
206206
tag.begin()) &&
207207
tag[2] == ':' && tag[3] == 'Z' && tag[4] == ':') {
208-
reference_samples = gbwtgraph::parse_reference_samples_tag(tag.substr(5));
208+
auto parsed_reference_samples =
209+
gbwtgraph::parse_reference_samples_tag(tag.substr(5));
210+
reference_samples.clear();
211+
reference_samples.insert(parsed_reference_samples.begin(),
212+
parsed_reference_samples.end());
209213
}
210214
start = end + 1;
211215
}

0 commit comments

Comments
 (0)