comparison signature.r @ 0:a35e6f9c1d34 draft

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