As explained in the Chromatograms class documentation, the Chromatograms
object is a container for chromatographic data that includes chromatographic
peaks data (retention time and related intensity values, also referred to
as peaks data variables in the context of Chromatograms
) and metadata of
individual chromatograms (so called chromatograms variables).
The peaks data variables information can be accessed using the
peaksData()
function. It is also possible to access specific peaks
variables using $
.
The peaks data can be accessed, replaced but also filtered/subsetted. Refer to the sections below for more details.
# S4 method for class 'Chromatograms'
peaksData(
object,
columns = peaksVariables(object),
f = processingChunkFactor(object),
BPPARAM = bpparam(),
drop = FALSE,
...
)
# S4 method for class 'Chromatograms'
peaksData(object) <- value
# S4 method for class 'Chromatograms'
peaksVariables(object, ...)
# S4 method for class 'Chromatograms'
rtime(object, ...)
# S4 method for class 'Chromatograms'
rtime(object) <- value
# S4 method for class 'Chromatograms'
intensity(object, ...)
# S4 method for class 'Chromatograms'
intensity(object) <- value
# S4 method for class 'Chromatograms'
filterPeaksData(
object,
variables = character(),
ranges = numeric(),
match = c("any", "all"),
keep = TRUE
)
A Chromatograms object.
For peaksData()
: optional character
with column
names (peaks variables) that should be included in the
returned list
of data.frame
. By default, all columns are returned.
Available variables can be found by calling peaksVariables()
on the
object.
factor
defining the grouping to split the Chromatograms
object.
Parallel setup configuration. See BiocParallel::bpparam()
for more information.
logical(1)
For peaksData()
, default to FALSE
. If TRUE
,
and one column is called by the user, the method returns a list of
vector of the single column requested.
Additional arguments passed to the method.
For rtime()
and intensity()
: numeric
vector with the
values to replace the current values. The length of the vector must
match the number of peaks data pairs in the Chromatograms
object.
For filterPeaksData()
: character
vector with the names
of the peaks data variables to filter for. The list of available
peaks data variables can be obtained with peaksVariables()
.
For filterPeaksData()
: a numeric
vector of paired values
(upper and lower boundary) that define the ranges to filter the
object
. These paired values need to be in the same order as the
variables
parameter (see below).
For filterPeaksData()
: character(1)
defining whether the
condition has to match for all provided ranges
(match = "all"
;
the default), or for any of them (match = "any"
).
For filterPeaksData()
: logical(1)
defining whether to
keep (keep = TRUE
) or remove (keep = FALSE
) the chromatographic
peaks data that match the condition.
Functions that filter a Chromatograms
's peaks data (i.e., peaksData
).
These functions remove peaks data that do not meet the
specified conditions. If a chromatogram in a Chromatograms
object is
filtered, only the corresponding peaks variable pairs (i.e., rows) in the
peaksData
are removed, while the chromatogram itself remains in the object.
The available functions to filter chromatographic peaks data include:
filterPeaksData()
: Filters numerical peaks data variables based on the
specified numerical ranges
parameter. This method returns the same input
Chromatograms
object, but the filtering step is added to the processing
queue. The filtered data will be reflected when the user accesses
peaksData
. This function does not reduce the number of chromatograms
in the object, but it removes the specified peaks data (e.g., "rtime" and
"intensity" pairs) from the peaksData
.
In the case of a read-only backend, (such as the ChromBackendMzR), the replacement of the peaks data is not possible. The peaks data can be filtered, but the filtered data will not be saved in the backend. This means the original mzml files will not be affected by computations performed on the Chromatograms.
Chromatograms for a general description of the Chromatograms
object, and chromData for accessing,substituting and filtering
chromatographic variables. For more information on the queuing
of processings and parallelization for larger dataset processing
see processingQueue.
# Create a Chromatograms object
cdata <- data.frame(
msLevel = c(1L, 1L, 1L),
mz = c(112.2, 123.3, 134.4),
chromIndex = c(1L, 2L, 3L)
)
pdata <- list(
data.frame(
rtime = c(12.4, 12.8, 13.2, 14.6),
intensity = c(123.3, 153.6, 2354.3, 243.4)
),
data.frame(
rtime = c(45.1, 46.2),
intensity = c(100, 80.1)
),
data.frame(
rtime = c(12.4, 12.8, 13.2, 14.6),
intensity = c(123.3, 153.6, 2354.3, 243.4)
)
)
be <- backendInitialize(new("ChromBackendMemory"),
chromData = cdata,
peaksData = pdata
)
chr <- Chromatograms(be)
# Access peaks data
peaksData(chr)
#> [[1]]
#> rtime intensity
#> 1 12.4 123.3
#> 2 12.8 153.6
#> 3 13.2 2354.3
#> 4 14.6 243.4
#>
#> [[2]]
#> rtime intensity
#> 1 45.1 100.0
#> 2 46.2 80.1
#>
#> [[3]]
#> rtime intensity
#> 1 12.4 123.3
#> 2 12.8 153.6
#> 3 13.2 2354.3
#> 4 14.6 243.4
#>
# Access specific peaks data variables
peaksData(chr, columns = "rtime")
#> [[1]]
#> rtime
#> 1 12.4
#> 2 12.8
#> 3 13.2
#> 4 14.6
#>
#> [[2]]
#> rtime
#> 1 45.1
#> 2 46.2
#>
#> [[3]]
#> rtime
#> 1 12.4
#> 2 12.8
#> 3 13.2
#> 4 14.6
#>
rtime(chr)
#> [[1]]
#> [1] 12.4 12.8 13.2 14.6
#>
#> [[2]]
#> [1] 45.1 46.2
#>
#> [[3]]
#> [1] 12.4 12.8 13.2 14.6
#>
# Replace peaks data
rtime(chr)[[1]] <- c(1, 2, 3, 4)
# Filter peaks data
filterPeaksData(chr, variables = "rtime", ranges = c(12.5, 13.5))
#> Chromatographic data (Chromatograms) with 3 chromatograms in a ChromBackendMemory backend:
#> chromIndex msLevel mz
#> 1 1 1 112.2
#> 2 2 1 123.3
#> 3 3 1 134.4
#> ... 0 more chromatogram variables/columns
#> ... 2 peaksData variables
#> Lazy evaluation queue: 1 processing step(s)
#> Processing:
#> Filter: remove peaks based on the variables: rtimethe ranges: 12.5, 13.5and the match condition: any [Mon May 5 10:08:11 2025]
#> Filter: remove peaks based on the variables: rtimethe ranges: 12.5, 13.5and the match condition: all [Mon May 5 10:08:11 2025]