annotate NmrNormalization_script.R @ 3:966fcf7ae66e draft

planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
author lecorguille
date Thu, 26 Oct 2017 06:01:14 -0400
parents
children 221cbd549c40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
1 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
2 # SPECTRA NORMALIZATION FROM SPECTRAL DATA #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
3 # User : Galaxy #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
4 # Original data : -- #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
5 # Starting date : 20-10-2014 #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
6 # Version 1 : 27-01-2015 #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
7 # Version 2 : 27-02-2015 #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
8 # #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
9 # Input files: #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
10 # - Data matrix containing bucketed and integrated spectra to normalize #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
11 # - Sample metadata matrix containing at least biological factor of interest #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
12 # - Scaling method: Total intensity/Probabilistic Quotient Normalization #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
13 # - Control group: name of control to compute median reference spectra #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
14 # - Graph: normalization result representation #
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
15 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
16 NmrNormalization <- function(dataMatrix,scalingMethod=c("None","Total","PQN","BioFactor"),sampleMetadata=NULL,
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
17 bioFactor=NULL,ControlGroup=NULL,graph=c("None","Overlay","One_per_individual"),
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
18 nomFichier=NULL,savLog.txtC=NULL)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
19 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
20
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
21 ## Option
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
22 ##---------------
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
23 strAsFacL <- options()$stringsAsFactors
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
24 options(stingsAsFactors = FALSE)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
25 options(warn = -1)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
26
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
27
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
28 ## Constants
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
29 ##---------------
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
30 topEnvC <- environment()
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
31 flgC <- "\n"
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
32
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
33 ## Log file (in case of integration into Galaxy)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
34 ##----------------------------------------------
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
35 if(!is.null(savLog.txtC))
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
36 sink(savLog.txtC, append = TRUE)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
37
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
38 ## Functions definition
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
39 ##---------------------
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
40 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
41 # Total intensity normalization
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
42 # Input parameters
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
43 # - data : bucketed spectra (rows=buckets; columns=samples)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
44 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
45 NmrBrucker_total <- function(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
46 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
47 # Total intensity normalization
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
48 data.total <- apply(data,2,sum)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
49 data.normalized <- data[,1]/data.total[1]
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
50 for (i in 2:ncol(data))
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
51 data.normalized <- cbind(data.normalized,data[,i]/data.total[i])
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
52 colnames(data.normalized) <- colnames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
53 rownames(data.normalized) <- rownames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
54 return(data.normalized)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
55 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
56
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
57
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
58 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
59 # Biological factor normalization
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
60 # Input parameters
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
61 # - data : bucketed spectra (rows=buckets; columns=samples)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
62 # - sampleMetadata : dataframe with biological factor of interest measured for each invidual
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
63 # - bioFactor : name of the column cotaining the biological factor of interest
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
64 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
65 NmrBrucker_bioFact <- function(data,sampleMetadata,bioFactor)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
66 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
67 # Total intensity normalization
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
68 data.normalized <- data[,1]/bioFactor[1]
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
69 for (i in 2:ncol(data))
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
70 data.normalized <- cbind(data.normalized,data[,i]/bioFactor[i])
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
71 colnames(data.normalized) <- colnames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
72 rownames(data.normalized) <- rownames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
73 return(data.normalized)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
74 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
75
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
76
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
77 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
78 # Probabilistic quotient normalization (PQN)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
79 # Input parameters
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
80 # - data : bucketed spectra (rows=buckets; columns=samples)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
81 # - sampleMetadata : dataframe with treatment group of inviduals
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
82 # - pqnFactor : number of the column cotaining the biological facor of interest
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
83 # - nomControl : name of the treatment group
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
84 #################################################################################################################
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
85 NmrBrucker_pqn <- function(data,sampleMetadata,pqnFactor,nomControl)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
86 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
87 # Total intensity normalization
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
88 data.total <- apply(data,2,sum)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
89 data.normalized <- data[,1]/data.total[1]
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
90 for (i in 2:ncol(data))
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
91 data.normalized <- cbind(data.normalized,data[,i]/data.total[i])
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
92 colnames(data.normalized) <- colnames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
93 rownames(data.normalized) <- rownames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
94
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
95 # Reference spectrum
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
96 # Recuperation spectres individus controle
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
97 control.spectra <- data.normalized[,sampleMetadata[,pqnFactor]==nomControl]
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
98 spectrum.ref <- apply(control.spectra,1,median)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
99
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
100 # Ratio between normalized and reference spectra
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
101 data.normalized.ref <- data.normalized/spectrum.ref
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
102
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
103 # Median ratio
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
104 data.normalized.ref.median <- apply(data.normalized.ref,1,median)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
105
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
106 # Normalization
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
107 data.normalizedPQN <- data.normalized[,1]/data.normalized.ref.median
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
108 for (i in 2:ncol(data))
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
109 data.normalizedPQN <- cbind(data.normalizedPQN,data.normalized[,i]/data.normalized.ref.median)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
110 colnames(data.normalizedPQN) <- colnames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
111 rownames(data.normalizedPQN) <- rownames(data)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
112
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
113 return(data.normalizedPQN)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
114 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
115
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
116
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
117 ## Tests
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
118 if (scalingMethod=="QuantitativeVariable")
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
119 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
120 if(mode(sampleMetadata[,bioFactor]) == "character")
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
121 bioFact <- factor(sampleMetadata[,bioFactor])
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
122 else
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
123 bioFact <- sampleMetadata[,bioFactor]
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
124 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
125
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
126 ## Spectra scaling depending on the user choice
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
127 if (scalingMethod == "None")
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
128 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
129 NormalizedBucketedSpectra <- dataMatrix
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
130 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
131 else if (scalingMethod == "Total")
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
132 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
133 NormalizedBucketedSpectra <- NmrBrucker_total(dataMatrix)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
134 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
135 else if (scalingMethod == "PQN")
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
136 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
137 NormalizedBucketedSpectra <- NmrBrucker_pqn(dataMatrix,sampleMetadata,bioFactor,ControlGroup)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
138 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
139 else if (scalingMethod == "QuantitativeVariable")
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
140 {
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
141 NormalizedBucketedSpectra <- NmrBrucker_bioFact(dataMatrix,sampleMetadata,bioFact)
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
142 }
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
143
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
144 ## OUTPUTS
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
145 return(list(NormalizedBucketedSpectra))
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
146
966fcf7ae66e planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
lecorguille
parents:
diff changeset
147 }