annotate aldex2.R @ 0:f4d0bd4b4d6d draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
author iuc
date Wed, 29 Jun 2022 07:36:45 +0000
parents
children 75214276e2b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
1 #!/usr/bin/env Rscript
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
2
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
3 suppressPackageStartupMessages(library("ALDEx2"))
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
4 suppressPackageStartupMessages(library("data.table"))
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
5 suppressPackageStartupMessages(library("qgraph"))
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
6 suppressPackageStartupMessages(library("optparse"))
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
7
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
8 option_list <- list(
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
9 make_option(c("--aldex_test"), action = "store", dest = "aldex_test", default = NULL, help = "Indicates which analysis to perform"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
10 make_option(c("--analysis_type"), action = "store", dest = "analysis_type", help = "Indicates which analysis to perform"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
11 make_option(c("--cutoff_effect"), action = "store", dest = "cutoff_effect", type = "integer", default = NULL, help = "Effect size cutoff for plotting"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
12 make_option(c("--cutoff_pval"), action = "store", dest = "cutoff_pval", type = "double", default = NULL, help = "Benjamini-Hochberg fdr cutoff"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
13 make_option(c("--denom"), action = "store", dest = "denom", help = "Indicates which features to retain as the denominator for the Geometric Mean calculation"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
14 make_option(c("--effect"), action = "store", dest = "effect", default = "false", help = "Calculate abundances and effect sizes"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
15 make_option(c("--feature_name"), action = "store", dest = "feature_name", default = NULL, help = "Name of the feature from the input data to be plotted"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
16 make_option(c("--group_names"), action = "store", dest = "group_names", help = "Group names vector"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
17 make_option(c("--group_nums"), action = "store", dest = "group_nums", default = NULL, help = "Group number for continuous numeric vector"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
18 make_option(c("--hist_plot"), action = "store", dest = "hist_plot", default = "false", help = "Indicates whether to plot a histogram of p-values for the first Dirichlet Monte Carlo instance"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
19 make_option(c("--include_sample_summary"), action = "store", dest = "include_sample_summary", default = "false", help = "Include median clr values for each sample"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
20 make_option(c("--iterate"), action = "store", dest = "iterate", default = "false", help = "Indicates whether to iteratively perform a test"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
21 make_option(c("--num_cols"), action = "store", dest = "num_cols", help = "Number of columns in group vector"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
22 make_option(c("--num_cols_in_groups"), action = "store", dest = "num_cols_in_groups", default = NULL, help = "Number of columns in each group dewfining the continuous numeric vector"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
23 make_option(c("--num_mc_samples"), action = "store", dest = "num_mc_samples", type = "integer", help = "Number of Monte Carlo samples"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
24 make_option(c("--output"), action = "store", dest = "output", help = "output file"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
25 make_option(c("--paired_test"), action = "store", dest = "paired_test", default = "false", help = "Indicates whether to do paired-sample tests"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
26 make_option(c("--plot_test"), action = "store", dest = "plot_test", default = NULL, help = "The method of calculating significance"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
27 make_option(c("--plot_type"), action = "store", dest = "plot_type", default = NULL, help = "The type of plot to be produced"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
28 make_option(c("--reads"), action = "store", dest = "reads", help = "Input reads table"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
29 make_option(c("--xlab"), action = "store", dest = "xlab", default = NULL, help = "x lable for the plot"),
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
30 make_option(c("--ylab"), action = "store", dest = "ylab", default = NULL, help = "y lable for the plot")
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
31 )
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
32
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
33 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
34 args <- parse_args(parser, positional_arguments = TRUE)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
35 opt <- args$options
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
36
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
37 get_boolean_value <- function(val) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
38 if (val == "true") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
39 return(TRUE)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
40 } else {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
41 return(FALSE)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
42 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
43 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
44
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
45 # Read the input reads file into a data frame.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
46 reads_df <- read.table(file = opt$reads, header = TRUE, sep = "\t", row.names = 1, dec = ".", as.is = FALSE)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
47
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
48 # Split the group_names and num_cols into lists of strings.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
49 group_names_str <- as.character(opt$group_names)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
50 group_names_list <- strsplit(group_names_str, ",")[[1]]
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
51 num_cols_str <- as.character(opt$num_cols)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
52 num_cols_list <- strsplit(num_cols_str, ",")[[1]]
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
53 # Construct conditions vector.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
54 conditions_vector <- c()
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
55 for (i in seq_along(num_cols_list)) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
56 num_cols <- as.integer(num_cols_list[i])
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
57 group_name <- group_names_list[i]
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
58 for (j in 1:num_cols) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
59 conditions_vector <- cbind(conditions_vector, group_name)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
60 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
61 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
62 # The conditions_vector is now a matrix,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
63 # so coerce it back to a vector.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
64 conditions_vector <- as.vector(conditions_vector)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
65
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
66 # Convert boolean values to boolean.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
67 effect <- get_boolean_value(opt$effect)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
68 include_sample_summary <- get_boolean_value(opt$include_sample_summary)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
69 iterate <- get_boolean_value(opt$iterate)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
70
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
71 if (opt$analysis_type == "aldex") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
72 aldex_obj <- aldex(reads = reads_df,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
73 conditions_vector,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
74 mc.samples = opt$num_mc_samples,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
75 test = opt$aldex_test,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
76 effect = effect,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
77 include.sample.summary = include_sample_summary,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
78 denom = opt$denom,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
79 iterate = iterate)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
80 } else {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
81 # Generate Monte Carlo samples of the Dirichlet distribution for each sample. Convert each
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
82 # instance using a log-ratio transform. This is the input for all further analyses.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
83 aldex_clr_obj <- aldex.clr(reads_df, conditions_vector, mc.samples = opt$num_mc_samples, denom = opt$denom)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
84
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
85 if (opt$analysis_type == "aldex_corr") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
86 if (!is.null(opt$cont_var)) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
87 # Read the input cont_var vector.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
88 cont_var <- as.numeric(read.table(file = opt$cont_var, header = FALSE, sep = "\t"))
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
89 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
90
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
91 # Split the group_names and num_cols into lists of strings.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
92 group_nums_str <- as.character(opt$group_nums)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
93 group_nums_list <- strsplit(group_nums_str, ",")[[1]]
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
94 num_cols_in_groups_str <- as.character(opt$num_cols_in_groups)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
95 num_cols_in_groups_list <- strsplit(num_cols_in_groups_str, ",")[[1]]
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
96 # Construct continuous numeric vector.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
97 cont_var_vector <- c()
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
98 for (i in seq_along(num_cols_in_groups_list)) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
99 num_cols_in_group <- as.integer(num_cols_in_groups_list[i])
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
100 group_num <- group_nums_list[i]
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
101 for (j in 1:num_cols_in_group) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
102 cont_var_vector <- cbind(cont_var_vector, group_num)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
103 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
104 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
105 # The cont_var_vector is now a matrix,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
106 # so coerce it back to a vector.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
107 cont_var_vector <- as.numeric(as.vector(cont_var_vector))
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
108
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
109 aldex_obj <- aldex.corr(aldex_clr_obj, cont.var = cont_var_vector)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
110 } else if (opt$analysis_type == "aldex_effect") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
111 aldex_obj <- aldex.effect(aldex_clr_obj, include_sample_summary)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
112 } else if (opt$analysis_type == "aldex_expected_distance") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
113 dist <- aldex.expectedDistance(aldex_clr_obj)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
114 png(filename = opt$output)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
115 qgraph(dist, layout = "spring", vsize = 1)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
116 dev.off()
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
117 } else if (opt$analysis_type == "aldex_kw") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
118 aldex_obj <- aldex.kw(aldex_clr_obj)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
119 } else if (opt$analysis_type == "aldex_plot") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
120 aldex_obj <- aldex(reads = reads_df,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
121 conditions_vector,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
122 mc.samples = opt$num_mc_samples,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
123 test = opt$aldex_test,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
124 effect = effect,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
125 include.sample.summary = include_sample_summary,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
126 denom = opt$denom,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
127 iterate = iterate)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
128 png(filename = opt$output)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
129 aldex.plot(x = aldex_obj,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
130 type = opt$plot_type,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
131 test = opt$plot_test,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
132 cutoff.pval = opt$cutoff_pval,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
133 cutoff.effect = opt$cutoff_effect,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
134 xlab = opt$xlab,
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
135 ylab = opt$ylab)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
136 dev.off()
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
137 } else if (opt$analysis_type == "aldex_plot_feature") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
138 png(filename = opt$output)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
139 aldex.plotFeature(aldex_clr_obj, opt$feature_name)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
140 dev.off()
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
141 } else if (opt$analysis_type == "aldex_ttest") {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
142 paired_test <- get_boolean_value(opt$paired_test)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
143 hist_plot <- get_boolean_value(opt$hist_plot)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
144 aldex_obj <- aldex.ttest(aldex_clr_obj, paired.test = paired_test, hist.plot = hist_plot)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
145 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
146 }
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
147 if ((opt$analysis_type != "aldex_expected_distance") && (opt$analysis_type != "aldex_plot") && (opt$analysis_type != "aldex_plot_feature")) {
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
148 # Output the ALDEx object.
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
149 write.table(aldex_obj, file = opt$output, append = FALSE, sep = "\t", dec = ".", row.names = FALSE, col.names = TRUE)
f4d0bd4b4d6d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/aldex2 commit b99f09cf03f075a6881d192b0f1233233289fa60
iuc
parents:
diff changeset
150 }