Mercurial > repos > iuc > volcanoplot
comparison test-data/out.rscript @ 5:44608d0193ed draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/volcanoplot commit 8464d1b013c316d88b37884be521c0ef50be5623"
author | iuc |
---|---|
date | Sun, 06 Jun 2021 09:12:22 +0000 |
parents | |
children | 83c573f2e73c |
comparison
equal
deleted
inserted
replaced
4:73b8cb5bddcd | 5:44608d0193ed |
---|---|
1 | |
2 # Galaxy settings start --------------------------------------------------- | |
3 | |
4 # setup R error handling to go to stderr | |
5 options(show.error.messages = F, error = function() {cat(geterrmessage(), file = stderr()); q("no", 1, F)}) | |
6 | |
7 # we need that to not crash galaxy with an UTF8 error on German LC settings. | |
8 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
9 | |
10 | |
11 # Load packages ----------------------------------------------------------- | |
12 | |
13 suppressPackageStartupMessages({ | |
14 library(dplyr) | |
15 library(ggplot2) | |
16 library(ggrepel) | |
17 }) | |
18 | |
19 | |
20 # Import data ------------------------------------------------------------ | |
21 | |
22 # Check if header is present by checking if P value column is numeric or not | |
23 | |
24 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) | |
25 | |
26 first_pvalue <- first_line[, 3] | |
27 | |
28 if (is.numeric(first_pvalue)) { | |
29 print("No header row detected") | |
30 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) | |
31 } else { | |
32 print("Header row detected") | |
33 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) | |
34 } | |
35 | |
36 | |
37 # Format data ------------------------------------------------------------ | |
38 | |
39 # Create columns from the column numbers specified | |
40 results <- results %>% mutate(fdr = .[[4]], | |
41 pvalue = .[[3]], | |
42 logfc = .[[2]], | |
43 labels = .[[1]]) | |
44 | |
45 # Get names for legend | |
46 down <- unlist(strsplit('Down,Not Sig,Up', split = ","))[1] | |
47 notsig <- unlist(strsplit('Down,Not Sig,Up', split = ","))[2] | |
48 up <- unlist(strsplit('Down,Not Sig,Up', split = ","))[3] | |
49 | |
50 # Set colours | |
51 colours <- setNames(c("cornflowerblue", "grey", "firebrick"), c(down, notsig, up)) | |
52 | |
53 # Create significant (sig) column | |
54 results <- mutate(results, sig = case_when( | |
55 fdr < 0.05 & logfc > 0.0 ~ up, | |
56 fdr < 0.05 & logfc < -0.0 ~ down, | |
57 TRUE ~ notsig)) | |
58 | |
59 | |
60 # Specify genes to label -------------------------------------------------- | |
61 labelfile <- read.delim('/private/var/folders/zn/m_qvr9zd7tq0wdtsbq255f8xypj_zg/T/tmpfpemuuun/files/4/2/f/dataset_42fc8a63-f9cc-435b-9bb3-dd106b708cd9.dat') | |
62 results <- mutate(results, labels = ifelse(labels %in% labelfile[, 1], labels, "")) | |
63 | |
64 | |
65 # Create plot ------------------------------------------------------------- | |
66 | |
67 pdf("out.pdf") | |
68 p <- ggplot(results, aes(x = logfc, y = -log10(pvalue))) + | |
69 geom_point(aes(colour = sig)) + | |
70 scale_color_manual(values = colours) + | |
71 scale_fill_manual(values = colours) + | |
72 theme(panel.grid.major = element_blank(), | |
73 panel.grid.minor = element_blank(), | |
74 panel.background = element_blank(), | |
75 axis.line = element_line(colour = "black"), | |
76 legend.key = element_blank()) | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 # Set legend title | |
84 p <- p + labs(colour = "") | |
85 | |
86 # Add gene labels in boxes | |
87 p <- p + geom_label_repel(aes(label = labels, fill = sig), | |
88 segment.colour = "black", | |
89 colour = "white", | |
90 min.segment.length = 0, | |
91 show.legend = FALSE) | |
92 | |
93 print(p) | |
94 dev.off() | |
95 | |
96 | |
97 # Save RData ------------------------------------------------------------- | |
98 save.image(file="volcanoplot.RData") | |
99 | |
100 | |
101 # R and Package versions ------------------------------------------------- | |
102 sessionInfo() | |
103 |