This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is the order of records in the bam file produced by bwa the same as the order in the input fastq file?

Hi all,

I was wondering if the order of records in a bamfile produced by bwa aln/mem/sampe is guaranteed to be the same as in the fastq files that were used as input.

I checked the bwa manual but the only thing I found is this: "Repetitive read pairs will be placed randomly" (part of sampe description).

If anyone has an idea, I'd welcome your feedback!

Best,
~Lina

mem fastq bwa aln sampe

3 answers

Yes, the same.

Not necessarily. Sometime this can be in sorted in target mapping position. You can check this easily by command;

samtools view file.bam

bwa won't coordinate-sort for you. It's possible that the default output order matches the input. One would just need to compare an input and output to see. If it doesn't and Lina F needs that, then bowtie2 with the --reorder option will work.

I apologize for any mistaken assumption.

No worries, lh3 just replied anyway and he's obviously the definitive source on this sort of thing :)

Thanks for the feedback!

It looks like the default order matches the input for my data, but I just wanted to find out if that is guaranteed by bwa. To be on the safe side, I'll assume it's not guaranteed.

A wild guess without having checked anything...: If bwa runs on one thread then output order = input order. If bwa runs on multiple threads input and output orders might differ.

Sounds reasonable! Currently I'm running bwa on a single thread but I might have to move to more than one in the future...

Log in to answer this question.