Mercurial > repos > ethevenot > batchcorrection
annotate easyrlibrary-lib/miniTools.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 ##################################################### |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
2 # Mini tools for Galaxy scripting |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
3 # Coded by: M.Petera, |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
4 # - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
5 # R functions to use in R scripts and wrappers |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
6 # to make things easier (lightening code, reducing verbose...) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
7 # - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
8 # V0: script structure + first functions |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
9 # V1: addition of functions to handle special characters in identifiers |
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 |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
13 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
14 # Function to call packages without printing all the verbose |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
15 # (only getting the essentials, like warning messages for example) |
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 shyLib <- function(...){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
18 for(i in 1:length(list(...))){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
19 suppressPackageStartupMessages(library(list(...)[[i]],character.only=TRUE)) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
20 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
21 } |
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 #example: shyLib("xcms","pcaMethods") |
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 |
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 # Fonction pour sourcer les scripts R requis |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
29 # /!\ ATTENTION : actuellement la fonction n'est pas chargee au lancement du script, |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
30 # il faut donc la copier-coller dans le wrapper R pour pouvoir l'utiliser. |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
31 |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
32 if(FALSE){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
33 source_local <- function(...){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
34 argv <- commandArgs(trailingOnly = FALSE) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
35 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
|
36 for(i in 1:length(list(...))){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
37 source(paste(base_dir, list(...)[[i]], sep="/")) |
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 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
40 } |
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 #example: source_local("filter_script.R","RcheckLibrary.R") |
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 |
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 # Functions to stock identifiers before applying make.names() and |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
48 # to reinject it into final matrices |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
49 # Note: it reproduces the original order of datasets' identifiers |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
50 # - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
51 # stockID: stocks original identifiers and original order |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
52 # -> needs checked data regarding table match |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
53 # reproduceID: reinjects original identifiers and original order into final tables |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
54 # -> function to be used at the very end, when exporting tables |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
55 |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
56 stockID <- function(dataMatrix, Metadata, Mtype){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
57 # dataMatrix = data.frame containing dataMatrix |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
58 # Metadata = data.frame containing sampleMetadata or variableMetadata |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
59 # Mtype = "sample" or "variable" depending on Metadata content |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
60 cname <- colnames(dataMatrix)[1] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
61 # dataMatrix temporary-stock + transfo - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
62 if(Mtype=="sample"){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
63 id.ori <- colnames(dataMatrix)[-1] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
64 colnames(dataMatrix) <- make.names(colnames(dataMatrix)) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
65 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
66 if(Mtype=="variable"){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
67 id.ori <- dataMatrix[,1] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
68 dataMatrix[,1] <- make.names(dataMatrix[,1]) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
69 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
70 # global stock - - - - - - - - - - - - - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
71 id.new <- data.frame(order.ori=c(1:length(Metadata[,1])),Metadata[,1], |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
72 id.new=make.names(Metadata[,1]),id.ori, |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
73 id.new.DM=make.names(id.ori),stringsAsFactors=FALSE) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
74 colnames(id.new)[c(2,4)] <- c(colnames(Metadata)[1],cname) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
75 # Metadata transfo + returning data - - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
76 Metadata[,1] <- make.names(Metadata[,1]) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
77 return(list(id.match=id.new, dataMatrix=dataMatrix, Metadata=Metadata)) |
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 #example: A<-stockID(myDM,mysM,"sample") ; myDM<-A$dataMatrix ; mysM<-A$Metadata ; A<-A$id.match |
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 reproduceID <- function(dataMatrix, Metadata, Mtype, id.match){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
82 # dataMatrix = data.frame containing dataMatrix |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
83 # Metadata = data.frame containing sampleMetadata or variableMetadata |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
84 # Mtype = "sample" or "variable" depending on Metadata content |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
85 # id.match = 'id.match' element produced by stockID |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
86 #Metadada - - - - - - - - - - - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
87 temp.table <- id.match[,c(1,2,3)] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
88 ## Removing deleted rows |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
89 for(i in 1:(dim(id.match)[1])){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
90 if(!(temp.table[i,3]%in%Metadata[,1])){temp.table[i,1] <- 0} |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
91 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
92 if(length(which(temp.table[,1]==0))!=0){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
93 temp.table <- temp.table[-c(which(temp.table[,1]==0)),] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
94 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
95 ## Restoring original identifiers and order |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
96 temp.table <- merge(x=temp.table,y=Metadata,by.x=3,by.y=1) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
97 temp.table <- temp.table[order(temp.table$order.ori),] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
98 Metadata <- temp.table[,-c(1,2)] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
99 rownames(Metadata) <- NULL |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
100 #dataMatrix - - - - - - - - - - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
101 rownames(dataMatrix)<-dataMatrix[,1] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
102 if(Mtype=="sample"){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
103 dataMatrix <- t(dataMatrix[,-1]) |
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 temp.table <- id.match[,c(1,4,5)] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
106 ## Removing deleted rows |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
107 for(i in 1:(dim(id.match)[1])){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
108 if(!(temp.table[i,3]%in%rownames(dataMatrix))){temp.table[i,1] <- 0} |
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 if(length(which(temp.table[,1]==0))!=0){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
111 temp.table <- temp.table[-c(which(temp.table[,1]==0)),] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
112 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
113 ## Restoring original identifiers and order |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
114 temp.table <- merge(x=temp.table,y=dataMatrix,by.x=3,by.y=0) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
115 temp.table <- temp.table[order(temp.table$order.ori),] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
116 if(Mtype=="variable"){ |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
117 dataMatrix <- temp.table[,-c(1,2,4)] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
118 colnames(dataMatrix)[1] <- colnames(id.match)[4] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
119 } else { |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
120 rownames(temp.table) <- temp.table[,3] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
121 temp.table <- t(temp.table[,-c(1,2,3)]) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
122 dataMatrix <- data.frame(rownames(temp.table),temp.table) |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
123 colnames(dataMatrix)[1] <- colnames(id.match)[4] |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
124 } |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
125 rownames(dataMatrix) <- NULL |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
126 # return datasets - - - - - - - - - - - |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
127 return(list(dataMatrix=dataMatrix, Metadata=Metadata)) |
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 #example: B<-reproduceID(myDM,mysM,"sample",A) ; myDM<-B$dataMatrix ; mysM<-B$Metadata |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
130 |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
131 |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
132 |
b74d1d533dea
planemo upload for repository https://github.com/workflow4metabolomics/batchcorrection.git commit 241fb99a843e13195c5054cd9731e1561f039bde
ethevenot
parents:
diff
changeset
|
133 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |