This is a test version of Biostars. For the public version, visit https://www.biostars.org.
nonamecheck not working in bedtools coverage

Hello,

I am running this command line in bedtools 2.27.1

bedtools coverage -nonamecheck -d -sorted -a file.bed -b file.bam  > file.cov

and I get this error

ERROR: Database file file.bam contains chromosome chrM, but the query file does not.
       Please rerun with the -g option for a genome file.
       See documentation for details.

I don't have access to the genome file and I guess nonamecheck is not working,

Thanks a lot

Best regards

bedtools

1 answer

Hello,

the genome file is need if you want to use -sorted. You can extract this information from your bam file as all informations are in the header.

$ samtools view -H file.bam|grep @SQ|sed 's/@SQ\tSN://'|sed 's/LN://' > genome.txt

fin swimmer

(I'm sure there is more beautiful sed command ;) )


Edit: Just for documentation the sed commands can be combined in one:

sed 's/@SQ\tSN:\|LN://g'

Wouldn't be -nonamecheck enaugh for this?

-nonamecheck    For sorted data, don't throw an error if the file has different naming conventions
        for the same chromosome. ex. "chr1" vs "chr01".

Are you mixing and matching the genomes by any chance? BED file from one provider where as BAM aligned to a different one?

No no, I have got just a bam

Hm, I don't know what -nonamecheck does behind the scene.. Maybe it just ignores lower/upper cases and leading zeros?

genomax suggested to me, that it also could be a naming mismatch between the bam file and your bed file. How is the name for chrM in the bed file? Maybe chrMT or just MT.?

fin swimmer

My bed file doesn't have any region in chrMT nor chrM

Interesting. Then why are you getting this? Or you just don't have any chrM regions in your bed file (and that is just a warning).

Database file file.bam contains chromosome chrM, but the query file does not.

Yes, I don't have any chrM regions in my bed file, but I do have in my bam. The message of bedtools should be a warning but it is not. Bedtools stops and the coverage in chrX regions are not calculated.

This has solved my problem, but still, with bedtools 2.17 we didn't need this, and I think it is not intuitive.

You can accept @fin swimmer's answer (green check mark) to provide to closure to this thread since your problem is solved.

Log in to answer this question.