Skip to content

Instantly share code, notes, and snippets.

@genometoolbox
Created June 13, 2014 20:16
###########################
# Using samtools idxstats # # quickest approach
###########################
# Total Alignments
samtools idxstats filename.bam | awk '{s+=$3+$4} END {print s}'
# Mapped Alignments
samtools idxstats filename.bam | awk '{s+=$3} END {print s}'
# Unmapped Alignments
samtools idxstats filename.bam | awk '{s+=$4} END {print s}'
#######################
# Using samtools view # # more options
#######################
# Total Alignments
samtools view -c filename.bam
# Mapped Alignments
samtools view -c -F 4 filename.bam
# Unmapped Alignments
samtools view -c -f 4 filename.bam
# Mapped Alignment and its Mate Mapped
samtools view -c -f 1 -F 12 filename.bam
# Total Reads
samtools view filename.bam | cut -f 1 | sort | uniq | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment