Cheat sheet for SAMtools
#getting the insert size from a BAM file
samtools view -F 0x4 accepted_hits.bam | awk '{if ($9 >0) {sum+=$9;sumsq+=$9*$9;N+=1}} END {print "mean = " sum/N " SD=" sqrt(sumsq/N - (sum/N)**2)}'
#slicing a BAM file
samtools view aln.sorted.bam chr2:20100000-20200000
# extract a subsequence from a FASTA file
# 1) Index the Fasta file
samtools faidx hs37d5.ch20.fa
# 2) Fetch the sequence
samtools faidx hs37d5.ch20.fa |20:10000000-11000000