calculateMetricsFromSpectra: Calculate QC metrics from a Spectra object

View source: R/function_calculateMetrics_from_Spectra.R

calculateMetricsFromSpectraR Documentation

Calculate QC metrics from a Spectra object

Description

The function calculateMetricsFromSpectra calculates quality metrics from a Spectra object. The function will calculate the metrics per sample according to the grouping parameter f, e.g. dataOrigin information.

Two format options are available:

- format = "data.frame" returns the metrics as a data.frame,
- format = "mzQC" returns the metrics as a list of MzQCmzQC objects.

Usage

calculateMetricsFromSpectra(
  spectra,
  metrics,
  filterEmptySpectra = FALSE,
  f = dataOrigin(spectra),
  format = c("data.frame", "mzQC"),
  ...,
  BPPARAM = bpparam()
)

Arguments

spectra

Spectra object

metrics

character specifying the quality metrics to be calculated on spectra

filterEmptySpectra

logical(1) specifying if empty entries and entries with intensity zero of the Spectra object will be removed

f

character defining which spectra in spectra belong to one sample. Defaults to f = dataOrigin(spectra). Spectra from the same original data file are processed together (and in parallel for different files).

format

character(1) specifying if metrics are returned as a data.frame (format = "data.frame") or as a list of MzQCmzQC objects (format = "mzQC")

...

arguments passed to the quality metrics functions defined in metrics

BPPARAM

Parallel processing setup. Defaults to BPPARAM = bpparam(). See [bpparam()] for details on parallel processing with BiocParallel.

Details

The metrics are defined by the argument metrics. Further arguments passed to the quality metric functions can be specified by .... The additional arguments ... are matched against the formal arguments of the quality metric functions.

Samples will be processed in parallel using the default parallel processing setup ([bpparam()]) or with the parallel processing setup defined with parameter BPPARAM.

Setting the argument filterEmptySpectra to TRUE will remove zero-length entries, zero-intensity entries, and entries with intensities that are Inf from the Spectra object.

Value

In case of format = "data.frame", a data.frame containing in the columns the metrics for the different spectra of identical dataOrigin{spectra} (in rows). In case of format = "mzQC", a list of MzQCmzQC objects containing the metrics for the different spectra of identical dataOrigin{spectra}

Author(s)

Thomas Naake, Johannes Rainer

Examples

library(msdata)
library(Spectra)

## define file names containing spectra data for the samples
fls <- dir(system.file("sciex", package = "msdata"), full.names = TRUE)

## import the data and add it to the spectra object
spectra <- Spectra(fls, backend = MsBackendMzR())

## define the quality metrics to be calculated
metrics <- c("areaUnderTic", "chromatographyDuration", "msSignal10xChange")

## calculate the metrics
## additional parameters passed to the quality metrics functions
## (msLevel is an argument of areaUnderTic and msSignal10xChange,
## relativeTo is an argument of msSignal10xChange) passed to ...

## format = "data.frame"
calculateMetricsFromSpectra(spectra = spectra, metrics = metrics,
    format = "data.frame", msLevel = 1, change = "jump", relativeTo = "Q1")
calculateMetricsFromSpectra(spectra = spectra, metrics = metrics, 
    format = "data.frame", msLevel = 1, change = "fall", 
    relativeTo = "previous")
    
## format = "mzQC"
##calculateMetricsFromSpectra(spectra = spectra, metrics = metrics,
##    format = "mzQC", msLevel = 1, change = "jump", relativeTo = "Q1")
##calculateMetricsFromSpectra(spectra = spectra, metrics = metrics, 
##    format = "mzQC", msLevel = 1, change = "fall", relativeTo = "previous")

tnaake/MsQuality documentation built on Oct. 31, 2024, 2:41 a.m.