annotate batch_correction_all_loess_wrapper.R @ 0:71d83d8920bf draft

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