Thursday 31 March 2011

Convert SAM / BAM to fasta / fastq

Probably one of the most freq FAQ

latest thread in biostar
http://biostar.stackexchange.com/questions/6993/convert-bam-file-to-fasta-file

Samtofastq using Picard
http://picard.sourceforge.net/command-line-overview.shtml#SamToFastq

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)
http://biostar.stackexchange.com/questions/6993/convert-bam-file-to-fasta-file/6994#6994 

2 comments:

  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?

    ReplyDelete
  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...

    ReplyDelete

Datanami, Woe be me