# Error using htseq-count: Could not retrieve index file

I have a total RNAseq dataset that I aligned using STAR producing BAM files (sorted by coordinates). I am now trying to get counts for the lncRNA sequences using htseq-count, with the command:

htseq-count -m intersection-nonempty -f bam -i gene_id -r pos -s reverse ./OVCA429_Aligned.sortedByCoord.out.bam ./GRCh38_latest_genomic.gtf > ./OVCA429.counts.txt


This is the output:

[E::idx_find_and_load] Could not retrieve index file for './OVCA429_587680_1_1.rnaseq.fastqAligned.sortedByCoord.out.bam'
100000 GFF lines processed.
200000 GFF lines processed.
300000 GFF lines processed.
400000 GFF lines processed.
...(truncated output here)...
3775001 GFF lines processed.
[E::idx_find_and_load] Could not retrieve index file for './OVCA429_587680_1_1.rnaseq.fastqAligned.sortedByCoord.out.bam'
100000 alignment records processed.
200000 alignment records processed.
300000 alignment records processed.
...(truncated output here)...

Output text file:
__no_feature    20368875
__ambiguous 0
__too_low_aQual 0
__not_aligned   0
__alignment_not_unique  2634439


I've read through the htseq-count literature but it never asks to include an index file, therefore i'm not sure how to deal with this problem. Any help/ suggestions would be welcome! Thank you, in advance.

The problem seems to be missing index files of the bam files (therefore the error message that the index file is missing). You should be able to generate those with samtools, e.g.
samtools index ./OVCA429_587680_1_1.rnaseq.fastqAligned.sortedByCoord.out.bam

• I have created the index using what Kamil suggested but I am not able to generate the counts file. This is what I use: for i in *fastqAligned.sortedByCoord.out.bam; do htseq-count -r pos -f bam $i /gpfs/scratch/mice/GCA-000001635.90-GRCm39-genomic.gtf >$i_output_basename.counts ; done Jan 12 at 17:05
• @christosnoutsos 1. that was not an answer. You should open a new question, link this one and explain why the solution did not work for you. 2. I would put quotation marks around $i in $i_output_basename.counts, i.e. "\$i"_output_basename.counts. You probably created a bunch of files .count that replaced each other. Jan 12 at 20:53