Skip to content

Instantly share code, notes, and snippets.

@thanhleviet
Forked from bede/sam_to_consensus_fa.sh
Created May 22, 2017 23:44
Show Gist options
  • Save thanhleviet/08f576006111dbd34fe7b4f177e15596 to your computer and use it in GitHub Desktop.
Save thanhleviet/08f576006111dbd34fe7b4f177e15596 to your computer and use it in GitHub Desktop.
Bioinformatics code golf: SAM to consensus FASTA
# SAM to consensus FASTA code golf, inspired by http://lab.loman.net/2015/07/28/calling-haploid-consensus-sequence/
# Starting with a SAM:
samtools view -bS seqs.sam | samtools sort - seqs # Generate and sort BAM
samtools index seqs.bam # Index BAM
# Starting with an indexed BAM:
samtools mpileup -ud 1000 -f seqs_ref.fasta seqs.bam | bcftools call -c | vcfutils.pl vcf2fq | seqtk seq -a - > seqs.consensus.fa # Generate pileup, call variants, convert to fq, convert to fa
# Who can do better? The bar is set low...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment