# hail.java.FatalError: FileNotFoundException: ... .bgen.idx does not exist

**URL:** <https://discuss.hail.is/t/hail-java-fatalerror-filenotfoundexception-bgen-idx-does-not-exist/351>\
**Category:** Help \[0.1\]\
**Created:** [November 5, 2017, 1:19pm UTC](https://discuss.hail.is/t/hail-java-fatalerror-filenotfoundexception-bgen-idx-does-not-exist/351 "2017-11-05T13:19:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephane\_Bourgeois](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@Stephane\_Bourgeois](https://discuss.hail.is/u/Stephane_Bourgeois)\
**Post date:** [November 5, 2017, 1:19pm UTC](https://discuss.hail.is/t/hail-java-fatalerror-filenotfoundexception-bgen-idx-does-not-exist/351/1 "2017-11-05T13:19:15Z")

</div>

Hi,

I’m getting an error and I don’t know why, as far as I know bgen files don’t require indexing before importing (and I’ve never seen a .bgen.idx), so can someone tell me what’s happening here?

```
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
Running on Apache Spark version 2.1.0
SparkUI available at http://10.2.213.83:4040
Welcome to
     ____ <>__
    / /_/ / ____ / /
   / __ / _ `/ / /
  /_/ /_/\_,_/_/_/ version 0.1-6e815ac
2017-11-05 12:56:53 Hail: INFO: Number of BGEN files parsed: 23
2017-11-05 12:56:53 Hail: INFO: Number of samples in BGEN files: 7135
2017-11-05 12:56:53 Hail: INFO: Number of variants across all BGEN files: 40405505
Traceback (most recent call last):
  File "regression1.py", line 22, in <module>
    hc.import_bgen('/mnt/volume/imputed_genotypes/*.bgen', sample_file='/mnt/volume/imputed_genotypes/MT_chr1.sample').split_multi().write('/mnt/volume/imputed_genotypes/MT.vds')
  File "<decorator-gen-476>", line 2, in import_bgen
  File "/usr/local/hail/python/hail/java.py", line 121, in handle_py4j
    'Error summary: %s' % (deepest, full, Env.hc().version, deepest))
hail.java.FatalError: FileNotFoundException: File file:/mnt/volume/imputed_genotypes/MT_chr7.bgen.idx does not exist

```

The bgen files were created by converting imputed VCFs (output of Sanger imputation pipeline) to bgen using QCtool v2 rc6:

```
for i in {1..22} X
do
qctool2 -g /mnt/volume/imputed_genotypes/MT.vcfs/$i.vcf.gz -og MT_chr$i.bgen -os MT_chr$i.sample -assume-chromosome $i -vcf-genotype-field GP
done
```

---

<div class="post-metadata">

**Author:** ![maryhaas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/maryhaas/32/141_2.png) [@maryhaas](https://discuss.hail.is/u/maryhaas)\
**Post date:** [November 5, 2017, 5:07pm UTC](https://discuss.hail.is/t/hail-java-fatalerror-filenotfoundexception-bgen-idx-does-not-exist/351/2 "2017-11-05T17:07:00Z")

</div>

Hail uses an index file that it creates in order to work with bgen files more efficiently. You should run [`index_bgen()`](https://hail.is/docs/stable/hail.HailContext.html#hail.HailContext.index_bgen) first to create the `.idx` index file (only need to do this once & should do it separately - see doc), then `import_bgen()` will work.

As an aside, there’s also a new bgen indexing tool, [bgenix](https://bitbucket.org/gavinband/bgen/wiki/bgenix), to work with bgen files in non-Hail contexts.

---

<div class="post-metadata">

**Author:** ![Stephane\_Bourgeois](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@Stephane\_Bourgeois](https://discuss.hail.is/u/Stephane_Bourgeois)\
**Post date:** [November 6, 2017, 10:15am UTC](https://discuss.hail.is/t/hail-java-fatalerror-filenotfoundexception-bgen-idx-does-not-exist/351/3 "2017-11-06T10:15:43Z")

</div>

Thank you, I did miss the “(assuming it has already been indexed)”, and I searched for _.idx_ and nothing popped up… obviously should have searched for _index_ instead.

Yes, I know about bgenix, but the extension is different, so I figured Hail doesn’t use these.

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [November 10, 2017, 6:39pm UTC](https://discuss.hail.is/t/hail-java-fatalerror-filenotfoundexception-bgen-idx-does-not-exist/351/4 "2017-11-10T18:39:34Z")

</div>

Thanks for the documentation feedback @Stephane_Bourgeois, I’ve created three PRs to address the issues you faced:

- [#2411 Improve search-ability of .idx in docs](https://github.com/hail-is/hail/pull/2411)
- [#2412 Improve error message when bgen.idx doesn’t exist](https://github.com/hail-is/hail/pull/2412)
- [#2413 Improve documentation of import\_bgen](https://github.com/hail-is/hail/pull/2413)
