Mercurial > repos > iuc > seaborn
changeset 0:293a939f28c8 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/seaborn commit 24dc6373560bd5e409fca84154634f5a528001c3
author | iuc |
---|---|
date | Wed, 14 May 2025 08:39:42 +0000 |
parents | |
children | |
files | macros.xml seaborn.xml test-data/mtcars.txt |
diffstat | 3 files changed, 398 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros.xml Wed May 14 08:39:42 2025 +0000 @@ -0,0 +1,87 @@ +<macros> + <token name="@TOOL_VERSION@">0.13.2</token> + <token name="@VERSION_SUFFIX@">0</token> + + <xml name="edam"> + <edam_topics> + <edam_topic>topic_0092</edam_topic> + </edam_topics> + <edam_operations> + <edam_operation>operation_0337</edam_operation> + </edam_operations> + </xml> + + <xml name="requirements"> + <requirements> + <requirement type="package" version="@TOOL_VERSION@">seaborn</requirement> + <yield/> + </requirements> + </xml> + + <xml name="inputs"> + <param argument="--input_data" type="data" format="tsv,tabular,csv,parquet" label="Input data table" help="Provide the input data file in one of the supported formats: TSV, TXT, CSV, or Parquet. This file will be used to generate the plot." /> + </xml> + + <xml name="transformation"> + <param name="transformation" type="select" label="Transformation" help="Choose a transformation function to apply to the numerical data in the input file. This can be useful for scaling or normalizing the data before plotting."> + <option value="lambda x: x" selected="true">no transformation</option> + <option value="np.log10">log10</option> + <option value="np.log2">log2</option> + </param> + </xml> + + <xml name="columns" tokens="header"> + <param name="xcol" type="data_column" data_ref="input_data" label="x-axis" optional="true" use_header_names="@HEADER@" help="Select the column from the input data to use for the x-axis of the plot."/> + <param name="ycol" type="data_column" data_ref="input_data" label="y-axis" optional="true" use_header_names="@HEADER@" help="Select the column from the input data to use for the y-axis of the plot."/> + <section name="advanced_input" title="Advanced"> + <param name="hue" type="data_column" data_ref="input_data" label="hue" optional="true" use_header_names="@HEADER@" help="Select a column to group data by color (hue) in the plot. This is useful for visualizing categorical data."/> + <param name="col" type="data_column" data_ref="input_data" label="column-facetting" optional="true" use_header_names="@HEADER@" help="Select a column to create facets (subplots) along the columns of the plot grid. This is useful for visualizing how data varies across different categories or groups in the selected column."/> + <param name="row" type="data_column" data_ref="input_data" label="row-facetting" optional="true" use_header_names="@HEADER@" help="Select a column to create facets (subplots) along the rows of the plot grid. This allows you to compare data across different categories or groups in the selected column."/> + </section> + </xml> + + <token name="@INIT@"> +import pandas as pd +import seaborn as sns +import numpy as np +import matplotlib.pyplot as plt + +file_name = "$input_data" +file_extension = "$input_data.ext" + +transformation = $transformation +output_format = "png" +output_file = "${output_file}" + +# load and transform data +if file_extension == "csv": + df = pd.read_csv(file_name, index_col=index_col) +elif file_extension in ["tsv", "tabular"]: + df = pd.read_csv(file_name, sep="\t", index_col=index_col) +elif file_extension == "parquet": + df = pd.read_parquet(file_name, index_col=index_col) +else: + raise ValueError(f"Unsupported file format: {file_extension}") +data = df.apply(lambda x: transformation(x) if np.issubdtype(x.dtype, np.number) else x) + </token> + + <xml name="creator"> + <creator> + <person + givenName="Helge" + familyName="Hecht" + url="https://github.com/hechth" + identifier="0000-0001-6744-996X" /> + <organization + url="https://www.recetox.muni.cz/" + email="GalaxyToolsDevelopmentandDeployment@space.muni.cz" + name="RECETOX MUNI" /> + </creator> + </xml> + + <xml name="citation"> + <citations> + <citation type="doi">10.21105/joss.03021</citation> + </citations> + </xml> +</macros> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/seaborn.xml Wed May 14 08:39:42 2025 +0000 @@ -0,0 +1,278 @@ +<tool id="seaborn" name="seaborn" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0" license="MIT"> + <description>generate various plots using seaborn</description> + + <macros> + <import>macros.xml</import> + </macros> + + <expand macro="edam"/> + <expand macro="requirements"/> + <expand macro="creator" /> + + <command detect_errors="exit_code"><![CDATA[ + python3 '${run_script}' + ]]></command> + + <configfiles> + <configfile name="run_script"><![CDATA[ +index_col = False + +@INIT@ + +plot = $plot + +fig = plot( + data, + #if $xcol + x = data.columns.values[$xcol - 1], + #end if + #if $ycol + y = data.columns.values[$ycol - 1], + #end if + #if $hue + hue = data.columns.values[$hue - 1], + #end if + #if $col + col = data.columns.values[$col - 1], + #end if + #if $row + row = data.columns.values[$row - 1], + #end if + #if $legend + legend = $legend, + #end if + #if $kind + kind = '$kind' + #end if +) + +#if $legend_pos +plt.legend(loc='$legend_pos') +#end if + +plt.savefig(f"{output_file}", format=output_format, dpi=300) + ]]></configfile> + </configfiles> + <inputs> + <expand macro="inputs"/> + <expand macro="transformation"/> + + <param name="plot" type="select" label="Plot to choose from seaborn" help="Select the type of plot you want to generate using seaborn. Each option corresponds to a specific seaborn plotting function."> + <option value="sns.scatterplot">scatterplot</option> + <option value="sns.displot">displot</option> + <option value="sns.jointplot">jointplot</option> + <option value="sns.barplot">barplot</option> + <option value="sns.boxplot">boxplot</option> + <option value="sns.violinplot">violinplot</option> + <option value="sns.lmplot">lmplot</option> + <option value="sns.histplot">histplot</option> + </param> + + <conditional name="header"> + <param name="has_header" type="select" display="radio" label="Does your table have a header?" help="Specify whether the input data contains a header row. If yes, column names will be used for selection." refresh_on_change="true"> + <option value="yes" selected="true">yes</option> + <option value="no">no</option> + </param> + <when value="yes"> + <expand macro="columns" header="true" /> + </when> + <when value="no"> + <expand macro="columns" header="false" /> + </when> + </conditional> + + <section name="advanced" title="Advanced Options"> + <param name="kind" type="select" label="Kind specification" optional="true" help="Specify the kind of plot to generate for multi-plot functions like `sns.relplot` or `sns.catplot`."> + <option value="hist">hist</option> + <option value="kde">kde</option> + <option value="reg">reg</option> + <option value="scatter">scatter</option> + <option value="hex">hex</option> + <option value="resid">resid</option> + <option value="ecdf">ecdf</option> + </param> + <param name="legend" type="select" label="Legend" help="Specify the type of legend to display on the plot. Options include 'auto', 'brief', 'full', or None to disable the legend." optional="true"> + <option value="'auto'">auto</option> + <option value="'brief'">brief</option> + <option value="'full'">full</option> + <option value="False">none</option> + <sanitizer invalid_char=""> + <valid initial="string.ascii_letters"> + <add value="'" /> + </valid> + </sanitizer> + </param> + <param name="legend_pos" type="select" optional="true" label="Legend position" help="Choose the position of the legend on the plot. Options include various corners and sides of the plot."> + <option value="center right">center right</option> + <option value="center left">center left</option> + <option value="upper right">upper right</option> + <option value="upper left">upper left</option> + <option value="lower right">lower right</option> + <option value="lower left">lower left</option> + </param> + </section> + </inputs> + <outputs> + <data name="output_file" format="png" label="${tool.name} ${plot} of ${on_string}" /> + </outputs> + <tests> + <!-- Test 1: Generate a scatterplot --> + <test> + <param name="input_data" value="mtcars.txt"/> + <param name="plot" value="sns.scatterplot" /> + <conditional name="header"> + <param name="has_header" value="yes" /> + <param name="xcol" value="2" /> <!-- Column 2: mpg --> + <param name="ycol" value="3" /> <!-- Column 3: cyl --> + </conditional> + <output name="output_file"> + <assert_contents> + <has_image_channels channels="4"/> + <has_image_height height="1440"/> + <has_image_width width="1920" /> + <has_image_center_of_mass center_of_mass="960.65, 718.85" eps="0.1"/> + </assert_contents> + </output> + </test> + + <!-- Test 2: Generate a barplot --> + <test> + <param name="input_data" value="mtcars.txt"/> + <param name="plot" value="sns.barplot" /> + <conditional name="header"> + <param name="has_header" value="yes" /> + <param name="xcol" value="3" /> <!-- Column 3: cyl --> + <param name="ycol" value="2" /> <!-- Column 2: mpg --> + </conditional> + <output name="output_file"> + <assert_contents> + <has_image_channels channels="4"/> + <has_image_height height="1440"/> + <has_image_width width="1920" /> + <has_image_center_of_mass center_of_mass="971.48, 692.18" eps="0.2"/> + </assert_contents> + </output> + </test> + + <!-- Test 3: Generate a boxplot with hue --> + <test> + <param name="input_data" value="mtcars.txt"/> + <param name="plot" value="sns.boxplot" /> + <conditional name="header"> + <param name="has_header" value="yes" /> + <param name="xcol" value="3" /> <!-- Column 3: cyl --> + <param name="ycol" value="2" /> <!-- Column 2: mpg --> + <section name="advanced_input"> + <param name="hue" value="4" /> <!-- Column 4: disp --> + </section> + </conditional> + <output name="output_file"> + <assert_contents> + <has_image_channels channels="4"/> + <has_image_height height="1440"/> + <has_image_width width="1920" /> + <has_image_center_of_mass center_of_mass="957.48, 720.14" eps="0.1"/> + </assert_contents> + </output> + </test> + + <!-- Test 4: Generate a violinplot with advanced options --> + <test> + <param name="input_data" value="mtcars.txt"/> + <param name="plot" value="sns.violinplot" /> + <conditional name="header"> + <param name="has_header" value="yes" /> + <param name="xcol" value="3" /> <!-- Column 3: cyl --> + <param name="ycol" value="2" /> <!-- Column 2: mpg --> + </conditional> + <section name="advanced"> + <param name="legend" value="'brief'" /> + <param name="legend_pos" value="upper right" /> + </section> + <output name="output_file"> + <assert_contents> + <has_image_channels channels="4"/> + <has_image_height height="1440"/> + <has_image_width width="1920" /> + <has_image_center_of_mass center_of_mass="959.80, 716.27" eps="0.1"/> + </assert_contents> + </output> + </test> + + <!-- Test 5: Generate a lmplot with hue --> + <test> + <param name="input_data" value="mtcars.txt"/> + <param name="plot" value="sns.boxplot" /> + <conditional name="header"> + <param name="has_header" value="yes" /> + <param name="xcol" value="2" /> <!-- Column 2: mpg --> + <param name="ycol" value="5" /> <!-- Column 5: hp --> + <section name="advanced_input"> + <param name="hue" value="3" /> <!-- Column 3: cyl --> + </section> + </conditional> + <output name="output_file"> + <assert_contents> + <has_image_channels channels="4"/> + <has_image_height height="1440"/> + <has_image_width width="1920" /> + <has_image_center_of_mass center_of_mass="958.93, 716.80" eps="0.1"/> + </assert_contents> + </output> + </test> + + </tests> + <help><![CDATA[ +.. class:: infomark + +**What it does** + +This tool allows you to generate a variety of plots using the Seaborn library, a Python data visualization library based on Matplotlib. It supports multiple plot types, including scatter plots, bar plots, box plots, and more. The tool is designed to work with tabular data in formats such as TSV, CSV, TXT, or Parquet. + +Seaborn provides a high-level interface for drawing attractive and informative statistical graphics. This tool integrates Seaborn's functionality into Galaxy, enabling users to create publication-quality plots without requiring programming knowledge. + +**Usage** + +1. **Input**: Provide a tabular data file in one of the supported formats (TSV, CSV, TXT, or Parquet). +2. **Plot Type**: Choose the type of plot you want to generate (e.g., scatterplot, barplot, boxplot). +3. **Advanced Options**: Customize the plot further by specifying parameters such as legend type, legend position, and data transformations. +4. **Output**: The tool generates a PNG image of the plot, which can be downloaded or used in further analyses. + +**Example Input** + +Here is an example of a simple input dataset: + ++------------+------------+------------+ +| Category | Value1 | Value2 | ++============+============+============+ +| A | 10 | 20 | ++------------+------------+------------+ +| B | 15 | 25 | ++------------+------------+------------+ +| C | 20 | 30 | ++------------+------------+------------+ + +**Example Output** + +If you select a scatterplot with `Value1` on the x-axis and `Value2` on the y-axis, the tool will generate a scatterplot visualizing the relationship between these two variables. + +**Parameters** + +- **Input Data Table**: Upload your data file in TSV, CSV, TXT, or Parquet format. +- **Plot Type**: Select the type of plot to generate (e.g., scatterplot, barplot, etc.). +- **Legend**: Specify the type of legend to display (e.g., auto, brief, full, or None). +- **Legend Position**: Choose the position of the legend on the plot (e.g., upper right, lower left, etc.). +- **Data Transformation**: Apply transformations such as log10 or log2 to numerical data. + +**Links** + +- For more information about Seaborn, visit the official documentation: https://seaborn.pydata.org/ +- For detailed parameter descriptions, refer to the Galaxy tool documentation. + +**Output** + +The tool generates a PNG file containing the plot. The file can be downloaded or used as input for other tools in Galaxy. + + ]]></help> + <expand macro="citation"/> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/mtcars.txt Wed May 14 08:39:42 2025 +0000 @@ -0,0 +1,33 @@ +brand mpg cyl disp hp drat wt qsec vs am gear carb +Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4 +Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4 +Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1 +Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 +Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2 +Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1 +Duster 360 14.3 8 360 245 3.21 3.57 15.84 0 0 3 4 +Merc 240D 24.4 4 146.7 62 3.69 3.19 20 1 0 4 2 +Merc 230 22.8 4 140.8 95 3.92 3.15 22.9 1 0 4 2 +Merc 280 19.2 6 167.6 123 3.92 3.44 18.3 1 0 4 4 +Merc 280C 17.8 6 167.6 123 3.92 3.44 18.9 1 0 4 4 +Merc 450SE 16.4 8 275.8 180 3.07 4.07 17.4 0 0 3 3 +Merc 450SL 17.3 8 275.8 180 3.07 3.73 17.6 0 0 3 3 +Merc 450SLC 15.2 8 275.8 180 3.07 3.78 18 0 0 3 3 +Cadillac Fleetwood 10.4 8 472 205 2.93 5.25 17.98 0 0 3 4 +Lincoln Continental 10.4 8 460 215 3 5.424 17.82 0 0 3 4 +Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4 +Fiat 128 32.4 4 78.7 66 4.08 2.2 19.47 1 1 4 1 +Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 +Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.9 1 1 4 1 +Toyota Corona 21.5 4 120.1 97 3.7 2.465 20.01 1 0 3 1 +Dodge Challenger 15.5 8 318 150 2.76 3.52 16.87 0 0 3 2 +AMC Javelin 15.2 8 304 150 3.15 3.435 17.3 0 0 3 2 +Camaro Z28 13.3 8 350 245 3.73 3.84 15.41 0 0 3 4 +Pontiac Firebird 19.2 8 400 175 3.08 3.845 17.05 0 0 3 2 +Fiat X1-9 27.3 4 79 66 4.08 1.935 18.9 1 1 4 1 +Porsche 914-2 26 4 120.3 91 4.43 2.14 16.7 0 1 5 2 +Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.9 1 1 5 2 +Ford Pantera L 15.8 8 351 264 4.22 3.17 14.5 0 1 5 4 +Ferrari Dino 19.7 6 145 175 3.62 2.77 15.5 0 1 5 6 +Maserati Bora 15 8 301 335 3.54 3.57 14.6 0 1 5 8 +Volvo 142E 21.4 4 121 109 4.11 2.78 18.6 1 1 4 2