view heatmap2.xml @ 5:3b37b1b1c3a7 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/heatmap2 commit b04b237daba99e6992b27d1b65524744feb07d7d"
author iuc
date Tue, 12 Apr 2022 15:53:40 +0000
parents ca7cb0eaad62
children 566197475670
line wrap: on
line source

<tool id="ggplot2_heatmap2" name="heatmap2" version="@VERSION@">
    <macros>
        <token name="@VERSION@">3.1.1</token>
    </macros>
    <requirements>
        <requirement type="package" version="@VERSION@">r-gplots</requirement>
        <requirement type="package" version="1.1_3">r-rcolorbrewer</requirement>
    </requirements>
    <command detect_errors="exit_code"><![CDATA[
cat '$script' &&
Rscript '$script'
    ]]></command>
    <configfiles>
        <configfile name="script"><![CDATA[
## Setup R error handling to go to stderr
options(show.error.messages=F, error=function(){cat(geterrmessage(), file=stderr()); q("no",1,F)})

## Unify locale settings
loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")

## Import library
library("RColorBrewer")
library("gplots")

input <- read.delim('$input1', sep='\t', header=TRUE)

mat_input <- data.matrix(input[,2:ncol(input)])
rownames(mat_input) <- input[,1]

#if $transform == "none"
    linput <- mat_input
#elif $transform == "log2"
    linput <- log2(mat_input)
#elif $transform == "log2plus1"
    linput <- log2(mat_input+1)
#elif $transform == "log10"
    linput <- log10(mat_input)
#elif $transform == "log10plus1"
    linput <- log10(mat_input+1)
#end if

#if $zscore_cond.zscore == "rows":
    linput <- t(apply(linput, 1, scale))
    colnames(linput) <- colnames(input)
    rownames(linput) <- input[,1]
    scale <- "none"
#elif $zscore_cond.zscore == "cols":
    linput <- apply(linput, 2, scale)
    rownames(linput) <- input[,1]
    scale <- "none"
#elif $zscore_cond.zscore == "none":
    scale <- "$zscore_cond.scale"
#end if

srtCol <- 45
#if $labels == "both"
    rlabs <- NULL
    clabs <- NULL
#elif $labels == "rows"
    rlabs <- NULL
    clabs <- FALSE
    srtCol <- NULL
#elif $labels == "columns"
    rlabs <- FALSE
    clabs <- NULL
#elif $labels == "none"
    rlabs <- FALSE
    clabs <- FALSE
    srtCol <- NULL
#end if

#if $cluster_cond.cluster == "yes":
    dendrogramtoplot <- "$cluster_cond.cluster_cols_rows"
    #if $cluster_cond.cluster_cols_rows == "both"
        reorder_cols <- TRUE
        reorder_rows <- TRUE
    #elif $cluster_cond.cluster_cols_rows == "row"
        reorder_cols <- FALSE
        reorder_rows <- TRUE
    #elif $cluster_cond.cluster_cols_rows == "column"
        reorder_cols <- TRUE
        reorder_rows <- FALSE
    #end if
    hclust_fun <- function(x) hclust(x, method='$cluster_cond.clustering')
    #if $cluster_cond.distance == 'pearson_correlation':
        dist_fun <- function(x) as.dist(1 - cor(t(x)))
    #elif $cluster_cond.distance == 'spearmann_correlation':
        dist_fun <- function(x) as.dist(1 - cor(t(x), method="spearman"))
    #else:
        dist_fun <- function(x) dist(x, method='$cluster_cond.distance')
    #end if
#else:
    dendrogramtoplot <- "none"
    reorder_cols <- FALSE
    reorder_rows <- FALSE
    hclust_fun <- hclust
    dist_fun <- dist
#end if

ncolors <- 50
#if $colorchoice.type == "palettes":
    colused <- brewer.pal(ncolors, "$colorchoice.name")
#elif $colorchoice.type == "two"
    colused <- colorRampPalette(c("$colorchoice.color1", "$colorchoice.color2"))(ncolors)
#elif $colorchoice.type == "three"
    colused <- colorRampPalette(c("$colorchoice.color1", "$colorchoice.color2", "$colorchoice.color3"))(ncolors)
#end if

#if $image_file_format == "pdf":
    pdf(file='$output1')
#else:
    png(file='$output1')
#end if

heatmap.2(linput, dendrogram=dendrogramtoplot, Colv=reorder_cols, Rowv=reorder_rows,
    distfun=dist_fun, hclustfun=hclust_fun, scale = scale, labRow = rlabs, labCol = clabs,
    col=colused, trace="none", density.info = "none", margins=c(8,8),
    main = '$title', key.xlab='$key', keysize=1, cexCol=0.8, cexRow = 0.8, srtCol=srtCol)

dev.off()
        ]]></configfile>
    </configfiles>

    <inputs>
        <param name="input1" type="data" format="tabular"
               label="Input should have column headers - these will be the columns that are plotted and row names."/>
        <param name="title" type="text" format="txt" label="Plot title"/>
        <param name="key" type="text" format="txt" label="key title"/>
        <param name="transform" type="select" label="Data transformation">
            <option value="none">Plot the data as it is</option>
            <option value="log2">Log2(value) transform my data</option>
            <option value="log2plus1">Log2(value+1) transform my data</option>
            <option value="log10">Log10(value) transform my data</option>
            <option value="log10plus1">Log10(value+1) transform my data</option>
        </param>
        <conditional name="zscore_cond">
            <param name="zscore" type="select" label="Compute z-scores prior to clustering">
                <option value="none">Do not compute z-scores</option>
                <option value="rows">Compute on rows</option>
                <option value="cols">Compute on columns</option>
            </param>
            <when value="none">
                <param name="scale" type="select" label="Scale data on the plot (after clustering)" >
                    <option value="none" selected="true">Do not scale my data</option>
                    <option value="row">Scale my data by row</option>
                    <option value="column">Scale my data by column</option>
                </param>
            </when>
            <when value="rows"/>
            <when value="cols"/>
        </conditional>
        <conditional name="cluster_cond">
            <param name="cluster" type="select" label="Enable data clustering">
                <option value="yes">Yes</option>
                <option value="no">No</option>
            </param>
            <when value="yes">
                <param name="cluster_cols_rows" type="select" label="Clustering columns and rows">
                    <option value="both" selected="true">Cluster rows and columns</option>
                    <option value="row">Cluster rows and not columns</option>
                    <option value="column">Cluster columns and not rows</option>
                </param>
                <param name="distance" type="select" label="Distance method" help="The method used to compute the distance (dissimilarity) between both rows and columns. Default: Euclidean" >
                    <option value="euclidean" selected="true">Euclidean</option>
                    <option value="maximum">Maximum</option>
                    <option value="manhattan">Manhattan</option>
                    <option value="canberra">Canberra</option>
                    <option value="binary">Binary</option>
                    <option value="minkowski">Minkowski</option>
                    <option value="pearson_correlation">Pearson's correlation (1 - correlation coefficient)</option>
                    <option value="spearmann_correlation">Spearmann's correlation (1 - correlation coefficient)</option>
                </param>
                <param name="clustering" type="select" label="Clustering method" help="The method used to compute the hierarchical clustering. Default: Complete" >
                    <option value="complete" selected="true">Complete</option>
                    <option value="average">Average (= UPGMA)</option>
                    <option value="ward.D">ward.D</option>
                    <option value="ward.D2">ward.D2</option>
                    <option value="single">single</option>
                    <option value="mcquitty">mcquitty (= WPGMA)</option>
                    <option value="median">median (= WPGMC)</option>
                    <option value="centroid">centroid (= UPGMC)</option>
                </param>
            </when>
            <when value="no"/>
        </conditional>
        <param name="labels" type="select" label="Labeling columns and rows" >
            <option value="both" selected="true">Label my columns and rows</option>
            <option value="rows">Label rows and not columns</option>
            <option value="columns">Label columns and not rows</option>
            <option value="none">Do not label rows or columns</option>
        </param>
        <conditional name="colorchoice">
            <param name="type" type="select" label="Type of colormap to use">
                <option value="palettes">RColorBrewer palettes</option>
                <option value="two">Gradient with 2 colors</option>
                <option value="three">Gradient with 3 colors</option>
            </param>
            <when value="palettes">
                <param name="name" type="select" label="Name of the colormap">
                    <option value="BrBG">BrBG</option>
                    <option value="PiYG">PiYG</option>
                    <option value="PRGn">PRGn</option>
                    <option value="PuOr">PuOr</option>
                    <option value="RdBu">RdBu</option>
                    <option value="RdGy">RdGy</option>
                    <option value="RdYlBu">RdYlBu</option>
                    <option value="RdYlGn">RdYlGn</option>
                    <option value="Spectral">Spectral</option>
                    <option value="Blues">Blues</option>
                    <option value="BuGn">BuGn</option>
                    <option value="BuPu">BuPu</option>
                    <option value="GnBu">GnBu</option>
                    <option value="Greens">Greens</option>
                    <option value="Greys">Greys</option>
                    <option value="Oranges">Oranges</option>
                    <option value="OrRd">OrRd</option>
                    <option value="PuBu">PuBu</option>
                    <option value="PuBuGn">PuBuGn</option>
                    <option value="PuRd">PuRd</option>
                    <option value="Purples">Purples</option>
                    <option value="RdPu">RdPu</option>
                    <option value="Reds">Reds</option>
                    <option value="YlGn">YlGn</option>
                    <option value="YlGnBu">YlGnBu</option>
                    <option value="YlOrBr">YlOrBr</option>
                    <option value="YlOrRd">YlOrRd</option>
                </param>
            </when>
            <when value="two">
                <param name="color1" type="color" value="#ffffff" label="First color" />
                <param name="color2" type="color" value="#ff0000" label="Second color" />
            </when>
            <when value="three">
                <param name="color1" type="color" value="#0000ff" label="First color" />
                <param name="color2" type="color" value="#ffffff" label="Second color" />
                <param name="color3" type="color" value="#ff0000" label="Third color" />
            </when>
        </conditional>
        <param name="image_file_format" type="select" label="Output format">
            <option value="pdf">PDF</option>
            <option value="png">PNG</option>
        </param>
    </inputs>
    <outputs>
        <data name="output1" format="pdf">
            <change_format>
                <when input="image_file_format" value="png" format="png" />
            </change_format>
        </data>
    </outputs>
    <tests>
        <test>
            <param name="input1" value="mtcars.txt"/>
            <param name="cluster" value="yes"/>
            <param name="type" value="two"/>
            <output name="output1" file="result1.pdf" compare="sim_size"/>
        </test>
        <test>
            <param name="input1" value="mtcars.txt"/>
            <param name="cluster" value="no"/>
            <param name="image_file_format" value="png"/>
            <output name="output1" file="result2.png" compare="sim_size"/>
        </test>
        <test>
            <param name="input1" value="mtcars.txt"/>
            <param name="zscore" value="cols"/>
            <param name="cluster" value="yes"/>
            <param name="cluster_cols_rows" value="row"/>
            <param name="labels" value="rows"/>
            <param name="type" value="three"/>
            <param name="image_file_format" value="png"/>
            <output name="output1" file="result3.png" compare="sim_size"/>
        </test>
        <test>
            <param name="input1" value="mtcars.txt"/>
            <param name="cluster" value="yes"/>
            <param name="distance" value="pearson_correlation"/>
            <param name="type" value="two"/>
            <output name="output1" file="result1pearson.pdf" compare="sim_size"/>
        </test>
    </tests>
    <help><![CDATA[
This tool employs the heatmap.2 function from the R gplots package and will generate a heatmap of your data. If clustering is enabled, the heatmap uses the Euclidean distance method and the Complete hierarchical clustering method by default.

Input data should have row labels in the first column and column labels. For example, the row labels (the first column) should represent gene IDs and the column labels should represent sample IDs.
    ]]></help>
    <citations>
    </citations>
</tool>