Extract properly paired reads from a BAM file using SamTools

For a few different types of sequence analysis I need to extract read pairs that are properly mapped and satisfy some map quality filter, but I always forget the command line. So here it is:

To read pairs from a bam file (-b) that map with mapQ≥30 including the bam file header (-h). The -f 0x2 option corresponds to the bitwise flags that specify that reads need to be properly paired. Proper pairing means reads are in Read1 forward, Read2 reverse orientation or Read1 reverse, Read2 forward orientation.

$ samtools view -q 30 -f 0x2 -b -h in.bam > out.bam

To extract single end reads from a bam file (-b) that map with mapQ≥30 including the bam file header (-h).

$ samtools view -q 30 -b -h in.bam > out.bam

Popular posts from this blog

Mass download from google drive using R

Data analysis step 8: Pathway analysis with GSEA

Installing R-4.0 on Ubuntu 18.04 painlessly