This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BAM to FASTA

Hi everyone,

I am new working with Samtools and I need to convert a .BAM to a .fasta. I checked all the posts that I could but I do not have what I am looking for.

I used: samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}'

I did not get the .fasta format that I use to see. The .fasta generated has some "cuts" and "intervals" with a several number of "Ns". I am looking for a continuous "normal" .fasta and I do not mind whether it has Ns at all.

I also saw this, but did not tried: samtools bam2fq input.bam | seqtk seq -A > output.fa (Could this one help me?)

Thanks very much Community,

Ivan

bam to fasta bam fasta samtools

1 answer

Current samtools (v.1.x) has fasta option to convert BAM to Fasta.

Usage: samtools fasta [options...] <in.bam>

Log in to answer this question.