I am trying to use samtools (samtools 1.7Using htslib 1.7-2) to extract only reads that were mapped once and were not marked as duplicates by Picard.
As I understand
samtools view -F -"flag" excludes following flags from the bam file.
The flags I want to exlude are: flag 4 is unmapped, flag 256 is secondary alignment. So using flag 260 I am getting:
samtools view -F -260 $f | grep 'NH:i:1\b' | wc -l
I get 9104 reads (It is a single cell).
This includes only reads that have flag 0. (Although I was hoping to get also 16 which is on the reverse strand).
When I want to exclude also the duplicates (flag 1024 but also 1004?) I try using flag -1284 :
samtools view -F -1284 $f | grep 'NH:i:1\b' | wc -l
but then I get much more reads: 21411
When I look at the reads of the second option they give reads of flag 0 and flag 1024 (which I was hoping to exclude) and it doesn't contain flag 16 which I was hoping to include.
Could somebody explain me this result?
What is your way to get only primary, unique, non duplicate aligned reads?
Thanks in advance