Skip to content

Instantly share code, notes, and snippets.

@elowy01
Last active October 16, 2022 12:22
Show Gist options
  • Save elowy01/21929ad87152254d592743da8f741eb7 to your computer and use it in GitHub Desktop.
Save elowy01/21929ad87152254d592743da8f741eb7 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment