LangilleLab / microbiome_helper

A repository of bioinformatic scripts, SOPs, and tutorials for analyzing microbiome data.
GNU General Public License v3.0
430 stars 205 forks source link

Problem running FAPROTAX collapse_table.py in Python 3.6 #27

Closed brookeweigel closed 6 years ago

brookeweigel commented 6 years ago

Hello!

I'm trying to run Faprotax on a .biom file from QIIME2. I am using Python 3.6.3. I got this code to work before, but that was was Python 2.7, and my default python is now set to 3.6. I'm not sure if this changed anything, but I am now getting an error when I try to run the script. It looks like it is a syntax issue within the collapse_table.py script:

Brookes-MacBook-Pro:Faprotax_16S_function brookeweigel$ python collapse_table.py -i Nereocystis-feature-table.biom -o functional_table_Nereocystis.tsv -g FAPROTAX.txt --collapse_by_metadata 'taxonomy' -v

File "collapse_table.py", line 1212 print "%sERROR: Duplicate group names. The following %d group names were used multiple times:\n%s %s\n"%(args.verbose_prefix,len(duplicate_group_names),args.verbose_prefix,("\n"+args.verbose_prefix+" ").join(duplicate_group_names)) ^ SyntaxError: invalid syntax

Any help would be much appreciated! Thanks! :)

gavinmdouglas commented 6 years ago

Yes that is a syntax difference between python 2 and 3 - print needs to be used as a function in python 3 (i.e. there need to be parentheses around what you are printing) as described here: https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function.

You can run the command with python 2.7 to avoid this error. You might want to look into conda, which allows you to manage multiple environments with different python versions: https://conda.io/docs/user-guide/getting-started.html

brookeweigel commented 6 years ago

Thanks! It works now, in Python 2.7. For anyone else struggling with a Miniconda default Python 3, this is how I created a new virtual environment for Python 2.7, and ran the code in that environment:

Set up a new virtual env called “Python2” and install python 2.7 there

$ conda create -n python2 python=2.7 anaconda

To activate this environment, use:

> source activate python2

#

To deactivate an active environment, use:

> source deactivate

#

install pip into the python2 env

$ conda install -n python2 pip

$ source activate python2 (python2) $ python --version Python 2.7.14 :: Anaconda custom (64-bit)

(python2) $ pip install biom-format

Run FAPROTAX command, now in Python 2

(python2) $ python ./collapse_table.py -i Nereocystis-feature-table.biom -o functional_table_Nereocystis.tsv -g FAPROTAX.txt --collapse_by_metadata 'taxonomy' -v

gavinmdouglas commented 6 years ago

Glad to hear you have it working now and thanks for posting your pipeline!