annotate univariate_script.R @ 0:ef64d3752050 draft

planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
author ethevenot
date Wed, 27 Jul 2016 11:44:34 -0400
parents
children 09799fc16bc6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
1 univariateF <- function(datMN,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
2 samDF,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
3 varDF,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
4 facC,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
5 tesC = c("ttest", "wilcoxon", "anova", "kruskal", "pearson", "spearman")[1],
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
6 adjC = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none")[7],
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
7 thrN = 0.05) {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
8
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
9
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
10 ## Option
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
11 ##---------------
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
12
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
13 strAsFacL <- options()$stringsAsFactors
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
14 options(stingsAsFactors = FALSE)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
15 options(warn = -1)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
16
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
17 if(mode(samDF[, facC]) == "character") {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
18 facFcVn <- factor(samDF[, facC])
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
19 facLevVc <- levels(facFcVn)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
20 } else
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
21 facFcVn <- samDF[, facC]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
22
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
23 cat("\nPerforming '", tesC, "'\n", sep="")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
24
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
25 varPfxC <- paste0(make.names(facC), "_", tesC, "_")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
26
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
27 if(tesC %in% c("ttest", "wilcoxon", "pearson", "spearman")) {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
28
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
29 switch(tesC,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
30 ttest = {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
31 staF <- function(y) diff(tapply(y, facFcVn, function(x) mean(x, na.rm = TRUE)))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
32 tesF <- function(y) t.test(y ~ facFcVn)[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
33 },
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
34 wilcoxon = {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
35 staF <- function(y) diff(tapply(y, facFcVn, function(x) median(x, na.rm = TRUE)))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
36 tesF <- function(y) wilcox.test(y ~ facFcVn)[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
37 },
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
38 pearson = {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
39 staF <- function(y) cor(facFcVn, y, method = "pearson", use = "pairwise.complete.obs")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
40 tesF <- function(y) cor.test(facFcVn, y, method = "pearson", use = "pairwise.complete.obs")[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
41 },
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
42 spearman = {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
43 staF <- function(y) cor(facFcVn, y, method = "spearman", use = "pairwise.complete.obs")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
44 tesF <- function(y) cor.test(facFcVn, y, method = "spearman", use = "pairwise.complete.obs")[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
45 })
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
46
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
47 staVn <- apply(datMN, 2, staF)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
48
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
49 fdrVn <- p.adjust(apply(datMN,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
50 2,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
51 tesF),
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
52 method = adjC)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
53
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
54 sigVn <- as.numeric(fdrVn < thrN)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
55
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
56 if(tesC %in% c("ttest", "wilcoxon"))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
57 varPfxC <- paste0(varPfxC, paste(rev(facLevVc), collapse = "-"), "_")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
58
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
59 varDF[, paste0(varPfxC, ifelse(tesC %in% c("ttest", "wilcoxon"), "dif", "cor"))] <- staVn
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
60
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
61 varDF[, paste0(varPfxC, adjC)] <- fdrVn
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
62
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
63 varDF[, paste0(varPfxC, "sig")] <- sigVn
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
64
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
65 } else if(tesC == "anova") {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
66
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
67 ## getting the names of the pairwise comparisons 'class1Vclass2'
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
68 prwVc <- rownames(TukeyHSD(aov(datMN[, 1] ~ facFcVn))[["facFcVn"]])
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
69
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
70 aovMN <- t(apply(datMN, 2, function(varVn) {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
71
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
72 aovMod <- aov(varVn ~ facFcVn)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
73 pvaN <- summary(aovMod)[[1]][1, "Pr(>F)"]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
74 hsdMN <- TukeyHSD(aovMod)[["facFcVn"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
75 c(pvaN, c(hsdMN[, c("diff", "p adj")]), as.numeric(hsdMN[, "p adj"] < thrN))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
76
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
77 }))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
78
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
79 aovMN[, 1] <- p.adjust(aovMN[, 1], method = adjC)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
80 sigVn <- as.numeric(aovMN[, 1] < thrN)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
81 aovMN <- cbind(aovMN[, 1], sigVn, aovMN[, 2:ncol(aovMN)])
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
82 ## aovMN[which(aovMN[, 2] < 1), (3 + length(prwVc)):ncol(aovMN)] <- NA
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
83 colnames(aovMN) <- paste0(varPfxC,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
84 c(adjC,
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
85 "sig",
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
86 paste0(prwVc, "_dif"),
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
87 paste0(prwVc, "_pva"),
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
88 paste0(prwVc, "_sig")))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
89 aovMN[which(aovMN[, paste0(varPfxC, "sig")] < 1), paste0(varPfxC, c(paste0(prwVc, "_pva"), paste0(prwVc, "_sig")))] <- NA
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
90
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
91 varDF <- cbind.data.frame(varDF, as.data.frame(aovMN))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
92
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
93 } else if(tesC == "kruskal") {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
94
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
95 ## getting the names of the pairwise comparisons 'class1Vclass2'
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
96 nemMN <- posthoc.kruskal.nemenyi.test(datMN[, 1], facFcVn, "Tukey")[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
97 nemVl <- c(lower.tri(nemMN, diag = TRUE))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
98 nemClaMC <- cbind(rownames(nemMN)[c(row(nemMN))][nemVl],
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
99 colnames(nemMN)[c(col(nemMN))][nemVl])
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
100 nemNamVc <- paste0(nemClaMC[, 1], "-", nemClaMC[, 2])
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
101 nemNamVc <- paste0(varPfxC, nemNamVc)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
102
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
103 nemMN <- t(apply(datMN, 2, function(varVn) {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
104
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
105 pvaN <- kruskal.test(varVn ~ facFcVn)[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
106 varNemMN <- posthoc.kruskal.nemenyi.test(varVn, facFcVn, "Tukey")[["p.value"]]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
107 c(pvaN, c(varNemMN))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
108
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
109 }))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
110 pvaVn <- nemMN[, 1]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
111 fdrVn <- p.adjust(pvaVn, method = adjC)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
112 sigVn <- as.numeric(fdrVn < thrN)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
113 nemMN <- nemMN[, c(FALSE, nemVl)]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
114 colnames(nemMN) <- paste0(nemNamVc, "_pva")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
115 nemSigMN <- nemMN < thrN
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
116 mode(nemSigMN) <- "numeric"
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
117 colnames(nemSigMN) <- paste0(nemNamVc, "_sig")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
118 nemMN[sigVn < 1, ] <- NA
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
119 nemSigMN[sigVn < 1, ] <- NA
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
120
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
121 difMN <- sapply(1:nrow(nemClaMC), function(prwI) {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
122 prwVc <- nemClaMC[prwI, ]
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
123 prwVi <- which(facFcVn %in% prwVc)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
124 prwFacFc <- factor(as.character(facFcVn)[prwVi], levels = prwVc)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
125 apply(datMN[prwVi, ], 2, function(varVn) -diff(as.numeric(tapply(varVn, prwFacFc, function(x) median(x, na.rm = TRUE)))))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
126 })
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
127 colnames(difMN) <- gsub("_sig", "_dif", colnames(nemSigMN))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
128
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
129 nemMN <- cbind(fdrVn, sigVn, difMN, nemMN, nemSigMN)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
130 colnames(nemMN)[1:2] <- paste0(varPfxC, c(adjC, "sig"))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
131
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
132 varDF <- cbind.data.frame(varDF, as.data.frame(nemMN))
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
133
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
134 }
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
135
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
136 names(sigVn) <- rownames(varDF)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
137 sigSumN <- sum(sigVn, na.rm = TRUE)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
138 if(sigSumN) {
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
139 cat("\nThe following ", sigSumN, " variable", ifelse(sigSumN > 1, "s", ""), " (", round(sigSumN / length(sigVn) * 100), "%) ", ifelse(sigSumN > 1, "were", "was"), " found significant at the ", thrN, " level:\n", sep = "")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
140 cat(paste(rownames(varDF)[sigVn > 0], collapse = "\n"), "\n", sep = "")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
141 } else
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
142 cat("\nNo significant variable found at the selected ", thrN, " level\n", sep = "")
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
143
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
144 options(stingsAsFactors = strAsFacL)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
145
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
146 return(varDF)
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
147
ef64d3752050 planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff changeset
148 }