Skip to content

Commit

Permalink
Merge pull request #25 from yguitton/dev
Browse files Browse the repository at this point in the history
[EN ATTENTE] merging corrections
  • Loading branch information
jsaintvanne authored Aug 30, 2023
2 parents afcb1d4 + b8957ad commit abb966b
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 223 deletions.
2 changes: 1 addition & 1 deletion CPSeeker.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MyAppName "CPSeeker"
#define MyAppVersion "2.0.0"
#define MyAppVersion "2.1.0"
#define MyAppExeName "CPSeeker.bat"

[Setup]
Expand Down
53 changes: 25 additions & 28 deletions server/deconvolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ overlap_peaks <- function(peaks, eic, baseline, noise) {
#' }
merge_peaks <- function(peaks, eic, baseline, noise){
lm <- c(min(peaks$lmin), max(peaks$lmax))
intb <- pracma::trapz(eic[lm[1]:lm[2], 'int'] - baseline[lm[1]:lm[2]])
intb <- pracma::trapz(eic[lm[1]:lm[2], 'rt'], eic[lm[1]:lm[2], 'int'] - baseline[lm[1]:lm[2]])
new_peak <- data.frame(
mz = peaks[1, "mz"],
mzmin = min(peaks[, "mzmin"]),
mzmax = max(peaks[, "mzmax"]),
rt = peaks[1, "rt"],
rtmin = min(peaks[, "rtmin"]),
rtmax = max(peaks[, "rtmax"]),
into = pracma::trapz(eic[lm[1]:lm[2], 'int']),
into = pracma::trapz(eic[lm[1]:lm[2], 'rt'], eic[lm[1]:lm[2], 'int']),
intb = intb,
maxo = max(peaks[, "maxo"]),
sn = if (noise == 0) intb
Expand Down Expand Up @@ -474,15 +474,15 @@ integrate2 <- function(eic, lm, baseline, noise, missing_scans, mzmat, scale = N
mz <- do.call(xcms:::mzCenter.wMean, list(
mz = mz_vals[, "mz"],
intensity = mz_vals[, "int"]))
intb <- pracma::trapz(eic[lm[1]:lm[2], 'int'] - baseline[lm[1]:lm[2]])
intb <- pracma::trapz(eic[lm[1]:lm[2], 'rt'], eic[lm[1]:lm[2], 'int'] - baseline[lm[1]:lm[2]])
data.frame(
mz = mz,
mzmin = mz_range[1],
mzmax = mz_range[2],
rt = eic[center, 'rt'] / 60,
rtmin = eic[lm[1], 'rt'] / 60,
rtmax = eic[lm[2], 'rt'] / 60,
into = pracma::trapz(eic[lm[1]:lm[2], 'int']),
into = pracma::trapz(eic[lm[1]:lm[2], 'rt'], eic[lm[1]:lm[2], 'int']),
intb = intb,
maxo = max(mz_vals[, "int"]),
sn = if (noise == 0) intb
Expand Down Expand Up @@ -568,34 +568,31 @@ deconvolution <- function(xr, theoric_patterns, chemical_ids, scalerange, scanra
lm <- c(roi[1] - traces[[1]]$eic[roi[1], "scan"] + 1, roi[2] - traces[[1]]$eic[roi[1], "scan"] + 1)
basepeaks <- integrate2(traces[[1]]$eic[roi[1]:roi[2], ], lm,
baselines[[1]][roi[1]:roi[2]], noises[1], missing_scans,
traces[[1]]$mzmat[which(
traces[[1]]$mzmat[, "scan"] %in% roi[1]:roi[2])
, , drop = FALSE])
}
else{
traces[[1]]$mzmat[which(traces[[1]]$mzmat[, "scan"] %in% roi[1]:roi[2]), , drop = FALSE])
}else{
# extend roi for better integration
roi <- range(
(if (min(roi) - extend_range < 1) 1 else min(roi) - extend_range) :
(if (max(roi) + extend_range > nrow(traces[[1]]$eic)) nrow(traces[[1]]$eic) else max(roi) + extend_range)
)
basepeaks <- integrate(traces[[1]]$eic[roi[1]:roi[2], ], scalerange,
baselines[[1]][roi[1]:roi[2]], noises[1], missing_scans,
traces[[1]]$mzmat[which(
traces[[1]]$mzmat[, "scan"] %in% roi[1]:roi[2])
, , drop = FALSE])
roi <- range(
(if (min(roi) - extend_range < 1) 1 else min(roi) - extend_range) :
(if (max(roi) + extend_range > nrow(traces[[1]]$eic)) nrow(traces[[1]]$eic) else max(roi) + extend_range)
)
basepeaks <- integrate(traces[[1]]$eic[roi[1]:roi[2], ], scalerange,
baselines[[1]][roi[1]:roi[2]], noises[1], missing_scans,
traces[[1]]$mzmat[which(
traces[[1]]$mzmat[, "scan"] %in% roi[1]:roi[2])
, , drop = FALSE])
}

if (length(basepeaks) == 0) next
basepeaks <- cbind(basepeaks, abundance = 100, iso = "A")
if(is.vector(scanrange)) basepeaks <- basepeaks[(basepeaks$rt > scanrange[1] & basepeaks$rt < scanrange[2]),]
if(is.vector(scanrange)) basepeaks <- basepeaks[(basepeaks$rt > scanrange[1] & basepeaks$rt < scanrange[2]),]
if(nrow(basepeaks) == 0) next
basepeak <- basepeaks[which.max(basepeaks$maxo),]
peaks2 <- NULL
scores <- c(theoric_patterns[[i]][1, "weight"])
deviations <- c(theoric_patterns[[i]][1, "mz"] - basepeak[1, "mz"])
deviations <- c(basepeak[1, "mz"] - theoric_patterns[[i]][1, "mz"])
weight <- c(theoric_patterns[[i]][1, "weight"])
continue_integration <- TRUE
k <- 2
k <- 2 # To avoid iso = A
while (k < length(traces) & continue_integration) {
eic <- traces[[k]]$eic
mzmat <- traces[[k]]$mzmat
Expand All @@ -613,7 +610,7 @@ deconvolution <- function(xr, theoric_patterns, chemical_ids, scalerange, scanra
theoric_patterns[[i]][k, "abundance"]) *
theoric_patterns[[i]][k, "weight"])
deviations <- c(deviations,
theoric_patterns[[i]][k, "mz"] - peak[1, "mz"])
peak[1, "mz"] - theoric_patterns[[i]][k, "mz"])
weight <- c(weight, theoric_patterns[[i]][k, "weight"])
peaks2 <- rbind(peaks2, peak)
} else continue_integration <- FALSE
Expand All @@ -625,8 +622,8 @@ deconvolution <- function(xr, theoric_patterns, chemical_ids, scalerange, scanra
score = sum(scores) * 100,
deviation = mean(deviations) * 10**3,
chemical_ion = chemical_ids[i],
intensities = length(traces)*sum(peaks2[,"maxo"])/k,
weighted_deviations = sum(deviations*weight)/sum(weight)
intensities = sum(peaks2[,"into"]),
weighted_deviations = sum(deviations*weight)/sum(weight)
))
}

Expand Down Expand Up @@ -685,7 +682,7 @@ deconvolution_std <- function(xr, theoric_patterns, chemical_ids = NA, scalerang

if (length(basepeaks) == 0) next
basepeaks <- cbind(basepeaks, abundance = 100, iso = "A")
if(is.vector(scanrange)) basepeaks <- basepeaks[(basepeaks$rt > scanrange[1] & basepeaks$rt < scanrange[2]),]
if(is.vector(scanrange)) basepeaks <- basepeaks[(basepeaks$rt > scanrange[1] & basepeaks$rt < scanrange[2]),]
if(nrow(basepeaks) == 0) next
basepeak <- basepeaks[which.max(basepeaks$maxo),]
peaks2 <- NULL
Expand All @@ -711,7 +708,7 @@ deconvolution_std <- function(xr, theoric_patterns, chemical_ids = NA, scalerang
theoric_patterns[[i]][k, "abundance"]) *
theoric_patterns[[i]][k, "weight"])
deviations <- c(deviations,
theoric_patterns[[i]][k, "mz"] - peak[1, "mz"])
peak[1, "mz"] - theoric_patterns[[i]][k, "mz"])
weight <- c(weight, theoric_patterns[[i]][k, "weight"])
peaks2 <- rbind(peaks2, peak)
} else continue_integration <- FALSE
Expand All @@ -723,8 +720,8 @@ deconvolution_std <- function(xr, theoric_patterns, chemical_ids = NA, scalerang
score = sum(scores) * 100,
deviation = mean(deviations) * 10**3,
chemical_ion = chemical_ids[i],
intensities = length(traces)*sum(peaks2[,"maxo"])/k,
weighted_deviations = sum(deviations*weight)/sum(weight)
intensities = sum(peaks2[,"into"]),
weighted_deviations = sum(deviations*weight)/sum(weight)
))
}

Expand Down
Loading

0 comments on commit abb966b

Please # to comment.