Mercurial > repos > artbio > sr_bowtie_dataset_annotation
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/barplot.r Sun Feb 10 18:31:51 2019 -0500 @@ -0,0 +1,48 @@ +if (length(commandArgs(TRUE)) == 0) { + system("Rscript barplot.r -h", intern = F) + q("no") +} + + +# load packages that are provided in the conda env +options( show.error.messages=F, + error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) +loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") +warnings() +library(optparse) +library(ggplot2) +library(scales) + + + +#Arguments +option_list = list( + make_option( + c("-i", "--input"), + default = NA, + type = 'character', + help = "Input file that contains count data (no header)" + ), + make_option( + c("-o", "--barplot"), + default = NA, + type = 'character', + help = "PDF output file" + ) +) + +opt = parse_args(OptionParser(option_list = option_list), + args = commandArgs(trailingOnly = TRUE)) + + +## +annotations = read.delim(opt$input, header=F) +colnames(annotations) = c("class", "counts") +annotations = cbind(annotations, fraction=annotations$counts/annotations$counts[1]) +annotations = annotations[-1,] +# ggplot2 plotting +ggplot(annotations, aes(x="classes", y=fraction, fill=class)) + +geom_bar(width = .7, position=position_stack(), stat = "identity") + +geom_text(aes(label = percent(fraction)), position = position_stack(vjust = 0.5),size = 4) +ggtitle('Class proportions') +ggsave(file=opt$barplot, device="pdf")