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