Hclust2: ImportError: No module named matplotlib.ticker

Dear bioBakery Team,

I am trying to run your Metaphlan3 Tutorial (https://github.com/biobakery/biobakery/wiki/metaphlan3) on own datasets that I have been QC’d by KneadData. When I want to generate a heatmap utilizing hclust2 I am running into a Traceback:

$ hclust2.py -i TRIAL_1_profiled_species.txt -o TRIAL_1_profiled_species.png

Traceback (most recent call last):
File “/home/plichtubuntu/miniconda2/envs/hlcust2_env/bin/hclust2.py”, line 5, in
import matplotlib.ticker as ticker
ImportError: No module named matplotlib.ticker

I am using Ubuntu 20.04 and Miniconda and all tools have been installed using conda. I created different environments for KneadData (v0.7.6), Metaphlan3 (v3.0 with db mpa_v30_CHOCOPhlAn_201901) and hclust2 (v0.99). I also tried installing hclust2 into the Metaphlan3 env, but it tells me there conflicts due to python3 and python2.

Can you help me to solve this problem?

Thanks a lot and enhoy your weekend,
Philipp

Hi Philipp,
Can you open a python console using the interpreter installed in the environment and check if the import line (import matplotlib.ticker as ticker) works?
I’ve tried to install in a new clean conda env hclust2 from bioconda and I can run it without any problem.

Hey Francesco,

thanks for your fast reply! I Am very new to conda/python etc., so I hope I did everything right:

I opened a terminal and activated the hclust2 environment. Next I searched for the python PATH by using which python and executed it. In the interactive python terminal I run

import matplotlib.ticker as ticker

Matplotlib seems correctly installed since the library was imported successfully. Could you try reinstalling hclust2 in a new and clean environment?

conda env remove -y -n hlcust2_env
conda create -y -n hclust2 python=2.7
conda activate hclust2
conda install -c bioconda hclust2

I removed the old hclust2_env and created a new one using exactly your commands. Now I am receiving this error:

I used the same command as in my first post:
$ hclust2.py -i TRIAL_1_profiled_species.txt -o TRIAL_1_profiled_species.png

I played around with the system $PATH variables and to me it seems there is something messed up. I installed a clean Virtual Machine with Ubuntu 20.04 and installed hclust2, metaphlan3 and graphlan each in new and clean conda environments.

Again, I received the same Traceback as shown in my last post when running hclust2.py from the hlcust2_environment. anaconda3/envs/hclust2_env/bin is in the $PATH.
After adding adding the ./graphlan_env to the $PATH, I receive the same traceback.

Now I added ./graphlan_env/bin to the $PATH and I see the following:

After adding ./metaphlan3_env and ./metaphlan3_env/bin to the $PATH, I again receive the traceback from my previous post:

Might there be something wrong with the system variable $PATH?

Hi Philipp,
manual append of paths into $PATH with conda is not advised, in this case, hclust2.py will use the python interpreter installed into the graphlan environment.

The ValueError is raised when the hierarchy clustering is performed and some NA are included, you should try changing --flinkage and --slinkage or suppress the hierarchy clustering.

You need a file named init.py (two underscores on each side) in every folder in the hierarchy. This is what python looks for to know that it should access a particular folder. The files are meant to contain initialization instructions but even if you create them empty this will solve it. To get rid of this error “ImportError: No module named”, you just need to create init.py in the appropriate directory and everything will work fine.