Converting to fasta from .bam
1
0
Entering edit mode
9.6 years ago
zgayk ▴ 90

Hello,

​I haven't found a good reference on how to convert an alignment currently in the .bam format back to .fasta. I was assuming there was a way to do this using Samtools, but I haven't found one. I did see a reference to a Bam2fastq converter, but that is a separate software package.

Thanks very much for any insights you might have.

Zach

alignment • 2.3k views
ADD COMMENT
1
Entering edit mode
9.6 years ago

One easy way is to convert to BED with bam2bed and awk the columns you want into FASTA form:

$ bam2bed < reads.bam | awk '{print ">"$4"\n"$12;}' - > reads.fa

For instance:

$ bam2bed < contigs.bam | awk '{print ">"$4"\n"$12;}' - | head
>Contig545|m.1503
ATGGAGGTGATTGATTTTTCGGAGACGGAGATGGAAGCAGCGGAGCAGCTAGTGCAATTGAGCGAGGATGATACGTTGAGCTGTAGCAGCGGTACAGGCTTGAGCGTTAGCGGTTGTGAAGGCGGATTCCATAGGAAGAGACACAGCGATGTTATTAGTGATGAGGTGCAAAACGACGGCGTTGTACGTACGACGATGAATAACAATGCTACAGACGCTCAATGTTTTGTGAAGGCAATCACGGAGACGAACATAATAAGGAGGAGGTATAAGAAGAAAAAGTTTCGGTCTCTTGCGAGTCTTTACAGGGCAACGAAGGAGATGACGACGGACGAGTTGATCTAG
>Contig1727|m.4383
TTAATCCATTTGTTTCACTTTGTTAGCAGTCTCAATTGGTTTCTTGCTGATCATTTCATGATGGGATATATCTGTGTGGAATCTTTGTTTTGGTTTGACTTTTTGGTCGATGATGATTGACGTTAAGGCTTGTTTCTCAAAACATTCGCAGTGGCCGCCTAAGGCTTTCGCCTTTCGCCGGGCTTGAGAGCTTATGATGTTTTTATCCTTCCTTGGATGTCTGAGACCAAT
>Contig1477|m.3679
TTATAAAAAAGCAATACTATCATGGCGTTGGGGCGAGAAAGAGGCGCAACACATGCCTGTGAGTCCATGACGGCTCCAGAACTCTTCAGTATCAGCGACTCCGTGGATCCTGACTCTTCTCGTGCTCTTCGTGTCTGTGTTGAAGTAGAAAACATAGAAGGGCTGGGCAGGGCCTGGCAGAGATGTTGGGGAGAAAATGATTTCACCGGCCTTGTTGGTTCCTTGGGAGATCATACGCTGACTCCTCCGGAAAGCGAAGGGAAGAGACAAGGAAAGCTGAAATGATTGTCTGGACCACTCATGTTTGGTCACATCCTCCAGTATCCAAAGATCAAAACGGTCGAAAGAAGAACCAGTTCTCAAACAGTTTGTTGGTACAAGGACATCTAGCTTCCCTTTGTATTCTATCAATGATGTATAAACCTTCCAAACCAGGACCTCCTTAGGCGTAGTGATAAAACTTAGTATCCTCTCATATCTTACATCAAAGCACACAAACACAGGAGGAGTTTGATTTGGAACAGAAGCAGCATAATAGATGAAACCATTGATGCTTAGTCCCACAGTCATAGGGCAATAATACGGGGAGGTTCCTTGCGTTTC
ADD COMMENT
1
Entering edit mode

Thank you very much for your help.

ADD REPLY

Login before adding your answer.

Traffic: 1869 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6