Mercurial > repos > artbio > sr_bowtie_dataset_annotation
annotate barplot.r @ 6:8829656d6999 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:41 -0400 |
parents | e11f91575af6 |
children | 3bddd7ab96e3 |
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 |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
7 # load packages that are provided in the conda env |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
8 options( show.error.messages=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
|
9 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, 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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 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
|
15 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
|
16 |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
17 |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
18 #Arguments |
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 option_list = list( |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
20 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
|
21 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
|
22 default = NA, |
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 type = 'character', |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
24 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
|
25 ), |
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 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
|
27 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
|
28 default = NA, |
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 type = 'character', |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
30 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
|
31 ) |
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 opt = parse_args(OptionParser(option_list = option_list), |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
35 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
|
36 |
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 |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
38 ## |
008de522b3ea
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 53e9bab2c20411f34ac09688de2f2cc8ae8c46a4
artbio
parents:
diff
changeset
|
39 annotations = read.delim(opt$input, header=F) |
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
|
40 colnames(annotations) = c("sample", "class", "percent_of_reads", "total") |
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
|
41 annotations$percent=round(annotations$percent_of_reads/annotations$total*100, digits=2) |
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
|
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 |
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
|
45 Sasha.Trubetskoy.Palette <- c('#e6194b', '#3cb44b', '#ffe119', '#4363d8', '#f58231', |
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
|
46 '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', |
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
|
47 '#008080', '#e6beff', '#9a6324', '#fffac8', '#800000', |
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
|
48 '#aaffc3', '#808000', '#ffd8b1', '#000075', '#808080') |
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
|
49 nb.cols <- 19 # 10 with colorRampPalette |
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
|
50 # mycolors <- colorRampPalette(brewer.pal(8, "Paired"))(nb.cols) |
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
|
51 mycolors <- Sasha.Trubetskoy.Palette[1:nb.cols] |
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
|
52 |
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
|
53 ggtitle('Class proportions') |
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
|
54 ggplot(annotations, aes(x=total/2, y = percent_of_reads, fill = class, width = total)) + |
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
|
55 geom_bar(position="fill", stat="identity") + |
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
|
56 facet_wrap(~sample, ncol=3 ) + |
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 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), size=2,show.legend = F) + |
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 coord_polar(theta="y") + |
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 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 axis.title.y = 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
|
65 legend.position="bottom") + |
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
|
66 geom_text(aes(x = total/2, y= .5, label = paste(round(total/1000000, digits=3), "M"), vjust = 4, hjust=-1), size=2) |
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
|
67 ggsave(file=opt$barplot, device="pdf") |
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
|
68 |