Skip to content

Commit 4fc82c6

Browse files
committed
new --unmapped option in sambamba view
1 parent d899d5d commit 4fc82c6

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

main.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import sambamba.utils.common.ldc_gc_workaround;
3030
import std.stdio;
3131

3232
void printUsage() {
33-
stderr.writeln("sambamba v0.4.1");
33+
stderr.writeln("sambamba v0.4.2");
3434
stderr.writeln();
3535
stderr.writeln("Usage: sambamba [command] [args...]");
3636
stderr.writeln();

sambamba/view.d

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void printUsage() {
5959
stderr.writeln(" output to stdout only reference names and lengths in JSON");
6060
stderr.writeln(" -c, --count");
6161
stderr.writeln(" output to stdout only count of matching records, hHI are ignored");
62+
stderr.writeln(" -U, --unmapped");
63+
stderr.writeln(" output reads with RNAME = *; available for indexed BAM only");
6264
stderr.writeln(" -v, --valid");
6365
stderr.writeln(" output only valid alignments");
6466
stderr.writeln(" -S, --sam-input");
@@ -105,6 +107,7 @@ bool with_header;
105107
bool header_only;
106108
bool reference_info_only;
107109
bool count_only;
110+
bool unmapped_only;
108111
bool skip_invalid_alignments;
109112
bool is_sam;
110113

@@ -137,6 +140,7 @@ int view_main(string[] args) {
137140
"header|H", &header_only,
138141
"reference-info|I", &reference_info_only,
139142
"count|c", &count_only,
143+
"unmapped|U", &unmapped_only,
140144
"valid|v", &skip_invalid_alignments,
141145
"sam-input|S", &is_sam,
142146
"show-progress|p", &show_progress,
@@ -198,6 +202,18 @@ int sambambaMain(T)(T _bam, TaskPool pool, string[] args)
198202
return 0;
199203
}
200204

205+
static if (is(T == SamReader)) {
206+
if (unmapped_only) {
207+
stderr.writeln("--unmapped option is available only for indexed BAMs");
208+
return -1;
209+
}
210+
}
211+
212+
if (unmapped_only && args.length > 2) {
213+
stderr.writeln("--unmapped option can't be used together with regions");
214+
return -1;
215+
}
216+
201217
if (header_only && !count_only) {
202218
// write header to stdout
203219
(new HeaderSerializer(stdout, format)).writeln(bam.header);
@@ -255,7 +271,10 @@ int sambambaMain(T)(T _bam, TaskPool pool, string[] args)
255271
runProcessor(bam, reads, read_filter);
256272
bar.finish();
257273
} else {
258-
runProcessor(bam, bam.reads!withoutOffsets(), read_filter);
274+
if (unmapped_only)
275+
runProcessor(bam, bam.unmappedReads(), read_filter);
276+
else
277+
runProcessor(bam, bam.reads!withoutOffsets(), read_filter);
259278
}
260279
} else { // SamFile
261280
runProcessor(bam, bam.reads, read_filter);

0 commit comments

Comments
 (0)