Entering edit mode
8.2 years ago
gaiusjaugustus
▴
230
Hello, I am trying to extract reads at 1 base pair from many bam files. Each bam file has a bai file with the same name+.bai in the same folder.
When I run
samtools view myfile.bam
I get the output, but when I add coordinates such as
samtools view myfile.bam "chr1:1-100000"
I get the following error:
[bam_index_load] fail to load BAM index.
[main_samview] random alignment retrieval only works for indexed BAM files.
My understanding is that the bai file is the index it needs. Am I missing something?
Thanks in advance.
Thanks for the quick response. Is there an easy way to be sure that the BAM is sorted? I've started trying to sort and it's going to be a long while (files are 30+ GB each), so I'd rather not resort to re-sorting if I don't have to.
Also, any way to tell how the index was generated? Again, indexing is a long process so if I can easily get these working, I'd prefer this.
To see if things are sorted, take a look at this post: Is My Bam File Sorted ?
One way to attempt to check and see if the index might have been generated using another program (which, in this case, basically just means an earlier version of samtools, though I'm not exactly sure where backwards compatibility would break) would be to check the dates on the files with
ls -la
. If the BAM is much older than your index, you may have a problem. It's much more likely that your indices might be named the same but were actually from other BAMs - I've seen it happen a few times with several people working on a project. You don't need to test all of them; just test a single one and see if it fixes the issue. It shouldn't take too much time, and you'll know if it works.