Question: Samtools view does not recognize that I already have index file
0
gravatar for gaiusjaugustus
2.4 years ago by
United States
gaiusjaugustus130 wrote:

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.

samtools • 863 views
ADD COMMENTlink modified 2.4 years ago by Brice Sarver2.5k • written 2.4 years ago by gaiusjaugustus130
2
gravatar for Brice Sarver
2.4 years ago by
Brice Sarver2.5k
United States
Brice Sarver2.5k wrote:

Some things to consider:

  1. Your index may old or generated with a program other than samtools. You might want to regenerate it.
  2. Make sure the BAM itself is sorted by coordinate. Also make sure that the names are correct between the two files, i.e., you didn't change the name of the BAM after indexing or something.
  3. The index itself also needs to be accessible and readable by samtools.
ADD COMMENTlink modified 2.4 years ago • written 2.4 years ago by Brice Sarver2.5k

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.

ADD REPLYlink written 2.4 years ago by gaiusjaugustus130

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.

ADD REPLYlink modified 2.4 years ago • written 2.4 years ago by Brice Sarver2.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 718 users visited in the last hour