annotate abims_anova.r @ 11:102049093b7d draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/anova commit 4922313a0e9569326b7723c41babb89f998dbfd9
author lecorguille
date Tue, 13 Mar 2018 09:47:21 -0400
parents b147b17759a6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
1 #!/usr/local/public/bin/Rscript
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
2 # version="1.1"
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
3
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
4 # date: 06-06-2012
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
5 # update: 18-02-2014
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
6 # **Authors** Gildas Le Corguille ABiMS - UPMC/CNRS - Station Biologique de Roscoff - gildas.lecorguille|at|sb-roscoff.fr
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
7
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
8 # abims_anova.r version 20140218
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
9
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
10 library(batch)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
11
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
12
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
13 # function avova
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
14 anova = function (file, sampleinfo, varinfo, mode="column", condition=1, interaction=F, method="BH", threshold=0.01, selection_method="intersection", sep=";", dec=".", outputdatapvalue="anova.data.output", outputdatasignif="anova.datasignif.output") {
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
15
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
16
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
17 if (sep=="tabulation") sep="\t"
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
18 if (sep=="semicolon") sep=";"
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
19 if (sep=="comma") sep=","
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
20
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
21 anova_formula_operator = "+"
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
22 if (interaction) anova_formula_operator = "*"
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
23
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
24 # -- import --
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
25 data=read.table(file, header = TRUE, row.names=1, sep = sep, quote="\"", dec = dec, fill = TRUE, comment.char="",na.strings = "NA", check.names=FALSE)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
26
11
102049093b7d planemo upload for repository https://github.com/workflow4metabolomics/anova commit 4922313a0e9569326b7723c41babb89f998dbfd9
lecorguille
parents: 10
diff changeset
27 if (mode == "row") {data=t(data)} else {data=as.matrix(data)}
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
28
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
29 sampleinfoTab=read.table(sampleinfo, header = TRUE, row.names=1, sep = sep, quote="\"")
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
30 rownames(sampleinfoTab) = make.names(rownames(sampleinfoTab))
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
31
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
32 varinfoTab=read.table(varinfo, header = TRUE, sep = sep, quote="\"")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
33 if(sum(colnames(data)!=varinfoTab[,1])!=0){ # if ID not exactly identical
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
34 if(sum(colnames(data)[order(colnames(data))]!=varinfoTab[order(varinfoTab[,1]),1])==0){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
35 # reorder data matrix to match variable metadata order
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
36 data = data[,match(varinfoTab[,1],colnames(data))]
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
37 }else{
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
38 stop(paste0("\nVariables' ID do not match between your data matrix and your variable",
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
39 "metadata file. \nPlease check your data."))
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
40 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
41 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
42
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
43 # -- group --
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
44 match_data_sampleinfoTab = match(rownames(data),rownames(sampleinfoTab))
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
45 if (sum(is.na(match_data_sampleinfoTab)) > 0) {
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
46 write("ERROR: There is a problem during to match sample names from the data matrix and from the sample info (presence of NA).", stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
47 write("You may need to use change the mode (column/row)", stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
48 write("10 first sample names in the data matrix:", stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
49 write(head(colnames(data)), stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
50 write("10 first sample names in the sample info:", stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
51 write(head(rownames(sampleinfoTab)), stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
52 quit("no",status=10)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
53 }
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
54
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
55
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
56 # -- anova --
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
57
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
58 # formula
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
59 grps=list()
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
60 anova_formula_s = "data ~ "
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
61 cat("\ncontrasts:\n")
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
62 for (i in 1:length(condition)) {
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
63 grps[[i]] = factor(sampleinfoTab[,condition[i]][match_data_sampleinfoTab])
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
64 anova_formula_s = paste(anova_formula_s, "grps[[",i,"]]",anova_formula_operator, sep="")
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
65 cat(condition[i],"\t",levels(grps[[i]]),"\n")
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
66 # write("Current groups: ", stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
67 # write(grp[[i]], stderr())
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
68 }
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
69 anova_formula_s = substr(anova_formula_s, 1, nchar(anova_formula_s)-1)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
70 anova_formula = as.formula(anova_formula_s)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
71
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
72
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
73
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
74 # anova
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
75 manovaObjectList = manova(anova_formula)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
76 manovaList = summary.aov(manovaObjectList)
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
77
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
78 # condition renaming
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
79 manovaRownames = gsub(" ","",rownames(manovaList[[1]]))
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
80 manovaNbrPvalue = length(manovaRownames)-1
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
81 manovaRownames = manovaRownames[-(manovaNbrPvalue+1)]
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
82
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
83 for (i in 1:length(condition)) {
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
84 manovaRownames = sub(paste("grps\\[\\[",i,"\\]\\]",sep=""),condition[i],manovaRownames)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
85 anova_formula_s = sub(paste("grps\\[\\[",i,"\\]\\]",sep=""),condition[i],anova_formula_s)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
86 }
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
87
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
88 # log
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
89 cat("\nanova_formula",anova_formula_s,"\n")
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
90
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
91 # p-value
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
92 aovPValue = sapply(manovaList,function(x){x[-(manovaNbrPvalue+1),5]})
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
93 if(length(condition) == 1) aovPValue = t(aovPValue)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
94 rownames(aovPValue) = paste("pvalue_",manovaRownames,sep="")
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
95
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
96 # p-value adjusted
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
97 if(length(condition) == 1) {
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
98 aovAdjPValue = t(p.adjust(aovPValue,method=method))
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
99 } else {
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
100 aovAdjPValue = t(apply(aovPValue,1,p.adjust, method=method))
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
101 }
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
102 rownames(aovAdjPValue) = paste("pval.",method,".",manovaRownames,sep="")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
103
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
104 # selection
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
105 colSumThreshold = colSums(aovAdjPValue <= threshold)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
106 if (selection_method == "intersection") {
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
107 datafiltered = data[,colSumThreshold == nrow(aovAdjPValue ), drop=FALSE]
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
108 } else {
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
109 datafiltered = data[,colSumThreshold != 0, drop=FALSE]
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
110 }
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
111 selected.var = rep("no",ncol(data))
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
112 selected.var[colnames(data)%in%colnames(datafiltered)] = "yes"
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
113
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
114 #data=rbind(data, aovPValue, aovAdjPValue)
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
115 varinfoTab=cbind(varinfoTab, round(t(aovAdjPValue),10), selected.var)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
116
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
117 # group means
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
118 for (i in 1:length(condition)) {
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
119 for(j in levels(grps[[i]])){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
120 subgp = rownames(sampleinfoTab[which(sampleinfoTab[,condition[i]]==j),])
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
121 modmean = colMeans(data[which(rownames(data)%in%subgp),],na.rm=TRUE)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
122 varinfoTab=cbind(varinfoTab, modmean)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
123 colnames(varinfoTab)[ncol(varinfoTab)] = paste0("Mean_",condition[i],".",j)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
124 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
125 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
126 colnames(varinfoTab) = make.unique(colnames(varinfoTab))
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
127
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
128 # pdf for significant variables
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
129 pdf(outputdatasignif)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
130 ### Venn diagram
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
131 if(nrow(aovAdjPValue)>5){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
132 pie(100,labels=NA,main=paste0("Venn diagram only available for maximum 5 terms\n",
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
133 "(your analysis concerns ",nrow(aovAdjPValue)," terms)\n\n",
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
134 "Number of significant variables relatively to\nyour chosen threshold and ",
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
135 "selection method: ",ncol(datafiltered)),cex.main=0.8)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
136 }else{
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
137 vennlist = list(NULL)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
138 names(vennlist) = rownames(aovAdjPValue)[1]
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
139 if(length(colnames(aovAdjPValue))==0){colnames(aovAdjPValue)=varinfoTab[,1]}
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
140 for(i in 1:nrow(aovAdjPValue)){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
141 vennlist[[rownames(aovAdjPValue)[i]]]=colnames(aovAdjPValue[i,which(aovAdjPValue[i,]<=threshold),drop=FALSE])
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
142 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
143 if(length(vennlist)==0){ pie(100,labels=NA,main="No significant ions was found.")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
144 }else{ library(venn) ; venn(vennlist, zcolor="style", cexil=2, cexsn=1.5) }
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
145 }
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
146 ### Boxplot
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
147 par(mfrow=c(2,2),mai=rep(0.5,4))
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
148 data <- as.data.frame(data)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
149 for(i in 1:nrow(aovAdjPValue)){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
150 factmain = gsub(paste0("pval.",method,"."),"",rownames(aovAdjPValue)[i])
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
151 factsignif = aovAdjPValue[i,which(aovAdjPValue[i,]<=threshold),drop=FALSE]
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
152 if((ncol(factsignif)!=0)&(factmain%in%colnames(sampleinfoTab))){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
153 for(j in 1:ncol(factsignif)){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
154 varsignif = gsub(" Response ","",colnames(factsignif)[j])
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
155 boxplot(as.formula(paste0("data$",varsignif," ~ sampleinfoTab$",factmain)),
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
156 main=paste0(factmain,"\n",varsignif), col="grey", mai=7)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
157 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
158 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
159 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
160 dev.off()
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
161
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
162 # summary for significant variables
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
163 cat("\n\n- - - - - - - number of significant variables - - - - - - -\n\n")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
164 for(i in 1:nrow(aovAdjPValue)){
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
165 cat(rownames(aovAdjPValue)[i],"-",
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
166 sum(aovAdjPValue[i,]<=threshold),"significant variable(s)\n")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
167 }
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
168 cat("\nIf some of your factors are missing here, this may be due to\neffects",
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
169 "not estimable; your design may not be balanced enough.\n")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
170
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
171 # -- output / return --
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
172 write.table(varinfoTab, outputdatapvalue, sep=sep, quote=F, row.names=FALSE)
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
173
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
174 # log
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
175 cat("\nthreshold:",threshold,"\n")
10
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
176 cat("result:",ncol(datafiltered),"/",ncol(data),"\n\n")
b147b17759a6 planemo upload for repository https://github.com/workflow4metabolomics/anova commit 28838bb8dafd6d286157db77f181ed8a1b586664
lecorguille
parents: 0
diff changeset
177
0
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
178 quit("no",status=0)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
179 }
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
180
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
181 # log
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
182 cat("ANOVA\n\n")
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
183 cat("Arguments\n")
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
184 args <- commandArgs(trailingOnly = TRUE)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
185 print(args)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
186
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
187 listArguments = parseCommandArgs(evaluate=FALSE)
8dd2a438bfba Uploaded
lecorguille
parents:
diff changeset
188 do.call(anova, listArguments)