Mercurial > repos > artbio > sr_bowtie_dataset_annotation
comparison barplot.r @ 0:bfe92ceffe57 draft
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 60340e9e0d2795b88e23fd57e1ccb190918bf337"
| author | artbio |
|---|---|
| date | Mon, 07 Oct 2019 08:40:15 -0400 |
| parents | |
| children | 19ba2e38e8ec |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:bfe92ceffe57 |
|---|---|
| 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(ggrepel) | |
| 15 library(RColorBrewer) | |
| 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("sample", "class", "percent_of_reads", "total") | |
| 41 annotations$percent=round(annotations$percent_of_reads/annotations$total*100, digits=2) | |
| 42 # ggplot2 plotting | |
| 43 | |
| 44 # Define the number of colors you want | |
| 45 Sasha.Trubetskoy.Palette <- c('#e6194b', '#3cb44b', '#ffe119', '#4363d8', '#f58231', | |
| 46 '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', | |
| 47 '#008080', '#e6beff', '#9a6324', '#fffac8', '#800000', | |
| 48 '#aaffc3', '#808000', '#ffd8b1', '#000075', '#808080') | |
| 49 nb.cols <- 19 # 10 with colorRampPalette | |
| 50 # mycolors <- colorRampPalette(brewer.pal(8, "Paired"))(nb.cols) | |
| 51 mycolors <- Sasha.Trubetskoy.Palette[1:nb.cols] | |
| 52 | |
| 53 ggtitle('Class proportions') | |
| 54 ggplot(annotations, aes(x=total/2, y = percent_of_reads, fill = class, width = total)) + | |
| 55 geom_bar(position="fill", stat="identity") + | |
| 56 facet_wrap(~sample, ncol=3 ) + | |
| 57 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), size=2,show.legend = F) + | |
| 58 coord_polar(theta="y") + | |
| 59 labs(x = "Class fractions (%)") + | |
| 60 scale_fill_manual(values = mycolors) + | |
| 61 theme(axis.text = element_blank(), | |
| 62 axis.ticks = element_blank(), | |
| 63 panel.grid = element_blank(), | |
| 64 axis.title.y = element_blank(), | |
| 65 legend.position="bottom") + | |
| 66 geom_text(aes(x = total/2, y= .5, label = paste(round(total/1000000, digits=3), "M"), vjust = 4, hjust=-1), size=2) | |
| 67 ggsave(file=opt$barplot, device="pdf") | |
| 68 |
