extractSpectraData: Conversion between objects from the Spectra and MSnbase...

View source: R/functions-MSpectra.R

extractSpectraDataR Documentation

Conversion between objects from the Spectra and MSnbase packages

Description

The Spectra package provides a more robust and efficient infrastructure for mass spectrometry data handling and analysis. So, wherever possible, the newer Spectra package should be used instead of the MSnbase. The functions listed here allow to convert between objects from the MSnbase and Spectra packages.

extractSpectraData extracts the spectra data (m/z and intensity values including metadata) from MSnExp, OnDiskMSnExp, Spectrum1, Spectrum2 objects (or list of such objects) and returns these as a DataFrame that can be used to create a Spectra::Spectra object.This function enables thus to convert data from the old MSnbase package to the newer Spectra package.

To convert a Spectra object to a MSpectra object use as(sps, "MSpectra") where sps is a Spectra object.

Usage

extractSpectraData(x)

Arguments

x

a list of Spectrum objects or an object extending MSnExp or a MSpectra object.

Value

  • extracSpectraData() returns a DataFrame() with the full spectrum data that can be passed to the Spectra::Spectra() function to create a Spectra object.

  • as(x, "MSpectra") returns a MSpectra object with the content of the Spectra object x.

Note

Coercion from Spectra to a MSpectra will only assign values to the contained Spectrum1 and Spectrum2 objects, but will not add all eventually spectra variables present in Spectra.

Author(s)

Johannes Rainer

Examples


## Read an mzML file with MSnbase
fl <- system.file("TripleTOF-SWATH", "PestMix1_SWATH.mzML",
    package = "msdata")
data <- filterRt(readMSData(fl, mode = "onDisk"), rt = c(1, 6))

## Extract the data as a DataFrame
res <- extractSpectraData(data)
res

library(Spectra)
## This can be used as an input for the Spectra constructor of the
## Spectra package:
sps <- Spectra::Spectra(res)
sps

## A Spectra object can be coerced to a MSnbase MSpectra object using
msps <- as(sps, "MSpectra")

lgatto/MSnbase documentation built on Nov. 12, 2024, 10:58 a.m.