readMgfData: Import mgf files as 'MSnExp' instances.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/readWriteMgfData.R

Description

Reads a mgf file and generates an "MSnExp" object.

Usage

1
2
readMgfData(filename, pdata = NULL, centroided = TRUE, smoothed = FALSE,
verbose = isMSnbaseVerbose(), cache = 1)

Arguments

filename

character vector with file name to be read.

pdata

an object of class "AnnotatedDataFrame".

smoothed

Logical indicating whether spectra already smoothed or not. Default is 'FALSE'. Used to initialise "MSnProcess" object in processingData slot.

centroided

Logical indicating whether spectra are centroided or not. Default is 'TRUE'. Used to initialise "MSnProcess" object in processingData slot.

cache

Numeric indicating caching level. Default is 1. Under development.

verbose

verbosity flag.

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.

Value

An instance of

Author(s)

Guangchuang Yu <guangchuangyu@gmail.com> and Laurent Gatto <lg390@cam.ac.uk>

See Also

writeMgfData method to write the content of "Spectrum" or "MSnExp" objects to mgf files. Raw data files can also be read with the readMSData function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  data(itraqdata)
  writeMgfData(itraqdata, con="itraqdata.mgf", COM="MSnbase itraqdata")
  itraqdata2 <- readMgfData("itraqdata.mgf")
  ## note that the order of the spectra is altered
  ## and precision of some values (precursorMz for instance)
  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)
  ## is TRUE
  all.equal(as.data.frame(itraqdata2[[1]]),as.data.frame(itraqdata[[1]]))
  ## is TRUE
  all.equal(as.data.frame(itraqdata2[[3]]),as.data.frame(itraqdata[[11]]))
  ## is TRUE
  f <- dir(system.file(package="MSnbase",dir="extdata"),
           full.name=TRUE,
           pattern="test.mgf")
  (x <- readMgfData(f))
  x[[2]]
  precursorMz(x[[2]])
  precursorIntensity(x[[2]])
  precursorMz(x[[1]])
  precursorIntensity(x[[1]]) ## was not in test.mgf
  scanIndex(x)

Example output

Loading required package: BiocGenerics
Loading required package: parallel

Attaching package:BiocGenericsThe following objects are masked frompackage:parallel:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked frompackage:stats:

    IQR, mad, sd, var, xtabs

The following objects are masked frompackage:base:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min

Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: mzR
Loading required package: Rcpp
Loading required package: S4Vectors
Loading required package: stats4

Attaching package:S4VectorsThe following object is masked frompackage:base:

    expand.grid

Loading required package: ProtGenerics

Attaching package:ProtGenericsThe following object is masked frompackage:stats:

    smooth


This is MSnbase version 2.16.0 
  Visit https://lgatto.github.io/MSnbase/ to get started.


Attaching package:MSnbaseThe following object is masked frompackage:base:

    trimws

 [1]  1 10 11 12 13 14 15 16 17 18 19  2 20 21 22 23 24 25 26 27 28 29  3 30 31
[26] 32 33 34 35 36 37 38 39  4 40 41 42 43 44 45 46 47 48 49  5 50 51 52 53 54
[51] 55  6  7  8  9
[1] TRUE
[1] TRUE
[1] TRUE
MSn experiment data ("MSnExp")
Object size in memory: 0.01 Mb
- - - Spectra data - - -
 MS level(s): 2 
 Number of spectra: 3 
 MSn retention times: 17:8 - 18:47 minutes
- - - Processing information - - -
Data loaded: Wed Dec  9 12:37:11 2020 
 MSnbase version: 2.16.0 
- - - Meta data  - - -
phenoData
  rowNames: 1
  varLabels: sampleNames fileNumbers
  varMetadata: labelDescription
Loaded from:
  test.mgf 
protocolData: none
featureData
  featureNames: X1 X2 X3
  fvarLabels: TITLE PEPMASS ... SCANS (5 total)
  fvarMetadata: labelDescription
experimentData: use 'experimentData(object)'
Object of class "Spectrum2"
 Precursor: 787.8283 
 Retention time: 18:37 
 Charge: 2 
 MSn level: 2 
 Peaks count: 21 
 Total ion count: 124558.3 
[1] 787.8283
[1] 880650.4
[1] 816.3383
[1] 0
  X1   X2   X3 
2162 2406 2432 

MSnbase documentation built on Jan. 23, 2021, 2 a.m.