rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
34 stars 24 forks source link

`filterFourierTransformArtefacts` fails when used with other processings #302

Closed Adafede closed 9 months ago

Adafede commented 9 months ago

Hi!

Pseudocode below:

library(Spectra)

spd <- DataFrame(
  msLevel = c(2L, 2L, 2L),
  polarity = c(1L, 1L, 1L),
  id = c("HMDB0000001", "HMDB0000001", "HMDB0001847"),
  name = c("1-Methylhistidine", "1-Methylhistidine", "Caffeine"))

## Assign m/z and intensity values.
spd$mz <- list(
  c(109.2, 124.2, 124.5, 170.16, 170.52),
  c(83.1, 96.12, 97.14, 109.14, 124.08, 125.1, 170.16),
  c(56.0494, 69.0447, 83.0603, 109.0395, 110.0712,
    111.0551, 123.0429, 138.0662, 195.0876))
spd$intensity <- list(
  c(3.407, 47.494, 3.094, 100.0, 13.240),
  c(6.685, 4.381, 3.022, 16.708, 100.0, 4.565, 40.643),
  c(0.459, 2.585, 2.446, 0.508, 8.968, 0.524, 0.974, 100.0, 40.994))

sps <- Spectra(spd)

## Works
sps2 <- sps |>
  Spectra::filterFourierTransformArtefacts() |> 
  Spectra::applyProcessing()

## Fails
sps2 <- sps |>
  Spectra::filterIntensity(c(0,Inf)) |> 
  Spectra::filterFourierTransformArtefacts() |> 
  Spectra::applyProcessing()

## Fails
sps2 <- sps |>
  Spectra::filterFourierTransformArtefacts() |> 
  Spectra::filterIntensity(c(0,Inf)) |> 
  Spectra::applyProcessing()

## Current workaround
sps2 <- sps
sps2@backend@peaksData <- sps2@backend@peaksData |>
  lapply(FUN = Spectra:::.peaks_remove_fft_artifact)
sps2 <- sps2 |>
  Spectra::filterIntensity(c(0,Inf)) |> 
  Spectra::applyProcessing()
jorainer commented 9 months ago

Thanks for reporting @Adafede - very stragen. I'll look into it.

jorainer commented 9 months ago

Added a fix. Should be OK with the new versions (in both the main branch -> Bioc devel and RELEASE_3_17 branch).

Adafede commented 9 months ago

šŸ‘šŸ¼ Thank you very much!

jorainer commented 9 months ago

Closing issue now - feel free to re-open if needed.