Mercurial > repos > iuc > phyloseq_from_biom
annotate phyloseq_plot_bar.R @ 7:04ba1fa0fe57 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
author | iuc |
---|---|
date | Thu, 13 Mar 2025 09:49:28 +0000 |
parents | 847f433f202b |
children |
rev | line source |
---|---|
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env Rscript |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
2 |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
3 # Load libraries |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
4 suppressPackageStartupMessages(library("optparse")) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
5 suppressPackageStartupMessages(library("phyloseq")) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
6 suppressPackageStartupMessages(library("ggplot2")) |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
7 suppressPackageStartupMessages(library("dplyr")) |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
8 |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
9 # Define options |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
10 option_list <- list( |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
11 make_option(c("--input"), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
12 action = "store", dest = "input", |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
13 help = "Input file containing a phyloseq object" |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
14 ), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
15 make_option(c("--x"), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
16 action = "store", dest = "x", |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
17 help = "Variable for x-axis (e.g., 'Sample', 'Phylum')" |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
18 ), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
19 make_option(c("--fill"), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
20 action = "store", dest = "fill", default = NULL, |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
21 help = "Variable for fill color (e.g., 'Genus', 'Order'). Use 'ASV' as argument to show each OTU/ASV." |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
22 ), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
23 make_option(c("--facet"), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
24 action = "store", dest = "facet", default = NULL, |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
25 help = "Facet by variable (optional)" |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
26 ), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
27 make_option(c("--output"), |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
28 action = "store", dest = "output", |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
29 help = "Output file (PDF)" |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
30 ), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
31 make_option(c("--topX"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
32 action = "store", dest = "topX", default = NULL, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
33 help = "Show only the top X taxa based on abundance (e.g., '10') (optional)" |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
34 ), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
35 make_option(c("--keepOthers"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
36 action = "store_true", dest = "keepOthers", default = FALSE, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
37 help = "Keep taxa not in topX and label them as 'Others' (optional)" |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
38 ), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
39 make_option(c("--keepNonAssigned"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
40 action = "store_true", dest = "keepNonAssigned", default = FALSE, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
41 help = "Keep taxa labeled as 'Not Assigned' (optional)" |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
42 ), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
43 make_option(c("--normalize"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
44 action = "store_true", dest = "normalize", default = FALSE, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
45 help = "Normalize abundances to sum to 100% (optional)" |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
46 ), |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
47 make_option(c("--normalize_x"), |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
48 action = "store_true", dest = "normalize_x", default = FALSE, |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
49 help = "Normalize x groups to sum up to 100%" |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
50 ), |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
51 make_option(c("--width"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
52 action = "store", dest = "width", default = 10, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
53 type = "numeric", help = "Width of the output plot in inches" |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
54 ), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
55 make_option(c("--height"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
56 action = "store", dest = "height", default = 8, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
57 type = "numeric", help = "Height of the output plot in inches" |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
58 ), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
59 make_option(c("--device"), |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
60 action = "store", dest = "device", default = "pdf", |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
61 help = "Output format (e.g., 'pdf', 'png', 'jpg')" |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
62 ), |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
63 make_option(c("--nolines"), |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
64 action = "store_true", dest = "nolines", default = FALSE, |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
65 help = "Remove borders (lines) around bars (TRUE/FALSE)" |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
66 ) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
67 ) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
68 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
69 |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
70 # Parse arguments |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
71 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
72 args <- parse_args(parser, positional_arguments = TRUE) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
73 opt <- args$options |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
74 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
75 |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
76 # Validate required options |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
77 if (is.null(opt$input) || opt$input == "") { |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
78 stop("Error: Input file is required.") |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
79 } |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
80 if (is.null(opt$output) || opt$output == "") { |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
81 stop("Error: Output file is required.") |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
82 } |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
83 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
84 if (is.null(opt$fill) || opt$fill == "") { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
85 print(paste("No fill chosen using ASV")) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
86 opt$fill <- "ASV" |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
87 } |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
88 |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
89 # Load phyloseq object |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
90 print(paste("Trying to read:", opt$input)) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
91 physeq <- readRDS(opt$input) |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
92 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
93 ## Allow to use OTU as tax group |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
94 # Extract rownames (taxids) from the tax_table and add them as a new column |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
95 taxids <- rownames(tax_table(physeq)) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
96 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
97 # Get the number of columns in the tax_table |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
98 num_columns <- ncol(tax_table(physeq)) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
99 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
100 # Add the taxids as a new last column in the tax_table |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
101 tax_table(physeq) <- cbind(tax_table(physeq), taxid = taxids) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
102 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
103 # Rename the last column to 'ASV' / OTU does conflict with phyloseq logic |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
104 colnames(tax_table(physeq))[num_columns + 1] <- "ASV" |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
105 |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
106 # Normalize to relative abundances if requested |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
107 if (opt$normalize) { |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
108 print("Normalizing abundances to sum to 100%...") |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
109 physeq <- transform_sample_counts(physeq, function(x) 100 * x / sum(x)) |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
110 } |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
111 |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
112 # Debug: Check available taxonomic ranks |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
113 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
114 tax_ranks <- colnames(tax_table(physeq)) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
115 sample_vars <- colnames(sample_data(physeq)) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
116 |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
117 print("Available taxonomic ranks:") |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
118 print(tax_ranks) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
119 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
120 print("Available metadata:") |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
121 print(sample_vars) |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
122 |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
123 # Handle missing or unassigned taxa for all ranks |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
124 if (opt$keepNonAssigned) { |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
125 # Replace NA or empty values with 'Not Assigned' for all ranks |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
126 |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
127 for (rank in tax_ranks) { |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
128 if (rank %in% tax_ranks) { |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
129 # replace NA or empty values with 'Not Assigned' |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
130 tax_table(physeq)[, rank][is.na(tax_table(physeq)[, rank])] <- "Not Assigned" |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
131 } |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
132 } |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
133 } |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
134 |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
135 # Filter to top X taxa if requested |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
136 if (!is.null(opt$topX) && opt$topX != "") { |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
137 topX <- as.numeric(opt$topX) |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
138 if (is.na(topX) || topX <= 0) { |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
139 stop("Error: topX should be a positive number.") |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
140 } |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
141 |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
142 tax_rank <- opt$fill |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
143 if (!tax_rank %in% colnames(tax_table(physeq))) { |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
144 stop(paste("Error: Tax rank", tax_rank, "not found in tax_table.")) |
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
145 } |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
146 |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
147 physeq_agg <- tax_glom(physeq, taxrank = tax_rank) |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
148 taxa_abundance <- taxa_sums(physeq_agg) |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
149 tax_table_agg <- tax_table(physeq_agg) |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
150 taxa_abundance_by_rank <- tapply(taxa_abundance, tax_table_agg[, tax_rank], sum) |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
151 top_taxa <- names(sort(taxa_abundance_by_rank, decreasing = TRUE))[1:topX] |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
152 |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
153 print("Top taxa:") |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
154 print(top_taxa) |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
155 |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
156 otus_in_top_taxa <- rownames(tax_table_agg)[tax_table_agg[, tax_rank] %in% top_taxa] |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
157 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
158 # Group non-top OTUs as 'Others' if requested |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
159 if (opt$keepOthers) { |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
160 # Update the tax_table to assign 'Others' to non-top taxa |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
161 tax_table(physeq_agg)[, tax_rank][!rownames(tax_table_agg) %in% otus_in_top_taxa] <- "Others" |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
162 physeq <- physeq_agg |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
163 } else { |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
164 physeq <- prune_taxa(otus_in_top_taxa, physeq_agg) |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
165 } |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
166 } |
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
167 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
168 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
169 # normalize x groups if needed |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
170 if (opt$x %in% sample_vars) { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
171 if (opt$normalize_x && !is.null(opt$x) && opt$x != "") { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
172 physeq_agg <- merge_samples(physeq, opt$x) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
173 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
174 physeq <- transform_sample_counts(physeq_agg, function(x) (x / sum(x) * 100)) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
175 opt$x <- NULL # set to Null since we do not need x for downstream now |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
176 opt$facet <- NULL # set to Null since facetting does not work with normalize x |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
177 warning(paste("normalize x does not work with facetting")) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
178 } |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
179 } else { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
180 warning(paste("x", opt$x, "not found in sample data. Skipping normalize_x.")) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
181 } |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
182 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
183 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
184 # Check if the facet variable is valid and exists |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
185 facet_var <- NULL |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
186 if (!is.null(opt$facet) && opt$facet != "") { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
187 if (opt$facet %in% sample_vars || opt$facet %in% tax_ranks) { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
188 facet_var <- opt$facet # Store facet variable for later |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
189 } else { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
190 warning(paste("Facet variable", opt$facet, "not found in sample data or tax ranks. Skipping faceting.")) |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
191 } |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
192 } |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
193 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
194 # Determine if faceting is needed |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
195 facet_formula <- if (!is.null(facet_var)) as.formula(paste("~", facet_var)) else NULL |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
196 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
197 # Define color based on the `nolines` option |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
198 plot_color <- ifelse(opt$nolines, NA, "black") |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
199 |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
200 # Generate bar plot |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
201 if (!is.null(opt$x) && opt$x != "") { |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
202 p <- plot_bar(physeq, |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
203 x = opt$x, |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
204 fill = opt$fill |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
205 ) + facet_wrap(facet_formula, scales = "free_x") + |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
206 geom_bar( |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
207 stat = "identity", |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
208 position = "stack", |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
209 aes(fill = !!sym(opt$fill)), |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
210 color = plot_color |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
211 ) |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
212 } else { |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
213 p <- plot_bar(physeq, |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
214 fill = opt$fill |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
215 ) + facet_wrap(facet_formula, scales = "free_x") + |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
216 geom_bar( |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
217 stat = "identity", |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
218 position = "stack", |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
219 aes(fill = !!sym(opt$fill)), |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
220 color = plot_color |
6
847f433f202b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit d6888da7aba38b97f6cb827355f2de436565684a
iuc
parents:
5
diff
changeset
|
221 ) |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
222 } |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
223 |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
224 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
225 # Reorder fill levels to ensure "Not Assigned" and "Others" are at the bottom if they exist |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
226 fill_values <- unique(p$data[[opt$fill]]) # Get unique fill values |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
227 new_levels <- setdiff(fill_values, c("Not Assigned", "Others")) # Exclude "Not Assigned" and "Others" |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
228 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
229 if ("Not Assigned" %in% fill_values) { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
230 new_levels <- c("Not Assigned", new_levels) # Place "Not Assigned" at the bottom if it exists |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
231 } |
7
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
232 if ("Others" %in% fill_values) { |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
233 new_levels <- c("Others", new_levels) # Place "Others" at the bottom if it exists |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
234 } |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
235 |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
236 # Apply the new levels to the fill variable in the plot data |
04ba1fa0fe57
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit a5ae2f86b2955290a4c81ab234f02cc51020f970
iuc
parents:
6
diff
changeset
|
237 p$data[[opt$fill]] <- factor(p$data[[opt$fill]], levels = new_levels) |
1
1feea247d08a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 10dfb1308ff858c6623c7dd9215a3bdf518427f9
iuc
parents:
diff
changeset
|
238 |
4
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
239 # Save to output file |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
240 ggsave( |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
241 filename = opt$output, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
242 plot = p, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
243 width = opt$width, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
244 height = opt$height, |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
245 device = opt$device |
b8a4de1a4e19
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/phyloseq commit 26f87cc62468c9c329b33246af4f14e2659856f9
iuc
parents:
1
diff
changeset
|
246 ) |