Mercurial > repos > artbio > small_rna_signatures
comparison signature.r @ 11:8d3ca9652a5b draft
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_signatures commit 8691f2575cacd71c971338658198a1324e5f9370"
author | artbio |
---|---|
date | Sat, 23 Oct 2021 22:55:19 +0000 |
parents | a35e6f9c1d34 |
children | aa5e2c64dff8 |
comparison
equal
deleted
inserted
replaced
10:68ee7c84d498 | 11:8d3ca9652a5b |
---|---|
1 ## Setup R error handling to go to stderr | 1 ## Setup R error handling to go to stderr |
2 #options(show.error.messages=F, | 2 options(show.error.messages = F, |
3 #error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) | 3 error = function() { |
4 cat(geterrmessage(), file = stderr()) | |
5 q("no", 1, F) | |
6 } | |
7 ) | |
4 warnings() | 8 warnings() |
5 | 9 |
6 library(RColorBrewer) | 10 library(RColorBrewer) |
7 library(lattice) | 11 library(lattice) |
8 library(latticeExtra) | 12 library(latticeExtra) |
9 library(grid) | 13 library(grid) |
10 library(gridExtra) | 14 library(gridExtra) |
11 library(optparse) | 15 library(optparse) |
12 | 16 |
13 option_list <- list( | 17 option_list <- list( |
14 make_option("--h_dataframe", type="character", help="path to h-signature dataframe"), | 18 make_option("--h_dataframe", type = "character", |
15 make_option("--z_dataframe", type="character", help="path to z-signature dataframe"), | 19 help = "path to h-signature dataframe"), |
16 make_option("--plot_method", type = "character", help="How data should be plotted (global or lattice)"), | 20 make_option("--z_dataframe", type = "character", |
17 make_option("--pdf", type = "character", help="path to the pdf file with plots"), | 21 help = "path to z-signature dataframe"), |
18 make_option("--title", type = "character", help="Graph Title") | 22 make_option("--plot_method", type = "character", |
23 help = "How data should be plotted (global or lattice)"), | |
24 make_option("--pdf", type = "character", help = "path to the pdf file with plots"), | |
25 make_option("--title", type = "character", help = "Graph Title") | |
19 ) | 26 ) |
20 | |
21 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) | 27 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) |
22 args = parse_args(parser) | 28 args <- parse_args(parser) |
23 | |
24 | |
25 | |
26 | 29 |
27 # data frames implementation | 30 # data frames implementation |
28 h_dataframe = read.delim(args$h_dataframe, header=F) | 31 h_dataframe <- read.delim(args$h_dataframe, header = F) |
29 colnames(h_dataframe) = c("chrom", "overlap", "sig", "z-score") | 32 colnames(h_dataframe) <- c("chrom", "overlap", "sig", "z-score") |
30 h_dataframe$sig = h_dataframe$sig * 100 # to get probs in % | 33 h_dataframe$sig <- h_dataframe$sig * 100 # to get probs in % |
31 z_dataframe = read.delim(args$z_dataframe, header=F) | 34 z_dataframe <- read.delim(args$z_dataframe, header = F) |
32 colnames(z_dataframe) = c("chrom", "overlap", "sig", "z-score") | 35 colnames(z_dataframe) <- c("chrom", "overlap", "sig", "z-score") |
33 | 36 |
34 # functions | 37 # functions |
35 globalgraph = function () { | 38 globalgraph <- function() { |
36 pdf(args$pdf) | 39 pdf(args$pdf) |
37 par(mfrow=c(2,2),oma = c(0, 0, 3, 0)) | 40 par(mfrow = c(2, 2), oma = c(0, 0, 3, 0)) |
38 | 41 plot(z_dataframe[z_dataframe$chrom == "all_chromosomes", c(2, 3)], |
39 plot(z_dataframe[z_dataframe$chrom == "all_chromosomes", c(2,3)], | 42 type = "h", main = "Numbers of pairs", cex.main = 1, xlab = "overlap (nt)", |
40 type = "h", main="Numbers of pairs", cex.main=1, xlab="overlap (nt)", | 43 ylab = "Numbers of pairs", col = "darkslateblue", lwd = 4) |
41 ylab="Numbers of pairs", col="darkslateblue", lwd=4) | |
42 | 44 |
43 plot(z_dataframe[z_dataframe$chrom == "all_chromosomes", c(2,4)], | 45 plot(z_dataframe[z_dataframe$chrom == "all_chromosomes", c(2, 4)], |
44 type = "l", main="Number of pairs Z-scores", cex.main=1, xlab="overlap (nt)", | 46 type = "l", main = "Number of pairs Z-scores", cex.main = 1, xlab = "overlap (nt)", |
45 ylab="z-score", pch=19, cex=0.2, col="darkslateblue", lwd=2) | 47 ylab = "z-score", pch = 19, cex = 0.2, col = "darkslateblue", lwd = 2) |
46 | 48 |
47 plot(h_dataframe[h_dataframe$chrom == "all_chromosomes", c(2,3)], | 49 plot(h_dataframe[h_dataframe$chrom == "all_chromosomes", c(2, 3)], |
48 type = "l", main="Overlap probabilities", cex.main=1, xlab="overlap (nt)", | 50 type = "l", main = "Overlap probabilities", cex.main = 1, |
49 ylab="Probability [%]", ylim=c(0,50), pch=19, col="darkslateblue", lwd=2) | 51 xlab = "overlap (nt)", |
52 ylab = "Probability [%]", ylim = c(0, 50), pch = 19, | |
53 col = "darkslateblue", lwd = 2) | |
50 | 54 |
51 plot(h_dataframe[h_dataframe$chrom == "all_chromosomes", c(2,4)], | 55 plot(h_dataframe[h_dataframe$chrom == "all_chromosomes", c(2, 4)], |
52 type = "l", main="Overlap Probability Z-scores", cex.main=1, | 56 type = "l", main = "Overlap Probability Z-scores", cex.main = 1, |
53 xlab="overlap (nt)", ylab="z-score", pch=19, cex=0.2, | 57 xlab = "overlap (nt)", ylab = "z-score", pch = 19, cex = 0.2, |
54 col="darkslateblue", lwd=2) | 58 col = "darkslateblue", lwd = 2) |
59 mtext(args$title, outer = TRUE, cex = 1) | |
60 dev.off() | |
61 } | |
55 | 62 |
56 mtext(args$title, outer = TRUE, cex=1) | 63 treillisgraph <- function(df, ...) { |
57 dev.off() | 64 pdf(args$pdf, paper = "special", height = 11.69, width = 6) |
58 } | 65 p <- xyplot(sig ~ overlap | factor(method, levels = unique(method)) + chrom, |
59 | 66 data = df, |
60 treillisgraph = function (df, ...) { | |
61 pdf(args$pdf, paper="special", height=11.69, width=6 ) # 8.2677 | |
62 p = xyplot(sig ~ overlap|factor(method, levels=unique(method))+chrom, data = df, | |
63 type = "l", | 67 type = "l", |
64 col='darkblue', | 68 col = "darkblue", |
65 cex=0.5, | 69 cex = 0.5, |
66 scales=list(y=list(tick.number=4, relation="free", cex=0.6, rot=0), x=list(cex=0.6, alternating=FALSE)), | 70 scales = list(y = list(tick.number = 4, relation = "free", cex = 0.6, |
71 rot = 0), | |
72 x = list(cex = 0.6, alternating = FALSE)), | |
67 xlab = "Overlap", | 73 xlab = "Overlap", |
68 ylab = "signature (Nbr of pairs / Overlap prob.)", | 74 ylab = "signature (Nbr of pairs / Overlap prob.)", |
69 main = args$title, | 75 main = args$title, |
70 par.strip.text=list(cex=.5), | 76 par.strip.text = list(cex = .5), |
71 pch=19, lwd =2, | 77 pch = 19, lwd = 2, |
72 as.table=TRUE, | 78 as.table = TRUE, |
73 layout=c(2,12), | 79 layout = c(2, 12), |
74 newpage = T, | 80 newpage = T, |
75 ...) | 81 ...) |
76 plot(p) | 82 plot(p) |
77 dev.off() | 83 dev.off() |
78 } | 84 } |
79 | 85 |
80 # main | 86 # main |
81 | 87 |
82 if (args$plot_method=="global") { | 88 if (args$plot_method == "global") { |
83 globalgraph() | 89 globalgraph() |
84 } | 90 } |
85 | 91 |
86 if(args$plot_method=="lattice") { | 92 if (args$plot_method == "lattice") { |
87 # rearrange dataframes | 93 # rearrange dataframes |
88 h_sig = h_dataframe[,c(1,2,3)] | 94 h_sig <- h_dataframe[, c(1, 2, 3)] |
89 h_sig = cbind(rep("Overlap Prob (%)", length(h_sig[,1])), h_sig) | 95 h_sig <- cbind(rep("Overlap Prob (%)", length(h_sig[, 1])), h_sig) |
90 colnames(h_sig) = c("method", "chrom", "overlap", "sig") | 96 colnames(h_sig) <- c("method", "chrom", "overlap", "sig") |
91 z_pairs = z_dataframe[,c(1,2,3)] | 97 z_pairs <- z_dataframe[, c(1, 2, 3)] |
92 z_pairs = cbind(rep("Nbr of pairs", length(z_pairs[,1])), z_pairs) | 98 z_pairs <- cbind(rep("Nbr of pairs", length(z_pairs[, 1])), z_pairs) |
93 colnames(z_pairs) = c("method", "chrom", "overlap", "sig") | 99 colnames(z_pairs) <- c("method", "chrom", "overlap", "sig") |
94 lattice_df = rbind(z_pairs, h_sig) | 100 lattice_df <- rbind(z_pairs, h_sig) |
95 par.settings.treillis=list(strip.background = list( | 101 par_settings_treillis <- list(strip.background = list( |
96 col = c("lightblue", "lightgreen"))) | 102 col = c("lightblue", "lightgreen"))) |
97 | 103 treillisgraph(lattice_df, par.settings = par_settings_treillis) |
98 treillisgraph(lattice_df, par.settings=par.settings.treillis) | |
99 } | 104 } |