# HG changeset patch # User marie-tremblay-metatoul # Date 1495524771 14400 # Node ID cbea5e9fd0b4601308c614ba07cb417282d1cdb5 # Parent 68e2d63bece0fb0357dff0601a8645cf31b25325 Uploaded diff -r 68e2d63bece0 -r cbea5e9fd0b4 nmr_preprocessing/NmrPreprocessing_script.R --- a/nmr_preprocessing/NmrPreprocessing_script.R Fri May 05 07:13:02 2017 -0400 +++ b/nmr_preprocessing/NmrPreprocessing_script.R Tue May 23 03:32:51 2017 -0400 @@ -550,7 +550,7 @@ # InternalReferencing ## ==================================================== -InternalReferencing <- function(RawSpect_data, RawSpect_info, method = c("max", "thres"), +InternalReferencing <- function(Spectrum_data, Fid_info, method = c("max", "thres"), range = c("near0", "all", "window"), ppm.ref = 0, shiftHandling = c("zerofilling", "cut", "NAfilling", "circular"), c = 2, pc = 0.02, fromto.RC = NULL, @@ -560,9 +560,9 @@ # Data initialisation and checks ---------------------------------------------- - begin_info <- beginTreatment("InternalReferencing", RawSpect_data, RawSpect_info) - RawSpect_data <- begin_info[["Signal_data"]] - RawSpect_info <- begin_info[["Signal_info"]] + begin_info <- beginTreatment("InternalReferencing", Spectrum_data, Fid_info) + Spectrum_data <- begin_info[["Signal_data"]] + Fid_info <- begin_info[["Signal_info"]] # Check input arguments @@ -582,9 +582,9 @@ if (!is.null(fromto.RC)) { diff <- diff(unlist(fromto.RC))[1:length(diff(unlist(fromto.RC)))%%2 !=0] for (i in 1:length(diff)) { - if (diff[i] <= 0) { - stop(paste("Invalid region removal because from > to")) - } + if (ppm == TRUE & diff[i] >= 0) { + stop(paste("Invalid region removal because from <= to in ppm")) + } else if (ppm == FALSE & diff[i] <= 0) {stop(paste("Invalid region removal because from >= to in column index"))} } } @@ -627,15 +627,15 @@ # Apply the method ('thres' or 'max') on spectra # ---------------------------------------------- - n <- nrow(RawSpect_data) - m <- ncol(RawSpect_data) + n <- nrow(Spectrum_data) + m <- ncol(Spectrum_data) # The Sweep Width has to be the same since the column names are the same - SW <- RawSpect_info[1, "SW"] # Sweep Width in ppm (semi frequency scale in ppm) + SW <- Fid_info[1, "SW"] # Sweep Width in ppm (semi frequency scale in ppm) ppmInterval <- SW/m # FIXME divide by two ?? if (range == "all") { - Data <- RawSpect_data + Data <- Spectrum_data } else { if (range == "near0") { fromto.RC <- list(c(-(SW * pc)/2, (SW * pc)/2)) # automatic fromto values in ppm @@ -644,7 +644,7 @@ # if ppm == TRUE, then fromto is in the colnames values, else, in the column # index if (ppm == TRUE) { - colindex <- as.numeric(colnames(RawSpect_data)) + colindex <- as.numeric(colnames(Spectrum_data)) } else { colindex <- 1:m } @@ -659,9 +659,9 @@ vector <- rep(0, m) vector[unlist(Int)] <- 1 if (n > 1) { - Data <- sweep(RawSpect_data, MARGIN = 2, FUN = "*", vector) # Cropped_Spectrum + Data <- sweep(Spectrum_data, MARGIN = 2, FUN = "*", vector) # Cropped_Spectrum } else { - Data <- RawSpect_data * vector + Data <- Spectrum_data * vector } # Cropped_Spectrum } @@ -701,17 +701,17 @@ ppmScale <- ppmScale + ppm.ref - Spectrum_data <- matrix(fill, nrow = n, ncol = -(end - start) + 1, - dimnames = list(rownames(RawSpect_data), ppmScale)) + Spectrum_data_calib <- matrix(fill, nrow = n, ncol = -(end - start) + 1, + dimnames = list(rownames(Spectrum_data), ppmScale)) for (i in 1:n) { shift <- (1 - TMSPpeaks[i]) + start - Spectrum_data[i, (1 + shift):(m + shift)] <- RawSpect_data[i, ] + Spectrum_data_calib[i, (1 + shift):(m + shift)] <- Spectrum_data[i, ] } if (shiftHandling == "cut") { - Spectrum_data = as.matrix(stats::na.omit(t(Spectrum_data))) - Spectrum_data = t(Spectrum_data) - base::attr(Spectrum_data, "na.action") <- NULL + Spectrum_data_calib = as.matrix(stats::na.omit(t(Spectrum_data_calib))) + Spectrum_data_calib = t(Spectrum_data_calib) + base::attr(Spectrum_data_calib, "na.action") <- NULL } @@ -730,13 +730,13 @@ } ppmScale <- ppmScale + ppm.ref - Spectrum_data <- matrix(nrow=n, ncol=end-start+1, - dimnames=list(rownames(RawSpect_data), ppmScale)) + Spectrum_data_calib <- matrix(nrow=n, ncol=end-start+1, + dimnames=list(rownames(Spectrum_data), ppmScale)) for (i in 1:n) { shift <- (maxpeak-TMSPpeaks[i]) - Spectrum_data[i,(1+shift):m] <- RawSpect_data[i,1:(m-shift)] + Spectrum_data_calib[i,(1+shift):m] <- Spectrum_data[i,1:(m-shift)] if (shift > 0) { - Spectrum_data[i,1:shift] <- RawSpect_data[i,(m-shift+1):m] + Spectrum_data_calib[i,1:shift] <- Spectrum_data[i,(m-shift+1):m] } } } @@ -757,9 +757,9 @@ fromto <- fromto.RC } else { fromto <- list() - idcol <- as.numeric(colnames(RawSpect_data)) + idcol <- as.numeric(colnames(Spectrum_data)) for (i in 1:length(fromto.RC)) { - fromto[[i]] <- as.numeric(colnames(RawSpect_data))[fromto.RC[[i]]] + fromto[[i]] <- as.numeric(colnames(Spectrum_data))[fromto.RC[[i]]] } } } else { @@ -767,7 +767,7 @@ } # TMSPloc in ppm - TMSPloc <- as.numeric(colnames(RawSpect_data))[TMSPpeaks[rowindex_graph]] + TMSPloc <- as.numeric(colnames(Spectrum_data))[TMSPpeaks[rowindex_graph]] # num plot per window num.stacked <- 6 @@ -778,7 +778,7 @@ Legend = "TMSP search zone and location") # vlines for TMSP peak - addlines <- data.frame(rowname = rownames(RawSpect_data)[rowindex_graph],TMSPloc) + addlines <- data.frame(rowname = rownames(Spectrum_data)[rowindex_graph],TMSPloc) nn <- length(rowindex_graph) i <- 1 @@ -789,7 +789,7 @@ last <- min(i + num.stacked - 1, nn) - melted <- reshape2::melt(Re(RawSpect_data[i:last, ]), + melted <- reshape2::melt(Re(Spectrum_data[i:last, ]), varnames = c("rowname", "ppm")) plots[[j]] <- ggplot2::ggplot() + ggplot2::theme_bw() + @@ -819,7 +819,7 @@ # Return the results ---------------------------------------------- - Spectrum_data <- endTreatment("InternalReferencing", begin_info, Spectrum_data) + Spectrum_data <- endTreatment("InternalReferencing", begin_info, Spectrum_data_calib) if (is.null(plots)) { return(Spectrum_data) @@ -837,8 +837,8 @@ ZeroOrderPhaseCorrection <- function(Spectrum_data, method = c("rms", "manual", "max"), plot_rms = NULL, returnAngle = FALSE, createWindow = TRUE, - angle = NULL, plot_spectra = FALSE, quant = 0.95, - ppm = TRUE, fromto.0OPC = NULL) { + angle = NULL, plot_spectra = FALSE, + ppm = TRUE, exclude = list(c(5.1,4.5))) { # Data initialisation and checks ---------------------------------------------- @@ -848,7 +848,7 @@ # optimal angles createWindow : for plot_rms plots angle : If angle is not NULL, # spectra are rotated according to the angle vector values # plot_spectra : if TRUE, plot rotated spectra - # quant: probability for sample quantile used to trim the spectral intensities + begin_info <- beginTreatment("ZeroOrderPhaseCorrection", Spectrum_data) @@ -861,7 +861,7 @@ # Check input arguments method <- match.arg(method) checkArg(ppm, c("bool")) - checkArg(unlist(fromto.0OPC), c("num"), can.be.null = TRUE) + checkArg(unlist(exclude), c("num"), can.be.null = TRUE) # method in c("max", "rms") ----------------------------------------- @@ -869,39 +869,25 @@ # angle is found by optimization # rms function to be optimised - rms <- function(ang, y, meth = c("max", "rms"), p = 0.95) { + rms <- function(ang, y, meth = c("max", "rms")) { # if (debug_plot) { graphics::abline(v=ang, col='gray60') } roty <- y * exp(complex(real = 0, imaginary = ang)) # spectrum rotation Rey <- Re(roty) if (meth == "rms") { - si <- sign(Rey) # sign of intensities - - Rey[abs(Rey) >= quantile(abs(Rey), p)] <- quantile(abs(Rey), p) # trim the values - Rey <- abs(Rey) * si # spectral trimmed values - - if ((sum(Rey==0)/length(Rey)) >= 0.99) { - stop("More than 99% of intensities are null, the rms criterion cannot work properly. \n - Either increase p or the window(s) in fromto.0OPC") - } ReyPos <- Rey[Rey >= 0] # select positive intensities - - # POSss = sum((ReyPos-mean(ReyPos))^2) # centred SS for positive intensities - POSss <- sum((ReyPos)^2) # SS for positive intensities - - # ss = sum((Rey - mean(Rey) )^2) # centred SS for all intensities - ss <- sum((Rey)^2) # SS for all intensities - + POSss <- sum((ReyPos)^2, na.rm = TRUE) # SS for positive intensities + ss <- sum((Rey)^2, na.rm = TRUE) # SS for all intensities return(POSss/ss) # criterion : SS for positive values / SS for all intensities - } else { - maxi <- max(Rey) - return(maxi) - } + } else { + maxi <- max(Rey, na.rm = TRUE) + return(maxi) + } } # Define the interval where to search for (by defining Data) - if (is.null(fromto.0OPC)) { + if (is.null(exclude)) { Data <- Spectrum_data } else { @@ -913,22 +899,23 @@ colindex <- 1:m } - # Second check for the argument fromto.0OPC - diff <- diff(unlist(fromto.0OPC))[1:length(diff(unlist(fromto.0OPC)))%%2 != 0] - for (i in 1:length(diff)) { - if (diff[i] < 0) { - stop(paste("Invalid region removal because from > to")) - } + # Second check for the argument exclude + diff <- diff(unlist(exclude))[1:length(diff(unlist(exclude)))%%2 !=0] + for (i in 1:length(diff)) { + if (ppm == TRUE & diff[i] >= 0) { + stop(paste("Invalid region removal because from <= to in ppm")) + } else if (ppm == FALSE & diff[i] <= 0) {stop(paste("Invalid region removal because from >= to in column index"))} } - Int <- vector("list", length(fromto.0OPC)) - for (i in 1:length(fromto.0OPC)) { - Int[[i]] <- indexInterval(colindex, from = fromto.0OPC[[i]][1], - to = fromto.0OPC[[i]][2], inclusive = TRUE) + + Int <- vector("list", length(exclude)) + for (i in 1:length(exclude)) { + Int[[i]] <- indexInterval(colindex, from = exclude[[i]][1], + to = exclude[[i]][2], inclusive = TRUE) } - vector <- rep(0, m) - vector[unlist(Int)] <- 1 + vector <- rep(1, m) + vector[unlist(Int)] <- 0 if (n > 1) { Data <- sweep(Spectrum_data, MARGIN = 2, FUN = "*", vector) # Cropped_Spectrum } else { @@ -953,8 +940,8 @@ # work in either [-pi;pi] or [0;2pi] (this is not easy to be convinced by that I # agree) and we can check which one it is simply by the following trick - f0 <- rms(0, Data[k, ], p = quant, meth = method) - fpi <- rms(pi, Data[k, ], p = quant, meth = method) + f0 <- rms(0, Data[k, ],meth = method) + fpi <- rms(pi, Data[k, ], meth = method) if (f0 < fpi) { interval <- c(-pi, pi) } else { @@ -967,7 +954,7 @@ x <- seq(min(interval), max(interval), length.out = 100) y <- rep(1, 100) for (K in (1:100)) { - y[K] <- rms(x[K], Data[k, ], p = quant, meth = method) + y[K] <- rms(x[K], Data[k, ], meth = method) } if (createWindow == TRUE) { grDevices::dev.new(noRStudioGD = FALSE) @@ -978,7 +965,7 @@ # Best angle best <- stats::optimize(rms, interval = interval, maximum = TRUE, - y = Data[k,], p = quant, meth = method) + y = Data[k,], meth = method) ang <- best[["maximum"]] @@ -1011,32 +998,12 @@ stop(paste("angle has length", length(angle), "and there are", n, "spectra to rotate.")) } for (k in 1:n) { - Spectrum_data[k, ] <- Spectrum_data[k, ] * exp(complex(real = 0, imaginary = ang)) + Spectrum_data[k, ] <- Spectrum_data[k, ] * exp(complex(real = 0, imaginary = - angle[k])) } } - # #================== Detect a 180° rotation due to the water signal MEAN_Q = c() - # for (i in 1:nrow(Spectrum_data)) { data = Re(Spectrum_data[i,]) data_p = - # data[data >= stats::quantile(data[data >=0 ], p.zo)] data_n = data[data <= - # stats::quantile(data[data <0 ], (1-p.zo))] mean_quant = (sum(data_p) + - # sum(data_n)) / (length(data_p) +length(data_n)) # mean(p.zo% higher pos and neg - # values) MEAN_Q = c(MEAN_Q, mean_quant) } vect = which(MEAN_Q < 0) if - # (length(vect)!=0) { warning('The mean of', p.zo,' positive and negative - # quantiles is negative for ', paste0(rownames(Spectrum_data)[vect],'; ')) - # if(rotation == TRUE) { warning(' An automatic 180 degree rotation is applied to - # these spectra') Angle[vect] = Angle[vect] + pi } } vect_risk = - # which(MEAN_Q<0.1*mean(MEAN_Q[MEAN_Q>0])) # is there any MEAN_Q with a very low - # value copared to mean of positive mean values? if (length(vect_risk)!=0) - # { warning('the rotation angle for spectra', - # paste0(rownames(Spectrum_data)[vect_risk],'; '), 'might not be optimal, you - # need to check visually for those spectra') } # result of automatic rotation for - # (k in vect_risk) { Spectrum_data[k,] <- Spectrum_data[k,] * exp(complex(real=0, - # imaginary=Angle[k])) } #================== - - - # Draw spectra if (plot_spectra == TRUE) { nn <- ceiling(n/4) @@ -1070,6 +1037,7 @@ } + ## ==================================================== # Baseline Correction ## ==================================================== diff -r 68e2d63bece0 -r cbea5e9fd0b4 nmr_preprocessing/NmrPreprocessing_wrapper.R --- a/nmr_preprocessing/NmrPreprocessing_wrapper.R Fri May 05 07:13:02 2017 -0400 +++ b/nmr_preprocessing/NmrPreprocessing_wrapper.R Tue May 23 03:32:51 2017 -0400 @@ -70,11 +70,22 @@ ##====================================================== ##====================================================== +# graphical inputs +FirstOPCGraph <- argLs[["FirstOPCGraph"]] +SSGraph <- argLs[["SSGraph"]] +ApodGraph <- argLs[["ApodGraph"]] +FTGraph <- argLs[["FTGraph"]] +SRGraph <- argLs[["SRGraph"]] +ZeroOPCGraph <- argLs[["ZeroOPCGraph"]] +BCGraph <- argLs[["BCGraph"]] +FinalGraph <- argLs[["FinalGraph"]] + + # 1rst order phase correction ------------------------ # Inputs ## Data matrix Fid_data0 <- read.table(argLs[["dataMatrixFid"]],header=TRUE, check.names=FALSE, sep='\t') -Fid_data0 <- Fid_data0[,-1] +# Fid_data0 <- Fid_data0[,-1] Fid_data0 <- as.matrix(Fid_data0) ## Samplemetadata @@ -120,7 +131,7 @@ # Fourier transform ---------------------------------- # Inputs -FTGraph <- argLs[["FTGraph"]] + # Internal referencering ---------------------------------- # Inputs @@ -138,11 +149,11 @@ # if (shiftReferencing=="YES") # { # - shiftReferencingMethod <- argLs[["shiftReferencingMethod"]] - - if (shiftReferencingMethod == "thres") { - shiftTreshold <- argLs[["shiftTreshold"]] - } + # shiftReferencingMethod <- argLs[["shiftReferencingMethod"]] + # + # if (shiftReferencingMethod == "thres") { + # shiftTreshold <- argLs[["shiftTreshold"]] + # } shiftReferencingRange <- argLs[["shiftReferencingRange"]] @@ -151,15 +162,18 @@ } if (shiftReferencingRange == "window"){ - shiftReferencingRangeList <- NULL - shiftReferencingRangeLeft <- argLs[["shiftReferencingRangeLeft"]] - shiftReferencingRangeRight <- argLs[["shiftReferencingRangeRight"]] - shiftReferencingRangeList <- list(shiftReferencingRangeList,c(shiftReferencingRangeLeft,shiftReferencingRangeRight)) + shiftReferencingRangeList <- list() + for(i in which(names(argLs)=="shiftReferencingRangeLeft")) + { + shiftReferencingRangeLeft <- argLs[[i]] + shiftReferencingRangeRight <- argLs[[i+1]] + shiftReferencingRangeList <- c(shiftReferencingRangeList,list(c(shiftReferencingRangeLeft,shiftReferencingRangeRight))) + } } shiftHandling <- argLs[["shiftHandling"]] - ppm_ref <- argLs[["ppm_ref"]] + # } @@ -171,27 +185,24 @@ createWindow = TRUE angle = NULL plot_spectra = FALSE -quant = 0.95 ppm = TRUE -fromto.0OPC = NULL +exclude = NULL zeroOrderPhaseMethod <- argLs[["zeroOrderPhaseMethod"]] -if (zeroOrderPhaseMethod=='rms') -{ - quant <- argLs[["quant"]] -} -if (zeroOrderPhaseMethod=='max') -{ + +if (zeroOrderPhaseMethod=='manual'){ angle <- argLs[["angle"]] } -searchZoneZeroPhase <- argLs[["searchZoneZeroPhase.choice"]] -if (searchZoneZeroPhase == "YES") { - searchZoneZeroPhaseList <- NULL - searchZoneZeroPhaseLeft <- argLs[["shiftReferencingRangeLeft"]] - searchZoneZeroPhaseRight <- argLs[["shiftReferencingRangeRight"]] - searchZoneZeroPhaseList <- list(searchZoneZeroPhaseList,c(searchZoneZeroPhaseLeft,searchZoneZeroPhaseRight)) +excludeZoneZeroPhase <- argLs[["excludeZoneZeroPhase.choice"]] +if (excludeZoneZeroPhase == 'YES') { + excludeZoneZeroPhaseList <- list() + for(i in which(names(argLs)=="excludeZoneZeroPhase_left")) { + excludeZoneZeroPhaseLeft <- argLs[[i]] + excludeZoneZeroPhaseRight <- argLs[[i+1]] + excludeZoneZeroPhaseList <- c(excludeZoneZeroPhaseList,list(c(excludeZoneZeroPhaseLeft,excludeZoneZeroPhaseRight))) } - + exclude <- excludeZoneZeroPhaseList +} # Baseline Correction ------------------------------- @@ -235,20 +246,45 @@ # FirstOrderPhaseCorrection --------------------------------- Fid_data <- FirstOrderPhaseCorrection(Fid_data0, Fid_info = samplemetadataFid, group_delay = NULL) +if (FirstOPCGraph == "YES") { + title = "FIDs after First Order Phase Correction" + DrawSignal(Fid_data, subtype = "stacked", + ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, + xlab = "Frequency", num.stacked = 4, + main = title, createWindow=FALSE) +} # SolventSuppression --------------------------------- Fid_data <- SolventSuppression(Fid_data, lambda.ss = lambda, ptw.ss = ptwSS, plotSolvent = F, returnSolvent = F) +if (SSGraph == "YES") { + title = "FIDs after Solvent Suppression " + DrawSignal(Fid_data, subtype = "stacked", + ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, + xlab = "Frequency", num.stacked = 4, + main = title, createWindow=FALSE) +} + + # Apodization --------------------------------- Fid_data <- Apodization(Fid_data, Fid_info = samplemetadataFid, DT = NULL, type.apod = apodization, phase = phase, rectRatio = rectRatio, gaussLB = gaussLB, expLB = expLB, plotWindow = F, returnFactor = F) +if (ApodGraph == "YES") { + title = "FIDs after Apodization" + DrawSignal(Fid_data, subtype = "stacked", + ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, + xlab = "Frequency", num.stacked = 4, + main = title, createWindow=FALSE) +} + + # FourierTransform --------------------------------- Spectrum_data <- FourierTransform(Fid_data, Fid_info = samplemetadataFid, reverse.axis = TRUE) if (FTGraph == "YES") { - title = "Fourier transformed specta" + title = "Fourier transformed spectra" DrawSignal(Spectrum_data, subtype = "stacked", ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, xlab = "Frequency", num.stacked = 4, @@ -257,45 +293,59 @@ # InternalReferencing --------------------------------- # if (shiftReferencing=="YES") { -Spectrum_data <- InternalReferencing(Spectrum_data, samplemetadataFid, method = shiftReferencingMethod, range = shiftReferencingRange, +Spectrum_data <- InternalReferencing(Spectrum_data, samplemetadataFid, method = "max", range = shiftReferencingRange, ppm.ref = 0, shiftHandling = shiftHandling,ppm = TRUE, - c = shiftTreshold, fromto.RC = shiftReferencingRangeList, pc = pctNear0) + c = shiftTreshold, fromto.RC = shiftReferencingRangeList, pc = pctNear0) + +if (SRGraph == "YES") { + title = "Spectra after Shift Referencing" + DrawSignal(Spectrum_data, subtype = "stacked", + ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, + xlab = "Frequency", num.stacked = 4, + main = title, createWindow=FALSE) +} # } # ZeroOrderPhaseCorrection --------------------------------- -Spectrum_data <- ZeroOrderPhaseCorrection(Spectrum_data, method = zeroOrderPhaseMethod, - plot_rms = plot_rms, returnAngle = returnAngle, - createWindow = createWindow,angle = angle, - plot_spectra = plot_spectra, quant = quant, - ppm = ppm, fromto.0OPC = fromto.0OPC) +Spectrum_data <- ZeroOrderPhaseCorrection(Spectrum_data, method = zeroOrderPhaseMethod, + plot_rms = plot_rms, returnAngle = returnAngle, + createWindow = createWindow,angle = angle, + plot_spectra = plot_spectra, + ppm = ppm, exclude = exclude) +if (ZeroOPCGraph == "YES") { title = "Spectra after Zero Order Phase Correction" DrawSignal(Spectrum_data, subtype = "stacked", ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, xlab = "Frequency", num.stacked = 4, main = title, createWindow=FALSE) +} # BaselineCorrection --------------------------------- -Spectrum_data <- BaselineCorrection(Spectrum_data, ptw.bc = TRUE, maxIter = maxIter, lambda.bc = lambdaBc, p.bc = pBc, eps = epsilon, returnBaseline = F) +Spectrum_data <- BaselineCorrection(Spectrum_data, ptw.bc = ptwBc, maxIter = maxIter, lambda.bc = lambdaBc, p.bc = pBc, eps = epsilon, returnBaseline = F) +if (BCGraph == "YES") { title = "Spectra after Baseline Correction" DrawSignal(Spectrum_data, subtype = "stacked", ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, xlab = "Frequency", num.stacked = 4, main = title, createWindow=FALSE) +} + # NegativeValuesZeroing --------------------------------- if (NegativetoZero=="YES") { + Spectrum_data <- NegativeValuesZeroing(Spectrum_data) +} - Spectrum_data <- NegativeValuesZeroing(Spectrum_data) - - title = "Spectra after Negative Values Zeroing" +if (FinalGraph == "YES") { + title = "Final preprocessed spectra" DrawSignal(Spectrum_data, subtype = "stacked", ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, xlab = "Frequency", num.stacked = 4, main = title, createWindow=FALSE) - } +} invisible(dev.off()) diff -r 68e2d63bece0 -r cbea5e9fd0b4 nmr_preprocessing/NmrPreprocessing_xml.xml --- a/nmr_preprocessing/NmrPreprocessing_xml.xml Fri May 05 07:13:02 2017 -0400 +++ b/nmr_preprocessing/NmrPreprocessing_xml.xml Tue May 23 03:32:51 2017 -0400 @@ -1,4 +1,4 @@ - + Preprocessing of 1D NMR spectra @@ -10,6 +10,8 @@ Rscript $__tool_directory__/NmrPreprocessing_wrapper.R ## First order phase correction + ## Graphical display + FirstOPCGraph $FirstOPCGraph ## Data matrix of FID spectra dataMatrixFid $dataMatrixFid ## Sample metadata matrix @@ -20,9 +22,14 @@ ## Smoothing parameter lambda $lambda ptwSS $ptwSS + ## Graphical display + SSGraph $SSGraph ## Apodization + ## Graphical display + ApodGraph $ApodGraph + apodizationMethod $apodizationMethod.method #if $apodizationMethod.method == "exp": ## Line broadening for the exponential window @@ -54,18 +61,15 @@ gaussLB $apodizationMethod.gaussLB #end if - ## Fourier transform ## Graphical display FTGraph $FTGraph ## Shift referencing - ## Method used to find the TMSP peaks in spectra - shiftReferencingMethod $shiftReferencingMethod.method - #if $shiftReferencingMethod.method == "thres": - shiftTreshold $shiftReferencingMethod.shiftTreshold - #end if + ## Graphical display + SRGraph $SRGraph + ## Definition of the search zone shiftReferencingRange $shiftReferencingRange.method #if $shiftReferencingRange.method == "near0": @@ -78,24 +82,27 @@ #end for #end if shiftHandling $shiftHandling + ## Zero order phase correction - zeroOrderPhaseMethod $zeroOrderPhaseMethod.method - #if $zeroOrderPhaseMethod.method == "rms": - ## Line broadening for the exponential window - quant $zeroOrderPhaseMethod.quant - #end if - searchZoneZeroPhase.choice ${searchZoneZeroPhase.choice} - #if str($searchZoneZeroPhase.choice) == "YES": - #for $i in $searchZoneZeroPhase.conditions: - searchZoneZeroPhase_left ${i.searchZoneZeroPhase_left} - searchZoneZeroPhase_right ${i.searchZoneZeroPhase_right} + ## Graphical display + ZeroOPCGraph $ZeroOPCGraph + + zeroOrderPhaseMethod $zeroOrderPhaseMethod + + excludeZoneZeroPhase.choice ${excludeZoneZeroPhase.choice} + #if str($excludeZoneZeroPhase.choice) == "YES": + #for $i in $excludeZoneZeroPhase.conditions: + excludeZoneZeroPhase_left ${i.excludeZoneZeroPhase_left} + excludeZoneZeroPhase_right ${i.excludeZoneZeroPhase_right} #end for #end if ## Baseline correction + ## Graphical display + BCGraph $BCGraph ptwBc $ptwBc maxIter $maxIter lambdaBc $lambdaBc @@ -106,7 +113,11 @@ ## sets negative intensities to zero NegativetoZero $NegativetoZero - + ## final spectra + ## Graphical display + FinalGraph $FinalGraph + + ## Outputs dataMatrixOut $dataMatrixOut graphOut $graphOut @@ -118,14 +129,28 @@ - + ## First order phase correction + + + + + + ## Water and / or solvents suppression + + + + + + + ## Apodization + - + + - + + + + + + ## Fourier transform - - - - + ## shift Referencing + - + - + + + + + + - - - + ## zero Order Phase Correction + + + + + - - - - + + + + - - - + + + - + + + + + + ## baseline correction + + + + + + - - - - + + + + + + ## NegativetoZero + + ## final spectra + + + + + @@ -269,7 +313,7 @@ These steps correspond to the following steps in the PEPS-NMR R library (https://github.com/ManonMartin/PEPSNMR): -* First order phase correction +* Group Delay suppression (First order phase correction) * Removal of solvent residuals signal from the FID * Apodization to increase the Signal-to-Noise ratio of the FID * Fourier transformation @@ -287,7 +331,6 @@ The **types of apodization** are: - * exp: The signal is multiplied by a decreasing exponential exp(-t/LineBroadening). * cos2: The signal is multiplied by the value of a cosinus squared from 0 (where its value is 1) until pi/2 (where its value is 0). @@ -306,13 +349,6 @@ **Shift referencing** ---------------------- -Different **methods for shift referencing**: - -* max: the maximum intensity in the search zone is defined as the reference compound peak. - -* thres: the reference compound peak is the first peak in the spectrum higher than a predefined threshold (c) which is computed as: c*(cumulated_mean/cumulated_sd). - - The **searching window** can be adapted: * near0: the search concentrates around the 0ppm. @@ -333,8 +369,6 @@ * cut: The ppm values for which some spectra are not defined are removed. -**ppm value of the reference compound**: By default, the ppm value of the reference compound is set to 0, but any arbitrary value in the ppm interval can be used instead. - **Zero Order Phase correction** ----------------------------------- @@ -348,7 +382,7 @@ * max: Optimization of the maximal spectral intensity. -**Search zone for the Zero order phase correction**: enables to optimize the criterion only on the selected spectral window(s). +** Exclusion area(s) for the Zero order phase correction**: enables to optimize the criterion with excluded spectral window(s), by default the water region is excluded. **Baseline computation**