MsBackendMsp: MS data backend for msp files

View source: R/MsBackendMsp.R

MsBackendMspR Documentation

MS data backend for msp files

Description

The MsBackendMsp class supports import of MS/MS spectra data from files in NIST MSP file format. MsBackendMsp extends the MsBackendDataFrame() backend directly and supports thus the applyProcessing() function to make data manipulations persistent.

New objects are created with the MsBackendMsp function. The backendInitialize method has to be subsequently called to initialize the object and import MS/MS data from (one or more) msp files.

The MsBackendMsp backend provides an export method that allows to export the data from the Spectra object (parameter x) to a file in msp format. Parameters to this function are:

  • x: the Spectra object that should be exported.

  • file: character(1) with the desired file name.

  • mapping: named character providing the mapping between spectra variables and MSP data fields. Defaults to mapping = spectraVariableMapping(MsBackendMsp()).

  • allVariables: logical(1) whether all spectra variables in x should be exported or only those defined with mapping.

  • exportName: logical(1) whether a NAME field should always be exported even if not provided in x.

See the package vignette for details and examples.

The spectraVariableMapping function allows to provide the mapping between spectra variable names (i.e. the names that will be used for the spectra variables in the Spectra() object) and the data field names of the MSP file. Parameter format allows to select pre-defined mappings. Currently supported mapping flavors are:

  • format = "msp": default MSP field names. Should work with standard NIST MSP files or MSP files exported from MS-DIAL.

  • format = "mona": MSP file format from MoNA including LipidBlast.

Usage

## S4 method for signature 'MsBackendMsp'
backendInitialize(
  object,
  file,
  mapping = spectraVariableMapping(object),
  ...,
  BPPARAM = bpparam()
)

MsBackendMsp()

## S4 method for signature 'MsBackendMsp'
spectraVariableMapping(object, format = c("msp", "mona"))

## S4 method for signature 'MsBackendMsp'
export(
  object,
  x,
  file = tempfile(),
  mapping = spectraVariableMapping(MsBackendMsp()),
  allVariables = TRUE,
  exportName = TRUE,
  ...
)

Arguments

object

Instance of MsBackendMsp class.

file

character with the (full) file name(s) of the msp file(s) from which MS/MS data should be imported or exported.

mapping

named character vector to rename MSP fields to spectra variables (see spectraVariableMapping()). This allows to correctly import also custom fields or data from files with different MSP flavors.

...

Currently ignored.

BPPARAM

Parameter object defining the parallel processing setup to import data in parallel. Defaults to BPPARAM = bpparam(). See bpparam() for more information.

format

For spectraVariableMapping: character(1) specifying for which MSP flavour the mapping should be returned. Currently supported are: format = "msp" (generic MSP format, for example for MS-DIAL MSP files) and format = "mona" (MSP files in MoNA flavour).

x

For export: a Spectra() object that should be exported to the specified MSP file.

allVariables

logical(1) whether all spectra variables in x should be exported or only those defined with mapping.

exportName

logical(1) whether a NAME field should always be exported even if not provided in x.

Value

MsBackendMsp and backendInitialize return an instance of a MsBackendMsp class. spectraVariableMapping a named character vector with the mapping between spectra variables and MSP data fields.

Author(s)

Steffen Neumann, Michael Witting, Laurent Gatto and Johannes Rainer

Examples


## Import spectra from a MSP file from LipidBlast
f <- system.file("extdata", "small-export-LipidBlast.msp",
    package = "MsBackendMsp")
be <- backendInitialize(MsBackendMsp(), f)
be

be$msLevel
be$intensity
be$mz

## precursor m/z are however all missing
be$precursorMz

## Default spectra variable mapping
spectraVariableMapping(MsBackendMsp())

## In fact, to read MSP files in "LipidBlast flavour" (same as MoNA) we
## should use a different spectra variable mapping
spectraVariableMapping(MsBackendMsp(), "mona")

## Importing the data with this will correctly retrieve data
be <- backendInitialize(MsBackendMsp(), f,
    mapping = spectraVariableMapping(MsBackendMsp(), "mona"))
be$precursorMz

## Other fields are also correctly mapped, but might need to be converted
## to e.g. numeric, such as "exactmass"
be$exactmass

be$exactmass <- as.numeric(be$exactmass)

be$adduct
be$formula

## Exporting Spectra objects in MSP format.

sps <- Spectra(be)
export(MsBackendMsp(), sps, file = stdout())

rformassspectrometry/MsBackendMsp documentation built on March 20, 2023, 9:45 a.m.