annotate summary_statistics.R @ 0:46ddb0591d8b draft default tip

planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
author vmarcon
date Thu, 18 Jan 2018 07:44:37 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
1 ###########################################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
2 # Quality controls and descriptive analysis plots #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
3 ###########################################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
4 # Authors: Melanie Petera #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
5 ###########################################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
6 # Description : This script allows various displays of data for quality #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
7 # control and descriptive analysis. The input data is a matrix of #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
8 # quantitative variables, and it returns chosen plots in png format #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
9 # and a table with chosen statistics. #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
10 ###########################################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
11 # Specific R packages: #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
12 # - edgeR (needed for MA plots) #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
13 ###########################################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
14 # Version 1 (06-06-2014): display boxplot, histogram, density plot, #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
15 # MA plot, pairs plot, and return a table of chosen statistics #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
16 # (quantiles, mean, variance, standard error of the mean) #
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
17 ###########################################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
18
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
19 desc_fct <- function(file.in, nacode, table_file, graph_file, stat, chosen.stat, ploting, chosen.plot, log_file){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
20 # Parameters:
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
21 # - file.in: count matrix input (tab-separated) [file name]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
22 # - nacode: missing value coding character
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
23 # - table_file: results file containing table of chosen statistics [file name]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
24 # - graph_file: pdf file containing plots for chosen statistics [file name]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
25 # - stat: should statistics be calculated? (TRUE/FALSE)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
26 # - chosen.stat: character listing the chosen statistics (comma-separated)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
27 # - ploting: should graphics be displayed? (TRUE/FALSE)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
28 # - chosen.plot: character listing the chosen plots (comma-separated)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
29 # - log_file: a log file [file name]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
30
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
31
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
32 ##########################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
33 # Read and verify data - - - - - - - - - - - -
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
34 # Checks valids for all modules
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
35
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
36 library(methods)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
37
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
38 log_error=function(message="") {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
39 line_use="line"
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
40 column_use="column"
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
41
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
42 cat("<HTML><HEAD><TITLE>Normalization report</TITLE></HEAD><BODY>\n",file=log_file,append=F,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
43 cat("&#9888 An error occurred while trying to read your table.\n<BR>",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
44 cat("Please check that:\n<BR>",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
45 cat("<UL>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
46 cat(" <LI> the table you want to process contains the same number of columns for each line</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
47 cat(" <LI> the first line of your table is a header line (specifying the name of each ",column_use,")</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
48 cat(" <LI> the first column of your table specifies the name of each ",line_use,"</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
49 cat(" <LI> both individual and variable names should be unique</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
50 cat(" <LI> each value is separated from the other by a <B>TAB</B> character</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
51 cat(" <LI> except for first line and first column, table should contain a numeric value</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
52 cat(" <LI> this value may contain character '.' as decimal separator or '",nacode,"' for missing values</LI>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
53 cat("</UL>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
54 cat("-------<BR>\nError messages recieved:<BR><FONT color=red>\n",conditionMessage(message),"</FONT>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
55 cat("</BODY></HTML>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
56 q(save="no",status=1)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
57 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
58
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
59 tab_in=tryCatch(
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
60 {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
61 tab_in=read.table(file.in,header=TRUE,na.strings=nacode,sep="\t",check.names=FALSE,quote="\"")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
62 },
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
63 error=function(cond) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
64 log_error(message=cond)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
65 return(NA)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
66 },
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
67 warning=function(cond) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
68 log_error(message=cond)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
69 return(NA)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
70 },
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
71 finally={
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
72 #Do nothing special
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
73 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
74 )
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
75
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
76 if (ncol(tab_in)<2) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
77 log_error(simpleCondition("The table you want to use contains less than two columns."))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
78 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
79
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
80 rn=as.character(tab_in[,1])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
81 if (length(rn)!=length(unique(rn))) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
82 duplicated_rownames=table(rn)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
83 duplicated_rownames=duplicated_rownames[duplicated_rownames>1]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
84 duplicated_rownames=names(duplicated_rownames)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
85 if (length(duplicated_rownames)>3) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
86 duplicated_rownames=c(duplicated_rownames[1:3],"...")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
87 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
88 duplicated_rownames=paste(duplicated_rownames,collapse=", ")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
89 log_error(simpleCondition(
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
90 paste("The table you want to use have duplicated values in the first column (",
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
91 " - duplicated names: ",duplicated_rownames,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
92 ))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
93 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
94 tab=tab_in[,-1]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
95 rownames(tab)=rn
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
96
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
97 #Check all columns are numerical
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
98 tab=as.matrix(tab)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
99 cell.with.na=c()
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
100 for (i in 1:ncol(tab)) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
101 na.v1=is.na(tab[,i])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
102 na.v2=is.na(as.numeric(tab[,i]))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
103 if (sum(na.v1)!=sum(na.v2)) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
104 sel=which(na.v1!=na.v2)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
105 sel=sel[1]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
106 value=tab[sel,i]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
107 log_error(simpleCondition(
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
108 paste("Column '",colnames(tab)[i],"' of your table contains non numerical values. Please check its content (on line #",sel,": value='",value,"').",sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
109 ))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
110 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
111 if (length(cell.with.na)==0 & sum(na.v1)!=0) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
112 cell.with.na=c(i,which(na.v1)[1])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
113 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
114 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
115
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
116 Dataset <- tab_in
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
117
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
118 ##########################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
119 # Statistics table computation - - - - - - - - -
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
120
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
121 log=""
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
122
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
123 if(stat=="T" & length(chosen.stat)!=0){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
124
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
125 stat.list <- strsplit(chosen.stat,",")[[1]]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
126 stat.res <- t(Dataset[0,,drop=FALSE])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
127
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
128 numdig <- 5
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
129
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
130 if("mean" %in% stat.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
131 stat.res <- cbind(stat.res,c("Mean",round(colMeans(Dataset[,-1],na.rm=TRUE),digits=numdig)))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
132 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
133
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
134 if("sd" %in% stat.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
135 colSd <- apply(Dataset[,-1],2,sd,na.rm=TRUE)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
136 stat.res <- cbind(stat.res,c("Std.Dev",round(colSd,digits=numdig)))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
137 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
138
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
139 if("variance" %in% stat.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
140 colVar <- apply(Dataset[,-1],2,var,na.rm=TRUE)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
141 stat.res <- cbind(stat.res,c("Variance",round(colVar,digits=numdig)))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
142 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
143
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
144 if(("median" %in% stat.list)&&(!("quartile" %in% stat.list))){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
145 colMed <- apply(Dataset[,-1],2,median,na.rm=TRUE)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
146 stat.res <- cbind(stat.res,c("Median",round(colMed,digits=numdig)))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
147 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
148
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
149 if("quartile" %in% stat.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
150 colQ <- round(apply(Dataset[,-1],2,quantile,na.rm=TRUE),digits=numdig)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
151 stat.res <- cbind(stat.res,c("Min",colQ[1,]),c("Q1",colQ[2,]),
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
152 c("Median",colQ[3,]),c("Q3",colQ[4,]),c("Max",colQ[5,]))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
153 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
154
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
155 if("decile" %in% stat.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
156 colD <- round(t(apply(Dataset[,-1],2,quantile,na.rm=TRUE,seq(0,1,0.1))),digits=numdig)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
157 colD <- rbind(paste("D",seq(0,10,1),sep=""),colD)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
158 stat.res <- cbind(stat.res,colD)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
159 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
160
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
161 write.table(stat.res,table_file,col.names=FALSE,sep="\t",quote=FALSE)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
162
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
163 log=paste(log,"&#10132; You choose to compute :",chosen.stat,"<BR>")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
164
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
165 } # end if(stat)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
166 else{
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
167 log=paste(log,"&#10132; You don't choose any stats<BR>")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
168 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
169
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
170 ##########################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
171 # Graphics generation - - - - - - - - - - - - -
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
172
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
173 if(ploting=="T" & length(chosen.plot)!=0){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
174
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
175 nb_graph_per_row=4
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
176 nb_graph=ncol(Dataset)-1
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
177
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
178 nb_row=round(nb_graph/nb_graph_per_row)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
179
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
180 nb_empty_plot=nb_graph %% nb_graph_per_row
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
181 if (nb_empty_plot != 0) {
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
182 nb_row=nb_row+1
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
183 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
184
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
185 page_height=3.5 * nb_row
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
186
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
187 pdf(file=graph_file,height=page_height)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
188
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
189 graph.list <- strsplit(chosen.plot,",")[[1]]
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
190
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
191 #For the pair plot, we stick to the default layout
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
192 if("pairsplot" %in% graph.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
193 pairs(Dataset[,-1])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
194 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
195
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
196 #For the other plots, we have 4 plots per line
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
197 par(mfrow=c(nb_row,nb_graph_per_row),mar=c(3, 3, 3, 1) + 0.1)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
198
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
199 if("boxplot" %in% graph.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
200 for(ech in 2:ncol(Dataset)){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
201 boxplot(Dataset[,ech],main=colnames(Dataset)[ech],xlab=NULL)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
202 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
203 #Complete page with empty plots
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
204 i=0; while (i<nb_empty_plot) {plot.new();i=i+1;}
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
205 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
206
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
207 if("histogram" %in% graph.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
208 for(ech in 2:ncol(Dataset)){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
209 hist(Dataset[,ech],main=colnames(Dataset)[ech],xlab=NULL)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
210 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
211 #Complete page with empty plots
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
212 i=0; while (i<nb_empty_plot) {plot.new();i=i+1;}
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
213 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
214
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
215 if("density" %in% graph.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
216 for(ech in 2:ncol(Dataset)){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
217 plot(density(Dataset[,ech],na.rm=TRUE),main=colnames(Dataset)[ech])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
218 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
219 #Complete page with empty plots
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
220 i=0; while (i<nb_empty_plot) {plot.new();i=i+1;}
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
221 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
222
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
223
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
224 if("MAplot" %in% graph.list){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
225 if(min(Dataset[,-1],na.rm=TRUE)<0){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
226 cat("\n----\nError: MAplot only available for positive variables\n----",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
227 q(save="no",status=1)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
228 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
229 library(limma)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
230
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
231 library(edgeR) #Warning : Import also limma package
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
232 for(ech in 2:(ncol(Dataset)-1)){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
233 for(ech2 in (ech+1):ncol(Dataset)){
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
234 temp.pair <- na.omit(Dataset[,c(ech,ech2)])
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
235 maPlot(temp.pair[,1],temp.pair[,2],main=paste(colnames(Dataset)[ech],"VS",colnames(Dataset)[ech2]))
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
236 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
237 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
238 #Do not complete page with empty plots for this plot because it generates nb_variables X nb_variables graphs
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
239 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
240
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
241 #Close pdf device
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
242 dev.off()
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
243
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
244 log=paste(log,"&#10132; You choose to plot :",chosen.plot,"<BR>")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
245 } # end if(ploting)
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
246 else{
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
247 log=paste(log,"&#10132; You don't choose any plot<BR>")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
248 }
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
249
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
250
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
251
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
252 ##########################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
253 # Treatment successfull
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
254 ##########################################################
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
255 cat("<HTML><HEAD><TITLE>Summary statistics report</TITLE></HEAD><BODY>\n",file=log_file,append=F,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
256 cat(log,file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
257 cat("&#10003; Your process is successfull!<BR>",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
258 cat("</BODY></HTML>\n",file=log_file,append=T,sep="")
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
259
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
260
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
261 } # end of function
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
262
46ddb0591d8b planemo upload commit a2411926bebc2ca3bb31215899a9f18a67e59556
vmarcon
parents:
diff changeset
263