This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Changing n_lvls in htslib hts.c, or, samtools index error "Numerical result out of range"

I'm just trying to index a sorted BAM with samtools index but get the error:

[E::hts_idx_push] Region 536892210..536892211 cannot be stored in a csi index with min_shift = 14, n_lvls = 5. Try using min_shift = 14, n_lvls >= 6 
samtools index: failed to create index for "868om_41_070_010.sorted.bam": Numerical result out of range

no .bai nor .cis is made by the command, as is suggested by enter link description here. I think i found where n_lvls is defined in hts.c (lines 1817, 1829, 1847). However I'm not sure I how I should proceed, i.e. what compiler and options should be used to compile hts.c after I change n_lvls.

samtools htslib sequence

1 answer

Instead of changing the number of levels, instead increase the interval size with -m 15. That will give you a maximum position of 1073741824 (for those wondering the maximum position that can be index is given by 1 << min_shift + n_lvls * 3, or simply 1 << min_shift + 15, since n_lvls is hard coded).

Edit: Actually, the default should work if you're using the most recent version of samtools and make sure to specify the -c option. Then what you're seeing should only happen if (A) you specify -m 0 (then the defaults, which are too small, are used) or (B) you have entries in your BAM file beyond the end of the chromosome.

Log in to answer this question.