comparison coverage_plotting.R @ 14:c163574c246f draft

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