Mercurial > repos > iuc > volcanoplot
comparison volcanoplot.R @ 3:6d532d760950 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/volcanoplot commit 16205b1cd782c5a4f7c08af7d4ee50dc5903418b
author | iuc |
---|---|
date | Tue, 12 Feb 2019 05:32:23 -0500 |
parents | d1d39c72b755 |
children |
comparison
equal
deleted
inserted
replaced
2:d1d39c72b755 | 3:6d532d760950 |
---|---|
25 "label_file", "f", 1, "character", | 25 "label_file", "f", 1, "character", |
26 "top_num", "t", 1, "integer", | 26 "top_num", "t", 1, "integer", |
27 "title", "T", 1, "character", | 27 "title", "T", 1, "character", |
28 "xlab", "X", 1, "character", | 28 "xlab", "X", 1, "character", |
29 "ylab", "Y", 1, "character", | 29 "ylab", "Y", 1, "character", |
30 "xmin", "m", 1, "double", | |
31 "xmax", "M", 1, "double", | |
32 "ymax", "W", 1, "double", | |
30 "legend", "L", 1, "character", | 33 "legend", "L", 1, "character", |
31 "llabs", "z", 1, "character"), | 34 "llabs", "z", 1, "character", |
35 "boxes", "b", 0, "logical"), | |
32 byrow=TRUE, ncol=4) | 36 byrow=TRUE, ncol=4) |
33 opt <- getopt(spec) | 37 opt <- getopt(spec) |
34 | 38 |
35 # Below modified from http://www.gettinggeneticsdone.com/2016/01/repel-overlapping-text-labels-in-ggplot2.html | 39 # Below modified from http://www.gettinggeneticsdone.com/2016/01/repel-overlapping-text-labels-in-ggplot2.html |
36 | 40 |
37 results <- read.delim(opt$input) | 41 results <- read.delim(opt$input) |
38 results$fdr <- results[, opt$fdr_col] | 42 results$fdr <- results[, opt$fdr_col] |
39 results$Pvalue <- results[, opt$pval_col] | 43 results$Pvalue <- results[, opt$pval_col] |
40 results$logFC <- results[, opt$lfc_col] | 44 results$logFC <- results[, opt$lfc_col] |
41 results$labels <- results[, opt$label_col] | 45 results$labels <- as.character(results[, opt$label_col]) |
42 label_down <- unlist(strsplit(opt$llabs, split=","))[1] | 46 label_down <- unlist(strsplit(opt$llabs, split=","))[1] |
43 label_notsig <- unlist(strsplit(opt$llabs, split=","))[2] | 47 label_notsig <- unlist(strsplit(opt$llabs, split=","))[2] |
44 label_up <- unlist(strsplit(opt$llabs, split=","))[3] | 48 label_up <- unlist(strsplit(opt$llabs, split=","))[3] |
45 colours <- setNames(c("cornflowerblue","grey","firebrick"),c(label_down,label_notsig,label_up)) | 49 colours <- setNames(c("cornflowerblue","grey","firebrick"),c(label_down,label_notsig,label_up)) |
46 | 50 |
47 results <- mutate(results, sig=ifelse((fdr<opt$signif_thresh & logFC>opt$lfc_thresh), label_up, ifelse((fdr<opt$signif_thresh & logFC < -opt$lfc_thresh),label_down, label_notsig))) | 51 results <- mutate(results, sig=ifelse((fdr<opt$signif_thresh & logFC>opt$lfc_thresh), label_up, ifelse((fdr<opt$signif_thresh & logFC < -opt$lfc_thresh),label_down, label_notsig))) |
48 results <- results[order(results$Pvalue),] | 52 results <- results[order(results$Pvalue),] |
49 if (!is.null(opt$label_file)) { | 53 if (!is.null(opt$label_file)) { |
50 labelfile <- read.delim(opt$label_file) | 54 labelfile <- read.delim(opt$label_file, stringsAsFactors=FALSE) |
51 # label genes specified in file | 55 # label genes specified in file |
52 tolabel <- filter(results, labels %in% labelfile[, 1]) | 56 results <- mutate(results, labels=ifelse(labels %in% labelfile[, 1], labels, "")) |
53 } else if (is.null(opt$top_num)) { | 57 } else if (is.null(opt$top_num)) { |
54 # label all significant genes | 58 # label all significant genes |
55 tolabel <- filter(results, sig != label_notsig) | 59 results <- mutate(results, labels=ifelse(sig != label_notsig, labels, "")) |
56 } else if (opt$top_num > 0) { | 60 } else if (opt$top_num > 0) { |
57 # label only top significant genes | 61 # label only top significant genes |
58 tolabel <- filter(results, sig != label_notsig) %>% | 62 top <- filter(results, sig != label_notsig) %>% top_n(n=-opt$top_num, Pvalue) |
59 top_n(n=-opt$top_num, Pvalue) | 63 results <- mutate(results, labels=ifelse(labels %in% top$labels, labels, "")) |
60 } else if (opt$top_num == 0) { | 64 } else if (opt$top_num == 0) { |
61 # no labels | 65 # no labels |
62 tolabel <- NULL | 66 results$labels <- NULL |
63 } | 67 } |
64 | 68 |
65 pdf("out.pdf") | 69 pdf("out.pdf") |
66 p <- ggplot(results, aes(logFC, -log10(Pvalue))) + | 70 p <- ggplot(results, aes(logFC, -log10(Pvalue))) + |
67 geom_point(aes(col=sig)) + | 71 geom_point(aes(col=sig)) + |
79 p <- p + xlab(opt$xlab) | 83 p <- p + xlab(opt$xlab) |
80 } | 84 } |
81 if (!is.null(opt$ylab)) { | 85 if (!is.null(opt$ylab)) { |
82 p <- p + ylab(opt$ylab) | 86 p <- p + ylab(opt$ylab) |
83 } | 87 } |
88 if (!is.null(opt$xmin) & !is.null(opt$xmax)) { | |
89 p <- p + xlim(opt$xmin, opt$xmax) | |
90 } | |
91 if (!is.null(opt$ymax)) { | |
92 p <- p + ylim(0, opt$ymax) | |
93 } | |
84 if (!is.null(opt$legend)) { | 94 if (!is.null(opt$legend)) { |
85 p <- p + labs(colour=opt$legend) | 95 p <- p + labs(colour=opt$legend) |
86 } else { | 96 } else { |
87 p <- p + labs(colour="") | 97 p <- p + labs(colour="") |
88 } | 98 } |
89 if (!is.null(tolabel)) { | 99 if (!is.null(results$labels)) { |
90 p <- p + geom_label_repel(data=tolabel, aes(label=labels, fill=factor(sig)), colour="white", segment.colour="black", show.legend=FALSE) | 100 if (!is.null(opt$boxes)) { |
101 p <- p + geom_label_repel(aes(label=labels, fill=sig), segment.colour="black", colour="white", min.segment.length=0, show.legend=FALSE) | |
102 } else { | |
103 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) | |
104 } | |
91 } | 105 } |
92 | 106 |
93 print(p) | 107 print(p) |
94 dev.off() | 108 dev.off() |
95 | 109 |