comparison 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
comparison
equal deleted inserted replaced
0:59ebf2c42c0e 1:7b7303fa20e3
46 46
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))) 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)))
48 results <- results[order(results$Pvalue),] 48 results <- results[order(results$Pvalue),]
49 if (!is.null(opt$label_file)) { 49 if (!is.null(opt$label_file)) {
50 labelfile <- read.delim(opt$label_file) 50 labelfile <- read.delim(opt$label_file)
51 # label genes specified in file
51 tolabel <- filter(results, labels %in% labelfile[, 1]) 52 tolabel <- filter(results, labels %in% labelfile[, 1])
52 } else if (!is.null(opt$top_num)) { 53 } else if (is.null(opt$top_num)) {
53 tolabel <- filter(results, fdr<opt$signif_thresh) %>% top_n(opt$top_num) 54 # label all significant genes
54 } else {
55 tolabel <- filter(results, fdr<opt$signif_thresh) 55 tolabel <- filter(results, fdr<opt$signif_thresh)
56 } else if (opt$top_num > 0) {
57 # label only top significant genes
58 tolabel <- filter(results, fdr<opt$signif_thresh) %>%
59 top_n(n=opt$top_num, Pvalue)
60 } else if (opt$top_num == 0) {
61 # no labels
62 tolabel <- NULL
56 } 63 }
57 64
58 pdf("out.pdf") 65 pdf("out.pdf")
59 p <- ggplot(results, aes(logFC, -log10(Pvalue))) + 66 p <- ggplot(results, aes(logFC, -log10(Pvalue))) +
60 geom_point(aes(col=sig)) + 67 geom_point(aes(col=sig)) +
61 geom_label_repel(data=tolabel, aes(label=labels, fill=factor(sig)), colour="white", segment.colour="black", show.legend=FALSE) +
62 scale_color_manual(values=colours) + 68 scale_color_manual(values=colours) +
63 scale_fill_manual(values=colours) + 69 scale_fill_manual(values=colours) +
64 theme(panel.grid.major = element_blank(), 70 theme(panel.grid.major = element_blank(),
65 panel.grid.minor = element_blank(), 71 panel.grid.minor = element_blank(),
66 panel.background = element_blank(), 72 panel.background = element_blank(),
67 axis.line = element_line(colour = "black"), 73 axis.line = element_line(colour = "black"),
68 legend.key=element_blank()) 74 legend.key=element_blank())
69 if (!is.null(opt$title)) { 75 if (!is.null(opt$title)) {
78 if (!is.null(opt$legend)) { 84 if (!is.null(opt$legend)) {
79 p <- p + labs(colour=opt$legend) 85 p <- p + labs(colour=opt$legend)
80 } else { 86 } else {
81 p <- p + labs(colour="") 87 p <- p + labs(colour="")
82 } 88 }
89 if (!is.null(tolabel)) {
90 p <- p + geom_label_repel(data=tolabel, aes(label=labels, fill=factor(sig)), colour="white", segment.colour="black", show.legend=FALSE)
91 }
83 92
84 print(p) 93 print(p)
85 dev.off() 94 dev.off()
86 95
87 cat("Session information:\n\n") 96 cat("Session information:\n\n")