1 Introduction

These are the live notes from my talk at the (remote) May Institute 2020. I will present material from

MSnbase, efficient and elegant R-based processing and visualisation of raw mass spectrometry data. Laurent Gatto, Sebastian Gibb, Johannes Rainer bioRxiv 2020.04.29.067868; doi: https://doi.org/10.1101/2020.04.29.067868

See also

Acknowledgement: Johannes Rainer and Sebastian Gibb

Questions about your data/analyses/issues:

2 On-disk backend

f <- msdata::proteomics(pattern = "201412", full.names = TRUE)
basename(f)
## [1] "TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01-20141210.mzML.gz"
library(MSnbase)
library(magrittr)

Reading on-disk is faster. See Figure 1a in the pre-print.

system.time(x_mem <- readMSData(f, mode = "inMemory"))
##    user  system elapsed 
##  59.396   0.432  59.520
system.time(x_dsk <- readMSData(f, mode = "onDisk"))
##    user  system elapsed 
##  11.132   0.336  11.201

The MSnExp class

x_dsk
## MSn experiment data ("OnDiskMSnExp")
## Object size in memory: 3.31 Mb
## - - - Spectra data - - -
##  MS level(s): 1 2 
##  Number of spectra: 7534 
##  MSn retention times: 0:0 - 60:2 minutes
## - - - Processing information - - -
## Data loaded [Thu May  7 19:51:53 2020] 
##  MSnbase version: 2.14.0 
## - - - Meta data  - - -
## phenoData
##   rowNames:
##     TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01-20141210.mzML.gz
##   varLabels: sampleNames
##   varMetadata: labelDescription
## Loaded from:
##   TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01-20141210.mzML.gz 
## protocolData: none
## featureData
##   featureNames: F1.S0001 F1.S0002 ... F1.S7534 (7534 total)
##   fvarLabels: fileIdx spIdx ... spectrum (35 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
fData(x_dsk)
##          fileIdx spIdx smoothed seqNum acquisitionNum msLevel polarity
## F1.S0001       1     1       NA      1              1       1        1
## F1.S0002       1     2       NA      2              2       1        1
## F1.S0003       1     3       NA      3              3       1        1
## F1.S0004       1     4       NA      4              4       1        1
## F1.S0005       1     5       NA      5              5       1        1
## F1.S0006       1     6       NA      6              6       1        1
## F1.S0007       1     7       NA      7              7       1        1
## F1.S0008       1     8       NA      8              8       1        1
## F1.S0009       1     9       NA      9              9       1        1
## F1.S0010       1    10       NA     10             10       1        1
## F1.S0011       1    11       NA     11             11       1        1
## F1.S0012       1    12       NA     12             12       1        1
## F1.S0013       1    13       NA     13             13       1        1
## F1.S0014       1    14       NA     14             14       1        1
##          originalPeaksCount totIonCurrent retentionTime basePeakMZ
## F1.S0001              25800       9187505        0.4584     445.12
## F1.S0002              25934       9118685        0.9725     445.12
## F1.S0003              26148       9247653        1.8524     445.12
## F1.S0004              26330       9195261        2.7424     445.12
## F1.S0005              26463       9202081        3.6124     445.12
## F1.S0006              25580       9451720        4.4925     445.12
## F1.S0007              25191       9370178        5.3825     445.12
## F1.S0008              26957       9297793        6.2525     445.12
## F1.S0009              26608       9543710        7.1324     445.12
## F1.S0010              27062       9437697        8.0324     445.12
## F1.S0011              25763       9244707        8.8925     445.12
## F1.S0012              25577       9294566        9.7724     445.12
## F1.S0013              26282       9231183       10.6624     445.12
## F1.S0014              24474       9163494       11.5324     445.12
##          basePeakIntensity collisionEnergy ionisationEnergy    lowMZ   highMZ
## F1.S0001          984171.2              NA                0 399.9987 2008.454
## F1.S0002          989260.4              NA                0 399.9985 2008.453
## F1.S0003          997621.7              NA                0 399.9983 2008.453
## F1.S0004          988598.2              NA                0 399.9981 2008.451
## F1.S0005          971233.9              NA                0 399.9983 2008.452
## F1.S0006         1000968.4              NA                0 399.9981 2008.451
## F1.S0007         1004060.4              NA                0 399.9980 2008.451
## F1.S0008          985961.2              NA                0 399.9980 2008.451
## F1.S0009         1012269.5              NA                0 399.9980 2008.451
## F1.S0010          983832.0              NA                0 399.9980 2008.451
## F1.S0011          976695.8              NA                0 399.9978 2008.450
## F1.S0012          994047.6              NA                0 399.9979 2008.450
## F1.S0013          971733.5              NA                0 399.9978 2008.450
## F1.S0014          987855.7              NA                0 399.9977 2008.449
##          precursorScanNum precursorMZ precursorCharge precursorIntensity
## F1.S0001               NA          NA              NA                 NA
## F1.S0002               NA          NA              NA                 NA
## F1.S0003               NA          NA              NA                 NA
## F1.S0004               NA          NA              NA                 NA
## F1.S0005               NA          NA              NA                 NA
## F1.S0006               NA          NA              NA                 NA
## F1.S0007               NA          NA              NA                 NA
## F1.S0008               NA          NA              NA                 NA
## F1.S0009               NA          NA              NA                 NA
## F1.S0010               NA          NA              NA                 NA
## F1.S0011               NA          NA              NA                 NA
## F1.S0012               NA          NA              NA                 NA
## F1.S0013               NA          NA              NA                 NA
## F1.S0014               NA          NA              NA                 NA
##          mergedScan mergedResultScanNum mergedResultStartScanNum
## F1.S0001         NA                  NA                       NA
## F1.S0002         NA                  NA                       NA
## F1.S0003         NA                  NA                       NA
## F1.S0004         NA                  NA                       NA
## F1.S0005         NA                  NA                       NA
## F1.S0006         NA                  NA                       NA
## F1.S0007         NA                  NA                       NA
## F1.S0008         NA                  NA                       NA
## F1.S0009         NA                  NA                       NA
## 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
##          mergedResultEndScanNum injectionTime
## F1.S0001                     NA      50.38262
## F1.S0002                     NA      51.13650
## F1.S0003                     NA      50.36058
## F1.S0004                     NA      51.23796
## F1.S0005                     NA      50.87993
## F1.S0006                     NA      50.30515
## F1.S0007                     NA      50.08440
## F1.S0008                     NA      49.81701
## F1.S0009                     NA      51.12255
## F1.S0010                     NA      50.92492
## F1.S0011                     NA      51.28786
## F1.S0012                     NA      48.79818
## F1.S0013                     NA      50.32028
## F1.S0014                     NA      50.93900
##                                   filterString
## F1.S0001 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0002 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0003 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0004 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0005 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0006 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0007 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0008 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0009 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0010 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0011 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0012 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0013 FTMS + p NSI Full ms [400.00-2000.00]
## F1.S0014 FTMS + p NSI Full ms [400.00-2000.00]
##                                           spectrumId centroided
## F1.S0001  controllerType=0 controllerNumber=1 scan=1      FALSE
## F1.S0002  controllerType=0 controllerNumber=1 scan=2      FALSE
## F1.S0003  controllerType=0 controllerNumber=1 scan=3      FALSE
## F1.S0004  controllerType=0 controllerNumber=1 scan=4      FALSE
## F1.S0005  controllerType=0 controllerNumber=1 scan=5      FALSE
## F1.S0006  controllerType=0 controllerNumber=1 scan=6      FALSE
## F1.S0007  controllerType=0 controllerNumber=1 scan=7      FALSE
## F1.S0008  controllerType=0 controllerNumber=1 scan=8      FALSE
## F1.S0009  controllerType=0 controllerNumber=1 scan=9      FALSE
## F1.S0010 controllerType=0 controllerNumber=1 scan=10      FALSE
## F1.S0011 controllerType=0 controllerNumber=1 scan=11      FALSE
## F1.S0012 controllerType=0 controllerNumber=1 scan=12      FALSE
## F1.S0013 controllerType=0 controllerNumber=1 scan=13      FALSE
## F1.S0014 controllerType=0 controllerNumber=1 scan=14      FALSE
##          ionMobilityDriftTime isolationWindowTargetMZ
## F1.S0001                   NA                      NA
## F1.S0002                   NA                      NA
## F1.S0003                   NA                      NA
## F1.S0004                   NA                      NA
## F1.S0005                   NA                      NA
## F1.S0006                   NA                      NA
## F1.S0007                   NA                      NA
## F1.S0008                   NA                      NA
## F1.S0009                   NA                      NA
## F1.S0010                   NA                      NA
## F1.S0011                   NA                      NA
## F1.S0012                   NA                      NA
## F1.S0013                   NA                      NA
## F1.S0014                   NA                      NA
##          isolationWindowLowerOffset isolationWindowUpperOffset
## F1.S0001                         NA                         NA
## F1.S0002                         NA                         NA
## F1.S0003                         NA                         NA
## F1.S0004                         NA                         NA
## F1.S0005                         NA                         NA
## F1.S0006                         NA                         NA
## F1.S0007                         NA                         NA
## F1.S0008                         NA                         NA
## F1.S0009                         NA                         NA
## F1.S0010                         NA                         NA
## F1.S0011                         NA                         NA
## F1.S0012                         NA                         NA
## F1.S0013                         NA                         NA
## F1.S0014                         NA                         NA
##          scanWindowLowerLimit scanWindowUpperLimit spectrum
## F1.S0001                  400                 2000        1
## F1.S0002                  400                 2000        2
## F1.S0003                  400                 2000        3
## F1.S0004                  400                 2000        4
## F1.S0005                  400                 2000        5
## F1.S0006                  400                 2000        6
## F1.S0007                  400                 2000        7
## F1.S0008                  400                 2000        8
## F1.S0009                  400                 2000        9
## F1.S0010                  400                 2000       10
## F1.S0011                  400                 2000       11
## F1.S0012                  400                 2000       12
## F1.S0013                  400                 2000       13
## F1.S0014                  400                 2000       14
##  [ reached 'max' / getOption("max.print") -- omitted 7520 rows ]
fvarLabels(x_dsk)
##  [1] "fileIdx"                    "spIdx"                     
##  [3] "smoothed"                   "seqNum"                    
##  [5] "acquisitionNum"             "msLevel"                   
##  [7] "polarity"                   "originalPeaksCount"        
##  [9] "totIonCurrent"              "retentionTime"             
## [11] "basePeakMZ"                 "basePeakIntensity"         
## [13] "collisionEnergy"            "ionisationEnergy"          
## [15] "lowMZ"                      "highMZ"                    
## [17] "precursorScanNum"           "precursorMZ"               
## [19] "precursorCharge"            "precursorIntensity"        
## [21] "mergedScan"                 "mergedResultScanNum"       
## [23] "mergedResultStartScanNum"   "mergedResultEndScanNum"    
## [25] "injectionTime"              "filterString"              
## [27] "spectrumId"                 "centroided"                
## [29] "ionMobilityDriftTime"       "isolationWindowTargetMZ"   
## [31] "isolationWindowLowerOffset" "isolationWindowUpperOffset"
## [33] "scanWindowLowerLimit"       "scanWindowUpperLimit"      
## [35] "spectrum"
sp <- x_dsk[[1]]
sp
## Object of class "Spectrum1"
##  Retention time: 0:0 
##  MSn level: 1 
##  Total ion count: 25800 
##  Polarity: 1
head(mz(sp))
## [1] 399.9987 400.0002 400.0017 400.0032 400.2951 400.2966
head(intensity(sp))
## [1] 0 0 0 0 0 0
plot(sp)

The on-disk data contains all spectra

length(x_dsk)
## [1] 7534
length(x_mem)
## [1] 6103
table(msLevel(x_dsk))
## 
##    1    2 
## 1431 6103

On-disk data uses less RAM. See Figure 1b in the pre-print.

pryr::object_size(x_mem)
## Registered S3 method overwritten by 'pryr':
##   method      from
##   print.bytes Rcpp
## 33.2 MB
pryr::object_size(x_dsk)
## 3.46 MB
x_dsk2 <- filterMsLevel(x_dsk, 2L)

Access to raw data is faster when already in RAM. See Figure 1d in pre-print.

system.time(x_dsk[[1]])
##    user  system elapsed 
##   1.856   0.118   1.892
system.time(x_mem[[1]])
##    user  system elapsed 
##   0.000   0.000   0.001

Filtering: retention time between 1000 and 3000 seconds

chr1 <- chromatogram(x_dsk)
chr1
## Chromatograms with 1 row and 1 column
##      TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01-20141210.mzML.gz
##                                                              <Chromatogram>
## [1,]                                                           length: 1431
## phenoData with 1 variables
## featureData with 1 variables
plot(chr1)

Filtering: keep TMT6 MZ range

plot(x_dsk2[[1227]], reporters = TMT6, full = TRUE)

TMT6
## Object of class "ReporterIons"
## TMT6: '6-plex TMT tags' with 6 reporter ions
##  - [TMT6.126] 126.1277 +/- 0.05 (red)
##  - [TMT6.127] 127.1311 +/- 0.05 (purple)
##  - [TMT6.128] 128.1344 +/- 0.05 (blue)
##  - [TMT6.129] 129.1378 +/- 0.05 (steelblue)
##  - [TMT6.130] 130.1411 +/- 0.05 (green)
##  - [TMT6.131] 131.1382 +/- 0.05 (yellow)
range(mz(TMT6))
## [1] 126.1277 131.1382

Filtering: keep 50% spectra with highest precursor ion intensity

median(precursorIntensity(x_dsk2))
## [1] 11364716
filter_ms <- function(x) {
   x <- x %>% 
      filterRt(c(1000, 3000)) %>% 
      filterMz(c(120, 135))
   x[precursorIntensity(x) > 11000000, ]
}

Filtering on-disk is much faster thank to lazy evaluation. See Figure 1c in the pre-print.

x_filt <- filter_ms(x_dsk2)
filter_ms(x_mem)
## MSn experiment data ("MSnExp")
## Object size in memory: 13.5 Mb
## - - - Spectra data - - -
##  MS level(s): 2 
##  Number of spectra: 2927 
##  MSn retention times: 19:3 - 49:55 minutes
## - - - Processing information - - -
## Data loaded: Thu May  7 19:51:37 2020 
## Data [logically] subsetted 4668 spectra: Thu May  7 19:52:25 2020 
## Filter: select retention time [1000-3000] and MS level(s), 2 [Thu May  7 19:52:29 2020] 
## Filter: trim MZ [120..135] on MS level(s) 2. 
## Data [logically] subsetted 2927 spectra: Thu May  7 19:52:38 2020 
##  MSnbase version: 2.14.0 
## - - - Meta data  - - -
## phenoData
##   rowNames:
##     TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01-20141210.mzML.gz
##   varLabels: sampleNames
##   varMetadata: labelDescription
## Loaded from:
##   TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01-20141210.mzML.gz 
## protocolData: none
## featureData
##   featureNames: F1.S0256 F1.S0347 ... F1.S4746 (2927 total)
##   fvarLabels: spectrum
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
x_filt[[1227]]
## Object of class "Spectrum2"
##  Precursor: 567.337 
##  Retention time: 31:6 
##  Charge: 2 
##  MSn level: 2 
##  Peaks count: 15 
##  Total ion count: 34649479
writeMSData

3 Prototyping: MSnbaseBoxCar

library(MSnbaseBoxCar)

bcf <- 
   dir(system.file("extdata", package = "MSnbaseBoxCar"),
    pattern = "boxcar.mzML", 
    full.names = TRUE)

Read the data

bc <- readMSData(bcf, mode = "onDisk") 
bc
## MSn experiment data ("OnDiskMSnExp")
## Object size in memory: 0.04 Mb
## - - - Spectra data - - -
##  MS level(s): 1 
##  Number of spectra: 16 
##  MSn retention times: 0:0 - 0:5 minutes
## - - - Processing information - - -
## Data loaded [Thu May  7 19:52:43 2020] 
##  MSnbase version: 2.14.0 
## - - - Meta data  - - -
## phenoData
##   rowNames: boxcar.mzML
##   varLabels: sampleNames
##   varMetadata: labelDescription
## Loaded from:
##   boxcar.mzML 
## protocolData: none
## featureData
##   featureNames: F1.S01 F1.S02 ... F1.S16 (16 total)
##   fvarLabels: fileIdx spIdx ... spectrum (35 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'

First full spectrum and 3 first BoxCar spectra

p <- plot(bc[1:4])

Identify sets of BoxCar spectra

fData(bc)$filterString
##  [1] "FTMS + p NSI Full ms [375.0000-1800.0000]"                                                                                                                                                                                                            
##  [2] "FTMS + p NSI SIM msx ms [299.0000-1701.0000, 299.0000-351.0000, 449.0000-501.0000, 599.0000-651.0000, 749.0000-801.0000, 899.0000-951.0000, 1049.0000-1101.0000, 1199.0000-1251.0000, 1349.0000-1401.0000, 1499.0000-1551.0000, 1649.0000-1701.0000]" 
##  [3] "FTMS + p NSI SIM msx ms [349.0000-1751.0000, 349.0000-401.0000, 499.0000-551.0000, 649.0000-701.0000, 799.0000-851.0000, 949.0000-1001.0000, 1099.0000-1151.0000, 1249.0000-1301.0000, 1399.0000-1451.0000, 1549.0000-1601.0000, 1699.0000-1751.0000]"
##  [4] "FTMS + p NSI SIM msx ms [399.0000-1801.0000, 399.0000-451.0000, 549.0000-601.0000, 699.0000-751.0000, 849.0000-901.0000, 999.0000-1051.0000, 1149.0000-1201.0000, 1299.0000-1351.0000, 1449.0000-1501.0000, 1599.0000-1651.0000, 1749.0000-1801.0000]"
##  [5] "FTMS + p NSI Full ms [375.0000-1800.0000]"                                                                                                                                                                                                            
##  [6] "FTMS + p NSI SIM msx ms [299.0000-1701.0000, 299.0000-351.0000, 449.0000-501.0000, 599.0000-651.0000, 749.0000-801.0000, 899.0000-951.0000, 1049.0000-1101.0000, 1199.0000-1251.0000, 1349.0000-1401.0000, 1499.0000-1551.0000, 1649.0000-1701.0000]" 
##  [7] "FTMS + p NSI SIM msx ms [349.0000-1751.0000, 349.0000-401.0000, 499.0000-551.0000, 649.0000-701.0000, 799.0000-851.0000, 949.0000-1001.0000, 1099.0000-1151.0000, 1249.0000-1301.0000, 1399.0000-1451.0000, 1549.0000-1601.0000, 1699.0000-1751.0000]"
##  [8] "FTMS + p NSI SIM msx ms [399.0000-1801.0000, 399.0000-451.0000, 549.0000-601.0000, 699.0000-751.0000, 849.0000-901.0000, 999.0000-1051.0000, 1149.0000-1201.0000, 1299.0000-1351.0000, 1449.0000-1501.0000, 1599.0000-1651.0000, 1749.0000-1801.0000]"
##  [9] "FTMS + p NSI Full ms [375.0000-1800.0000]"                                                                                                                                                                                                            
## [10] "FTMS + p NSI SIM msx ms [299.0000-1701.0000, 299.0000-351.0000, 449.0000-501.0000, 599.0000-651.0000, 749.0000-801.0000, 899.0000-951.0000, 1049.0000-1101.0000, 1199.0000-1251.0000, 1349.0000-1401.0000, 1499.0000-1551.0000, 1649.0000-1701.0000]" 
## [11] "FTMS + p NSI SIM msx ms [349.0000-1751.0000, 349.0000-401.0000, 499.0000-551.0000, 649.0000-701.0000, 799.0000-851.0000, 949.0000-1001.0000, 1099.0000-1151.0000, 1249.0000-1301.0000, 1399.0000-1451.0000, 1549.0000-1601.0000, 1699.0000-1751.0000]"
## [12] "FTMS + p NSI SIM msx ms [399.0000-1801.0000, 399.0000-451.0000, 549.0000-601.0000, 699.0000-751.0000, 849.0000-901.0000, 999.0000-1051.0000, 1149.0000-1201.0000, 1299.0000-1351.0000, 1449.0000-1501.0000, 1599.0000-1651.0000, 1749.0000-1801.0000]"
## [13] "FTMS + p NSI Full ms [375.0000-1800.0000]"                                                                                                                                                                                                            
## [14] "FTMS + p NSI SIM msx ms [299.0000-1701.0000, 299.0000-351.0000, 449.0000-501.0000, 599.0000-651.0000, 749.0000-801.0000, 899.0000-951.0000, 1049.0000-1101.0000, 1199.0000-1251.0000, 1349.0000-1401.0000, 1499.0000-1551.0000, 1649.0000-1701.0000]" 
## [15] "FTMS + p NSI SIM msx ms [349.0000-1751.0000, 349.0000-401.0000, 499.0000-551.0000, 649.0000-701.0000, 799.0000-851.0000, 949.0000-1001.0000, 1099.0000-1151.0000, 1249.0000-1301.0000, 1399.0000-1451.0000, 1549.0000-1601.0000, 1699.0000-1751.0000]"
## [16] "FTMS + p NSI SIM msx ms [399.0000-1801.0000, 399.0000-451.0000, 549.0000-601.0000, 699.0000-751.0000, 849.0000-901.0000, 999.0000-1051.0000, 1149.0000-1201.0000, 1299.0000-1351.0000, 1449.0000-1501.0000, 1599.0000-1651.0000, 1749.0000-1801.0000]"
tmp1 <- bc_groups(bc)
fData(tmp1)$bc_groups
##  [1] NA  1  1  1 NA  2  2  2 NA  3  3  3 NA  4  4  4

Remove non-BoxCar spectra

tmp2 <- filterBoxCar(tmp1)
fData(tmp2)$bc_groups
##  [1] 1 1 1 2 2 2 3 3 3 4 4 4
tmp2
## MSn experiment data ("OnDiskMSnExp")
## Object size in memory: 0.04 Mb
## - - - Spectra data - - -
##  MS level(s): 1 
##  Number of spectra: 12 
##  MSn retention times: 0:0 - 0:5 minutes
## - - - Processing information - - -
## Data loaded [Thu May  7 19:52:43 2020] 
##  MSnbase version: 2.14.0 
## - - - Meta data  - - -
## phenoData
##   rowNames: boxcar.mzML
##   varLabels: sampleNames
##   varMetadata: labelDescription
## Loaded from:
##   boxcar.mzML 
## protocolData: none
## featureData
##   featureNames: F1.S02 F1.S03 ... F1.S16 (12 total)
##   fvarLabels: fileIdx spIdx ... bc_groups (36 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
bc_plotly(tmp2[1:3])
## Loading required namespace: plotly

Remove peaks outside of BoxCar segments

tmp3 <- bc_zero_out_box(tmp2)
bc_plotly(tmp3[1:3])

Combine BoxCar spectra and segments into a new full scan

res <- combineSpectra(tmp3, 
               fcol = "bc_groups",
               method = boxcarCombine)
res
## MSn experiment data ("MSnExp")
## Object size in memory: 0.34 Mb
## - - - Spectra data - - -
##  MS level(s): 1 
##  Number of spectra: 4 
##  MSn retention times: 0:0 - 0:4 minutes
## - - - Processing information - - -
## Data converted from Spectra: Thu May  7 19:52:45 2020 
## BoxCar processed [Thu May  7 19:52:45 2020] 
## Spectra combined based on feature variable 'bc_groups' [Thu May  7 19:52:45 2020] 
##  MSnbase version: 2.14.0 
## - - - Meta data  - - -
## phenoData
##   rowNames: 1
##   varLabels: sampleNames
##   varMetadata: labelDescription
## Loaded from:
##   1 
## protocolData: none
## featureData
##   featureNames: F1.S02 F1.S06 F1.S10 F1.S14
##   fvarLabels: fileIdx spIdx ... bc_groups (36 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
writeMSData(res, file = "boxcar2.mzML")

Putting it all together with %>%

bc2 <- bc %>% 
   bc_groups() %>% 
   filterBoxCar() %>% 
   bc_zero_out_box() %>% 
   combineSpectra(fcol = "bc_groups",
                  method = boxcarCombine)