view heatmap2.xml @ 7:53460afd5115 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/heatmap2 commit 48958ce8d7a3b630dfcca78d12222ac67f1602fe
author iuc
date Wed, 08 Mar 2023 14:11:15 +0000
parents 566197475670
children 374e9062d874
line wrap: on
line source

<tool id="ggplot2_heatmap2" name="heatmap2" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="22.01">
    <macros>
        <token name="@TOOL_VERSION@">3.1.3</token>
        <token name="@VERSION_SUFFIX@">0</token>
    </macros>
    <requirements>
        <requirement type="package" version="@TOOL_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)[2:ncol(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 <- 30
#if $labels == "both"
    rlabs <- NULL
    clabs <- NULL
    label_margins <- c(8,8)
#elif $labels == "rows"
    rlabs <- NULL
    clabs <- FALSE
    srtCol <- NULL
    label_margins <- c(1,8)
#elif $labels == "columns"
    rlabs <- FALSE
    clabs <- NULL
    label_margins <- c(8,1)
#elif $labels == "none"
    rlabs <- FALSE
    clabs <- FALSE
    srtCol <- NULL
    label_margins <- c(1,1)
#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
        layout_matrix <- rbind(c(4,3), c(2,1))
        key_margins <- list(mar=c(4,0.5,2,1))
        lheight <- c(1, 5)
        lwidth <- c(1,3)
    #elif $cluster_cond.cluster_cols_rows == "row"
        reorder_cols <- FALSE
        reorder_rows <- TRUE
        layout_matrix <- rbind(c(3,4), c(2,1))
        key_margins <- list(mar=c(3,5,1,10))
        lheight <- c(1,7)
        lwidth <- c(1,3)
    #elif $cluster_cond.cluster_cols_rows == "column"
        reorder_cols <- TRUE
        reorder_rows <- FALSE
        layout_matrix <- rbind(c(4), c(3), c(1), c(2))
        key_margins <- list(mar=c(4,0.5,2,1))
        lheight <- c(0.3, 2, 6, 1)
        lwidth <- c(1)
    #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
    layout_matrix <- rbind(c(0,4,3), c(0,1,2))
    key_margins <- list(mar=c(3,5,1,10))
    lheight <- c(1,7)
    lwidth <- c(1,7,1)
    hclust_fun <- hclust
    dist_fun <- dist
    label_margins <- c(8,2)
#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', res=240, height=2000, width=2000)
#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=label_margins,
    main = '$title', cexCol=0.8, cexRow=0.8, srtCol=srtCol,
    keysize=3, key.xlab='$key', key.title='', key.par=key_margins,
    lmat=layout_matrix, lhei=lheight, lwid=lwidth)

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" selected="true">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" selected="true">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" selected="true">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" selected="true">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" selected="true">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>
        <test>
            <param name="input1" value="mtcars.txt"/>
            <param name="zscore" value="rows"/>
            <param name="type" value="three"/>
            <param name="image_file_format" value="png"/>
            <output name="output1" file="result4.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="scale" value="row"/>
            <param name="type" value="three"/>
            <param name="image_file_format" value="png"/>
            <output name="output1" file="result5.png" compare="sim_size"/>
        </test>
        <test>
            <param name="input1" value="mtcars.txt"/>
            <param name="cluster" value="yes"/>
            <param name="distance" value="spearmann_correlation"/>
            <param name="scale" value="column"/>
            <param name="type" value="three"/>
            <param name="image_file_format" value="png"/>
            <output name="output1" file="result6.png" 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>
        <citation type="bibtex">
            @ONLINE{heatmap2,
                title = {heatmap.2: Enhanced Heat Map},
                url = {https://rdocumentation.org/packages/gplots/versions/3.1.3/topics/heatmap.2}
            }
        </citation>
    </citations>
</tool>