UnboundLocalError: local variable 'idx' referenced before assignment

Hello everyone
I am using now metaphlan3, installed from github following the indications here (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

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

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

583628

What does it means?

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.

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

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?

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)

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

yes of course,
I sent you by mail

@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.