Hi everybody,
finally I managed to load my custom tool into Galaxy. What I need is give as input the ID of a gene and retrieve some data to be stored/displayed in a table.
Now my python code is storing this table in a tab file but I’m not able to display it in Galaxy.
That’s my 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" version="3.8">python</requirement>
<requirement type="package" version="2.18.4">requests</requirement>
<requirement type="package" version="0.8.9">tabulate</requirement>
<requirement type="package" version='8.0.1'>IPython</requirement>
</requirements>
<command><![CDATA[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" label='${tool.name} on ${input}' />
</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>
I tried substituting “data” with “output” but it’s not workning.
How can I get the output as a table?
I already tried to read some documentation but I didn’t find anything useful for me.
Thank you for the help
The current XML has a few problems it could help uncover. One simple example: single quotes instead of double around a requirement version.
As a quick solution, maybe try using the ToolFactory tool instead? You could use it directly (only) or create the wrapper that way and then compare it to what you have now.
ToolFactory is itself a tool – one that creates other tools, and it makes use of Planeno. See the tutorials for the how-to. It is available to install from the Main Toolshed: https://toolshed.g2.bx.psu.edu/. It isn’t hosted on public Galaxy servers for security reasons but it would be fine to install/use in your own private Galaxy server that isn’t exposed to the internet publically.
Thank you but I would prefer to not use external tools to program mine, also because this script it’s only a test, later my tool will be way more complex so I’m not sure I can use Planemo or ToolFactory.
Is there any way to better understand where is the error? Because watching other tools I can’t understand where is the difference… I setted the output in the xml file as the other tools and my python code it’s both printing the result (so I can actually see that I have the correct one in the info tab) and saving it in a tab file but I’m not able in any way to have it visible in the “view data” tab
How do you know that the tool even works? Here we established that you already have version conflicts:Galaxy local python Module Not Found Error
And because the tool will be executed in the background in a conda environment you need to execute python instead of python3.
Try to make a simple working “test” tool first. Your XML could be something like:
I managed to solve the error and now the tool is running fine (at the end of the job it is green).
I know that it is working in the correct way because if I print the result I can see the list in the “edit attributes” tab.
Here’s the code of my python script:
import sys
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)
def stop_err(msg):
sys.exit(msg)
def main():
try:
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']
textfile = open("output.tab", "w+")
for element in p_list:
textfile.write(element + "\t")
print(element)
textfile.close()
except Exception as ex:
stop_err('Error running get_pheno.py\n' + str(ex))
sys.exit(0)
if __name__ == "__main__":
main()