comparison coverage_plotting.R @ 0:da29af78a960 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
author artbio
date Mon, 24 Jul 2017 06:27:50 -0400
parents
children c163574c246f
comparison
equal deleted inserted replaced
-1:000000000000 0:da29af78a960
1 #!/usr/bin/env Rscript
2
3 # Help to be printed
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]"
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')"
8 hlp_output = "--output\tFILE\tFile to output the pdf to\n"
9
10 hlp = paste(hlp_description,hlp_usage,hlp_dataframe,hlp_type,hlp_output,sep="\n")
11 #print(hlp)
12
13 # Setup R error handling to go to stderr
14 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
15
16 library(optparse)
17 library(lattice)
18
19 # Get arguments
20 option_list <- list(
21 make_option(c("-d", "--dataframe"), type="character",
22 help="Dataframe containing coverage values obtained from mircounts.py"),
23 make_option(c("-t", "--type"), type="character", default="relative",
24 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")
26 )
27 parser <- OptionParser(usage = "%prog [options] file", option_list=option_list)
28 args = parse_args(parser)
29
30 if ( !('dataframe' %in% names(args)) || !('output' %in% names(args))) {
31 stop("'--dataframe' and '--output' parametters are not optional. Please retry.")
32 }
33
34 # Plot
35 coverage = read.delim(args$dataframe, header=T)
36 if (args$type =="relative") {
37 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),
39 strip=strip.custom(which.given=1, bg="lightblue"), layout=c(4,15),
40 as.table=T, xlab="Normalized Counts", ylab="Normalized coordinates",
41 main="miRNA coverage maps")
42 } else {
43 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),
45 strip=strip.custom(which.given=1, bg="lightblue"), layout=c(4,15),
46 as.table=T, xlab="Counts", ylab="Coordinates",
47 main="miRNA coverage plots")
48 }
49
50 # PDF output
51 pdf(file=args$output, paper="special", height=11.69, width=8.2677)
52 plot(graph, newpage = T)
53 dev.off()