This is a test version of Biostars. For the public version, visit https://www.biostars.org.
samtools idxstats on indexed BAM failed

I have an indexed BAM file foo.bam and its index foo.bam.bai. When I run samtools idxstats to get information about the index, I get the following error:

$ samtools idxstats foo.bam
[bam_idxstats] fail to load the index.

Both foo.bam and its index file are in the same directory. Is there anything I'm missing about this command?

Here is the version of samtools I am running:

Program: samtools (Tools for alignments in the SAM format)
Version: 0.2.0-rc8-60-g2455fd2-dirty (using htslib 0.2.0-rc8-20-g34082df)
index samtools bam

No, you are not missing anything in the command. Needless to ask but have you tried recreating the "index" file and running idxstats again.

No, I don't own the directory these files are located in. I can make a copy to test locally but it will take time. Are there issues accessing indexed BAM files with a newer version of samtools, when it is almost certain the index was generated with an older tool?

Perhaps there is a bug with this version of samtools?

$ samtools sort foo.bam foo.resorted.bam
[bam_sort_core] merging from 18 files...
$ samtools index foo.resorted.bam
Samtools-htslib-API: bam_index_build2() not yet implemented
Aborted (core dumped)

Yeah, you'll want to use the version on sourceforge still.

1 answer

Try leave out the last argument that worked for

samtools index -b file.bam

/john

leaving out last argument worked for me. I used sorted bam file to make an index.

samtools index -b file.sorted.bam

worked for me too

Log in to answer this question.