PNG as output of a tool

Hi everybody,
I’m writing the Python code for a tool that taking a matrix as input, it returns an heatmap as result.
When running the tool on Galaxy I get this error:

Traceback (most recent call last):
  File "/Users/andrea/Desktop/galaxy/tools/personal_tools/sys_workflow/", line 16, in <module>
  File "/Users/andrea/Desktop/galaxy/database/dependencies/_conda/envs/mulled-v1-e8e5c838ec73328e9b82c3fbfb3ba227afa87188721e8f9187093dbc4fdd3cb3/lib/python3.9/site-packages/seaborn/", line 65, in savefig
    self.figure.savefig(*args, **kwargs)
  File "/Users/andrea/Desktop/galaxy/database/dependencies/_conda/envs/mulled-v1-e8e5c838ec73328e9b82c3fbfb3ba227afa87188721e8f9187093dbc4fdd3cb3/lib/python3.9/site-packages/matplotlib/", line 3046, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/andrea/Desktop/galaxy/database/dependencies/_conda/envs/mulled-v1-e8e5c838ec73328e9b82c3fbfb3ba227afa87188721e8f9187093dbc4fdd3cb3/lib/python3.9/site-packages/matplotlib/", line 2259, in print_figure
    canvas = self._get_output_canvas(backend, format)
  File "/Users/andrea/Desktop/galaxy/database/dependencies/_conda/envs/mulled-v1-e8e5c838ec73328e9b82c3fbfb3ba227afa87188721e8f9187093dbc4fdd3cb3/lib/python3.9/site-packages/matplotlib/", line 2188, in _get_output_canvas
    raise ValueError(
ValueError: Format 'dat' is not supported (supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff)

I think that the problem is that Galaxy is passing a dat file as storage for the output.
In the xml file I specified that the output should be a png file but it seems to not be enough, how can I solve this?
Here’s the code:

xml file:

<tool id="sys_heatmap_tool" name="Heatmap " version="0.1.0">
  <description>of phenotype counts</description>
    <requirement type="package">seaborn</requirement>
	<requirement type="package">pandas</requirement>
	  <![CDATA[python3 "$__tool_directory__/" '$input' '$cluster' '$heatmap_out']]>
          <param name="input" type="data" label="Input file:" help="Enter the matrix with the counts of phenotypes"/>
		  <param name="cluster" type="select" label="Indicate which method use for clustering:">
			  <option value="single">single</option>
			  <option value="complete">complete</option>
			  <option value="average">average</option>
			  <option value="weighted">weighted</option>
			  <option value="centroid">centroid</option>
			  <option value="median">median</option>
		  <param name="dist" type="text" label="Distance metric to use for the data:" help="Enter the desired metrics"/>
	  <data format="png" name="heatmap_out" file="heatmap.png" label="Pheno count heatmap"/>
	  **What it does**
	  Given a matrix with counts of phenotypes, the tools retrieves the corresponding heatmap with clustering.
	  There user can choose between different methods of clustering:
	  More info about those metods can be found at:
	  The default distance used for clusters is the euclidean. The user can enter a different distance metric from here:

python code:

import sys
import seaborn as sns
import pandas as pd

mat = pd.read_csv(sys.argv[1], sep="\t", index_col=0) = 'MGI_id' = 'phen_sys'


s = sns.clustermap(mat,row_cluster=True,col_cluster=False, method=clust, cbar_pos=(0.01,0.01,0.01,0.2), cmap="mako")

Thank you for the help.

You can do something like:



<data format="png" name="output" from_work_dir="output.png" label="Pheno count heatmap" />


shutil.copyfile("output.png", sys.argv[2])
1 Like

Thank you, this works perfectly

1 Like