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