Skip to contents

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.

Usage

extractSpectraData(x)

Arguments

x

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

Value

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

Author

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
#> DataFrame with 50 rows and 37 columns
#>           fromFile     spIdx  smoothed scanIndex acquisitionNum   msLevel
#>          <integer> <integer> <logical> <integer>      <integer> <integer>
#> F1.S0010         1        10        NA        10             10         2
#> F1.S0011         1        11        NA        11             11         2
#> F1.S0012         1        12        NA        12             12         2
#> F1.S0013         1        13        NA        13             13         2
#> F1.S0014         1        14        NA        14             14         2
#> ...            ...       ...       ...       ...            ...       ...
#> F1.S0055         1        55        NA        55             55         2
#> F1.S0056         1        56        NA        56             56         2
#> F1.S0057         1        57        NA        57             57         2
#> F1.S0058         1        58        NA        58             58         2
#> F1.S0059         1        59        NA        59             59         2
#>           polarity originalPeaksCount totIonCurrent     rtime basePeakMZ
#>          <integer>          <integer>     <numeric> <numeric>  <numeric>
#> F1.S0010         1                340         83853     1.101    141.946
#> F1.S0011         1                491         61072     1.198    217.106
#> F1.S0012         1                296         28639     1.295    217.108
#> F1.S0013         1                301         26285     1.392    149.024
#> F1.S0014         1                292         27660     1.489    281.049
#> ...            ...                ...           ...       ...        ...
#> F1.S0055         1                373         89856     5.601    141.946
#> F1.S0056         1                532         66566     5.698    217.108
#> F1.S0057         1                301         30835     5.795    217.106
#> F1.S0058         1                256         23034     5.892    279.098
#> F1.S0059         1                310         27343     5.989    281.051
#>          basePeakIntensity collisionEnergy ionisationEnergy     lowMZ    highMZ
#>                  <numeric>       <numeric>        <numeric> <numeric> <numeric>
#> F1.S0010              6580               0                0         0         0
#> F1.S0011              1429               0                0         0         0
#> F1.S0012               501               0                0         0         0
#> F1.S0013               413               0                0         0         0
#> F1.S0014               714               0                0         0         0
#> ...                    ...             ...              ...       ...       ...
#> F1.S0055              7477               0                0         0         0
#> F1.S0056              1400               0                0         0         0
#> F1.S0057               432               0                0         0         0
#> F1.S0058               186               0                0         0         0
#> F1.S0059               496               0                0         0         0
#>          precursorScanNum precursorMZ precursorCharge precursorIntensity
#>                 <integer>   <numeric>       <integer>          <numeric>
#> F1.S0010               NA      163.75               0                  0
#> F1.S0011               NA      208.95               0                  0
#> F1.S0012               NA      244.05               0                  0
#> F1.S0013               NA      270.85               0                  0
#> F1.S0014               NA      299.10               0                  0
#> ...                   ...         ...             ...                ...
#> F1.S0055               NA      163.75               0                  0
#> F1.S0056               NA      208.95               0                  0
#> F1.S0057               NA      244.05               0                  0
#> F1.S0058               NA      270.85               0                  0
#> F1.S0059               NA      299.10               0                  0
#>          mergedScan mergedResultScanNum mergedResultStartScanNum
#>           <integer>           <integer>                <integer>
#> F1.S0010         NA                  NA                       NA
#> F1.S0011         NA                  NA                       NA
#> F1.S0012         NA                  NA                       NA
#> F1.S0013         NA                  NA                       NA
#> F1.S0014         NA                  NA                       NA
#> ...             ...                 ...                      ...
#> F1.S0055         NA                  NA                       NA
#> F1.S0056         NA                  NA                       NA
#> F1.S0057         NA                  NA                       NA
#> F1.S0058         NA                  NA                       NA
#> F1.S0059         NA                  NA                       NA
#>          mergedResultEndScanNum injectionTime filterString    spectrumId
#>                       <integer>     <numeric>  <character>   <character>
#> F1.S0010                     NA             0           NA sample=1 p...
#> F1.S0011                     NA             0           NA sample=1 p...
#> F1.S0012                     NA             0           NA sample=1 p...
#> F1.S0013                     NA             0           NA sample=1 p...
#> F1.S0014                     NA             0           NA sample=1 p...
#> ...                         ...           ...          ...           ...
#> F1.S0055                     NA             0           NA sample=1 p...
#> F1.S0056                     NA             0           NA sample=1 p...
#> F1.S0057                     NA             0           NA sample=1 p...
#> F1.S0058                     NA             0           NA sample=1 p...
#> F1.S0059                     NA             0           NA sample=1 p...
#>          centroided ionMobilityDriftTime isolationWindowTargetMZ
#>           <logical>            <numeric>               <numeric>
#> F1.S0010       TRUE                   NA                  163.75
#> F1.S0011       TRUE                   NA                  208.95
#> F1.S0012       TRUE                   NA                  244.05
#> F1.S0013       TRUE                   NA                  270.85
#> F1.S0014       TRUE                   NA                  299.10
#> ...             ...                  ...                     ...
#> F1.S0055       TRUE                   NA                  163.75
#> F1.S0056       TRUE                   NA                  208.95
#> F1.S0057       TRUE                   NA                  244.05
#> F1.S0058       TRUE                   NA                  270.85
#> F1.S0059       TRUE                   NA                  299.10
#>          isolationWindowLowerOffset isolationWindowUpperOffset
#>                           <numeric>                  <numeric>
#> F1.S0010                      24.25                      24.25
#> F1.S0011                      21.95                      21.95
#> F1.S0012                      14.15                      14.15
#> F1.S0013                      13.65                      13.65
#> F1.S0014                      15.60                      15.60
#> ...                             ...                        ...
#> F1.S0055                      24.25                      24.25
#> F1.S0056                      21.95                      21.95
#> F1.S0057                      14.15                      14.15
#> F1.S0058                      13.65                      13.65
#> F1.S0059                      15.60                      15.60
#>          scanWindowLowerLimit scanWindowUpperLimit  spectrum
#>                     <numeric>            <numeric> <integer>
#> F1.S0010                  140                  900        10
#> F1.S0011                  140                  900        11
#> F1.S0012                  140                  900        12
#> F1.S0013                  140                  900        13
#> F1.S0014                  140                  900        14
#> ...                       ...                  ...       ...
#> F1.S0055                  140                  900        55
#> F1.S0056                  140                  900        56
#> F1.S0057                  140                  900        57
#> F1.S0058                  140                  900        58
#> F1.S0059                  140                  900        59
#>                                   mz                         intensity
#>                        <NumericList>                     <NumericList>
#> F1.S0010 140.888,140.949,140.974,... 0.0999316,2.6204529,0.5139834,...
#> F1.S0011 140.901,140.913,140.958,... 0.0999386,0.1832319,0.5464582,...
#> F1.S0012 140.992,141.090,141.104,... 0.0599841,0.2358523,0.0800102,...
#> F1.S0013 140.872,141.957,143.089,... 0.0199862,0.0200630,0.0604285,...
#> F1.S0014 140.872,140.960,141.970,... 0.0799445,0.0199924,0.0200639,...
#> ...                              ...                               ...
#> F1.S0055 140.949,140.967,140.983,...    1.384358,0.183261,0.337385,...
#> F1.S0056 140.045,140.912,140.955,... 0.0597824,0.1823982,0.2357384,...
#> F1.S0057 141.094,141.963,141.981,...    0.288360,0.120379,0.100323,...
#> F1.S0058 140.876,141.955,141.972,... 0.0999327,0.1237221,0.0200640,...
#> F1.S0059 141.098,141.957,141.972,...    0.180017,0.020063,0.140449,...

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