How to fix: Query[…] is marked as paired, but its mate does not occur next to it in your BAM file


What is causing the error?

This error is caused when bedtools can’t handle the order that your reads are in. If you’ve just downloaded the bam from the tcga and haven’t checked, it is most likely that your bam file is sorted by chromosomal location. You can check the order by using the command:

This will output something like

Or

If you get SO:coordinate, you will need to sort your file using the code below, if it reads SO:queryname, skip to the next section

With a sorted bamfile your errors should hopefully go away

But Dr Prufstein, I already sorted my bam by readname!


The error is likely being caused by duplicate or orphaned reads in your bam file. You can search for these reads using the following commands;

If you find erroneous reads, you can filter these out using

I’m still having issues!

I’ve found issues with this when using bedtools bamtofastq. I’m not sure why, but I’ve had much better luck using the samtools equivalent samtools fastq. Please see below for my equivalencies.

Bedtools bamtofastq

samtools fastq

I hope that these tips help to sort your issues!
Prufstein

Leave a Reply

Your email address will not be published. Required fields are marked *