This is a test version of Biostars. For the public version, visit https://www.biostars.org.
From BAM to BAI to BIGWIG

Hello,

I have indexed my bam files as:

> samtools index -b file.bam

I get as a result a file.bam.bai. But when I try to convert it to BigWig with bamCoverage as:

> bamCoverage -b file.bam.bai -o file.bw

I get the following error:

[E::hts_hopen] fail to open file 'file.bam.bai'
[E::hts_open_format] fail to open file 'file.bam.bai'
The file file.bam.bai does not have BAM format

The error persists if I change the file name to file.bam.bai.

I checked with samtools flagstat, and I get the same error

> samtools flagstat file.bam.bai
[E::hts_hopen] fail to open file 'file.bam.bai'
[E::hts_open_format] fail to open file 'file.bam.bai'
samtools flagstat: Cannot open input file "file.bam.bai": Exec format error

If I dont index the bam file bamCoverage tells me i MUST index it first...

I think I have done this before without any problems and I dont understand why am I getting this error. Could it be that the files are corrupted? Any help is well appreciated!

bigwig samtools index bamcoverage bai

1 answer

The .bai file is just an index, you have to convert the .bam file to bigWig - as shown on the bamCoverage documentation:

bamCoverage -b reads.bam -o coverage.bw

Wow, that was simple! Thank you so much! :)

If an answer was helpful, please consider to mark it as accepted.

enter image description here

Hi,

I run the command line "bamCoverage -b reads.bam -o coverage.bw" in order to convert bam RNA-seq data to .bw files and I get error "command not found". Please advise what is wrong there. Thank you

Hi, it seems like you don't have deeptools installed. Try,

bamCoverage --help

If this doesn't show you the help page, follow the deeptools installation instructions

Log in to answer this question.