In this vignette, we will document various timings and benchmarkings of the recent MSnbase development, that focuses on on-disk data access (as opposed to in-memory). More details about the new implementation are documented in the respective classes manual pages.
As a benchmarking dataset, we are going to use a subset of an TMT 6-plex experiment acquired on an LTQ Orbitrap Velos, that is distributed with the msdata package
##  "TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.gz"
We need to load the MSnbase package and set the session-wide verbosity flag to
We first read the data using the original behaviour
readMSData function by setting the
mode argument to
"inMemory" to generates an in-memory representation of the MS2-level raw data and measure the time needed for this operation.
## user system elapsed ## 4.820 0.032 4.853
Next, we use the
readMSData function to generate an on-disk representation of the same data by setting
mode = "onDisk".
## user system elapsed ## 1.332 0.028 1.362
Creating the on-disk experiment is considerable faster and scales to much bigger, multi-file data, both in terms of object creation time, but also in terms of object size (see next section). We must of course make sure that these two datasets are equivalent:
##  TRUE
To compare the size occupied in memory of these two objects, we are going to use the
object_size function from the pryr package, which accounts for the data (the spectra) in the
assayData environment (as opposed to the
object.size function from the
## Registered S3 method overwritten by 'pryr': ## method from ## print.bytes Rcpp
## 2.77 MB
## 239 kB
The difference is explained by the fact that for
ondisk, the spectra are not created and stored in memory; they are access on disk when needed, such as for example for plotting:
The drawback of the on-disk representation is when the spectrum data has to actually be accessed. To compare access time, we are going to use the microbenchmark and repeat access 10 times to compare access to all 451 and a single spectrum in-memory (i.e. pre-loaded and constructed) and on-disk (i.e. on-the-fly access).
## Unit: microseconds ## expr min lq mean median uq ## spectra(inmem) 86.336 211.999 251.0411 236.1315 357.165 ## inmem[] 20.446 24.967 63.4019 76.8015 81.106 ## spectra(ondisk) 403012.538 406817.785 409852.3719 407493.3030 411760.528 ## ondisk[] 188997.645 189669.344 191115.9679 190564.1230 192475.499 ## max neval ## 363.137 10 ## 106.057 10 ## 428301.927 10 ## 194854.288 10
While it takes order or magnitudes more time to access the data on-the-fly rather than a pre-generated spectrum, accessing all spectra is only marginally slower than accessing all spectra, as most of the time is spent preparing the file for access, which is done only once.
On-disk access performance will depend on the read throughput of the disk. A comparison of the data import of the above file from an internal solid state drive and from an USB3 connected hard disk showed only small differences for the
onDisk mode (1.07 vs 1.36 seconds), while no difference were observed for accessing individual or all spectra. Thus, for this particular setup, performance was about the same for SSD and HDD. This might however not apply to setting in which data import is performed in parallel from multiple files.
Data access does not prohibit interactive usage, such as plotting, for example, as it is about 1/2 seconds, which is an operation that is relatively rare, compared to subsetting and filtering, which are faster for on-disk data:
## user system elapsed ## 0.100 0.000 0.101
## user system elapsed ## 0.012 0.000 0.012
Operations on the spectra data, such as peak picking, smoothing, cleaning, … are cleverly cached and only applied when the data is accessed, to minimise file access overhead. Finally, specific operations such as for example quantitation (see next section) are optimised for speed.
Below, we perform TMT 6-plex reporter ions quantitation on the first 100 spectra and verify that the results are identical (ignoring feature names).
## user system elapsed ## 2.872 0.072 2.950
## user system elapsed ## 0.292 0.020 0.310
##  TRUE
OnDiskMSnExp documentation files and the MSnbase developement vignette provide more information about implementation details.
On-disk support multiple MS levels in one object, while in-memory only supports a single level. While support for multiple MS levels could be added to the in-memory back-end, memory constrains make this pretty-much useless and will most likely never happen.
In-memory objects can be
load()ed, while on-disk can’t. As a workaround, the latter can be coerced to in-memory instances with
as(, "MSnExp"). We would need
mzML write support in mzR to be able to implement serialisation for on-disk data.
Whenever possible, accessing and processing on-disk data is delayed (lazy processing). These operations are stored in a processing queue until the spectra are effectively instantiated.
This document focuses on speed and size improvements of the new on-disk
MSnExp representation. The extend of these improvements will substantially increase for larger data.
For general functionality about the on-disk
MSnExp data class and MSnbase in general, see other vignettes available with