diff volcanoplot.R @ 1:7b7303fa20e3 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/volcanoplot commit c2b155f1fd4470ddecb5bd1c6e2c54dd46bfeaed
author iuc
date Sat, 29 Dec 2018 13:21:24 -0500
parents 59ebf2c42c0e
children d1d39c72b755
line wrap: on
line diff
--- a/volcanoplot.R	Tue Oct 23 06:57:26 2018 -0400
+++ b/volcanoplot.R	Sat Dec 29 13:21:24 2018 -0500
@@ -48,20 +48,26 @@
 results <- results[order(results$Pvalue),]
 if (!is.null(opt$label_file)) {
     labelfile <- read.delim(opt$label_file)
+    # label genes specified in file
     tolabel <- filter(results, labels %in% labelfile[, 1])
-} else if (!is.null(opt$top_num)) {
-    tolabel <- filter(results, fdr<opt$signif_thresh) %>% top_n(opt$top_num)
-} else {
+} else if (is.null(opt$top_num)) {
+    # label all significant genes
     tolabel <- filter(results, fdr<opt$signif_thresh)
+} else if (opt$top_num > 0) {
+    # label only top significant genes
+    tolabel <- filter(results, fdr<opt$signif_thresh) %>% 
+    top_n(n=opt$top_num, Pvalue)
+} else if (opt$top_num == 0) {
+    # no labels
+    tolabel <- NULL
 }
 
 pdf("out.pdf")
 p <- ggplot(results, aes(logFC, -log10(Pvalue))) +
     geom_point(aes(col=sig)) +
-    geom_label_repel(data=tolabel, aes(label=labels, fill=factor(sig)), colour="white", segment.colour="black", show.legend=FALSE) +
     scale_color_manual(values=colours) +
     scale_fill_manual(values=colours) +
-    theme(panel.grid.major = element_blank(), 
+    theme(panel.grid.major = element_blank(),
         panel.grid.minor = element_blank(),
         panel.background = element_blank(),
         axis.line = element_line(colour = "black"),
@@ -80,6 +86,9 @@
 } else {
     p <- p + labs(colour="")
 }
+if (!is.null(tolabel)) {
+    p <- p + geom_label_repel(data=tolabel, aes(label=labels, fill=factor(sig)), colour="white", segment.colour="black", show.legend=FALSE)
+}
 
 print(p)
 dev.off()