Entering edit mode
10.2 years ago
14134125465346445
★
3.6k
How do I fetch fully unaligned pairs and pairs with one unaligned read with samtools view?
How do I fetch fully unaligned pairs and pairs with one unaligned read with samtools view?
Cheating by using process substitution:
samtools cat -o output.bam <(samtools view -uf 12 input.bam) <(samtools view -uf 4 -F 8 input.bam) <(samtools view -uf 8 -F 4 input.bam)
Edit: Changed things to not compress, which should make things a bit faster.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
With a only a single command? That's not actually possible with the base samtools. You can do this with pysam (and probably Pierre's jvarkit), though.
or with 2 commands if need be
It boils down to lack of support for OR-ing flags in samtools, so that the only way to accomplish what you ask is splitting the set into three and concatenating the results (as shown below by Devon). Given that unaligned reads are infrequent, this means it takes 3x more CPU time than the straightforward approach.
Other than pysam, you could use sambamba (I'm the author) with flags
-F "unmapped or mate_is_unmapped"