Mercurial > repos > artbio > mircounts
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 14:c163574c246f | 15:ffcd42f85b61 |
|---|---|
| 8 hlp_output <- "--output\tFILE\tFile to output the pdf to\n" | 8 hlp_output <- "--output\tFILE\tFile to output the pdf to\n" |
| 9 | 9 |
| 10 hlp <- paste(hlp_description, hlp_usage, hlp_dataframe, hlp_type, hlp_output, sep = "\n") | 10 hlp <- paste(hlp_description, hlp_usage, hlp_dataframe, hlp_type, hlp_output, sep = "\n") |
| 11 | 11 |
| 12 # Setup R error handling to go to stderr | 12 # Setup R error handling to go to stderr |
| 13 options(show.error.messages = F, | 13 options(show.error.messages = FALSE, |
| 14 error = function() { | 14 error = function() { |
| 15 cat(geterrmessage(), file = stderr()); q("no", 1, F) | 15 cat(geterrmessage(), file = stderr()) |
| 16 q("no", 1, FALSE) | |
| 16 } | 17 } |
| 17 ) | 18 ) |
| 18 | 19 |
| 19 library(optparse) | 20 library(optparse) |
| 20 library(lattice) | 21 library(lattice) |
| 24 make_option(c("-d", "--dataframe"), type = "character", | 25 make_option(c("-d", "--dataframe"), type = "character", |
| 25 help = "Dataframe containing coverage values obtained from mircounts.py"), | 26 help = "Dataframe containing coverage values obtained from mircounts.py"), |
| 26 make_option(c("-t", "--type"), type = "character", default = "relative", | 27 make_option(c("-t", "--type"), type = "character", default = "relative", |
| 27 help = "Type of plotting, either relative or absoute coverage values (default = 'relative')"), | 28 help = "Type of plotting, either relative or absoute coverage values (default = 'relative')"), |
| 28 make_option(c("-o", "--output"), type = "character", help = "File to output the pdf to") | 29 make_option(c("-o", "--output"), type = "character", help = "File to output the pdf to") |
| 29 ) | 30 ) |
| 30 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) | 31 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) |
| 31 args <- parse_args(parser) | 32 args <- parse_args(parser) |
| 32 | 33 |
| 33 if (!("dataframe" %in% names(args)) || !("output" %in% names(args))) { | 34 if (!("dataframe" %in% names(args)) || !("output" %in% names(args))) { |
| 34 stop("'--dataframe' and '--output' parametters are not optional. Please retry.") | 35 stop("'--dataframe' and '--output' parametters are not optional. Please retry.") |
| 35 } | 36 } |
| 36 | 37 |
| 37 # Plot | 38 # Plot |
| 38 coverage <- read.delim(args$dataframe, header = T) | 39 coverage <- read.delim(args$dataframe, header = TRUE) |
| 39 if (args$type == "relative") { | 40 if (args$type == "relative") { |
| 40 graph <- xyplot(Norm_count ~ Norm_offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5, | 41 graph <- xyplot( |
| 41 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5), | 42 Norm_count ~ Norm_offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5, |
| 42 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15), | 43 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5), |
| 43 as.table = T, xlab = "Normalized Counts", ylab = "Normalized coordinates", | 44 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15), |
| 44 main = "miRNA coverage maps") | 45 as.table = TRUE, xlab = "Normalized Counts", ylab = "Normalized coordinates", |
| 46 main = "miRNA coverage maps" | |
| 47 ) | |
| 45 } else { | 48 } else { |
| 46 graph <- xyplot(Count ~ Offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5, | 49 graph <- xyplot( |
| 47 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5), | 50 Count ~ Offset | Mir_hairpin, data = coverage, col = c("darkblue"), type = "l", lwd = 1.5, |
| 48 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15), | 51 scales = list(x = list(cex = .5), y = list(cex = .5)), par.strip.text = list(cex = .5), |
| 49 as.table = T, xlab = "Counts", ylab = "Coordinates", | 52 strip = strip.custom(which.given = 1, bg = "lightblue"), layout = c(4, 15), |
| 50 main = "miRNA coverage plots") | 53 as.table = TRUE, xlab = "Counts", ylab = "Coordinates", |
| 54 main = "miRNA coverage plots" | |
| 55 ) | |
| 51 } | 56 } |
| 52 | 57 |
| 53 # PDF output | 58 # PDF output |
| 54 pdf(file = args$output, paper = "special", height = 11.69, width = 8.2677) | 59 pdf(file = args$output, paper = "special", height = 11.69, width = 8.2677) |
| 55 plot(graph, newpage = T) | 60 plot(graph, newpage = TRUE) |
| 56 dev.off() | 61 dev.off() |
