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.
you could try piping
samtools fastq
(formersamtools bam2fq
) tobwa
and save both disk and time:note: this works only for non-paired-end reads.
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?
from bwa manual page:
but unfortunately
samtools fastq
does not output interleaved reads.you can either try sorting reads by name BEFORE fastq generation:
or you can either try sorting reads by name AFTER fastq generation (which is slightly faster):
I found this suggested solution from samtools' documentation and modified it according to our context:
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.you could use samtofastq from Picard to convert your bam to fastq prior BWA mem alignment.