Question: How to get the consensus sequence from a BAM alignment
5
gravatar for bbb
19 months ago by
bbb50
Russian Federation
bbb50 wrote:

How to convert bam to fasta?

I have bam files and reference fasta. I want to get fasta sequence from bam file: see picture

Is there a software that can do this?

dna bam fasta • 6.0k views
ADD COMMENTlink modified 19 months ago by Istvan Albert ♦♦ 74k • written 19 months ago by bbb50
2

I have changed the post title for clarity and to allow the post to be referenced more easily.

ADD REPLYlink written 19 months ago by Istvan Albert ♦♦ 74k
3
gravatar for Istvan Albert
19 months ago by
Istvan Albert ♦♦ 74k
University Park, USA
Istvan Albert ♦♦ 74k wrote:

What the original poster needs is creating a consensus sequence out of BAM alignments. It is easy to misread that into the problem of extracting the read sequences from the BAM file.

See this for an answer: A: Error while trying to get consensus Fastq from BAM (notably the title of this post is incorrect as well, the OP there wants FASTA file not FASTQ)

But note that the problem can be more complicated than what it initially seems. It only works in ideal cases.

In the most general case the SNPs may not resolve into a single consensus sequence because that is not how the SNP callers work. They optimize the SNPs for a local region and not against a consensus. In addition in many (most) cases you may have a population of cells hence SNPs may represent different DNA molecules.

This is not to say that there is no value in producing a consensus but it is good to keep in mind the limitations of the the process.

ADD COMMENTlink modified 19 months ago • written 19 months ago by Istvan Albert ♦♦ 74k
1
gravatar for Sinji
19 months ago by
Sinji2.5k
UT Southwestern Medical Center
Sinji2.5k wrote:

You can do this using a combination of the bedtools getfasta and bedtools bamtobed functions. Here is the documentation.

bedtools bamtobed -i $INPUT_BAM > $OUTPUT_BED

bedtools getfasta -fi $INPUT_FASTA -bed $INPUT_BED -fo $OUTPUT_FASTA

EDIT: Seems I have mis-understood what you are attempting to do. I would disregard this post and read one of the other answers.

ADD COMMENTlink modified 19 months ago • written 19 months ago by Sinji2.5k
0
gravatar for genomax
19 months ago by
genomax37k
United States
genomax37k wrote:

One of these should help. If not search for additional similar threads on Biostars.
BAM/SAM to FASTA conversion
BAM format file to FASTA alignment file
Based on the image you posted the second link.

ADD COMMENTlink modified 19 months ago • written 19 months ago by genomax37k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 890 users visited in the last hour