annotate coverage_plotting.R @ 4:b7ac138bb781 draft default tip

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
author artbio
date Sun, 09 May 2021 17:06:45 +0000
parents 10f0e4c00b13
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
1 #!/usr/bin/env Rscript
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
2
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
3 # Help to be printed
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
4 hlp_description <- "This script takes a dataframe containing the coverage values for different miRNAs and plots them."
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
5 hlp_usage <- "Usage : coverage_ploting.R --dataframe [FILE] --type ['relative' or 'absolute'] --output [FILE]"
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
6 hlp_dataframe <- "--dataframe\tFILE\tThis is a dataframe containing coverage values obtained from mircounts.py"
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
7 hlp_type <- "--type\t\tSTRING\tType of ploting, either relative or absoute coverage values (default='relative')"
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
8 hlp_output <- "--output\tFILE\tFile to output the pdf to\n"
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
9
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
10 hlp <- paste(hlp_description, hlp_usage, hlp_dataframe, hlp_type, hlp_output, sep = "\n")
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
11
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
12 # Setup R error handling to go to stderr
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
13 options(show.error.messages = F,
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
14 error = function() {
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
15 cat(geterrmessage(), file = stderr()); q("no", 1, F)
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
16 }
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
17 )
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
18
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
19 library(optparse)
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
20 library(lattice)
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
21
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
22 # Get arguments
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
23 option_list <- list(
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
24 make_option(c("-d", "--dataframe"), type = "character",
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
25 help = "Dataframe containing coverage values obtained from mircounts.py"),
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
26 make_option(c("-t", "--type"), type = "character", default = "relative",
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
27 help = "Type of plotting, either relative or absoute coverage values (default = 'relative')"),
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
28 make_option(c("-o", "--output"), type = "character", help = "File to output the pdf to")
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
29 )
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
30 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
31 args <- parse_args(parser)
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
32
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
33 if (!("dataframe" %in% names(args)) || !("output" %in% names(args))) {
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
34 stop("'--dataframe' and '--output' parametters are not optional. Please retry.")
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
35 }
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
36
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
37 # Plot
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
38 coverage <- read.delim(args$dataframe, header = T)
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
39 if (args$type == "relative") {
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
40 graph <- xyplot(Norm_count ~ Norm_offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5,
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
41 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5),
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
42 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15),
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
43 as.table = T, xlab = "Normalized Counts", ylab = "Normalized coordinates",
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
44 main = "miRNA coverage maps")
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
45 } else {
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
46 graph <- xyplot(Count ~ Offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5,
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
47 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5),
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
48 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15),
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
49 as.table = T, xlab = "Counts", ylab = "Coordinates",
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
50 main = "miRNA coverage plots")
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
51 }
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
52
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
53 # PDF output
4
b7ac138bb781 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
54 pdf(file = args$output, paper = "special", height = 11.69, width = 8.2677)
0
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
55 plot(graph, newpage = T)
10f0e4c00b13 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 3a6181bd181729f642b75c4e689f063fc2821cf1
artbio
parents:
diff changeset
56 dev.off()