Created
January 17, 2019 21:49
-
-
Save slavailn/49236f8e31ff7e8668f649f12f61fa42 to your computer and use it in GitHub Desktop.
Get BWA mapping stats (mapped, unmapped reads, number of reads with MAPQ20)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
echo -e "Samplename\tTotal_reads\tMapped_reads\tUnmapped_reads\tMAPQ20_reads\tPercent_mapped\tPercent_MAPQ20_reads" | |
for file in ./*bam | |
do | |
filename=`basename $file` | |
samplename=${filename%.bam} | |
total_reads=`samtools view -c $file` | |
mapped_reads=`samtools view -c -F 4 $file` | |
unmapped_reads=`samtools view -c -f 4 $file` | |
mapq_20=`samtools view -c -q 20 $file` | |
percent_mapped=`bc <<< "scale = 3; ($mapped_reads/$total_reads)*100"` | |
percent_mapq20=`bc <<< "scale = 3; ($mapq_20/$total_reads)*100"` | |
echo -e "$samplename\t$total_reads\t$mapped_reads\t$unmapped_reads\t$mapq_20\t$percent_mapped\t$percent_mapq20" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment