Skip to content

Commit

Permalink
refactor: call functions for the processinQueue using namespace ::
Browse files Browse the repository at this point in the history
- Use direct namespace calls for functions used in the `Spectra`'s processing
  queue (i.e. using `MsCoreUtils::`) to ensure functions are called/available if
  run in parallel on Windows or called on a re-loaded object.
  • Loading branch information
jorainer committed Jun 5, 2024
1 parent 16bb472 commit 4a7522e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Spectra
Title: Spectra Infrastructure for Mass Spectrometry Data
Version: 1.15.2
Version: 1.15.3
Description: The Spectra package defines an efficient infrastructure
for storing and handling mass spectrometry spectra and functionality to
subset, process, visualize and compare spectra data. It provides different
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Spectra 1.15

## Changes in 1.15.3

- For evaluation of the `Spectra`'s processing queue: call functions from the
*MetaboCoreUtils* directly through their namespace (`MsCoreUtils::`) to avoid
errors if performed in parallel on Windows machines or if called on a
re-loaded object.

## Changes in 1.15.2

- Add `dataStorageDataPath()` and `dataStorageDataPath<-` methods to allow
Expand Down
28 changes: 15 additions & 13 deletions R/peaks-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ NULL
msLevel = spectrumMsLevel, ...) {
if (!spectrumMsLevel %in% msLevel || !length(x))
return(x)
x[which(between(x[, "intensity"], intensity)), , drop = FALSE]
x[which(MsCoreUtils::between(x[, "intensity"], intensity)), , drop = FALSE]
}

#' @description
Expand Down Expand Up @@ -146,8 +146,9 @@ NULL
keep = TRUE, ...) {
if (!spectrumMsLevel %in% msLevel || !length(x))
return(x)
no_match <- is.na(closest(x[, "mz"], mz, tolerance = tolerance, ppm = ppm,
duplicates = "keep", .check = FALSE))
no_match <- is.na(MsCoreUtils::closest(x[, "mz"], mz, tolerance = tolerance,
ppm = ppm, duplicates = "keep",
.check = FALSE))
if (keep) x[!no_match, , drop = FALSE]
else x[no_match, , drop = FALSE]
}
Expand All @@ -170,8 +171,8 @@ NULL
if (!spectrumMsLevel %in% msLevel || !length(x))
return(x)
if (keep)
x[between(x[, "mz"], mz), , drop = FALSE]
else x[!between(x[, "mz"], mz), , drop = FALSE]
x[MsCoreUtils::between(x[, "mz"], mz), , drop = FALSE]
else x[!MsCoreUtils::between(x[, "mz"], mz), , drop = FALSE]
}

#' @description
Expand Down Expand Up @@ -415,14 +416,14 @@ joinPeaksNone <- function(x, y, ...) {
return(x)
}

n <- noise(x[, 1L], x[, 2L], method = method, ...)
n <- MsCoreUtils::noise(x[, 1L], x[, 2L], method = method, ...)

l <- localMaxima(x[, 2L], hws = halfWindowSize)
l <- MsCoreUtils::localMaxima(x[, 2L], hws = halfWindowSize)

p <- which(l & x[, 2L] > (snr * n))

if (k > 0L) {
cbind(mz = refineCentroids(x = x[, 1L], y = x[, 2L], p = p,
cbind(mz = MsCoreUtils::refineCentroids(x = x[, 1L], y = x[, 2L], p = p,
k = k, threshold = threshold,
descending = descending),
intensity = x[p, 2L])
Expand Down Expand Up @@ -552,9 +553,10 @@ joinPeaksNone <- function(x, y, ...) {
.peaks_deisotope <-
function(x, substDefinition = isotopicSubstitutionMatrix("HMDB_NEUTRAL"),
tolerance = 0, ppm = 10, charge = 1, ...) {
iso_grps <- isotopologues(x, substDefinition = substDefinition,
tolerance = tolerance, ppm = ppm,
charge = charge)
iso_grps <- MetaboCoreUtils::isotopologues(
x, substDefinition = substDefinition,
tolerance = tolerance, ppm = ppm,
charge = charge)
if (length(iso_grps)) {
rem <- unique(unlist(lapply(iso_grps, `[`, -1), use.names = FALSE))
x[-rem, , drop = FALSE]
Expand Down Expand Up @@ -614,7 +616,7 @@ joinPeaksNone <- function(x, y, ...) {
msLevel = spectrumMsLevel, ...) {
if (!spectrumMsLevel %in% msLevel || !length(x))
return(x)
grps <- group(x[, "mz"], tolerance = tolerance, ppm = ppm)
grps <- MsCoreUtils::group(x[, "mz"], tolerance = tolerance, ppm = ppm)
lg <- length(grps)
if (grps[lg] == lg)
return(x)
Expand Down Expand Up @@ -649,7 +651,7 @@ joinPeaksNone <- function(x, y, ...) {
msLevel = spectrumMsLevel, ...) {
if (!spectrumMsLevel %in% msLevel || !nrow(x))
return(x)
keep <- is.na(closest(x[, "mz"], precursorMz, ppm = ppm,
keep <- is.na(MsCoreUtils::closest(x[, "mz"], precursorMz, ppm = ppm,
tolerance = tolerance, duplicates = "keep",
.check = FALSE))
x[keep, , drop = FALSE]
Expand Down

0 comments on commit 4a7522e

Please sign in to comment.