Hi everyone,
I’m trying to make a new tool on my local Galaxy using python.
I managed to create the python script and the xml file for the tool:
<tool id="get_pheno" name="Get phenotypes" version="0.1.0">
<description>for a gene from IMPC</description>
<requirements>
<requirement type="package">tabulate</requirement>
<requirement type="package">IPython</requirement>
</requirements>
<command>python3 '${__tool_directory__}/get_pheno.py' '$input' '$output'</command>
<inputs>
<param name="input" type='text' label='Input gene:'/>
</inputs>
<outputs>
<data format="tabular" name="output" />
</outputs>
<help>
This tool retrieves a list of phenotypes related to a gene entered by the user. The input must be an MGI id.
</help>
</tool>
And this is the code I’m using:
import sys
import subprocess
import requests
import tabulate
from IPython.display import HTML, display
impc_api_url = "https://www.gentar.org/impc-dev-api/"
impc_api_search_url = f"{impc_api_url}/genes"
impc_api_gene_bundle_url = f"{impc_api_url}/geneBundles"
# 1-Given a gene id, retrieve all the phenotypes related to it (id and name)
mgi_accession_id = str(sys.argv[1])
gene_url = f"{impc_api_search_url}/{mgi_accession_id}"
gene_data = requests.get(gene_url).json()
p_list = gene_data['significantMpTermNames']
display(HTML(tabulate.tabulate([i for i in p_list], headers="Phenotype Name", tablefmt='html')))
When running the tool, Galaxy is retrieving me this error:
Traceback (most recent call last):
File "/Users/.../galaxy/tools/personal_tools/get_pheno.py", line 4, in <module>
import tabulate
ModuleNotFoundError: No module named 'tabulate'
Now, looking in the admin section for the dependencies, I can see that the two packages are signed as managed by conda.
How can I solve this error?
Thank you very much for the help
EDIT: By adding the version number to the packages it seems that everything it’s fine from the dependencies manager, but now I’m getting this error:
Conda dependency seemingly installed but failed to build job environment.
Debugging the error is not so easy (for me) but for now you can try this and maybe someone else gives a better answer:
Try to activate the environment (with the same conda that galaxy is using) from the command line (it starts with ‘mulled-v1-’) and try to execute your script. Also inside that evironment check the python version. I have the feeling you need to add python as a requirement.
Thank you for your reply. For the input part I found a solution on my own and it’s working as intended.
Unfortunately I’m still having issues with the packages. I have the exact same error by using python as additional requirement. And again in the dependencies manager it says that all the packages are correctly installed.
(I see your edit now and removed my previous answer)
Did you let galaxy install conda or you pointed to an existing installation? And which version of galaxy are you using? And do you have other tools that do work?
Not 100% sure if it was the case with this specific error (I am not a galaxy developer). But removing the environment or packages and re-execute the tool can help. But this is a quick trick and dependend on the version I thought.
I’m using the last version and I let Galaxy to install Conda. Moreover, I tried to delete and reinstall Galaxy but again in the manager it says that all dependencies are installed but when I run the tool it says that “tabulate” was not found.
I tried other tools but they are working normally.
I don’t know why but without changing anything the old error just come back…
Using the last command you suggested me I got this:
/Users/.../Desktop/Galaxy/galaxy/.venv/bin/python
Traceback (most recent call last):
File "/Users/andrea/Desktop/Galaxy/galaxy/tools/personal_tools/get_pheno.py", line 3, in <module>
import tabulate
ModuleNotFoundError: No module named 'tabulate
I’m adding the xml code here since I can’t edit the original post:
<tool id="get_pheno" name="Get phenotypes" version="0.1.0">
<description>for a gene from IMPC</description>
<requirements>
<requirement type="package" version="3.8">python</requirement>
<requirement type="package" version="0.8.9">tabulate</requirement>
<requirement type="package" version='7.12.0'>IPython</requirement>
</requirements>
<command><![CDATA[which python; python '${__tool_directory__}/get_pheno.py' '$input' '$output']]></command>
<inputs>
<param name="input" type='text' label='Input gene:'/>
</inputs>
<outputs>
<data format="tabular" name="output" />
</outputs>
<help>
This tool retrieves a list of phenotypes related to a gene entered by the user. The input must be an MGI id.
</help>
</tool>
So the tool is using the python installation of the virtualenv, instead of the conda package. So now we know the problem. I do not know a solution on top of my head now. But will think about it, my very first hunch was a problem with conda but you said everything was installed and you see the packages in the manage dependencies page.
If you start galaxy with the command sh run.sh --daemon by default a galaxy.log file will be made. Maybe if you start galaxy like that and execute the tool again this log file will give more hints.
I’m not sure about this because I’m new to Galaxy too. From the dependencies screen I can see that the packages are installed and they are managed by Conda.
In the Galaxy yml file I also setted conda_auto_init and conda_auto_install on true.
EDIT: By changing the default settings in the galaxy.yml file I’m no more able to install new dependencies and also Galaxy cannot find the already installed ones
You can start galaxy with the command sh run.sh --daemon this will start galaxy in the background and by default it creates the log file galaxy.log. To stop galaxy you can use the command sh run.sh --stop-daemon.
oke, there is one last thing I could think off (considering you mostly use default settings).
When you start galaxy from the commandline do you see something like (base) at the beginning of the line where you type in your command? If yes, first use command"
oke, well starting galaxy while you are in the base environment mostly causes the error you having. So you completely stopped galaxy, made sure you are not in base, started galaxy again. What is the output of which python?
Looking in the log file this time the package not recognized it’s “requests” which is the one before “tabulate” in the code. By adding it to the requirements, if I go to the “manage dependencies” tab here I have:
For now I would recommend to turn off galaxy, remove the galaxy.log file and start it again (run.sh --daemon)
Then you can try to remove the environment or/and packages from the admin menu (uninstall). It is possible that uninstallation does not work but we will see that later. And after that you can try to execute the tool again. If it does not work there should be something usefull in the log file.