annotate decon.R @ 0:bd267e082f86 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
author iuc
date Wed, 06 Aug 2025 08:38:24 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
1 suppressPackageStartupMessages(library(microDecon))
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
2 suppressPackageStartupMessages(library(optparse))
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
3
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
4 # Define command-line options
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
5 option_list <- list(
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
6 make_option(c("-m", "--mode"), type = "character", help = "Mode of operation: decon, remove.cont, remove.thresh, decon.diff", metavar = "MODE"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
7 make_option(c("-d", "--data_file"), type = "character", help = "Path to the data file (CSV format expected)", metavar = "FILE"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
8 make_option(c("-o", "--output"), type = "character", default = NULL, help = "Output file from remove.cont or remove.thresh (used in decon.diff)", metavar = "FILE"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
9 make_option(c("-b", "--numb_blanks"), type = "integer", default = NULL, help = "Number of blank samples"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
10 make_option(c("-n", "--numb_ind"), type = "character", default = NULL, help = "Number of individuals (eval-parsed)"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
11 make_option(c("-t", "--taxa"), type = "logical", default = FALSE, help = "Taxa flag (TRUE or FALSE)"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
12 make_option(c("-r", "--runs"), type = "integer", default = NULL, help = "Number of runs"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
13 make_option(c("-T", "--thresh"), type = "double", default = NULL, help = "Threshold value"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
14 make_option(c("-p", "--prop_thresh"), type = "double", default = NULL, help = "Proportional threshold value"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
15 make_option(c("-g", "--regression"), type = "double", default = NULL, help = "Regression value"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
16 make_option(c("-l", "--low_threshold"), type = "double", default = 40, help = "Low threshold [default: %default]"),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
17 make_option(c("-u", "--up_threshold"), type = "double", default = 400, help = "Upper threshold [default: %default]")
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
18 )
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
19
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
20 # Parse arguments
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
21 opt <- parse_args(OptionParser(option_list = option_list))
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
22
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
23 # Read main input data
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
24 microbe_data <- read.csv(opt$data_file, header = TRUE, stringsAsFactors = FALSE, check.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
25
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
26 if (opt$mode == "decon") {
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
27 result <- decon(
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
28 data = microbe_data,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
29 numb.blanks = opt$numb_blanks,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
30 numb.ind = eval(parse(text = opt$numb_ind)),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
31 taxa = opt$taxa,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
32 runs = opt$runs,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
33 thresh = opt$thresh,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
34 prop.thresh = opt$prop_thresh,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
35 regression = opt$regression,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
36 low.threshold = opt$low_threshold,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
37 up.threshold = opt$up_threshold
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
38 )
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
39 write.csv(result$decon.table, "decon_table.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
40 write.csv(result$reads.removed, "reads_removed.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
41 write.csv(result$sum.per.group, "difference_sum.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
42 write.csv(result$mean.per.group, "difference_mean.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
43 write.csv(result$OTUs.removed, "OTUs_removed.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
44 } else if (opt$mode == "remove_cont") {
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
45 result <- remove.cont(
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
46 data = microbe_data,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
47 numb.blanks = opt$numb_blanks,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
48 taxa = opt$taxa,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
49 runs = opt$runs,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
50 regression = opt$regression,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
51 low.threshold = opt$low_threshold,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
52 up.threshold = opt$up_threshold
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
53 )
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
54 write.csv(result, "decon_table.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
55 } else if (opt$mode == "remove_thresh") {
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
56 result <- remove.thresh(
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
57 data = microbe_data,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
58 numb.ind = eval(parse(text = opt$numb_ind)),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
59 taxa = opt$taxa,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
60 thresh = opt$thresh,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
61 prop.thresh = opt$prop_thresh
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
62 )
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
63 write.csv(result, "decon_table.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
64 } else if (opt$mode == "decon_diff") {
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
65 if (is.null(opt$output)) stop("Error: --output must be provided for decon.diff mode")
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
66 output_data <- read.csv(opt$output, header = TRUE, stringsAsFactors = FALSE, check.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
67 result <- decon.diff(
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
68 data = microbe_data,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
69 output = output_data,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
70 numb.blanks = opt$numb_blanks,
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
71 numb.ind = eval(parse(text = opt$numb_ind)),
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
72 taxa = opt$taxa
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
73 )
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
74 write.csv(result$decon.table, "decon_table.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
75 write.csv(result$reads.removed, "reads_removed.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
76 write.csv(result$sum.per.group, "difference_sum.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
77 write.csv(result$mean.per.group, "difference_mean.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
78 write.csv(result$OTUs.removed, "OTUs_removed.csv", row.names = FALSE)
bd267e082f86 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/micro_decon/ commit bb37578aa61bf4a47af262e02baf0a1c1d9d02c6
iuc
parents:
diff changeset
79 }