Samtools can be used to select reads above certain mapping quality. 

    samtools view -h -b -q 30 aligned.bam -o above.mapQ30.bam

**But, how to select a read below certain mapping quality - all aligned reads below mapQ 30?**

I know it can be done using awk. But, the pipeline gets lengthy and time consuming when first need to convert bam to sam - separate header - use awk for mapQ below 30 - add header - sam file - convert to bam.
Really, its taking a lots of time.

Thanks,


# Method B - requires samtools version 1.3

**first select the mapped reads only**
`samtools view -b -h -F 4 aligned.bam > mapped_only.bam`  # this selects for mapped reads only.

`samtools index mapped_only.bam`  # index the bam file

**Now separate the mapped reads above mapQ 40 and below**
`samtools -b -h -U below_mapQ40.bam -q 40 mapped_only.bam -o above_mapQ40.bam`   # make sure to use right samtools version (1.3)

`samtools index above_mapQ40.bam`    # this is bam file with reads with mapQ 40 and above

`samtools index below_mapQ40.bam`   # this is bam file with reads with mapQ below 40.
