Mercurial > repos > ethevenot > univariate
annotate univariate_script.R @ 2:09799fc16bc6 draft
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
author | ethevenot |
---|---|
date | Sat, 06 Aug 2016 12:42:42 -0400 |
parents | ef64d3752050 |
children | 140290de7986 |
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")) |
2
09799fc16bc6
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
ethevenot
parents:
0
diff
changeset
|
57 varPfxC <- paste0(varPfxC, paste(rev(facLevVc), collapse = "."), "_") |
0
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 |
2
09799fc16bc6
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
ethevenot
parents:
0
diff
changeset
|
70 prwVc <- gsub("-", ".", prwVc, fixed = TRUE) ## 2016-08-05: '-' character in dataframe column names seems not to be converted to "." by write.table on ubuntu R-3.3.1 |
09799fc16bc6
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
ethevenot
parents:
0
diff
changeset
|
71 |
0
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
72 aovMN <- t(apply(datMN, 2, function(varVn) { |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
73 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
74 aovMod <- aov(varVn ~ facFcVn) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
75 pvaN <- summary(aovMod)[[1]][1, "Pr(>F)"] |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
76 hsdMN <- TukeyHSD(aovMod)[["facFcVn"]] |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
77 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
|
78 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
79 })) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
80 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
81 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
|
82 sigVn <- as.numeric(aovMN[, 1] < thrN) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
83 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
|
84 ## 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
|
85 colnames(aovMN) <- paste0(varPfxC, |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
86 c(adjC, |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
87 "sig", |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
88 paste0(prwVc, "_dif"), |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
89 paste0(prwVc, "_pva"), |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
90 paste0(prwVc, "_sig"))) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
91 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
|
92 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
93 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
|
94 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
95 } else if(tesC == "kruskal") { |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
96 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
97 ## 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
|
98 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
|
99 nemVl <- c(lower.tri(nemMN, diag = TRUE)) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
100 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
|
101 colnames(nemMN)[c(col(nemMN))][nemVl]) |
2
09799fc16bc6
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
ethevenot
parents:
0
diff
changeset
|
102 nemNamVc <- paste0(nemClaMC[, 1], ".", nemClaMC[, 2]) |
0
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
103 nemNamVc <- paste0(varPfxC, nemNamVc) |
2
09799fc16bc6
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit 2c0d4d97c208edca1ada2035a7b7af9c4eb31afe
ethevenot
parents:
0
diff
changeset
|
104 |
0
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
105 nemMN <- t(apply(datMN, 2, function(varVn) { |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
106 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
107 pvaN <- kruskal.test(varVn ~ facFcVn)[["p.value"]] |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
108 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
|
109 c(pvaN, c(varNemMN)) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
110 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
111 })) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
112 pvaVn <- nemMN[, 1] |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
113 fdrVn <- p.adjust(pvaVn, method = adjC) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
114 sigVn <- as.numeric(fdrVn < thrN) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
115 nemMN <- nemMN[, c(FALSE, nemVl)] |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
116 colnames(nemMN) <- paste0(nemNamVc, "_pva") |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
117 nemSigMN <- nemMN < thrN |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
118 mode(nemSigMN) <- "numeric" |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
119 colnames(nemSigMN) <- paste0(nemNamVc, "_sig") |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
120 nemMN[sigVn < 1, ] <- NA |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
121 nemSigMN[sigVn < 1, ] <- NA |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
122 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
123 difMN <- sapply(1:nrow(nemClaMC), function(prwI) { |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
124 prwVc <- nemClaMC[prwI, ] |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
125 prwVi <- which(facFcVn %in% prwVc) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
126 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
|
127 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
|
128 }) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
129 colnames(difMN) <- gsub("_sig", "_dif", colnames(nemSigMN)) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
130 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
131 nemMN <- cbind(fdrVn, sigVn, difMN, nemMN, nemSigMN) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
132 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
|
133 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
134 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
|
135 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
136 } |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
137 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
138 names(sigVn) <- rownames(varDF) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
139 sigSumN <- sum(sigVn, na.rm = TRUE) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
140 if(sigSumN) { |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
141 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
|
142 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
|
143 } else |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
144 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
|
145 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
146 options(stingsAsFactors = strAsFacL) |
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 return(varDF) |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
149 |
ef64d3752050
planemo upload for repository https://github.com/workflow4metabolomics/univariate.git commit ca0e312e1c986c45310f37effe031f60009fbcab
ethevenot
parents:
diff
changeset
|
150 } |