annotate barplot.r @ 7:3bddd7ab96e3 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
author artbio
date Sun, 24 Oct 2021 23:52:11 +0000
parents 8829656d6999
children fd4a60fc3fca
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 # load packages that are provided in the conda env
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
7 options(show.error.messages = F,
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
8 error = function() {
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
9 cat(geterrmessage(), file = stderr())
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
10 q("no", 1, F)
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
11 }
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
12 )
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
13 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
14 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
15 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
16 library(ggplot2)
4
e11f91575af6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
artbio
parents: 3
diff changeset
17 library(ggrepel)
6
8829656d6999 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 60340e9e0d2795b88e23fd57e1ccb190918bf337"
artbio
parents: 4
diff changeset
18 library(RColorBrewer)
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
19
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
20 option_list <- list(
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
21 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
22 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
23 default = NA,
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
24 type = "character",
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
25 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
26 ),
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 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
28 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
29 default = NA,
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
30 type = "character",
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
31 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
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
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
35 opt <- parse_args(OptionParser(option_list = option_list),
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
36 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
37
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
38 annotations <- read.delim(opt$input, header = F)
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
39 colnames(annotations) <- c("sample", "class", "percent_of_reads", "total")
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
40 annotations$percent <- round(annotations$percent_of_reads / annotations$total * 100,
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
41 digits = 2)
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
42 ## ggplot2 plotting
6
8829656d6999 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 60340e9e0d2795b88e23fd57e1ccb190918bf337"
artbio
parents: 4
diff changeset
43
8829656d6999 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 60340e9e0d2795b88e23fd57e1ccb190918bf337"
artbio
parents: 4
diff changeset
44 # Define the number of colors you want
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
45 mycolors <- c("#e6194b", "#3cb44b", "#ffe119", "#4363d8", "#f58231",
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
46 "#911eb4", "#46f0f0", "#f032e6", "#bcf60c",
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
47 "#008080", "#e6beff", "#9a6324", "#fffac8", "#800000",
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
48 "#aaffc3", "#808000", "#ffd8b1", "#000075", "#808080")
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
49 ggtitle("Class proportions")
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
50 ggplot(annotations, aes(x = total / 2, y = percent_of_reads, fill = class, width = total)) +
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
51 geom_bar(position = "fill", stat = "identity") +
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
52 facet_wrap(~sample, ncol = 3) +
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
53 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5),
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
54 size = 2, show.legend = F) +
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
55 coord_polar(theta = "y") +
4
e11f91575af6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
artbio
parents: 3
diff changeset
56 labs(x = "Class fractions (%)") +
6
8829656d6999 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 60340e9e0d2795b88e23fd57e1ccb190918bf337"
artbio
parents: 4
diff changeset
57 scale_fill_manual(values = mycolors) +
4
e11f91575af6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
artbio
parents: 3
diff changeset
58 theme(axis.text = element_blank(),
e11f91575af6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
artbio
parents: 3
diff changeset
59 axis.ticks = element_blank(),
e11f91575af6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
artbio
parents: 3
diff changeset
60 panel.grid = element_blank(),
e11f91575af6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
artbio
parents: 3
diff changeset
61 axis.title.y = element_blank(),
7
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
62 legend.position = "bottom") +
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
63 geom_text(aes(x = total / 2, y = .5, label = paste(round(total / 1000000, digits = 3),
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
64 "M"),
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
65 vjust = 4, hjust = -1), size = 2)
3bddd7ab96e3 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 1010eff91c8ce7415d50adaf2f83ecc278295df8"
artbio
parents: 6
diff changeset
66 ggsave(file = opt$barplot, device = "pdf")