annotate NmrNormalization_script.R @ 0:a5e6499f1b4d draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
author marie-tremblay-metatoul
date Tue, 22 Nov 2016 06:42:44 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
1 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
2 # SPECTRA NORMALIZATION FROM SPECTRAL DATA #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
3 # User : Galaxy #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
4 # Original data : -- #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
5 # Starting date : 20-10-2014 #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
6 # Version 1 : 27-01-2015 #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
7 # Version 2 : 27-02-2015 #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
8 # #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
9 # Input files: #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
10 # - Data matrix containing bucketed and integrated spectra to normalize #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
11 # - Sample metadata matrix containing at least biological factor of interest #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
12 # - Scaling method: Total intensity/Probabilistic Quotient Normalization #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
13 # - Control group: name of control to compute median reference spectra #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
14 # - Graph: normalization result representation #
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
15 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
16 NmrNormalization <- function(dataMatrix,scalingMethod=c("None","Total","PQN","BioFactor"),sampleMetadata=NULL,
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
17 bioFactor=NULL,ControlGroup=NULL,graph=c("None","Overlay","One_per_individual"),
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
18 nomFichier=NULL,savLog.txtC=NULL)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
19 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
20
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
21 ## Option
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
22 ##---------------
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
23 strAsFacL <- options()$stringsAsFactors
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
24 options(stingsAsFactors = FALSE)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
25 options(warn = -1)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
26
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
27
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
28 ## Constants
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
29 ##---------------
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
30 topEnvC <- environment()
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
31 flgC <- "\n"
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
32
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
33 ## Log file (in case of integration into Galaxy)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
34 ##----------------------------------------------
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
35 if(!is.null(savLog.txtC))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
36 sink(savLog.txtC, append = TRUE)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
37
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
38 ## Functions definition
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
39 ##---------------------
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
40 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
41 # Total intensity normalization
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
42 # Input parameters
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
43 # - data : bucketed spectra (rows=buckets; columns=samples)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
44 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
45 NmrBrucker_total <- function(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
46 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
47 # Total intensity normalization
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
48 data.total <- apply(data,2,sum)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
49 data.normalized <- data[,1]/data.total[1]
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
50 for (i in 2:ncol(data))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
51 data.normalized <- cbind(data.normalized,data[,i]/data.total[i])
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
52 colnames(data.normalized) <- colnames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
53 rownames(data.normalized) <- rownames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
54 return(data.normalized)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
55 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
56
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
57
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
58 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
59 # Biological factor normalization
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
60 # Input parameters
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
61 # - data : bucketed spectra (rows=buckets; columns=samples)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
62 # - sampleMetadata : dataframe with biological factor of interest measured for each invidual
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
63 # - bioFactor : name of the column cotaining the biological factor of interest
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
64 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
65 NmrBrucker_bioFact <- function(data,sampleMetadata,bioFactor)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
66 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
67 # Total intensity normalization
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
68 data.normalized <- data[,1]/bioFactor[1]
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
69 for (i in 2:ncol(data))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
70 data.normalized <- cbind(data.normalized,data[,i]/bioFactor[i])
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
71 colnames(data.normalized) <- colnames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
72 rownames(data.normalized) <- rownames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
73 return(data.normalized)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
74 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
75
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
76
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
77 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
78 # Probabilistic quotient normalization (PQN)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
79 # Input parameters
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
80 # - data : bucketed spectra (rows=buckets; columns=samples)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
81 # - sampleMetadata : dataframe with treatment group of inviduals
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
82 # - pqnFactor : number of the column cotaining the biological facor of interest
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
83 # - nomControl : name of the treatment group
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
84 #################################################################################################################
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
85 NmrBrucker_pqn <- function(data,sampleMetadata,pqnFactor,nomControl)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
86 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
87 # Total intensity normalization
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
88 data.total <- apply(data,2,sum)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
89 data.normalized <- data[,1]/data.total[1]
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
90 for (i in 2:ncol(data))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
91 data.normalized <- cbind(data.normalized,data[,i]/data.total[i])
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
92 colnames(data.normalized) <- colnames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
93 rownames(data.normalized) <- rownames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
94
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
95 # Reference spectrum
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
96 # Recuperation spectres individus controle
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
97 control.spectra <- data.normalized[,sampleMetadata[,pqnFactor]==nomControl]
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
98 spectrum.ref <- apply(control.spectra,1,median)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
99
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
100 # Ratio between normalized and reference spectra
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
101 data.normalized.ref <- data.normalized/spectrum.ref
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
102
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
103 # Median ratio
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
104 data.normalized.ref.median <- apply(data.normalized.ref,1,median)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
105
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
106 # Normalization
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
107 data.normalizedPQN <- data.normalized[,1]/data.normalized.ref.median
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
108 for (i in 2:ncol(data))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
109 data.normalizedPQN <- cbind(data.normalizedPQN,data.normalized[,i]/data.normalized.ref.median)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
110 colnames(data.normalizedPQN) <- colnames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
111 rownames(data.normalizedPQN) <- rownames(data)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
112
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
113 return(data.normalizedPQN)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
114 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
115
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
116
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
117 ## Tests
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
118 if (scalingMethod=="QuantitativeVariable")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
119 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
120 if(mode(sampleMetadata[,bioFactor]) == "character")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
121 bioFact <- factor(sampleMetadata[,bioFactor])
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
122 else
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
123 bioFact <- sampleMetadata[,bioFactor]
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
124 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
125
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
126 ## Spectra scaling depending on the user choice
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
127 if (scalingMethod == "None")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
128 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
129 NormalizedBucketedSpectra <- dataMatrix
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
130 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
131 else if (scalingMethod == "Total")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
132 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
133 NormalizedBucketedSpectra <- NmrBrucker_total(dataMatrix)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
134 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
135 else if (scalingMethod == "PQN")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
136 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
137 NormalizedBucketedSpectra <- NmrBrucker_pqn(dataMatrix,sampleMetadata,bioFactor,ControlGroup)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
138 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
139 else if (scalingMethod == "QuantitativeVariable")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
140 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
141 NormalizedBucketedSpectra <- NmrBrucker_bioFact(dataMatrix,sampleMetadata,bioFact)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
142 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
143
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
144 # Graphic
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
145 if (graph != "None")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
146 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
147 # Graphic Device opening
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
148 pdf(nomFichier,onefile=TRUE)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
149 if (graph == "Overlay")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
150 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
151 ymax <- max(NormalizedBucketedSpectra)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
152 plot(1:length(NormalizedBucketedSpectra[,1]),NormalizedBucketedSpectra[,1],ylim=c(0,ymax),
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
153 type='l',col=1,xlab="Chemical shift",ylab="Intensity")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
154 for (i in 2:ncol(NormalizedBucketedSpectra))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
155 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
156 spectre <- NormalizedBucketedSpectra[,i]
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
157 lines(spectre,col=i)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
158 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
159 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
160 else
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
161 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
162 for (i in 1:ncol(NormalizedBucketedSpectra))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
163 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
164 plot(1:length(NormalizedBucketedSpectra[,i]),NormalizedBucketedSpectra[,i],type='l',col=1,
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
165 xlab="Chemical shift",ylab="Intensity")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
166 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
167 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
168 dev.off()
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
169 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
170
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
171 # Output datasets creation
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
172 if (scalingMethod == "None" || scalingMethod == "Total")
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
173 {
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
174 sampleMetadata <- data.frame(1:ncol(NormalizedBucketedSpectra))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
175 rownames(sampleMetadata) <- colnames(NormalizedBucketedSpectra)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
176 colnames(sampleMetadata) <- "SampleOrder"
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
177 }
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
178
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
179 variableMetadata <- data.frame(1:nrow(NormalizedBucketedSpectra))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
180 rownames(variableMetadata) <- rownames(NormalizedBucketedSpectra)
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
181 colnames(variableMetadata) <- "VariableOrder"
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
182
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
183 return(list(NormalizedBucketedSpectra,sampleMetadata,variableMetadata))
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
184
a5e6499f1b4d planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
marie-tremblay-metatoul
parents:
diff changeset
185 }