annotate coverage_plotting.R @ 15:ffcd42f85b61 draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
author artbio
date Sat, 10 Feb 2024 17:15:04 +0000
parents c163574c246f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
1 #!/usr/bin/env Rscript
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
2
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
3 # Help to be printed
14
c163574c246f "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."
c163574c246f "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]"
c163574c246f "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"
c163574c246f "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')"
c163574c246f "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
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
9
14
c163574c246f "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
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
11
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
12 # Setup R error handling to go to stderr
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
13 options(show.error.messages = FALSE,
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
14 error = function() {
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
15 cat(geterrmessage(), file = stderr())
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
16 q("no", 1, FALSE)
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
17 }
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
18 )
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
19
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
20 library(optparse)
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
21 library(lattice)
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
22
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
23 # Get arguments
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
24 option_list <- list(
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
25 make_option(c("-d", "--dataframe"), type = "character",
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
26 help = "Dataframe containing coverage values obtained from mircounts.py"),
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
27 make_option(c("-t", "--type"), type = "character", default = "relative",
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
28 help = "Type of plotting, either relative or absoute coverage values (default = 'relative')"),
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
29 make_option(c("-o", "--output"), type = "character", help = "File to output the pdf to")
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
30 )
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
31 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
32 args <- parse_args(parser)
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
33
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
34 if (!("dataframe" %in% names(args)) || !("output" %in% names(args))) {
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
35 stop("'--dataframe' and '--output' parametters are not optional. Please retry.")
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
36 }
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
37
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
38 # Plot
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
39 coverage <- read.delim(args$dataframe, header = TRUE)
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
40 if (args$type == "relative") {
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
41 graph <- xyplot(
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
42 Norm_count ~ Norm_offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5,
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
43 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5),
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
44 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15),
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
45 as.table = TRUE, xlab = "Normalized Counts", ylab = "Normalized coordinates",
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
46 main = "miRNA coverage maps"
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
47 )
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
48 } else {
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
49 graph <- xyplot(
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
50 Count ~ Offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5,
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
51 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5),
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
52 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15),
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
53 as.table = TRUE, xlab = "Counts", ylab = "Coordinates",
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
54 main = "miRNA coverage plots"
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
55 )
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
56 }
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
57
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
58 # PDF output
14
c163574c246f "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 51dc6c56c7d95fc229ffee958354211cd454fd36"
artbio
parents: 0
diff changeset
59 pdf(file = args$output, paper = "special", height = 11.69, width = 8.2677)
15
ffcd42f85b61 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 5eb8570dce4e22fb2759cc16c8e1ce9d304508fe
artbio
parents: 14
diff changeset
60 plot(graph, newpage = TRUE)
0
da29af78a960 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
61 dev.off()