annotate batch_correction_all_loess_wrapper.R @ 1:26d058657f66 draft

planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 069d178cba334ece9c857f7718436c81c2bafb6a-dirty
author ethevenot
date Sun, 09 Apr 2017 15:27:17 -0400
parents 78cb1efd7606
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
1 #!/usr/bin/env Rscript
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
2
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
3 library(batch) ## necessary for parseCommandArgs function
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
4 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
5
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
6 source_local <- function(fname){
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
7 argv <- commandArgs(trailingOnly = FALSE)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
8 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
9 source(paste(base_dir, fname, sep="/"))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
10 }
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
11
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
12 ## Import the different functions
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
13 source_local("batch_correction_all_loess_script.R")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
14
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
15 argVc <- unlist(args)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
16
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
17 ## argVc["method"] is either 'all_loess_pool' or 'all_loess_sample'
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
18 ## alternative version developped by CEA
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
19 ## all variables are treated with loess
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
20 ## the reference observations for loess are either 'pool'
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
21 ## ('all_loess_pool') or 'sample' ('all_loess_sample')
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
22
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
23
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
24 ##------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
25 ## Initializing
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
26 ##------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
27
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
28 ## options
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
29 ##--------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
30
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
31 strAsFacL <- options()$stringsAsFactors
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
32 options(stringsAsFactors = FALSE)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
33
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
34 ## libraries
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
35 ##----------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
36
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
37 suppressMessages(library(ropls))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
38
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
39 if(packageVersion("ropls") < "1.4.0")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
40 stop("Please use 'ropls' versions of 1.4.0 and above")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
41
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
42 ## constants
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
43 ##----------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
44
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
45 modNamC <- "Batch correction" ## module name
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
46
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
47 ## log file
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
48 ##---------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
49
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
50 ## sink(argVc["information"]) ## not implemented
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
51
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
52 cat("\nStart of the '", modNamC, "' Galaxy module call: ",
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
53 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
54
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
55 ## loading
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
56 ##--------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
57
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
58 rawMN <- t(as.matrix(read.table(argVc["dataMatrix"],
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
59 header = TRUE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
60 row.names = 1,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
61 sep = "\t")))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
62
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
63 samDF <- read.table(argVc["sampleMetadata"],
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
64 header = TRUE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
65 row.names = 1,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
66 sep = "\t")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
67
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
68 varDF <- read.table(argVc["variableMetadata"],
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
69 check.names = FALSE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
70 header = TRUE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
71 row.names = 1,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
72 sep = "\t") ## not used; for compatibility only
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
73
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
74 refC <- tolower(gsub("all_loess_", "", argVc["method"]))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
75
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
76 spnN <- as.numeric(argVc["span"])
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
77
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
78 ## checking
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
79 ##---------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
80
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
81 stopifnot(refC %in% c("pool", "sample"))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
82
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
83 if(refC == "pool" &&
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
84 !any("pool" %in% samDF[, "sampleType"]))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
85 stop("No 'pool' found in the 'sampleType' column; use the samples as normalization reference instead")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
86
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
87 refMN <- rawMN[samDF[, "sampleType"] == refC, ]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
88 refNasZerVl <- apply(refMN, 2,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
89 function(refVn)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
90 all(sapply(refVn,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
91 function(refN) {is.na(refN) || refN == 0})))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
92
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
93 if(sum(refNasZerVl)) {
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
94
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
95 refNasZerVi <- which(refNasZerVl)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
96 cat("The following variables have 'NA' or 0 values in all reference samples; they will be removed from the data:\n", sep = "")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
97 print(refNasZerVi)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
98 rawMN <- rawMN[, !refNasZerVl, drop = FALSE]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
99 varDF <- varDF[!refNasZerVl, , drop = FALSE]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
100
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
101 }
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
102
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
103 ##------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
104 ## Computation
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
105 ##------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
106
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
107
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
108 ## ordering (batch and injection order)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
109 ##-------------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
110
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
111 samDF[, "ordIniVi"] <- 1:nrow(rawMN)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
112 ordBatInjVi <- order(samDF[, "batch"], samDF[, "injectionOrder"])
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
113 rawMN <- rawMN[ordBatInjVi, ]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
114 samDF <- samDF[ordBatInjVi, ]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
115
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
116 ## signal drift and batch-effect correction
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
117 ##-----------------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
118
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
119 nrmMN <- shiftBatchCorrectF(rawMN,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
120 samDF,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
121 refC,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
122 spnN)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
123
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
124 ## figure
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
125 ##-------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
126
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
127 cat("\nPlotting\n")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
128
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
129 pdf(argVc["graph_output"], onefile = TRUE, width = 11, height = 7)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
130 plotBatchF(rawMN, samDF, spnN)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
131 plotBatchF(nrmMN, samDF, spnN)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
132 dev.off()
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
133
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
134 ## returning to initial order
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
135 ##---------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
136
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
137 ordIniVi <- order(samDF[, "ordIniVi"])
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
138 nrmMN <- nrmMN[ordIniVi, ]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
139 samDF <- samDF[ordIniVi, ]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
140 samDF <- samDF[, colnames(samDF) != "ordIniVi", drop=FALSE]
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
141
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
142
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
143 ##------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
144 ## Ending
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
145 ##------------------------------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
146
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
147
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
148 ## saving
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
149 ##-------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
150
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
151 datMN <- nrmMN
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
152
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
153 datDF <- cbind.data.frame(dataMatrix = colnames(datMN),
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
154 as.data.frame(t(datMN)))
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
155 write.table(datDF,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
156 file = argVc["dataMatrix_out"],
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
157 quote = FALSE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
158 row.names = FALSE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
159 sep = "\t")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
160
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
161 varDF <- cbind.data.frame(variableMetadata = rownames(varDF),
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
162 varDF) ## not modified; for compatibility only
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
163 write.table(varDF,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
164 file = argVc["variableMetadata_out"],
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
165 quote = FALSE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
166 row.names = FALSE,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
167 sep = "\t")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
168
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
169
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
170 res <- list(dataMatrix_raw = rawMN,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
171 dataMatrix_normalized = nrmMN,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
172 sampleMetadata = samDF)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
173 save(res,
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
174 file = argVc["rdata_output"]) ## for compatibility
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
175
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
176 ## closing
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
177 ##--------
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
178
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
179 cat("\nEnd of '", modNamC, "' Galaxy module call: ",
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
180 as.character(Sys.time()), "\n", sep = "")
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
181
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
182 ## sink()
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
183
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
184 options(stringsAsFactors = strAsFacL)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
185
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
186
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
187 rm(argVc)
78cb1efd7606 planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
ethevenot
parents:
diff changeset
188