Skip to content

Commit

Permalink
making it possible to just grab peaks after noise removal
Browse files Browse the repository at this point in the history
  • Loading branch information
rmflight committed Apr 15, 2023
1 parent 9254fb2 commit ae1b3ef
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ScanCentricPeakCharacterization
Title: Functionality for Characterizing Peaks in Mass Spectrometry in a
Scan-Centric Manner
Version: 0.3.59
Date: 2023-04-12
Version: 0.3.60
Date: 2023-04-14
Authors@R: person(given = c("Robert", "M"), family = c("Flight"), email
= "[email protected]", role = c("aut", "cre"))
Description: Provides a functions and classes for detecting,
Expand Down
6 changes: 4 additions & 2 deletions R/SCCharacterizePeaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ SCCharacterizePeaks = R6::R6Class("SCCharacterizePeaks",

#' @description
#' Do the peak characterization without saving
find_peaks = function(){
#'
#' @param stop_after_initial_detection should it stop after the initial peak finding
find_peaks = function(stop_after_initial_detection = FALSE){
log_message("Characterizing peaks ...")
if (inherits(self$sc_peak_region_finder, "R6")) {

Expand All @@ -167,7 +169,7 @@ SCCharacterizePeaks = R6::R6Class("SCCharacterizePeaks",
} else {
self$sc_zip$sc_peak_region_finder$sample_id = basename_no_file_ext(self$in_file)
}
self$sc_zip$sc_peak_region_finder$characterize_peaks()
self$sc_zip$sc_peak_region_finder$characterize_peaks(stop_after_initial_detection = stop_after_initial_detection)
self$sc_zip$sc_peak_region_finder$mzml_data = NULL
} else if ("function" %in% class(self$sc_peak_region_finder)) {
self$found_peaks = self$sc_peak_region_finder(self$sc_zip$sc_mzml, ...)
Expand Down
22 changes: 17 additions & 5 deletions R/SCPeakRegions.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ SCPeakRegionFinder = R6::R6Class("SCPeakRegionFinder",
#' @description
#' Split up signal regions by peaks found
#' @param use_regions an index of the regions we want to split up
split_peak_regions = function(use_regions = NULL){
#' @param stop_after_initial_detection should it do full characterization or stop
split_peak_regions = function(use_regions = NULL,
stop_after_initial_detection = FALSE){
log_message("Splitting signal regions by peaks ...")
if (is.null(use_regions)) {
use_regions = seq_len(length(self$peak_regions$peak_regions))
Expand All @@ -366,7 +368,8 @@ SCPeakRegionFinder = R6::R6Class("SCPeakRegionFinder",
min_scan = self$peak_regions$min_scan,
min_points = self$min_points,
n_zero = self$n_zero_tiles,
calculate_peak_area = self$calculate_peak_area)
calculate_peak_area = self$calculate_peak_area,
stop_after_initial_detection = stop_after_initial_detection)

self$peak_regions$peak_index = seq_len(length(self$peak_regions$peak_region_list))
},
Expand Down Expand Up @@ -495,10 +498,14 @@ SCPeakRegionFinder = R6::R6Class("SCPeakRegionFinder",

#' @description
#' Run the overall peak characterization from start to finish.
characterize_peaks = function(){
#' @param stop_after_initial_detection do we stop the whole process after finding initial peaks in each scan?
characterize_peaks = function(stop_after_initial_detection = FALSE){
self$add_regions()
self$reduce_sliding_regions()
self$split_peak_regions()
self$split_peak_regions(stop_after_initial_detection = stop_after_initial_detection)
if (stop_after_initial_detection) {
return(self)
}
self$remove_double_peaks_in_scans()
self$normalize_data()
self$find_peaks_in_regions()
Expand Down Expand Up @@ -902,7 +909,8 @@ subset_signal_reduce = function(in_points, min_points, metadata, calculate_peak_
# with peaks from at least min_scan scans (normally 10% of total scans).
# Finally, with that set, we go through and extract the original point and frequency data.
split_regions = function(signal_regions, frequency_point_regions, tiled_regions, min_scan, min_points = 4, n_zero = 1,
calculate_peak_area = FALSE) {
calculate_peak_area = FALSE,
stop_after_initial_detection = FALSE) {
# alternative idea to current implementation:
# take each scan, and then do the subsetting in parallel
# the object that needs to be cloned is "in_points", which is points from "frequency"
Expand All @@ -916,6 +924,10 @@ split_regions = function(signal_regions, frequency_point_regions, tiled_regions,
log_message("Finding peaks in each scan ...")
frequency_reduced = internal_map$map_function(frequency_in_signal, subset_signal_reduce, min_points, frequency_point_regions$metadata, calculate_peak_area)

if (stop_after_initial_detection) {
return(frequency_reduced)
}

# log_message("Finding regions with peaks ...")
tile_counts = IRanges::countOverlaps(tiled_regions, frequency_reduced[[1]])
n_scan = seq(2, length(frequency_reduced))
Expand Down
23 changes: 21 additions & 2 deletions man/SCCharacterizePeaks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions man/SCPeakRegionFinder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae1b3ef

Please sign in to comment.