# HG changeset patch # User iuc # Date 1622970742 0 # Node ID 44608d0193ed334ce1ae1d1f93a0186daafa6253 # Parent 73b8cb5bddcd755bb6898dc1ee76a52411ebbaa9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/volcanoplot commit 8464d1b013c316d88b37884be521c0ef50be5623" diff -r 73b8cb5bddcd -r 44608d0193ed test-data/out.pdf Binary file test-data/out.pdf has changed diff -r 73b8cb5bddcd -r 44608d0193ed test-data/out.rscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/out.rscript Sun Jun 06 09:12:22 2021 +0000 @@ -0,0 +1,103 @@ + +# Galaxy settings start --------------------------------------------------- + +# setup R error handling to go to stderr +options(show.error.messages = F, error = function() {cat(geterrmessage(), file = stderr()); q("no", 1, F)}) + +# we need that to not crash galaxy with an UTF8 error on German LC settings. +loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") + + +# Load packages ----------------------------------------------------------- + +suppressPackageStartupMessages({ + library(dplyr) + library(ggplot2) + library(ggrepel) +}) + + +# Import data ------------------------------------------------------------ + +# Check if header is present by checking if P value column is numeric or not + +first_line <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmpfpemuuun/files/8/3/7/dataset_8374ef6b-02c7-46f1-afc9-408a2a6cbde4.dat', header = FALSE, nrow = 1) + +first_pvalue <- first_line[, 3] + +if (is.numeric(first_pvalue)) { + print("No header row detected") + results <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmpfpemuuun/files/8/3/7/dataset_8374ef6b-02c7-46f1-afc9-408a2a6cbde4.dat', header = FALSE) +} else { + print("Header row detected") + results <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmpfpemuuun/files/8/3/7/dataset_8374ef6b-02c7-46f1-afc9-408a2a6cbde4.dat', header = TRUE) +} + + +# Format data ------------------------------------------------------------ + +# Create columns from the column numbers specified +results <- results %>% mutate(fdr = .[[4]], + pvalue = .[[3]], + logfc = .[[2]], + labels = .[[1]]) + +# Get names for legend +down <- unlist(strsplit('Down,Not Sig,Up', split = ","))[1] +notsig <- unlist(strsplit('Down,Not Sig,Up', split = ","))[2] +up <- unlist(strsplit('Down,Not Sig,Up', split = ","))[3] + +# Set colours +colours <- setNames(c("cornflowerblue", "grey", "firebrick"), c(down, notsig, up)) + +# Create significant (sig) column +results <- mutate(results, sig = case_when( + fdr < 0.05 & logfc > 0.0 ~ up, + fdr < 0.05 & logfc < -0.0 ~ down, + TRUE ~ notsig)) + + +# Specify genes to label -------------------------------------------------- +labelfile <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmpfpemuuun/files/4/2/f/dataset_42fc8a63-f9cc-435b-9bb3-dd106b708cd9.dat') +results <- mutate(results, labels = ifelse(labels %in% labelfile[, 1], labels, "")) + + +# Create plot ------------------------------------------------------------- + +pdf("out.pdf") +p <- ggplot(results, aes(x = logfc, y = -log10(pvalue))) + + geom_point(aes(colour = sig)) + + scale_color_manual(values = colours) + + scale_fill_manual(values = colours) + + theme(panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + panel.background = element_blank(), + axis.line = element_line(colour = "black"), + legend.key = element_blank()) + + + + + + +# Set legend title +p <- p + labs(colour = "") + +# Add gene labels in boxes +p <- p + geom_label_repel(aes(label = labels, fill = sig), + segment.colour = "black", + colour = "white", + min.segment.length = 0, + show.legend = FALSE) + +print(p) +dev.off() + + +# Save RData ------------------------------------------------------------- +save.image(file="volcanoplot.RData") + + +# R and Package versions ------------------------------------------------- +sessionInfo() + diff -r 73b8cb5bddcd -r 44608d0193ed test-data/out2.pdf Binary file test-data/out2.pdf has changed diff -r 73b8cb5bddcd -r 44608d0193ed volcanoplot.R --- a/volcanoplot.R Sun Aug 04 10:53:30 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -# setup R error handling to go to stderr -options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) - -# we need that to not crash galaxy with an UTF8 error on German LC settings. -loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") - -suppressPackageStartupMessages({ - library(dplyr) - library(getopt) - library(ggplot2) - library(ggrepel) -}) - -options(stringAsFactors = FALSE, useFancyQuotes = FALSE) -args <- commandArgs(trailingOnly = TRUE) - -spec <- matrix(c( - "input", "i", 1, "character", - "fdr_col", "a", 1, "integer", - "pval_col", "p", 1, "integer", - "lfc_col", "c", 1, "integer", - "label_col", "l", 1, "integer", - "signif_thresh", "s", 1, "double", - "lfc_thresh", "x", 1, "double", - "label_file", "f", 1, "character", - "top_num", "t", 1, "integer", - "title", "T", 1, "character", - "xlab", "X", 1, "character", - "ylab", "Y", 1, "character", - "xmin", "m", 1, "double", - "xmax", "M", 1, "double", - "ymax", "W", 1, "double", - "legend", "L", 1, "character", - "llabs", "z", 1, "character", - "boxes", "b", 0, "logical"), - byrow=TRUE, ncol=4) -opt <- getopt(spec) - -# Below modified from http://www.gettinggeneticsdone.com/2016/01/repel-overlapping-text-labels-in-ggplot2.html - -results <- read.delim(opt$input) -results$fdr <- results[, opt$fdr_col] -results$Pvalue <- results[, opt$pval_col] -results$logFC <- results[, opt$lfc_col] -results$labels <- as.character(results[, opt$label_col]) -label_down <- unlist(strsplit(opt$llabs, split=","))[1] -label_notsig <- unlist(strsplit(opt$llabs, split=","))[2] -label_up <- unlist(strsplit(opt$llabs, split=","))[3] -colours <- setNames(c("cornflowerblue","grey","firebrick"),c(label_down,label_notsig,label_up)) - -results <- mutate(results, sig=ifelse((fdropt$lfc_thresh), label_up, ifelse((fdr 0) { - # label only top significant genes - top <- filter(results, sig != label_notsig) %>% top_n(n=-opt$top_num, Pvalue) - results <- mutate(results, labels=ifelse(labels %in% top$labels, labels, "")) -} else if (opt$top_num == 0) { - # no labels - results$labels <- NULL -} - -pdf("out.pdf") -p <- ggplot(results, aes(logFC, -log10(Pvalue))) + - geom_point(aes(col=sig)) + - scale_color_manual(values=colours) + - scale_fill_manual(values=colours) + - theme(panel.grid.major = element_blank(), - panel.grid.minor = element_blank(), - panel.background = element_blank(), - axis.line = element_line(colour = "black"), - legend.key=element_blank()) -if (!is.null(opt$title)) { - p <- p + ggtitle(opt$title) -} -if (!is.null(opt$xlab)) { - p <- p + xlab(opt$xlab) -} -if (!is.null(opt$ylab)) { - p <- p + ylab(opt$ylab) -} -if (!is.null(opt$xmin) & !is.null(opt$xmax)) { - p <- p + xlim(opt$xmin, opt$xmax) -} -if (!is.null(opt$ymax)) { - p <- p + ylim(0, opt$ymax) -} -if (!is.null(opt$legend)) { - p <- p + labs(colour=opt$legend) -} else { - p <- p + labs(colour="") -} -if (!is.null(results$labels)) { - if (!is.null(opt$boxes)) { - p <- p + geom_label_repel(aes(label=labels, fill=sig), segment.colour="black", colour="white", min.segment.length=0, show.legend=FALSE) - } else { - p <- p + geom_text_repel(aes(label=labels, col=sig), min.segment.length=0, box.padding=0.3, point.padding=0.3, show.legend=FALSE) - } -} - -print(p) -dev.off() - -cat("Session information:\n\n") -sessionInfo() \ No newline at end of file diff -r 73b8cb5bddcd -r 44608d0193ed volcanoplot.xml --- a/volcanoplot.xml Sun Aug 04 10:53:30 2019 -0400 +++ b/volcanoplot.xml Sun Jun 06 09:12:22 2021 +0000 @@ -1,61 +1,180 @@ - + create a volcano plot + + topic_0092 + + + operation_0337 + - r-ggplot2 - r-ggrepel - r-dplyr - r-getopt + r-ggplot2 + r-ggrepel + r-dplyr /dev/null | grep -v -i "WARNING: ")", ggrepel version" $(R --vanilla --slave -e "library(ggrepel); cat(sessionInfo()\$otherPkgs\$ggrepel\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", dplyr version" $(R --vanilla --slave -e "library(dplyr); cat(sessionInfo()\$otherPkgs\$dplyr\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", getopt version" $(R --vanilla --slave -e "library(getopt); cat(sessionInfo()\$otherPkgs\$getopt\$Version)" 2> /dev/null | grep -v -i "WARNING: ") +echo $(R --version | grep version | grep -v GNU)", ggplot2 version" $(R --vanilla --slave -e "library(ggplot2); cat(sessionInfo()\$otherPkgs\$ggplot2\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", ggrepel version" $(R --vanilla --slave -e "library(ggrepel); cat(sessionInfo()\$otherPkgs\$ggrepel\$Version)" 2> /dev/null | grep -v -i "WARNING: ")", dplyr version" $(R --vanilla --slave -e "library(dplyr); cat(sessionInfo()\$otherPkgs\$dplyr\$Version)" 2> /dev/null | grep -v -i "WARNING: ") ]]> + + % mutate(fdr = .[[$fdr_col]], + pvalue = .[[$pval_col]], + logfc = .[[$lfc_col]], + labels = .[[$label_col]]) + +# Get names for legend +down <- unlist(strsplit('$plot_options.legend_labs', split = ","))[1] +notsig <- unlist(strsplit('$plot_options.legend_labs', split = ","))[2] +up <- unlist(strsplit('$plot_options.legend_labs', split = ","))[3] + +# Set colours +colours <- setNames(c("cornflowerblue", "grey", "firebrick"), c(down, notsig, up)) + +# Create significant (sig) column +results <- mutate(results, sig = case_when( + fdr < $signif_thresh & logfc > $lfc_thresh ~ up, + fdr < $signif_thresh & logfc < -$lfc_thresh ~ down, + TRUE ~ notsig)) + +## R code below is left aligned for R script output + +#if $labels.label_select != "none" +# Specify genes to label -------------------------------------------------- + #if $labels.label_select == "file" +labelfile <- read.delim('$labels.label_file') +results <- mutate(results, labels = ifelse(labels %in% labelfile[, 1], labels, "")) + #elif $labels.label_select == "signif" + #if $labels.top_num <= 0 +results <- mutate(results, labels = "") + #elif $labels.top_num > 0 +top <- results %>% + filter(sig != notsig) %>% + slice_min(order_by = pvalue, n = $labels.top_num) +toplabels <- pull(top, labels) +results <- mutate(results, labels = ifelse(labels %in% toplabels, labels, "")) + #else +results <- mutate(results, labels = ifelse(sig != notsig, labels, "")) + #end if + #end if +#end if + + +# Create plot ------------------------------------------------------------- + +pdf("out.pdf") +p <- ggplot(results, aes(x = logfc, y = -log10(pvalue))) + + geom_point(aes(colour = sig)) + + scale_color_manual(values = colours) + + scale_fill_manual(values = colours) + + theme(panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + panel.background = element_blank(), + axis.line = element_line(colour = "black"), + legend.key = element_blank()) + +#if not '$plot_options.title' +p <- p + ggtitle('$plot_options.title') +#end if + +#if not '$plot_options.xlab' +p <- p + xlab('$plot_options.xlab') +#end if + +#if not '$plot_options.ylab' +p <- p + ylab('$plot_options.ylab') +#end if + +#if not '$plot_options.xmin' and '$plot_options.xmax' +p <- p + xlim('$plot_options.xmin', '$plot_options.xmax') +#end if + +#if not '$plot_options.ymax' +p <- p + ylim(0, '$plot_options.ymax') +#end if + +# Set legend title +#if not '$plot_options.legend' +p <- p + labs(colour = '$plot_options.legend') +#else +p <- p + labs(colour = "") +#end if + +#if $labels.label_select != "none" +# Add gene labels in boxes + #if $plot_options.boxes +p <- p + geom_label_repel(aes(label = labels, fill = sig), + segment.colour = "black", + colour = "white", + min.segment.length = 0, + show.legend = FALSE) + #else +# Add gene labels +p <- p + geom_text_repel(aes(label = labels, col = sig), + min.segment.length = 0, + box.padding = 0.3, + point.padding = 0.3, + show.legend = FALSE) #end if - #if $plot_options.xmax: - -M '$plot_options.xmax' - #end if - #if $plot_options.ymax: - -W '$plot_options.ymax' - #end if - #if $plot_options.legend: - -L '$plot_options.legend' - #end if - -z '$plot_options.legend_labs' +#end if + +print(p) +dev.off() + -]]> +#if $out_options.rdata_out +# Save RData ------------------------------------------------------------- +save.image(file="volcanoplot.RData") +#end if + + +# R and Package versions ------------------------------------------------- +sessionInfo() + +]]> + @@ -89,12 +208,25 @@ +
+ + + +
- + + + out_options['rscript_out'] + + + out_options['rdata_out'] + - + @@ -102,9 +234,13 @@ - + + + + + - + @@ -114,7 +250,35 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +