metaphlan2.py error - TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

48 views
Skip to first unread message

aman

unread,
Nov 21, 2019, 12:40:57 PM11/21/19
to MetaPhlAn-users
Hi, I'm getting an error running metaphlan2.py. I suspected it might be a python error so I tried with both python2.7 and python3.6. I also tried using both the v295 and v294 databases in case that was an issue. Looking it up online I was only seeing answers that involve modifying the script, but I'm assuming metaphlan2.py is not the issue here. If it matters, I installed metaphlan2 using 
conda install -c bioconda metaphlan2


Error:
Help message for read_fastx.py
Traceback (most recent call last):
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1564, in <module>
    metaphlan2()
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1456, in metaphlan2
    tree = TaxTree( mpa_pkl, ignore_markers )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1133, in __init__
    add_lens( self.root )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1130, in add_lens
    lens.append( add_lens( c ) )
  File "/home/ec2-user/anaconda2/bin/metaphlan2.py", line 1131, in add_lens
    node.glen = sum(lens) / len(lens)
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

Script: 
metaphlan2.py fastqs/contig_list_trimmed_sampleE.fq --index v294_CHOCOPhlAn_201901 --nproc 28 --input_type fastq --bt2_ps very-sensitive-local --min_alignment_len 200 -s sams/sampleE.sam.bz2 --bowtie2out bowtie2/sampleE.bowtie2.bz2 -o profiles/profiled_sampleE.txt

I also tried running it as a bash script with python calling the metaphlan script, based on the strainphlan wiki (I tried this with python2 and python3:
#!/bin/bash
# run_metaphlan2.sh
mkdir
-p sams
mkdir
-p bowtie2
mkdir
-p profiles
for f in fastqs/*
do
    echo "Running metaphlan2 on ${f}"
    bn=$(basename ${f})
    python ~/anaconda2/bin/metaphlan2.py $f --index v295_CHOCOPhlAn_201901 --nproc 28 --input_type fastq --bt2_ps very-sensitive-local --min_alignment_len 200 -s sams/${bn}.sam.bz2 --bowtie2out bowtie2/${bn}.bowtie2.bz2 -o profiles/profiled_${bn}.txt
done

Python versions
(base) [ec2-user@ip-172-31-18-39 ~]$ python --version
Python 3.6.8
(base) [ec2-user@ip-172-31-18-39 ~]$ python2 --version
Python 2.7.16 :: Anaconda, Inc.

Len

unread,
Jan 10, 2020, 11:15:37 AM1/10/20
to MetaPhlAn-users
I'm having exact same issue with metaphlan 2.7.7 on Python 3.7.4.
I "installed" by downloading the latest release source from bitbucket.
The database used was v295.

metaphlan2.py --bowtie2_exe ../bowtie2 --bowtie2_build ../bowtie2-build --input_type fastq --bowtie2out tmp --nproc 32 --mpa_pkl db_v29 -x db_v29/mpa_v295_CHOCOPhlAn_201901 r1.fastq.gz,r2.fastq.gz > profiled_metagenome.txt

Help message for read_fastx.py
Traceback (most recent call last):

 
File "metaphlan2.py", line 1565, in <module>
    metaphlan2
()
 
File "metaphlan2.py", line 1457, in metaphlan2
    tree
= TaxTree( mpa_pkl, ignore_markers )
 
File "metaphlan2.py", line 1134, in __init__
    add_lens
( self.root )
 
File "metaphlan2.py", line 1131, in add_lens
    lens
.append( add_lens( c ) )
 
File "metaphlan2.py", line 1131, in add_lens
    lens
.append( add_lens( c ) )
 
File "metaphlan2.py", line 1131, in add_lens
    lens
.append( add_lens( c ) )
 
[Previous line repeated 4 more times]
 
File "metaphlan2.py", line 1132, in add_lens
    node
.glen = sum(lens) / len(lens)

Len

unread,
Jan 10, 2020, 11:33:18 AM1/10/20
to MetaPhlAn-users
I just saw another response in a different topic which indicates a version issue:

from the error, it seems that you are trying to use the latest database with MetaPhlAn 2.7 or older. mpa_v294_CHOCOPhlAn_201901 is only compatible with MetaPhlAn2 2.9. You can get this version from here https://bitbucket.org/biobakery/metaphlan2/src/2.9/
However, this version it is not final and it is still in testing.

Probably the metaphlan version installed over conda is also 2.7.
I'll try to install metaphlan 2.9 and try again on Monday.
Reply all
Reply to author
Forward
0 new messages