R/smoothChrom-method.R

#' Smooth Chromatograms
#'
#' @rdname smoothChrom
#' @param object a SRM object
#' @param cf matrix, a coefficient matrix generated by MsCoreUtils::coefMA or MsCoreUtils::coefWMA
#' @return a SRM object
#'
#' @export

setMethod('smoothChrom', signature = 'SRM',
          function(object, cf)
          {
            chrom_split  <-
              object@chroms %>% dplyr::group_by(sampleID, filter) %>% dplyr::group_split()
#
#             chrom_basecor <-
#               purrr::map(chrom_split, ~ {
#                 ptw::baseline.corr(.$int)
#               })
#
#             for (i in seq_along(chrom_split)) {
#               chrom_split[[i]]$int <- chrom_basecor[[i]]
#             }

            chrom_smooth <-
              purrr::map(chrom_split, ~ {
                MsCoreUtils::smooth(.$int, cf)
              })

            for (i in seq_along(chrom_split)) {
              chrom_split[[i]]$int <- chrom_smooth[[i]]
            }

            object@chroms <-
              chrom_split %>% dplyr::bind_rows()

            return(object)

          })
wilsontom/sRm documentation built on Sept. 20, 2023, 7:19 a.m.