Anyone has a simple solution for filtering reads in a BAM/SAM file having a certain TAG? This came up trying to filter out reads from 10x without a proper CB tag defined (which is causing troubles in downstream analysis tools).
I'm surprised there is no built-in command in samtools
for doing this (I opened an issue here). There is the -d TAG:VALUE
argument to filter in reads having a specific tag value, but no command to simply filter reads having the tag TAG. I will keep grep-ing my way for the time being, but I wonder if I'm missing a more robust and still simple solution.
Thanks for mentioning sambamba and samsift, I will take a look.
Just an update from @jkbonfield comment, I was trying to filter my sample BAM using specific TAG values. Based on this issue on SAMtools Github I could filter using the
-e
or--expr
expression parameter. From the example:You can remove reads with specific TAG values using
[HD]!=2
and including the reads without it![HD]
In my case, I wanted to have only reads without
![vW]
and with[vW]==1