Question: Mapping BAM/SAM file back to reference?!?!
gravatar for ab.tsubaki
3.5 years ago by
South Africa
ab.tsubaki50 wrote:

Hi all

So I have used BWA to align fastq files (mate pair, Illumina HiSeq) to a reference sequence. I then extracted the unmapped reads using samtools which gives me a bam file.


I would like to take this bam file and map it back to my reference sequence using BWA again. However bam files don't seem compatible - I do get an output sam file but the flagstat and other downstream tests then do not work. I have tried converting the bam to fastq and to fasta, same story. Though I get an output sam file from BWA alignment, I can either not visualize the sam file or downstream tests yield no results?


Is there something I'm missing here? Is it the paired end reads that are messing things up? Has anyone done something like this before?



bwa sam reference bam • 1.7k views
ADD COMMENTlink written 3.5 years ago by ab.tsubaki50

If you use bwa, you should run bamshuf first.

ADD REPLYlink written 3.5 years ago by lh331k

Oh good point lh3!
I remember reading somewhere than in some tools you have to shuffle the reads but also sort them by name so the pairs are together in the BAM file (but pairs are still randomly distributed). Im not sure if that's still required by bedtools's bamtofastq or other tools these days. Do you know anything about that? It's been a while since I did a bam -> fastq.

ADD REPLYlink modified 3.5 years ago • written 3.5 years ago by John12k

Bamshuf groups reads by names. Bwa reads a batch of reads and infers insert size distribution from the batch. When input reads are coordinate sorted, the inference is inaccurate and sometimes may fail. For bwa, it is important to use bamshuf. Those bam2fastq won't work well.

ADD REPLYlink written 3.5 years ago by lh331k

As a quick caveat, bamshuf has been renamed to collate in samtools. This is what I needed as well! Thanks!

ADD REPLYlink written 3.1 years ago by ben.johnson434310
Please log in to add an answer.


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