annotate barplot.r @ 3:008de522b3ea draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
author artbio
date Sun, 10 Feb 2019 18:31:51 -0500
parents
children e11f91575af6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
1 if (length(commandArgs(TRUE)) == 0) {
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
2 system("Rscript barplot.r -h", intern = F)
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
3 q("no")
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
4 }
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
5
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
6
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
7 # load packages that are provided in the conda env
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
8 options( show.error.messages=F,
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
9 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
10 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
11 warnings()
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
12 library(optparse)
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
13 library(ggplot2)
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
14 library(scales)
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
15
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
16
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
17
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
18 #Arguments
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
19 option_list = list(
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
20 make_option(
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
21 c("-i", "--input"),
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
22 default = NA,
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
23 type = 'character',
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
24 help = "Input file that contains count data (no header)"
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
25 ),
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
26 make_option(
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
27 c("-o", "--barplot"),
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
28 default = NA,
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
29 type = 'character',
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
30 help = "PDF output file"
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
31 )
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
32 )
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
33
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
34 opt = parse_args(OptionParser(option_list = option_list),
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
35 args = commandArgs(trailingOnly = TRUE))
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
36
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
37
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
38 ##
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
39 annotations = read.delim(opt$input, header=F)
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
40 colnames(annotations) = c("class", "counts")
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
41 annotations = cbind(annotations, fraction=annotations$counts/annotations$counts[1])
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
42 annotations = annotations[-1,]
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
43 # ggplot2 plotting
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
44 ggplot(annotations, aes(x="classes", y=fraction, fill=class)) +
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
45 geom_bar(width = .7, position=position_stack(), stat = "identity") +
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
46 geom_text(aes(label = percent(fraction)), position = position_stack(vjust = 0.5),size = 4)
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
47 ggtitle('Class proportions')
008de522b3ea planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff changeset
48 ggsave(file=opt$barplot, device="pdf")