This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in indexing .bam files from STAR alignment using SAMtools

I have created sorted .bam files using STAR. I am trying to create .bai files using SAMtools1.14 I am able to index all but one of the files (generated at the same time with the same STAR command), but I get the following error:

samtools index: "file.bam" is in a format that cannot be usefully indexed

I am unclear as to why this is happening and what to do to fix the file so I can proceed.

samtools bam star

Can you run samtools quickcheck -v your.bam?

I get:

file.bam was not identified as sequence data

when I run samtools -v quickcheck

What does this mean?

This error is given when you try to index a non-SAM, non-BAM and non-CRAM file, but it's a file that is a recognised data type. So maybe it's not actually a bam file?

Using "htsfile file.bam" will give you some clues as to what htslib believes the file contents to be. You can also try "samtools view file.bam" to see if it can even be displayed. If both check out then this is more interesting and pointing to an indexing issue, but I suspect you'll find something amiss before that.

You could also try doing "less file.bam" (or "zless file.bam" if it's gzipped) to visually inspect it incase something obvious leaps out.

1 answer

I am encountering the same error. The bam file is empty which is what causes samtools index to fail.

I'm not sure why the alignment bam file is empty though.

Edit: I got it to work. Make sure not to overload your resources. Try some of the suggestions here.

Log in to answer this question.