MsBackendMgf | R Documentation |
The MsBackendMgf
class supports import and export of MS/MS spectra data
from/to files in Mascot Generic Format
(mgf)
files. After initial import, the full MS data is kept in
memory. MsBackendMgf
extends the MsBackendDataFrame()
backend
directly and supports thus the applyProcessing()
function to make
data manipulations persistent.
New objects are created with the MsBackendMgf
function. The
backendInitialize
method has to be subsequently called to
initialize the object and import MS/MS data from (one or more) mgf
files.
The MsBackendMgf
backend provides an export
method that allows to export
the data from the Spectra
object (parameter x
) to a file in mgf format.
See the package vignette for details and examples.
Default mappings from fields in the MGF file to spectra variable names are
provided by the spectraVariableMapping
function. This function returns a
named character vector were names are the spectra variable names and the
values the respective field names in the MGF files. This named character
vector is submitted to the import and export function with parameter
mapping
. It is also possible to pass own mappings (e.g. for special
MGF dialects) with the mapping
parameter.
## S4 method for signature 'MsBackendMgf'
backendInitialize(
object,
files,
mapping = spectraVariableMapping(object),
nlines = -1L,
...,
BPPARAM = SerialParam()
)
MsBackendMgf()
## S4 method for signature 'MsBackendMgf'
spectraVariableMapping(object, format = c("mgf"))
## S4 method for signature 'MsBackendMgf'
export(
object,
x,
file = tempfile(),
mapping = spectraVariableMapping(object),
exportTitle = TRUE,
...
)
object |
Instance of |
files |
|
mapping |
for |
nlines |
for |
... |
Currently ignored. |
BPPARAM |
Parameter object defining the parallel processing
setup. If parallel processing is enabled (with |
format |
for |
x |
for |
file |
|
exportTitle |
|
See description above.
Laurent Gatto and Johannes Rainer
library(BiocParallel)
fls <- dir(system.file("extdata", package = "MsBackendMgf"),
full.names = TRUE, pattern = "mgf$")
## Create an MsBackendMgf backend and import data from test mgf files.
be <- backendInitialize(MsBackendMgf(), fls)
be
be$msLevel
be$intensity
be$mz
## The spectra variables that are available; note that not all of them
## have been imported from the MGF files.
spectraVariables(be)
## The variable "TITLE" represents the title of the spectrum defined in the
## MGF file
be$TITLE
## The default mapping of MGF fields to spectra variables is provided by
## the spectraVariableMapping function
spectraVariableMapping(MsBackendMgf())
## We can provide our own mapping e.g. to map the MGF field "TITLE" to a
## variable named "spectrumName":
map <- c(spectrumName = "TITLE", spectraVariableMapping(MsBackendMgf()))
map
## We can then pass this mapping with parameter `mapping` to the
## backendInitialize method:
be <- backendInitialize(MsBackendMgf(), fls, mapping = map)
## The title is now available as variable named spectrumName
be$spectrumName
## Next we create a Spectra object with this data
sps <- Spectra(be)
## We can use the 'MsBackendMgf' also to export spectra data in mgf format.
out_file <- tempfile()
export(sps, backend = MsBackendMgf(), file = out_file, map = map)
## The first 20 lines of the generated file:
readLines(out_file, n = 20)
## Next we add a new spectra variable to each spectrum
sps$spectrum_idx <- seq_along(sps)
## This new spectra variable will also be exported to the mgf file:
export(sps, backend = MsBackendMgf(), file = out_file, map = map)
readLines(out_file, n = 20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.