bwa mem on a bam file
1
0
Entering edit mode
7.3 years ago
vimartin ▴ 60

Hi,

I'm trying to use bwa mem for the first time and I wonder, is it possible to run it on a bam file instead of a fastq file? I noticed that bwa aln can be runned on bam file using '-b' but this option is invalid for bwa mem. The manual does not mention whether it is possible or not. I tried to simply run bwa mem on bam file and the output seems to be a header only sam file.

Does anyone has experience on the question?

Thanks in advance.

NGS bwa-mem bam • 9.8k views
ADD COMMENT
5
Entering edit mode
7.3 years ago
vimartin ▴ 60

Ok, I should have wait I guess. Finally I found the answer which is : no. This was detailed in the mail archive announcing the release of bwa mem. I put it as an answer in case someone else ask himself the same question.

http://sourceforge.net/p/bio-bwa/mailman/message/30527151/

ADD COMMENT
2
Entering edit mode

you could try piping samtools fastq (former samtools bam2fq) to bwa and save both disk and time:

samtools fastq reads.bam | bwa mem ref.fa -

note: this works only for non-paired-end reads.

ADD REPLY
0
Entering edit mode

Nice solution, but are you sure the -p parameter works well? Does bwa correctly pairs the paired end if they come from the stdin ? Have you tested it?

ADD REPLY
1
Entering edit mode

from bwa manual page:

If -p is used, the command assumes the 2i-th and the (2i+1)-th read in reads.fq constitute a read pair (such input file is said to be interleaved)

but unfortunately samtools fastq does not output interleaved reads.

you can either try sorting reads by name BEFORE fastq generation:

samtools sort -n reads.bam | samtools fastq - | bwa mem -p ref.fa -

or you can either try sorting reads by name AFTER fastq generation (which is slightly faster):

samtools fastq reads.bam | paste - - - - | sort -k1,1 -S 3G | tr '\t' '\n' | bwa mem -p ref.fa -
ADD REPLY
0
Entering edit mode

I found this suggested solution from samtools' documentation and modified it according to our context:

samtools collate -u -O reads.bam | samtools fastq -0 /dev/null -s /dev/null - | bwa mem -p ref.fa -

samtools collate is probably much faster than sorting by name. I haven't tested it myself though, so future comers should use it with caution. Also, this code discards the singleton / supplementary / secondary reads, which may or may not be desired.

ADD REPLY
1
Entering edit mode

you could use samtofastq from Picard to convert your bam to fastq prior BWA mem alignment.

ADD REPLY

Login before adding your answer.

Traffic: 1376 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