Setup codes
##specify paths to load the source codes, input data and save the output files
code_dir <- "./main_functions/"
data_dir <- "./tutorial_data/"
output_dir <- "./tutorial_data/"
setwd(code_dir)
{ source("pre_processing.R")
source("interpolation_increase_resolution.R")
source("normalization.R")
source("integral.R")
}
Step 1: Load raw data
setwd(data_dir)
spectra = read.csv("control_human_plasma.csv")
spectra = spectra[,-1]
ppm=as.numeric(spectra[,1])
nmr_sample=spectra[,-1]
Step 2: Baseline correction
nmr_basecorrect=apply(nmr_sample,2,FUN=pre_processing_fun,
ppm=ppm,a=0.7,b=4.1)
ppm_region=ppm[which(ppm>=0.7&ppm<=4.1)]

Step 3: Interpolation
#scale the input spectra to the length of 12000
nmr_inter=apply(nmr_basecorrect,2,FUN=interpolation_fun,
input_ppm=ppm_region,length=12000,
min=min(ppm_region),max=max(ppm_region))
ppm_inter=c(ppm_region,runif((12000-length(ppm_region)),min=min(ppm_region),
max=max(ppm_region)))
ppm_inter=ppm_inter[order(ppm_inter,decreasing = TRUE)]
Step 4: Normalization
##Normalize the area under the curve for each spectrum to 1
nmr_norm=apply(nmr_inter,2, FUN=normalize,ppm=ppm_inter)
ppm_norm=rev(ppm_inter)
## [1] "Area under the curve for each normalized plasma spectrum is:"
integral(ppm_norm,nmr_norm[,1])
## [1] 1
Step 5: Save the processed spectra for analysis
data_norm=cbind(ppm_norm,nmr_norm)
write.csv(data_norm,"./tutorial_data/control_processed_plasma.csv")