view ggplot_point.xml @ 13:3b12bf9b4b87 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ggplot2 commit d7460b880c9b329465b1616d1e6ab33d45f3893c
author iuc
date Tue, 24 Jan 2023 15:41:22 +0000
parents 5fe1dc76176e
children
line wrap: on
line source

<tool id="ggplot2_point" name="Scatterplot with ggplot2" version="@TOOL_VERSION@+galaxy1" profile="20.01">
    <expand macro="bio_tools"/>
    <macros>
        <import>macros.xml</import>
        <token name="@SIMPLE_GGLINE@">gg_line = geom_line(size=1, alpha=1, gg_factor)</token>
    </macros>
    <expand macro="requirements">
        <requirement type="package" version="2.1.0">r-svglite</requirement>
    </expand>
    <command detect_errors="exit_code"><![CDATA[
cat '$script' &&
Rscript '$script'
    ]]></command>
    <configfiles>
        <configfile name="script"><![CDATA[
@R_INIT@

## Import library
library(ggplot2)

@XY_SCALING@

@THEME@

@LEGEND@

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

## renaming columns so ggplot can use them
names(input)[$xplot] <- "xcol"
names(input)[$yplot] <- "ycol"

## choosing whether to plot data as multiple groups on one plot(factoring) OR multiple groups on different plots
#if $adv.factor.factoring == "Multiple"
     gg_facet = facet_wrap( ~ factor)
     gg_factor = NULL
     color_scale = NULL
     #if $adv.type_conditional.type_options == "lines":
        @SIMPLE_GGLINE@
     #elif $adv.type_conditional.points.pointoptions == "default"
        gg_point = geom_point(size=1, alpha=1, gg_factor)
        @SIMPLE_GGLINE@
     #else
        gg_point = geom_point(size=$adv.type_conditional.points.size, alpha=$adv.type_conditional.points.alpha, colour='$adv.type_conditional.points.pointcolor', shape=as.numeric('$adv.type_conditional.points.shape'))
        gg_line = geom_line(size=$adv.type_conditional.points.size, alpha=$adv.type_conditional.points.alpha, colour='$adv.type_conditional.points.pointcolor', shape=as.numeric('$adv.type_conditional.points.shape'))
     #end if

    names(input)[$adv.factor.factorcol] <- "factor"

#elif $adv.factor.factoring == "Single"
    gg_facet = NULL
    gg_factor = aes(colour=factor(factor))

    #if $adv.type_conditional.type_options == "lines":
        @SIMPLE_GGLINE@
    #elif $adv.type_conditional.points.pointoptions == "default"
        gg_point = geom_point(size=1, alpha=1, gg_factor)
        @SIMPLE_GGLINE@
    #else
        gg_point = geom_point(size=$adv.type_conditional.points.size, alpha=$adv.type_conditional.points.alpha, gg_factor, shape=as.numeric('$adv.type_conditional.points.shape'))
        gg_line = geom_line(size=$adv.type_conditional.points.size, alpha=$adv.type_conditional.points.alpha, gg_factor, shape=as.numeric('$adv.type_conditional.points.shape'))
    #end if

    #if $adv.factor.colororder == 1
        color_scale = scale_colour_hue(direction='$adv.factor.colororder')
    #else
        color_scale = scale_color_brewer(palette='$adv.factor.colors', direction='$adv.factor.colororder')
    #end if

    names(input)[$adv.factor.factorcol] <- "factor"
#else
    gg_facet = NULL
    gg_factor = NULL
    color_scale = NULL

    #if $adv.type_conditional.type_options == "lines":
        @SIMPLE_GGLINE@
    #elif $adv.type_conditional.points.pointoptions == "default"
        gg_point = geom_point(size=1, alpha=1, gg_factor)
        @SIMPLE_GGLINE@
    #else
        gg_point = geom_point(size=$adv.type_conditional.points.size, alpha=$adv.type_conditional.points.alpha, colour='$adv.type_conditional.points.pointcolor', shape=as.numeric('$adv.type_conditional.points.shape'))
        gg_line = geom_line(size=$adv.type_conditional.points.size, alpha=$adv.type_conditional.points.alpha, colour='$adv.type_conditional.points.pointcolor', shape=as.numeric('$adv.type_conditional.points.shape'))
    #end if
#end if

@TRANSFORM@

##axis label custization
#if $adv.axis_title_customization.axis_customization == "default"
    gg_axistitle = theme(axis.title = element_text(color = NULL, size = NULL, face = NULL))
#else
    gg_axistitle = theme(axis.title = element_text(color = '$adv.axis_text_customization.color', size = $adv.axis_text_customization.size, face = '$adv.axis_text_customization.face'))
#end if

##axis text(tick) custization
#if $adv.axis_text_customization.axis_customization == "default"
    gg_axistext = theme(axis.text = element_text(color = NULL, size = NULL, face = NULL))
#else
    gg_axistext = theme(axis.text = element_text(color = '$adv.axis_text_customization.color', size = $adv.axis_text_customization.size, face = '$adv.axis_text_customization.face'))
#end if

##plot title custimization
#if $adv.plot_title_customization.axis_customization == "default"
    gg_plottitle = theme(plot.title = element_text(color = NULL, size = NULL, face = NULL))
#else
    gg_plottitle = theme(plot.title = element_text(color='$adv.axis_text_customization.color', size=$adv.axis_text_customization.size, face='$adv.axis_text_customization.face'))
#end if

## grid line customization
#if $adv.gridlinecust == "default"
    gg_gridline = NULL
#elif $adv.gridlinecust == "hidemajor"
    gg_gridline = theme(panel.grid.major = element_blank())
#elif $adv.gridlinecust == "hideminor"
    gg_gridline = theme(panel.grid.minor = element_blank())
#elif $adv.gridlinecust == "hideboth"
    gg_gridline = theme(panel.grid.minor = element_blank(), panel.grid.major = element_blank())
#end if

## choose between graph types (points/lines/both)
#if $adv.type_conditional.type_options == "points"
    gg_line = NULL
#elif $adv.type_conditional.type_options == "lines"
    gg_point = NULL
#end if

#this is the actual ggplot command to make the final plot(s)
plot_out <- ggplot(input, aes(xcol, ycol)) + gg_point + gg_line + gg_facet +
    gg_theme + gg_scalex + gg_scaley + color_scale + gg_legend + ggtitle('$title') + xlab('$xlab') + ylab('$ylab')+
    gg_axistitle + gg_axistext + gg_plottitle + gg_gridline

@SAVE_OUTPUT@
        ]]></configfile>
    </configfiles>
    <inputs>
        <param name="input1" type="data" format="tabular" label="Input in tabular format" />
        <param name="xplot" type="integer" value="8" label="Column to plot on x-axis" />
        <param name="yplot" type="integer" value="9" label="Column to plot on y-axis" />

        <expand macro="title" />
        <expand macro="xy_lab" />
        <section name="adv" title="Advanced options">
            <conditional name="type_conditional">
                <param name="type_options" type="select" label="Type of plot" >
                        <option value="points">Points only (default)</option>
                        <option value="lines">Lines only </option>
                        <option value="pointslines">Points and Lines</option>
                </param>
                <when value ="points">
                    <expand macro="points_options"/>
                </when>
                <when value="pointslines">
                    <expand macro="points_options"/>
                </when>
                <when value="lines"/>
            </conditional>
            <conditional name="factor">
                <param name="factoring" type="select" label="Plotting multiple groups" >
                    <option value="Default" selected="true">No thanks - just plot the data as one group</option>
                    <option value="Single">Plot multiple groups of data on one plot</option>
                    <option value="Multiple">Plot multiple groups of data on individual plots</option>
                </param>
                <when value="Default">
                    <!--Do nothing here -->
                </when>
                <when value="Single">
                    <param name="factorcol" type="integer" value="1" label="column differentiating the different groups" />
                    <expand macro="colors" />
                    <param name="colororder" type="select" label="Reverse color scheme" >
                        <option value="1">Default order of color scheme</option>
                        <option value="-1">Reverse the order of my color scheme</option>
                    </param>
                </when>
                <when value="Multiple">
                    <param name="factorcol" type="integer" value="1" label="column differentiating the different groups" />
                </when>
            </conditional>
            <conditional name="axis_title_customization">
                <expand macro="axis_customization" label="Axis title options" />
            </conditional>
            <conditional name="axis_text_customization">
                <expand macro="axis_customization" label="Axis text options" />
            </conditional>
            <conditional name="plot_title_customization">
                <expand macro="axis_customization" label="Plot title options" />
            </conditional>
            <param name="gridlinecust" type="select" label="Grid lines">
                <option value="default">Default grid lines</option>
                <option value="hidemajor">Hide major grid lines</option>
                <option value="hideminor">Hide minor grid lines</option>
                <option value="hideboth">Hide major and minor grid lines</option>
            </param>
            <expand macro="transform" />
            <expand macro="xy_scaling" />
            <expand macro="theme" />
            <expand macro="legend" />
        </section>
        <section name="out" title="Output Options" expanded="true">
            <expand macro="dimensions" />
        </section>
    </inputs>
    <outputs>
        <expand macro="additional_output" />
    </outputs>
    <tests>
        <test>
            <param name="input1" value="mtcars.txt" ftype="tabular" />
            <param name="additional_output_format" value="pdf" />
            <output name="output2" file="ggplot_point_result1.pdf" compare="sim_size" />
        </test>
        <!-- Test text options-->
        <test>
            <param name="input1" value="mtcars.txt" ftype="tabular" />
            <section name="adv">
                <conditional name="type_conditional">
                    <param name="type_options" value="points"/>
                    <conditional name="points">
                        <param name="pointoptions" value="default"/>
                    </conditional>
                </conditional>
                <conditional name="axis_text_customization">
                    <param name="axis_customization" value="defined"/>
                    <param name="color" value="red"/>
                </conditional>
            </section>
            <param name="additional_output_format" value="pdf" />
            <output name="output2" file="ggplot_point_result2.pdf" compare="sim_size" />
        </test>
        <!-- Test lines option -->
        <test>
            <param name="input1" value="mtcars.txt" ftype="tabular" />
            <section name="adv">
                <conditional name="type_conditional">
                    <param name="type_options" value="lines"/>
                </conditional>
            </section>
            <param name="additional_output_format" value="pdf" />
            <output name="output2" file="ggplot_line_result1.pdf" compare="sim_size" />
        </test>
         <!-- Test defined point options options-->
        <test>
            <param name="input1" value="mtcars.txt" ftype="tabular" />
            <section name="adv">
                <conditional name="type_conditional">
                    <param name="type_options" value="points"/>
                    <conditional name="points">
                        <param name="pointoptions" value="defined"/>
                        <param name="size" value="2"/>
                        <param name="alpha" value="0.5"/>
                        <param name="pointcolor" value="gold"/>
                        <param name="shape" value="6"/>
                    </conditional>
                </conditional>
                <conditional name="axis_text_customization">
                    <param name="axis_customization" value="defined"/>
                    <param name="color" value="red"/>
                </conditional>
            </section>
            <param name="additional_output_format" value="pdf" />
            <output name="output2" file="ggplot_point_result3.pdf" compare="sim_size" />
        </test>
    </tests>
    <help><![CDATA[
This tool will generate a scatterplot representing data from two groups/conditions.

The input data should be in tabular format and the user can determine which groups (columns) to plot.

Multiple groups can be plotted on the same or multiple plots by providing a column with a group identifier under "advanced - plotting multiple groups".

Feel free to explore the (many) advanced options to customize your plot. Galaxy makes this type optimization easy for the user!

The ouput is a pdf file with your scatterplot. The dimensions of this file can be modified under "advanced - output dimensions"
    ]]></help>
    <expand macro="citations"/>
</tool>