<p>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 <code>samtools</code>, e.g.</p>
<pre><code>samtools index ./OVCA429_587680_1_1.rnaseq.fastqAligned.sortedByCoord.out.bam
</code></pre>

CC BY-SA 4.0
2020-09-13T18:56:10.030Z
As it happens I did have the index file as well, I just ended up naming it differently and so the application probably didn't recognise it. Once I changed the name to match the bam file, it worked out perfectly file. Nevertheless, thank you for your help! :)
anjali_yen
CC BY-SA 4.0
2020-09-14T10:20:48.777Z
Ah, I did not even think this could be a problem as samtools do not give you an option to give it a different name. GLad you resolved it!
Kamil S Jaron
CC BY-SA 4.0
2022-01-12T17:05:59.970Z
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`
christos noutsos
CC BY-SA 4.0
2022-01-12T20:53:00.530Z
@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.
Kamil S Jaron
CC BY-SA 4.0
2020-09-10T20:09:42.787Z
2020-09-10T20:09:42.787Z
Kamil S Jaron
<p>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:</p>
<pre><code>htseq-count -m intersection-nonempty -f bam -i gene_id -r pos -s reverse ./OVCA429_Aligned.sortedByCoord.out.bam ./GRCh38_latest_genomic.gtf &gt; ./OVCA429.counts.txt
</code></pre>
<p>This is the output:</p>
<pre><code>[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
</code></pre>
<p>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.</p>

<rna-seq><sam><errors><featurecounts>
Error using htseq-count: Could not retrieve index file
# Error using htseq-count: Could not retrieve index file

(Asked by: username_0 on 2020-09-10)

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.

**Tags:** rna-seq, sam, errors, featurecounts

---

## 1 answers

### Answer by username_1 on 2020-09-10. Score: 0 | Accepted answer

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

> **Comments:**
> **username_0**: As it happens I did have the index file as well, I just ended up naming it differently and so the application probably didn't recognise it. Once I changed the name to match the bam file, it worked out perfectly file. Nevertheless, thank you for your help! :)  
> **username_1**: Ah, I did not even think this could be a problem as samtools do not give you an option to give it a different name. GLad you resolved it!  
> **username_2**: 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`  
> **username_1**: @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.  

---

