Thursday, 31 March 2011

Convert SAM / BAM to fasta / fastq

Probably one of the most freq FAQ

latest thread in biostar

Samtofastq using Picard

Samtools and awk to make fasta from sam
samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta
Biopython and pysam (code contributed by Brad Chapman) 


  1. What about the calmd option? Sequences are full of '=' signs, will cause your awk script to fail; will some of the other tools handle it? Which?

  2. Maybe one should add that (at least with bwa) it is possible to do alignment drectly from BAM files without the need to convert to FastQ, which might be space-consuming...


Datanami, Woe be me