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