# UnboundLocalError: local variable 'idx' referenced before assignment

**URL:** <https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715>\
**Category:** MetaPhlAn\
**Created:** [July 14, 2020, 1:53pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715 "2020-07-14T13:53:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AQ7](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aq7/32/905_2.png) [@AQ7](https://forum.biobakery.org/u/AQ7)\
**Post date:** [July 14, 2020, 1:53pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/1 "2020-07-14T13:53:32Z")

</div>

Hello everyone  
I am using now metaphlan3, installed from github following the indications here ([https://github.com/biobakery/MetaPhlAn/wiki/MetaPhlAn-3.0](https://github.com/biobakery/MetaPhlAn/wiki/MetaPhlAn-3.0))

I have runned this command

` metaphlan ../Database/Late_Medieval6_TCAAGGCATCGG_R1.fastq.gz --input_type fastq --bowtie2db bowtie2db -o Profile.txt`

and then I get this error:

```
Downloading https://www.dropbox.com/sh/7qze7m7g9fe2xjg/AAA4XDP85WHon_eHvztxkamTa/file_list.txt?dl=1
Downloading file of size: 0.00 MB
0.01 MB 232.33 % 8.91 MB/sec 0 min -0 sec
Downloading https://www.dropbox.com/sh/7qze7m7g9fe2xjg/AAAyoJpOgcjop41VIHAGWIVLa/mpa_latest?dl=1
Downloading file of size: 0.00 MB
0.01 MB 31507.69 % 13.56 MB/sec 0 min -0 sec
Downloading MetaPhlAn database
Please note due to the size this might take a few minutes

File bowtie2db/file_list.txt already present!

Downloading https://www.dropbox.com/sh/7qze7m7g9fe2xjg/AADlxibskzbPHPoDl6S-FyKka/mpa_v30_CHOCOPhlAn_201901.tar?dl=1
Downloading file of size: 366.62 MB
366.62 MB 100.00 % 4.24 MB/sec 0 min -0 sec
Downloading https://www.dropbox.com/sh/7qze7m7g9fe2xjg/AACTzoUYDqZps8u2JqWCNCODa/mpa_v30_CHOCOPhlAn_201901.md5?dl=1
Downloading file of size: 0.00 MB
0.01 MB 12800.00 % 11.29 MB/sec 0 min -0 sec

Decompressing bowtie2db/mpa_v30_CHOCOPhlAn_201901.fna.bz2 into bowtie2db/mpa_v30_CHOCOPhlAn_201901.fna

Building Bowtie2 indexes
Removing uncompress database bowtie2db/mpa_v30_CHOCOPhlAn_201901.fna

Download complete
Traceback (most recent call last):
  File "/home/.local/bin/read_fastx.py", line 8, in <module>
    sys.exit(main())
  File "/home/.local/lib/python3.6/site-packages/metaphlan/utils/read_fastx.py", line 155, in main
    nreads += read_and_write_raw(f, opened=False, min_len=min_len)
  File "/home/.local/lib/python3.6/site-packages/metaphlan/utils/read_fastx.py", line 119, in read_and_write_raw
    nreads = read_and_write_raw_int(inf, min_len=min_len)
  File "/home/.local/lib/python3.6/site-packages/metaphlan/utils/read_fastx.py", line 111, in read_and_write_raw_int
    nreads = idx - discarded
UnboundLocalError: local variable 'idx' referenced before assignment

```

What it is happening is not so clear to me, does anyone have any suggestion about how resolve this issue? thanks a lot

---

<div class="post-metadata">

**Author:** ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)\
**Post date:** [July 20, 2020, 8:19am UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/2 "2020-07-20T08:19:08Z")

</div>

> [@AQ7](#):
>
> …/Database/Late\_Medieval6\_TCAAGGCATCGG\_R1.fastq.gz

Are you sure the file isn’t corrupted? Can you run ` zcat ../Database/Late_Medieval6_TCAAGGCATCGG_R1.fastq.gz | wc -l`?

---

<div class="post-metadata">

**Author:** ![AQ7](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aq7/32/905_2.png) [@AQ7](https://forum.biobakery.org/u/AQ7)\
**Post date:** [July 20, 2020, 10:32am UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/3 "2020-07-20T10:32:13Z")

</div>

I have tried to do zcat as you suggested and I get the following number as results:

583628

What does it means?

---

<div class="post-metadata">

**Author:** ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)\
**Post date:** [July 22, 2020, 7:14am UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/4 "2020-07-22T07:14:33Z")

</div>

This returns the total numbers of lines in the fastq file, 145907 reads.  
If you run directly `read_fastx.py -l 70 <file>` do you get the same error?  
Also, how did you retrieved your fastq.gz? Have you by any chances downloaded it using Google Chrome? Sometimes it happens that when you download gzip files, Chrome will automatically un-gzip them.

---

<div class="post-metadata">

**Author:** ![AQ7](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aq7/32/905_2.png) [@AQ7](https://forum.biobakery.org/u/AQ7)\
**Post date:** [July 22, 2020, 9:51am UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/5 "2020-07-22T09:51:14Z")

</div>

Hello,  
yes I have downloaded them but with firefox not chrome, is it the same? I have tried to download them several time but i always get the same problem.  
If i run the command you suggest I get this:

@M\_NS500468:16:H2MNCBGXX:2:21207:15252:11956\_1:N:0:CTCTGCA  
CGGTTATTTTGCTTGCGGTTCCCCGTATTCCCGTTTCATTGCCTTCGTGGACACGACCCATTGTTTGCCGTATTTGCAGGCATCGACGCCATTTA  
+  
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ  
@M\_NS500468:16:H2MNCBGXX:2:21207:23030:16556\_1:N:0:CTCTGCA  
TTGTCTTCCGCAACCAAAATTAAAAAAATGGCATTAGATCGGATGGCAGAAAAAGATGTAAAGGTATATTGCGAAGACAGGGGTGTCGTAGATAAAGAT  
+  
JJJ8JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ=JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ  
@M\_NS500468:16:H2MNCBGXX:2:21212:22160:2949\_1:N:0:CTCTGCA  
ATACAGCTGTAAGCTAGAATCATTTGCCACATTCATAATTCTTGAATAAATGTCAGTGGTCATTGTTTTCAGTGGCTTGGAATCACTAGATGCATTGTAT  
+  
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ  
@M\_NS500468:16:H2MNCBGXX:2:21212:21446:12744\_1:N:0:CTCTGCA  
TTATTTTCAGAGTCAACTTTAATGATCTTTATTTTACCAAGTAAATCACCTTCAATAGTTCCATTTGAAATCGCACTCTTATATTGACTTGTTGCAAT  
+  
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ/JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ  
@M\_NS500468:16:H2MNCBGXX:2:21212:2531:14147\_1:N:0:CTCTGCA  
ACTTATAGTGAATTGATCATATCCACAAGGCTCACAGCGTGTGCCAAGCCCTTTTCCTTGATTTGCATCAAGATATCAGGATCCTGTCTTGCCTGATATGATA  
+  
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ  
@M\_NS500468:16:H2MNCBGXX:2:21212:22463:14223\_1:N:0:CTCTGCA  
GCTGTCAGCGATGATGAGATGTCGGGATATGTGGATTTGGGACTGATGCAGAATAATATAATCGATTGGGACACCGGTAAAATTTATAGTTTATTTGA  
+  
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ  
@M\_NS500468:16:H2MNCBGXX:2:21301:1661:8770\_1:N:0:CTCTGCA  
ATTAGAGTCGGTTTTCTTGGTTTCAGATTGTTCTGATTGACTATCTTTCTTGTCATCTTTGTATTCTGCTAACAAGTTTGCTTTGTTATAACCTTCATAAA  
+  
JJJJJJJJJJJJJJJJJJJJ8JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ

---

<div class="post-metadata">

**Author:** ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)\
**Post date:** [July 22, 2020, 2:38pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/6 "2020-07-22T14:38:54Z")

</div>

Seems that is working, was the latest line printed something like `#nreads xxxx`?  
Could you please check which version of MetaPhlAn are you running with `metaphlan -v`?

---

<div class="post-metadata">

**Author:** ![AQ7](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aq7/32/905_2.png) [@AQ7](https://forum.biobakery.org/u/AQ7)\
**Post date:** [July 22, 2020, 3:17pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/7 "2020-07-22T15:17:48Z")

</div>

No the latest line printed is this:

```
@M_NS500468:16:H2MNCBGXX:1:23312:22608:20258_1:N:0:CTCTGCA
AGATTCAAGAGCGTTATGGCTACACCAAAGAACAGGTAGAAAAAGAATTGAGCGACTGGTTCGGCAAGAATTAAG
+
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ@JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ

```

while the metaphlan version is :

Metaphlan 3.0 (20 mar 2020)

---

<div class="post-metadata">

**Author:** ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)\
**Post date:** [July 22, 2020, 3:32pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/8 "2020-07-22T15:32:05Z")

</div>

I’m not able to reproduce the same error, could you please share with me the fastq?

---

<div class="post-metadata">

**Author:** ![AQ7](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/aq7/32/905_2.png) [@AQ7](https://forum.biobakery.org/u/AQ7)\
**Post date:** [July 22, 2020, 3:48pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/9 "2020-07-22T15:48:59Z")

</div>

yes of course,  
I sent you by mail

---

<div class="post-metadata">

**Author:** ![huminfo8](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/huminfo8/32/1481_2.png) [@huminfo8](https://forum.biobakery.org/u/huminfo8)\
**Post date:** [May 30, 2022, 5:17am UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-idx-referenced-before-assignment/715/11 "2022-05-30T05:17:47Z")

</div>

@fbeghini Hello from Japan.  
Is there any progress about tackling this problem?

Actually, I encountered same issue. If there is any update I would like to know it.
