The SAM specification indicates that column two of each line is a bitwise FLAG. This integer value contains a wealth of information about the particular alignment, but it's not easy to decode just by looking at it.
At this page, you can enter an integer value that will tell you exactly what a particular flag means. You can also construct your own flag by checking the various boxes.
Using this flag in combination with the -F
parameter in samtools view
will Filter out any alignments which contain the parameters specified in the flag.
For example: to have samtools view
not show any alignment that's flagged as a duplicate AND has an unmapped mate, you would use the following command:
samtools view -F 1032 [your.bam]
Let's say you don't want to see any read 2s of a paired-end dataset:
samtools view -F 128 [your.bam]
One more for grins. Let's say you wanted to skip any reads that were part of a pair AND where both reads mapped properly as a pair AND where the properly-mapped pair is not the primary alignment for that read pair:
samtools view -F 259 [your.bam]