Repository 'plot_grouped_barplot'
hg clone https://toolshed.g2.bx.psu.edu/repos/bebatut/plot_grouped_barplot

Changeset 0:6c9aac0d6ca2 (2016-04-18)
Commit message:
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_grouped_barplot commit c6ba903395dc6d41cb318c7d95a2d9cf3ca65313-dirty
added:
plot_grouped_barplot.R
plot_grouped_barplot.xml
static/images/output.pdf
static/images/output.png
test-data/input_file.txt
test-data/output_file.pdf
tool_dependencies.xml
b
diff -r 000000000000 -r 6c9aac0d6ca2 plot_grouped_barplot.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plot_grouped_barplot.R Mon Apr 18 10:08:25 2016 -0400
[
@@ -0,0 +1,87 @@
+library('getopt')
+
+option_specification = matrix(c(
+  'input_file', 'i', 2, 'character',
+  'output_pdf_file', 'p', 2, 'character',
+  'output_png_file', 'o', 2, 'character',
+  'output_svg_file', 's', 2, 'character',
+  'data_columns', 'd', 2, 'list',
+  'names', 'a', 2, 'character',
+  'names_column', 'n', 2, 'integer',
+  'xlab', 'x', 2, 'character',
+  'log', 'g', 2, 'logical',
+  'col', 'c', 2, 'list',
+  'bottom_margin', 'b', 2, 'integer',
+  'left_margin', 'l', 2, 'integer',
+  'top_margin', 't', 2, 'integer',
+  'right_margin', 'r', 2, 'integer',
+  'legend_pos','e',2,'character',
+  'replace_null','u',2,'logical',
+  'order','w',2,'logical',
+  'header','y',2,'logical'
+), byrow=TRUE, ncol=4);
+
+options = getopt(option_specification);
+
+header = TRUE
+if(!is.null(options$header)) header = options$header
+
+data = read.table(options$input_file, sep = '\t', h = header)
+if(!is.null(options$replace_null) && options$replace_null){
+  data[data == 0] = NA
+}
+if(!is.null(options$order) && options$order){
+  order = order(data[,2])
+  data = data[order,]
+}
+
+
+data_columns = c(2,3)
+if(!is.null(options$data_columns)){
+  data_columns = unlist(strsplit(options$data_columns, split=","))
+  data_columns = sapply(data_columns,as.integer)
+  } 
+names_column = 1
+if(!is.null(options$names_column)) names_column = options$names_column
+
+margin = c(5,19,1,1)
+if(!is.null(options$bottom_margin)) margin[1] = options$bottom_margin
+if(!is.null(options$left_margin)) margin[2] = options$left_margin
+if(!is.null(options$top_margin)) margin[3] = options$top_margin
+if(!is.null(options$right_margin)) margin[4] = options$right_margin
+
+xlab = ""
+if(!is.null(options$xlab)) xlab = options$xlab
+
+col = c('blue','red')
+if(!is.null(options$col)) col = unlist(strsplit(options$col, split=","))
+
+log = ""
+if(!is.null(options$log) && options$log) log = "x"
+
+legend_pos="topright"
+if(!is.null(options$legend_pos)) legend_pos = options$legend_pos
+
+names = c('Sample1','Sample2')
+
+if(!is.null(options$names)) names = unlist(strsplit(options$names, split=","))
+plot_barplot <- function(){
+    par(las=2)
+    par(mar=margin)
+    barplot(t(data[, data_columns]), horiz = T, xlab = xlab, beside=TRUE,
+        names.arg = data[, names_column], col = col, cex.names=0.7, 
+        cex.axis = 0.8, log = log)
+    legend(legend_pos, legend = names, fill = col, cex = 0.7)
+}
+
+if(!is.null(options$output_pdf_file)){
+    pdf(options$output_pdf_file)
+    plot_barplot()
+    dev.off()
+}
+
+if(!is.null(options$output_svg_file)){
+    svg(options$output_svg_file)
+    plot_barplot()
+    dev.off()
+}
\ No newline at end of file
b
diff -r 000000000000 -r 6c9aac0d6ca2 plot_grouped_barplot.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plot_grouped_barplot.xml Mon Apr 18 10:08:25 2016 -0400
[
@@ -0,0 +1,145 @@
+<tool id="plot_grouped_barplot" name="Plot grouped barplot" version="0.1.0">
+    <description>with R</description>
+
+    <requirements>
+        <requirement type="package" version="3.2.1">R</requirement>
+        <requirement type="package" version="1.20.0">r-getopt</requirement>
+    </requirements>
+
+    <stdio>
+        <exit_code range="1:" />
+        <exit_code range=":-1" />
+    </stdio>
+
+    <version_command></version_command>
+
+    <command><![CDATA[
+        Rscript $__tool_directory__/plot_grouped_barplot.R
+            --input_file $input_file
+            --header $header
+
+            #if str($output_format)=="pdf"
+                --output_pdf_file $output_pdf_file
+            #else
+                --output_svg_file $output_svg_file
+            #end if
+
+            #set $column_with_data=""
+            #set $colors=""
+            #set $names=""
+            #set $sep=""
+            #for sample in $samples:
+                #set $column_with_data = $column_with_data + $sep + str($sample.column_id)
+                #set $colors = $colors + $sep + str($sample.color)
+                #set $names = $names + $sep +str($sample.name)
+                #set $sep=","
+            #end for
+            #set $column_with_data = $column_with_data
+            #set $colors = $colors
+            #set $names = $names
+
+            --data_column $column_with_data
+            --col "$colors"
+            --names "$names"
+            --replace_null $replace_null
+            --order $order
+            --names_column $names_column
+            --xlab "$xlab"
+            --log $log
+            --bottom_margin $bottom_margin
+            --left_margin $left_margin
+            --top_margin $top_margin
+            --right_margin $right_margin
+            --legend_pos $legend_pos
+    ]]></command>
+
+    <inputs>
+        <param name="input_file" type="data" format="tabular,tsv,csv" label="Input file" help="File in tabular format with tab-separated columns and header in first line (--input_file)"/>
+
+        <param name="header" type="boolean" truevalue="TRUE" falsevalue="FALSE" checked="false" label="Header in first line?" help="(--header)"/>
+
+        <param name="output_format" label="Format for output image" type="select" help="">
+            <option value="pdf" selected="True">PDF</option>
+            <option value="svg">SVG</option>
+        </param>
+
+        <repeat name="samples" title="Add sample information (column id, name, color)" >
+            <param name="name" type="text" label="Name of the data" help="(--sample_name)"/>
+            <param name="column_id" type="data_column" data_ref="input_file" label="Column containing corresponding data" multiple="false" numerical="true" help="(after normalization, --charact_input_file)"/>
+            <param name="color" label="Bar color" type="text" value= "blue" help="R color (--col)"/>
+        </repeat>
+        <param name="replace_null" type="boolean" truevalue="TRUE" falsevalue="FALSE" label="Replace null values by NA?" help="(--replace_null)"/>
+        <param name="order" type="boolean" truevalue="TRUE" falsevalue="FALSE" label="Order given the first chosen data?" help="(--order)"/>
+
+        <param name="names_column" type="data_column" data_ref="input_file" multiple="false" numerical="false" label="Column containing data names?" help="(--names_column)" />
+
+        <param name="xlab" type="text" value="" label="Label for x axis" help="(--xlab)"/>
+
+        <param name="log" type="boolean" truevalue="TRUE" falsevalue="FALSE" label="Log scale?" help="(--log)"/>
+
+        <param name="bottom_margin" type="integer" value="5" label="Bottom margin" help="(--bottom_margin)"/>
+        <param name="left_margin" type="integer" value="19" label="Left margin" help="(--left_margin)"/>
+        <param name="top_margin" type="integer" value="1" label="Top margin" help="(--top_margin)"/>
+        <param name="right_margin" type="integer" value="1" label="Right margin" help="(--right_margin)"/>
+        <param name="legend_pos" label="Position of the legend" type="select" help="">
+            <option value="topright" selected="True">Top right</option>
+            <option value="topleft">Top left</option>
+            <option value="bottomright">Bottom right</option>
+            <option value="bottomleft">Bottom left</option>
+        </param>
+    </inputs>
+
+    <outputs>
+        <data name="output_pdf_file" format="pdf"
+            label="${tool.name} on ${on_string}: PDF barplot">
+            <filter>output_format=="pdf"</filter>
+        </data>
+        <data name="output_png_file" format="png"
+            label="${tool.name} on ${on_string}: PNG barplot">
+            <filter>output_format=="png"</filter>
+        </data>
+        <data name="output_svg_file" format="svg"
+            label="${tool.name} on ${on_string}: SVG barplot">
+            <filter>output_format=="svg"</filter>
+        </data>
+    </outputs>
+
+    <tests>
+        <test>
+            <param name="input_file" value="input_file.txt"/>
+            <param name='header' value="FALSE"/>
+            <param name="output_format" value="pdf"/>
+            <param name="samples_0|name" value="A"/>
+            <param name="samples_0|column_id" value="2"/>
+            <param name="samples_0|color" value="blue"/>
+            <param name="samples_1|name" value="B"/>
+            <param name="samples_1|column_id" value="3"/>
+            <param name="samples_1|color" value="red"/>
+            <param name="replace_null" value="FALSE"/>
+            <param name="order" value="FALSE"/>
+            <param name="names_column" value="1"/>
+            <param name='xlab' value=""/>
+            <param name='log' value="FALSE"/>
+            <param name='bottom_margin' value="5"/>
+            <param name="left_margin" value="19"/>
+            <param name='top_margin' value="1"/>
+            <param name='right_margin' value="1"/>
+            <param name="legend_pos" value="topright"/>
+            <output name="output_pdf_file" file="output_file.pdf"/>
+        </test>
+    </tests>
+
+    <help><![CDATA[
+**What it does**
+
+This tool plot a grouped barplot with multiple data:
+
+.. image:: $PATH_TO_IMAGES/output.png
+   :scale: 50 %
+
+This tool relies on R's barplot function. The input file must be a tabular file with multiple columns: a column with row names (for bar names) and a least a column with data. The output image is customizable (margin, legend positions, ...) and can be export in different format. 
+    ]]></help>
+
+    <citations>
+    </citations>
+</tool>
\ No newline at end of file
b
diff -r 000000000000 -r 6c9aac0d6ca2 static/images/output.pdf
b
Binary file static/images/output.pdf has changed
b
diff -r 000000000000 -r 6c9aac0d6ca2 static/images/output.png
b
Binary file static/images/output.png has changed
b
diff -r 000000000000 -r 6c9aac0d6ca2 test-data/input_file.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/input_file.txt Mon Apr 18 10:08:25 2016 -0400
b
@@ -0,0 +1,18 @@
+Replication initiation protein, truncated 0.195633 0.0431745
+Resolvase, putative 0.00060098 0.183306
+UniRef50_Q8CU99 0.173071 0.0296448
+Integrase 0.303569 0.0580151
+Replication initiation protein 0.857353 0.165635
+UniRef50_Z6ILY0 0.202075 0.0208634
+UniRef50_W1W6K4 0.248059 0.0318689
+UniRef50_F0RR64 0.000754535 0.152705
+Tetracycline resistance protein 0.51126 0.101236
+Plasmid recombination enzyme 0.214064 0.0334602
+Transposase, putative 0.00200612 0.562101
+putative transposase 0.000927295 0.113753
+Plasmid recombination enzyme type 3 0.660463 0.123898
+Toxin antitoxin system, antitoxin component 0 0.142345
+Transposase IS4 family protein 0.00381025 0.4416
+hypothetical protein DR_1761 0.00032663 0.185976
+UniRef50_Q9RV33 0.000328875 0.144057
+Rep 0.365541 0.06664
b
diff -r 000000000000 -r 6c9aac0d6ca2 test-data/output_file.pdf
b
Binary file test-data/output_file.pdf has changed
b
diff -r 000000000000 -r 6c9aac0d6ca2 tool_dependencies.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml Mon Apr 18 10:08:25 2016 -0400
b
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<tool_dependency>
+    <package name="R" version="3.2.1">
+        <repository changeset_revision="d0bf97420fb5" name="package_r_3_2_1" owner="iuc" toolshed="https://toolshed.g2.bx.psu.edu" />
+    </package>
+    <package name="r-getopt" version="1.20.0">
+        <repository changeset_revision="712cb82311a8" name="package_r_3_2_1_getopt_1_20_0" owner="bebatut" toolshed="https://toolshed.g2.bx.psu.edu" />
+    </package>
+</tool_dependency>