Open jorainer opened 1 year ago
backendInitialize,MsBackend
specifying the columns of the submitted DataFrame
that contain the peaks variables (see example below).Spectra
: addPeaksVariable <- function(x, i = seq_len(x), value = list(), name = character())
. Add or update a single peaks variable. Parameter i
allows to specify to which spectrum/spectra in x
the annotation should be added.filterMzValues
, filterIntensity
etc): these functions subset the peaksData
on-the-fly. Current implementations fail to correctly subset peaks annotations. Solution to add rownames to the peaks matrix (representing the index of each peak in the original data as returned by the backend) was discarded. A solution based on peaksData
returning a data.frame
instead of a matrix
will be tested.Examples
library(Spectra)
df <- data.frame(rtime = c(1.1, 1.2, 1.3, 1.4),
msLevel = 1L)
df$mz <- list(c(13, 14.1, 22, 23, 24, 49),
c(45.1, 56),
c(34.3, 134.4, 344, 443),
c(12.1, 31))
df$intensity <- list(c(100, 300, 30, 120, 12, 34),
c(345, 234),
c(123, 124, 145, 3),
c(122, 421))
#' add some arbitrary information for each peak to the data.frame
df$ann <- list(c("a", NA, "b", "c", "d", NA),
c("e", "f"),
c("g", "h", "i", NA),
c("j", "k"))
B <- Spectra(df, peaksVariables = c("mz", "intensity", "ann"))
#' Peak annotations get stored into @peaksDataFrame
B@backend@peaksDataFrame
peaksVariables(B)
[1] "mz" "intensity" "ann"
peaksData(B@backend, columns = peaksVariables(B))[[1L]]
mz intensity ann
[1,] "13.0" "100" "a"
[2,] "14.1" "300" NA
[3,] "22.0" " 30" "b"
[4,] "23.0" "120" "c"
[5,] "24.0" " 12" "d"
[6,] "49.0" " 34" NA
#' Not ideal because a matrix is returned...
#' In addition, the "generic" access is also supported
B$ann
Problems with filtering:
B2 <- filterMzValues(B, 23, tolerance = 1)
peaksData(B2, columns = c("mz", "intensity"))[[1L]]
mz intensity
[1,] 22 30
[2,] 23 120
[3,] 24 12
#' Peaks variables were/are not updated properly.
B2$ann[[1L]]
[1] "a" NA "b" "c" "d" NA
#' Error extracting peaksData (since a character vector is returned by `peaksData`
peaksData(B2, columns = c("mz", "intensity", "ann"))[[1L]]
Error in x * ppm : non-numeric argument to binary operator
Topics to discuss:
Spectra
(https://github.com/rformassspectrometry/Spectra/issues/287):peaksVariables
to list available peak variables (default"mz"
,"intensity"
).MsBackendSQL
,MsBackendMassbank
,MsBackendTimsTof
,MsBackendCompDb
andMsBackendMemory
support additional peaks variables.peaksData
returns them - but as alist
ofmatrix
.peaksAnnotation
?peaksDataFrame
(method forMsBackend
) return all peaks variables except m/z and intensity as alist
ofdata.frame
. Setter method to add/replace these values).peaksAnnotation,Spectra
needs to take care of that.