Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

writeMgfData-methods

Write an experiment or spectrum to an mgf file


Description

Methods writeMgfData write individual "Spectrum" instances of whole "MSnExp" experiments to a file in Mascot Generic Format (mgf) (see http://www.matrixscience.com/help/data_file_help.html for more details). Function readMgfData read spectra from and mgf file and creates an "MSnExp" object.

Arguments

object

An instance of class "Spectrum" or "MSnExp".

con

A valid connection or a character string with the name of the file to save the object. In case of the latter, a file connection is created. If not specified, 'spectrum.mgf' or 'experiment.mgf' are used depending on the class of object. Note that existing files are overwritted.

COM

Optional character vector with the value for the 'COM' field.

TITLE

Optional character vector with the value for the spectrum 'TITLE' field. Not applicable for experiments.

Details

Note that when reading an mgf file, the original order of the spectra is lost. Thus, if the data was originally written to mgf from an MSnExp object using writeMgfData, although the feature names will be identical, the spectra are not as a result of the reordering. See example below.

Methods

signature(object = "MSnExp")

Writes the full exeriment to an mgf file.

signature(object = "Spectrum")

Writes an individual spectrum to an mgf file.

See Also

readMgfData function to read data from and mgf file.

Examples

data(itraqdata)

f <- tempfile()

writeMgfData(itraqdata, con = f)

itraqdata2 <- readMgfData(f)

## note that the order of the spectra and precision of some values
## (precursorMz for instance) are altered
match(signif(precursorMz(itraqdata2),4),
      signif(precursorMz(itraqdata),4))

## [1]  1 10 11 12 13 14 15 16 17 18 ...
## ... but all the precursors are there
all.equal(sort(precursorMz(itraqdata2)),
          sort(precursorMz(itraqdata)),
          check.attributes = FALSE,
          tolerance = 10e-5)

all.equal(as.data.frame(itraqdata2[[1]]),
          as.data.frame(itraqdata[[1]]))

all.equal(as.data.frame(itraqdata2[[3]]),
          as.data.frame(itraqdata[[11]]))

all(featureNames(itraqdata2) == featureNames(itraqdata))

MSnbase

Base Functions and Classes for Mass Spectrometry and Proteomics

v2.16.1
Artistic-2.0
Authors
Laurent Gatto, Johannes Rainer and Sebastian Gibb with contributions from Guangchuang Yu, Samuel Wieczorek, Vasile-Cosmin Lazar, Vladislav Petyuk, Thomas Naake, Richie Cotton, Arne Smits, Martina Fisher, Ludger Goeminne, Adriaan Sticker and Lieven Clement.
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.