14
14
#include " ../alignment.hpp"
15
15
#include " ../vg.hpp"
16
16
#include " ../xg.hpp"
17
+ #include " ../hts_alignment_emitter.hpp"
17
18
#include < vg/io/stream.hpp>
18
19
#include < vg/io/vpkg.hpp>
19
20
#include < bdsg/overlays/overlay_helper.hpp>
@@ -23,10 +24,11 @@ using namespace vg;
23
24
using namespace vg ::subcommand;
24
25
25
26
void help_inject (char ** argv) {
26
- cerr << " usage: " << argv[0 ] << " inject [options] input.[bam|sam|cram] >output.gam" << endl
27
+ cerr << " usage: " << argv[0 ] << " inject -x graph.xg [options] input.[bam|sam|cram] >output.gam" << endl
27
28
<< endl
28
29
<< " options:" << endl
29
30
<< " -x, --xg-name FILE use this graph or xg index (required, non-XG formats also accepted)" << endl
31
+ << " -o, --output-format NAME output the alignments in NAME format (gam / gaf / json) [gam]" << endl
30
32
<< " -t, --threads N number of threads to use" << endl;
31
33
}
32
34
@@ -37,6 +39,8 @@ int main_inject(int argc, char** argv) {
37
39
}
38
40
39
41
string xg_name;
42
+ string output_format = " GAM" ;
43
+ std::set<std::string> output_formats = { " GAM" , " GAF" , " JSON" };
40
44
int threads = get_thread_count ();
41
45
42
46
int c;
@@ -46,12 +50,13 @@ int main_inject(int argc, char** argv) {
46
50
{
47
51
{" help" , no_argument, 0 , ' h' },
48
52
{" xg-name" , required_argument, 0 , ' x' },
53
+ {" output-format" , required_argument, 0 , ' o' },
49
54
{" threads" , required_argument, 0 , ' t' },
50
55
{0 , 0 , 0 , 0 }
51
56
};
52
57
53
58
int option_index = 0 ;
54
- c = getopt_long (argc, argv, " hx:t:" ,
59
+ c = getopt_long (argc, argv, " hx:o: t:" ,
55
60
long_options, &option_index);
56
61
57
62
// Detect the end of the options.
@@ -63,6 +68,19 @@ int main_inject(int argc, char** argv) {
63
68
case ' x' :
64
69
xg_name = optarg;
65
70
break ;
71
+
72
+ case ' o' :
73
+ {
74
+ output_format = optarg;
75
+ for (char & c : output_format) {
76
+ c = std::toupper (c);
77
+ }
78
+ if (output_formats.find (output_format) == output_formats.end ()) {
79
+ std::cerr << " error: [vg inject] Invalid output format: " << optarg << std::endl;
80
+ std::exit (1 );
81
+ }
82
+ }
83
+ break ;
66
84
67
85
case ' t' :
68
86
threads = parse<int >(optarg);
@@ -90,14 +108,14 @@ int main_inject(int argc, char** argv) {
90
108
}
91
109
unique_ptr<PathHandleGraph> path_handle_graph = vg::io::VPKG::load_one<PathHandleGraph>(xg_name);
92
110
bdsg::PathPositionOverlayHelper overlay_helper;
93
- PathPositionHandleGraph* xgidx = overlay_helper.apply (path_handle_graph.get ());
111
+ PathPositionHandleGraph* xgidx = overlay_helper.apply (path_handle_graph.get ());
94
112
95
- vg::io::ProtobufEmitter<Alignment> buf (cout);
96
- function< void (Alignment&)> lambda = [&buf](Alignment& aln) {
97
- # pragma omp critical (buf)
98
- {
99
- buf. write ( std::move ( aln));
100
- }
113
+ // We don't do HTS output formats but we do need an empty paths collection to make an alignment emitter
114
+ vector<tuple< path_handle_t , size_t , size_t >> paths;
115
+ unique_ptr<vg::io::AlignmentEmitter> alignment_emitter = get_alignment_emitter ( " - " , output_format, paths, threads, xgidx);
116
+
117
+ function< void (Alignment&)> lambda = [&](Alignment& aln) {
118
+ alignment_emitter-> emit_mapped_single ({ std::move (aln)});
101
119
};
102
120
if (threads > 1 ) {
103
121
hts_for_each_parallel (file_name, lambda, xgidx);
0 commit comments