forked from tianwei-yu/apLCMS
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
refactoringRefactor existing codeRefactor existing code
Description
This loop could be paralelized to speed up processing. The number of processor should be passed as a parameter.
recetox-aplcms/R/prof.to.features.R
Lines 927 to 966 in a393e64
| # loop over each group | |
| for (i in seq_along(feature_groups)) | |
| { | |
| # init variables | |
| feature_group <- feature_groups[[i]] |> dplyr::arrange_at("rt") | |
| num_features <- nrow(feature_group) | |
| # The estimation procedure for a single peak | |
| # Defines the dataframe containing median_mz, median_rt, sd1, sd2, and area | |
| if (num_features < 2) { | |
| time_weights <- all_diff_mean_rts[which(base.curve[, "base.curve"] %in% feature_group[2])] | |
| rt_peak_shape <- c(feature_group[1], feature_group[2], NA, NA, feature_group[3] * time_weights) | |
| peak_parameters <- rbind(peak_parameters, rt_peak_shape) | |
| } else { | |
| # find bandwidth for these particular range | |
| rt_range <- range(feature_group[, "rt"]) | |
| bw <- min(max(bandwidth * (max(rt_range) - min(rt_range)), min_bandwidth), max_bandwidth) | |
| bw <- seq(bw, 2 * bw, length.out = 3) | |
| if (bw[1] > 1.5 * min_bandwidth) { | |
| bw <- c(max(min_bandwidth, bw[1] / 2), bw) | |
| } | |
| rt_profile <- compute_chromatographic_profile(feature_group, base.curve) | |
| if (shape_model == "Gaussian") { | |
| rt_peak_shape <- compute_gaussian_peak_shape(rt_profile, bw, component_eliminate, BIC_factor, aver_diff) | |
| } else { | |
| rt_peak_shape <- bigauss.mix(rt_profile, sigma_ratio_lim = sigma_ratio_lim, bw = bw, moment_power = moment_power, peak_estim_method = peak_estim_method, eliminate = component_eliminate, BIC_factor = BIC_factor)$param[, c(1, 2, 3, 5)] | |
| } | |
| if (is.null(nrow(rt_peak_shape))) { | |
| peak_parameters <- rbind(peak_parameters, c(median(feature_group[, "mz"]), rt_peak_shape)) | |
| } else { | |
| for (m in 1:nrow(rt_peak_shape)) | |
| { | |
| rt_diff <- abs(feature_group[, "rt"] - rt_peak_shape[m, 1]) | |
| peak_parameters <- rbind(peak_parameters, c(mean(feature_group[which(rt_diff == min(rt_diff)), 1]), rt_peak_shape[m, ])) | |
| } | |
| } | |
| } | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
refactoringRefactor existing codeRefactor existing code