Skip to content

Instantly share code, notes, and snippets.

@bede
Last active July 17, 2017 17:15
Show Gist options
  • Save bede/28071fe56dae5a3d3b7a to your computer and use it in GitHub Desktop.
Save bede/28071fe56dae5a3d3b7a 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...
@bede
Copy link
Author

bede commented Sep 16, 2015

@nickloman suggests FreeBayes
http://lab.loman.net/2015/07/28/calling-haploid-consensus-sequence/

freebayes -f ref.fa -p 1 aln.sorted.bam > vcffile
vcf2fasta -f ref.fa -P 1 vcffile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment