fetch fully unaligned pairs and pairs with one unaligned read with samtools view
1
0
Entering edit mode
9.6 years ago

How do I fetch fully unaligned pairs and pairs with one unaligned read with samtools view?

samtools bam • 2.1k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

or with 2 commands if need be

ADD REPLY
0
Entering edit mode

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"

ADD REPLY
0
Entering edit mode
9.6 years ago

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.

ADD COMMENT

Login before adding your answer.

Traffic: 2487 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6