Mercurial > repos > iuc > volcanoplot
view test-data/out.rscript @ 8:2f557f6abbfb draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/volcanoplot commit 84949ce3d77433f035c14406fccc5bc6beaa7a0d
author | iuc |
---|---|
date | Wed, 05 Jun 2024 15:03:07 +0000 |
parents | 83c573f2e73c |
children |
line wrap: on
line source
# 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") # Galaxy settings end ----------------------------------------------------- # Load packages ----------------------------------------------------------- suppressPackageStartupMessages({ library(dplyr) library(ggplot2) library(ggrepel) }) # Import data ------------------------------------------------------------ results <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmprh4qip75/files/d/2/2/dataset_d2255b46-f0f6-4900-8b9e-bd352e34f303.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 -------------------------------------------------- # Import file with genes of interest labelfile <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmprh4qip75/files/5/e/5/dataset_5e5b8fb0-bf65-438e-9b5b-03a540d9aa5d.dat', header = TRUE) # Label the genes of interest in results table results <- mutate(results, labels = ifelse(labels %in% labelfile[, 1], labels, "")) # Create plot ------------------------------------------------------------- # Open file to save plot as PDF pdf("volcano_plot.pdf") # Set up base plot p <- ggplot(data = results, aes(x = logfc, y = -log10(pvalue))) + geom_point(aes(colour = sig)) + scale_color_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()) # Add gene labels p <- p + geom_text_repel(data = filter(results, labels != ""), aes(label = labels), min.segment.length = 0, max.overlaps = Inf, show.legend = FALSE) # Set legend title p <- p + theme(legend.title = element_blank()) # Print plot print(p) # Close PDF graphics device dev.off() # R and Package versions ------------------------------------------------- sessionInfo()