Mercurial > repos > artbio > sr_bowtie_dataset_annotation
comparison barplot.r @ 4:7e0dbc330dfc draft default tip
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit cf30b4fab90cf7910bb2900a05b85ca3344aae59
| author | artbio |
|---|---|
| date | Tue, 15 Nov 2022 00:44:20 +0000 |
| parents | 19ba2e38e8ec |
| children |
comparison
equal
deleted
inserted
replaced
| 3:990b37ae7d78 | 4:7e0dbc330dfc |
|---|---|
| 1 if (length(commandArgs(TRUE)) == 0) { | 1 if (length(commandArgs(TRUE)) == 0) { |
| 2 system("Rscript barplot.r -h", intern = F) | 2 system("Rscript barplot.r -h", intern = FALSE) |
| 3 q("no") | 3 q("no") |
| 4 } | 4 } |
| 5 | 5 |
| 6 # load packages that are provided in the conda env | 6 # load packages that are provided in the conda env |
| 7 options(show.error.messages = F, | 7 options(show.error.messages = FALSE, |
| 8 error = function() { | 8 error = function() { |
| 9 cat(geterrmessage(), file = stderr()) | 9 cat(geterrmessage(), file = stderr()) |
| 10 q("no", 1, F) | 10 q("no", 1, FALSE) |
| 11 } | 11 } |
| 12 ) | 12 ) |
| 13 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | 13 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
| 14 warnings() | 14 warnings() |
| 15 library(optparse) | 15 library(optparse) |
| 33 ) | 33 ) |
| 34 | 34 |
| 35 opt <- parse_args(OptionParser(option_list = option_list), | 35 opt <- parse_args(OptionParser(option_list = option_list), |
| 36 args = commandArgs(trailingOnly = TRUE)) | 36 args = commandArgs(trailingOnly = TRUE)) |
| 37 | 37 |
| 38 annotations <- read.delim(opt$input, header = F) | 38 annotations <- read.delim(opt$input, header = FALSE) |
| 39 colnames(annotations) <- c("sample", "class", "percent_of_reads", "total") | 39 colnames(annotations) <- c("sample", "class", "percent_of_reads", "total") |
| 40 annotations$percent <- round(annotations$percent_of_reads / annotations$total * 100, | 40 annotations$percent <- round(annotations$percent_of_reads / annotations$total * 100, |
| 41 digits = 2) | 41 digits = 2) |
| 42 ## ggplot2 plotting | 42 ## ggplot2 plotting |
| 43 | 43 |
| 49 ggtitle("Class proportions") | 49 ggtitle("Class proportions") |
| 50 ggplot(annotations, aes(x = total / 2, y = percent_of_reads, fill = class, width = total)) + | 50 ggplot(annotations, aes(x = total / 2, y = percent_of_reads, fill = class, width = total)) + |
| 51 geom_bar(position = "fill", stat = "identity") + | 51 geom_bar(position = "fill", stat = "identity") + |
| 52 facet_wrap(~sample, ncol = 3) + | 52 facet_wrap(~sample, ncol = 3) + |
| 53 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), | 53 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), |
| 54 size = 2, show.legend = F) + | 54 size = 2, show.legend = FALSE) + |
| 55 coord_polar(theta = "y") + | 55 coord_polar(theta = "y") + |
| 56 labs(x = "Class fractions (%)") + | 56 labs(x = "Class fractions (%)") + |
| 57 scale_fill_manual(values = mycolors) + | 57 scale_fill_manual(values = mycolors) + |
| 58 theme(axis.text = element_blank(), | 58 theme(axis.text = element_blank(), |
| 59 axis.ticks = element_blank(), | 59 axis.ticks = element_blank(), |
