Mercurial > repos > artbio > sr_bowtie_dataset_annotation
annotate barplot.r @ 4:e11f91575af6 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
| author | artbio |
|---|---|
| date | Wed, 20 Mar 2019 07:12:53 -0400 |
| parents | 008de522b3ea |
| children | 8829656d6999 |
| 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) |
|
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
|
15 |
|
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 #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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 ), |
|
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 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 ) |
|
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 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
|
34 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
|
35 |
|
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 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
|
39 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
|
40 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
|
41 # ggplot2 plotting |
|
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 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
|
43 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
|
44 geom_bar(position="fill", stat="identity") + |
|
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
|
45 facet_wrap(~sample, ncol=3 ) + geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), size=2,show.legend = F) + |
|
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
|
46 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
|
47 labs(x = "Class fractions (%)") + |
|
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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 |
