Mercurial > repos > artbio > sr_bowtie_dataset_annotation
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 2:243ed53cbc0d | 3:008de522b3ea |
|---|---|
| 1 if (length(commandArgs(TRUE)) == 0) { | |
| 2 system("Rscript barplot.r -h", intern = F) | |
| 3 q("no") | |
| 4 } | |
| 5 | |
| 6 | |
| 7 # load packages that are provided in the conda env | |
| 8 options( show.error.messages=F, | |
| 9 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) | |
| 10 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
| 11 warnings() | |
| 12 library(optparse) | |
| 13 library(ggplot2) | |
| 14 library(scales) | |
| 15 | |
| 16 | |
| 17 | |
| 18 #Arguments | |
| 19 option_list = list( | |
| 20 make_option( | |
| 21 c("-i", "--input"), | |
| 22 default = NA, | |
| 23 type = 'character', | |
| 24 help = "Input file that contains count data (no header)" | |
| 25 ), | |
| 26 make_option( | |
| 27 c("-o", "--barplot"), | |
| 28 default = NA, | |
| 29 type = 'character', | |
| 30 help = "PDF output file" | |
| 31 ) | |
| 32 ) | |
| 33 | |
| 34 opt = parse_args(OptionParser(option_list = option_list), | |
| 35 args = commandArgs(trailingOnly = TRUE)) | |
| 36 | |
| 37 | |
| 38 ## | |
| 39 annotations = read.delim(opt$input, header=F) | |
| 40 colnames(annotations) = c("class", "counts") | |
| 41 annotations = cbind(annotations, fraction=annotations$counts/annotations$counts[1]) | |
| 42 annotations = annotations[-1,] | |
| 43 # ggplot2 plotting | |
| 44 ggplot(annotations, aes(x="classes", y=fraction, fill=class)) + | |
| 45 geom_bar(width = .7, position=position_stack(), stat = "identity") + | |
| 46 geom_text(aes(label = percent(fraction)), position = position_stack(vjust = 0.5),size = 4) | |
| 47 ggtitle('Class proportions') | |
| 48 ggsave(file=opt$barplot, device="pdf") |
