From dbc456c54bcd7d63c4675d9f35142d0d298a65db Mon Sep 17 00:00:00 2001
From: GitHub Actions
sessionInfo()
## R Under development (unstable) (2024-12-10 r87437)
+## R Under development (unstable) (2024-12-15 r87442)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
@@ -2445,13 +2445,13 @@ Session information## [8] base
##
## other attached packages:
-## [1] MsCoreUtils_1.19.0 IRanges_2.41.2 Spectra_1.17.3
+## [1] MsCoreUtils_1.19.0 IRanges_2.41.2 Spectra_1.17.4
## [4] BiocParallel_1.41.0 S4Vectors_0.45.2 BiocGenerics_0.53.3
## [7] generics_0.1.3 BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] cli_3.6.3 knitr_1.49 rlang_1.1.4
-## [4] xfun_0.49 ProtGenerics_1.39.0 textshaping_0.4.1
+## [4] xfun_0.49 ProtGenerics_1.39.1 textshaping_0.4.1
## [7] clue_0.3-66 jsonlite_1.8.9 htmltools_0.5.8.1
## [10] ragg_1.3.3 sass_0.4.9 rmarkdown_2.29
## [13] evaluate_1.0.1 jquerylib_0.1.4 MASS_7.3-61
diff --git a/articles/Spectra-large-scale.html b/articles/Spectra-large-scale.html
index 68fe2b15..925efef5 100644
--- a/articles/Spectra-large-scale.html
+++ b/articles/Spectra-large-scale.html
@@ -25,7 +25,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -88,7 +88,7 @@
[aut] (ORCID: https://orcid.org/0000-0001-7406-4443), Philippine
Louail [aut] (ORCID: https://orcid.org/0009-0007-5429-6846), Jan Stanstrup
[ctb] (ORCID: https://orcid.org/0000-0003-0541-7369), Nir Shahaf
-[ctb], Mar Garcia-Aloy [ctb] (ORCID: https://orcid.org/0000-0002-1330-6610)
Last modified: 2024-12-16 09:14:28.747512
Compiled: Mon Dec 16 09:28:12 2024
+[ctb], Mar Garcia-Aloy [ctb] (ORCID: https://orcid.org/0000-0002-1330-6610)
Last modified: 2024-12-18 13:13:37.191968
Compiled: Wed Dec 18 13:28:28 2024
Introduction
@@ -358,7 +358,7 @@ Session information
sessionInfo()
-## R Under development (unstable) (2024-12-10 r87437)
+## R Under development (unstable) (2024-12-15 r87442)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
@@ -382,7 +382,7 @@ Session information## [8] base
##
## other attached packages:
-## [1] Spectra_1.17.3 BiocParallel_1.41.0 S4Vectors_0.45.2
+## [1] Spectra_1.17.4 BiocParallel_1.41.0 S4Vectors_0.45.2
## [4] BiocGenerics_0.53.3 generics_0.1.3 BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
@@ -390,7 +390,7 @@ Session information## [4] Rcpp_1.0.13-1 Biobase_2.67.0 parallel_4.5.0
## [7] cluster_2.1.8 jquerylib_0.1.4 systemfonts_1.1.0
## [10] IRanges_2.41.2 textshaping_0.4.1 yaml_2.3.10
-## [13] fastmap_1.2.0 R6_2.5.1 ProtGenerics_1.39.0
+## [13] fastmap_1.2.0 R6_2.5.1 ProtGenerics_1.39.1
## [16] knitr_1.49 htmlwidgets_1.6.4 MASS_7.3-61
## [19] bookdown_0.41 desc_1.4.3 bslib_0.8.0
## [22] rlang_1.1.4 cachem_1.1.0 xfun_0.49
diff --git a/articles/Spectra.html b/articles/Spectra.html
index e8bd6456..5f52c54f 100644
--- a/articles/Spectra.html
+++ b/articles/Spectra.html
@@ -25,7 +25,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -88,7 +88,7 @@
[aut] (ORCID: https://orcid.org/0000-0001-7406-4443), Philippine
Louail [aut] (ORCID: https://orcid.org/0009-0007-5429-6846), Jan Stanstrup
[ctb] (ORCID: https://orcid.org/0000-0003-0541-7369), Nir Shahaf
-[ctb], Mar Garcia-Aloy [ctb] (ORCID: https://orcid.org/0000-0002-1330-6610)
Last modified: 2024-12-16 09:14:28.747512
Compiled: Mon Dec 16 09:28:22 2024
+[ctb], Mar Garcia-Aloy [ctb] (ORCID: https://orcid.org/0000-0002-1330-6610)
Last modified: 2024-12-18 13:13:37.191968
Compiled: Wed Dec 18 13:28:39 2024
Introduction
@@ -796,8 +796,8 @@ Examples and use cases for
## file(s):
## 20171016_POOL_POS_3_105-134.mzML
## Processing:
-## Filter: select data origin(s) /__w/_temp/Library/msdata/sciex/20171016_POOL_POS_3_105-134.mzML [Mon Dec 16 09:28:27 2024]
-## Filter: select retention time [175..189] on MS level(s) 1 [Mon Dec 16 09:28:27 2024]
+## Filter: select data origin(s) /__w/_temp/Library/msdata/sciex/20171016_POOL_POS_3_105-134.mzML [Wed Dec 18 13:28:44 2024]
+## Filter: select retention time [175..189] on MS level(s) 1 [Wed Dec 18 13:28:44 2024]
Note that the use of the filter functions might be more efficient for
some backends, depending on their implementation, (e.g. database-based
backends could translate the filter function into a SQL
@@ -832,7 +832,7 @@
Examples and use cases for
## 4 2 NA NA
## ... 20 more variables/columns.
## Processing:
-## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024]
+## Merge 2 Spectra into one [Wed Dec 18 13:28:44 2024]
The resulting object contains now the data for all 4 MS2 spectra and
an union of all spectra variables from both objects.
@@ -925,9 +925,9 @@ Data manipulations## ... 20 more variables/columns.
## Lazy evaluation queue: 2 processing step(s)
## Processing:
-## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024]
-## Signal <= 10 in MS level(s) 2 set to 0 [Mon Dec 16 09:28:27 2024]
-## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Mon Dec 16 09:28:27 2024]
+## Merge 2 Spectra into one [Wed Dec 18 13:28:44 2024]
+## Signal <= 10 in MS level(s) 2 set to 0 [Wed Dec 18 13:28:44 2024]
+## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Wed Dec 18 13:28:45 2024]
It is possible to add also custom functions to the processing queue
of a Spectra
object. Such a function must take a peaks
matrix as its first argument, have ...
in the function
@@ -958,9 +958,9 @@
Data manipulations## ... 20 more variables/columns.
## Lazy evaluation queue: 3 processing step(s)
## Processing:
-## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024]
-## Signal <= 10 in MS level(s) 2 set to 0 [Mon Dec 16 09:28:27 2024]
-## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Mon Dec 16 09:28:27 2024]
+## Merge 2 Spectra into one [Wed Dec 18 13:28:44 2024]
+## Signal <= 10 in MS level(s) 2 set to 0 [Wed Dec 18 13:28:44 2024]
+## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Wed Dec 18 13:28:45 2024]
Object sps_2
has now 3 processing steps in its lazy
evaluation queue. Calling intensity()
on this object will
now return intensities that are half of the intensities of the original
@@ -1227,9 +1227,9 @@
Data manipulations## 4 2 NA NA
## ... 20 more variables/columns.
## Processing:
-## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024]
-## Signal <= 10 in MS level(s) 2 set to 0 [Mon Dec 16 09:28:27 2024]
-## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Mon Dec 16 09:28:27 2024]
+## Merge 2 Spectra into one [Wed Dec 18 13:28:44 2024]
+## Signal <= 10 in MS level(s) 2 set to 0 [Wed Dec 18 13:28:44 2024]
+## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Wed Dec 18 13:28:45 2024]
## ...1 more processings. Use 'processingLog' to list all.
Before applyProcessing()
the lazy evaluation queue
contained 2 processing steps, which were then applied to the peak data
@@ -1561,7 +1561,7 @@
Exporting spectra
fl <- tempfile()
export(sps, MsBackendMzR(), file = fl)
-## Writing file file1fd57b32f0f7...OK
+## Writing file file1c211ae340bf...OK
To evaluate which of the spectra variables were exported, we load the
exported data again and identify spectra variables in the original file
which could not be exported (because they are not defined variables in
@@ -1582,8 +1582,8 @@
Exporting spectra
fls <- c(tempfile(), tempfile())
export(sps, MsBackendMzR(), file = fls[c(1, 2, 1, 2)])
-## Writing file file1fd5713b4525...OK
-## Writing file file1fd51d89ecd...OK
+## Writing file file1c21195d1f8f...OK
+## Writing file file1c2138e6462b...OK
A more realistic use case for mzML export would be to export MS data
after processing, such as smoothing (using the smooth()
function) and centroiding (using the pickPeaks()
function)
@@ -1624,7 +1624,7 @@
Changing backends## 1862 1 259.752 931
## ... 33 more variables/columns.
## Processing:
-## Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:28:33 2024]
+## Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:28:50 2024]
With the call the full peak data was imported from the original mzML
files into the object. This has obviously an impact on the object’s
size, which is now much larger than before.
@@ -1832,7 +1832,7 @@ Session information
sessionInfo()
-## R Under development (unstable) (2024-12-10 r87437)
+## R Under development (unstable) (2024-12-15 r87442)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
@@ -1857,7 +1857,7 @@ Session information##
## other attached packages:
## [1] msdata_0.47.0 msentropy_0.1.4 Rcpp_1.0.13-1
-## [4] MsCoreUtils_1.19.0 Spectra_1.17.3 BiocParallel_1.41.0
+## [4] MsCoreUtils_1.19.0 Spectra_1.17.4 BiocParallel_1.41.0
## [7] S4Vectors_0.45.2 BiocGenerics_0.53.3 generics_0.1.3
## [10] BiocStyle_2.35.0
##
@@ -1866,7 +1866,7 @@ Session information## [4] Biobase_2.67.0 rhdf5filters_1.19.0 parallel_4.5.0
## [7] cluster_2.1.8 jquerylib_0.1.4 systemfonts_1.1.0
## [10] IRanges_2.41.2 textshaping_0.4.1 yaml_2.3.10
-## [13] fastmap_1.2.0 R6_2.5.1 ProtGenerics_1.39.0
+## [13] fastmap_1.2.0 R6_2.5.1 ProtGenerics_1.39.1
## [16] knitr_1.49 htmlwidgets_1.6.4 MASS_7.3-61
## [19] bookdown_0.41 desc_1.4.3 bslib_0.8.0
## [22] rlang_1.1.4 cachem_1.1.0 xfun_0.49
diff --git a/articles/index.html b/articles/index.html
index fd99973b..ca44500b 100644
--- a/articles/index.html
+++ b/articles/index.html
@@ -7,7 +7,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/authors.html b/authors.html
index 33926f87..494a7855 100644
--- a/authors.html
+++ b/authors.html
@@ -7,7 +7,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/index.html b/index.html
index 25ef469a..bb4b7e29 100644
--- a/index.html
+++ b/index.html
@@ -28,7 +28,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/news/index.html b/news/index.html
index 9b99b012..49b8f310 100644
--- a/news/index.html
+++ b/news/index.html
@@ -7,7 +7,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -40,11 +40,15 @@
Spectra 1.17
+
+Change in 1.17.3
- Fix
cbind2()
unit test for backends that fails if the number of spectra in the tested backend is (by chance) equal to 4.
diff --git a/pkgdown.yml b/pkgdown.yml
index 6c1aee30..09335f84 100644
--- a/pkgdown.yml
+++ b/pkgdown.yml
@@ -5,7 +5,7 @@ articles:
MsBackend: MsBackend.html
Spectra-large-scale: Spectra-large-scale.html
Spectra: Spectra.html
-last_built: 2024-12-16T09:26Z
+last_built: 2024-12-18T13:26Z
urls:
reference: https://rformassspectrometry.github.io/Spectra/reference
article: https://rformassspectrometry.github.io/Spectra/articles
diff --git a/reference/MsBackend.html b/reference/MsBackend.html
index 099ca03e..660169d1 100644
--- a/reference/MsBackend.html
+++ b/reference/MsBackend.html
@@ -63,7 +63,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/MsBackendCached.html b/reference/MsBackendCached.html
index 3add8ed9..0f049fe3 100644
--- a/reference/MsBackendCached.html
+++ b/reference/MsBackendCached.html
@@ -45,7 +45,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/Spectra.html b/reference/Spectra.html
index c8896415..d6071192 100644
--- a/reference/Spectra.html
+++ b/reference/Spectra.html
@@ -47,7 +47,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -438,7 +438,7 @@ Examples#> 1862 1 259.752 931
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:30 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:31 2024]
## The `MsBackendMemory()` supports the `setBackend()` method:
supportsSetBackend(MsBackendMemory())
diff --git a/reference/addProcessing.html b/reference/addProcessing.html
index 9e7fd6be..086fd7ed 100644
--- a/reference/addProcessing.html
+++ b/reference/addProcessing.html
@@ -25,7 +25,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -571,7 +571,7 @@ Examples#> PestMix1_DDA.mzML
#> Lazy evaluation queue: 1 processing step(s)
#> Processing:
-#> Signal <= 20 in MS level(s) 1, 2 set to 0 [Mon Dec 16 09:26:31 2024]
+#> Signal <= 20 in MS level(s) 1, 2 set to 0 [Wed Dec 18 13:26:33 2024]
## Get the intensities of the first spectrum before and after the
## operation
@@ -709,8 +709,8 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Scale peak intensities in spectra of MS level(s) 2. [Mon Dec 16 09:26:34 2024]
-#> Reset object. [Mon Dec 16 09:26:35 2024]
+#> Scale peak intensities in spectra of MS level(s) 2. [Wed Dec 18 13:26:36 2024]
+#> Reset object. [Wed Dec 18 13:26:37 2024]
lengths(sps_dda) |> head()
#> [1] 223 211 227 210 220 228
lengths(sps_mod) |> head()
@@ -744,9 +744,9 @@ Examples#> 7602 1 899.993 7602
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:37 2024]
-#> Remove peaks with intensities outside [5, Inf] in spectra of MS level(s) 1, 2. [Mon Dec 16 09:26:37 2024]
-#> Applied processing queue with 1 steps [Mon Dec 16 09:26:38 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:39 2024]
+#> Remove peaks with intensities outside [5, Inf] in spectra of MS level(s) 1, 2. [Wed Dec 18 13:26:39 2024]
+#> Applied processing queue with 1 steps [Wed Dec 18 13:26:40 2024]
## While we can't *undo* this filtering operation now using the `reset()`
## function, accessing the data would now be faster, because the operation
diff --git a/reference/chunkapply.html b/reference/chunkapply.html
index 531459dd..9b514b50 100644
--- a/reference/chunkapply.html
+++ b/reference/chunkapply.html
@@ -15,7 +15,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -114,7 +114,7 @@ Examples#> 0.003 0.000 0.003
system.time(chunkapply(x, sqrt, chunkSize = 200))
#> user system elapsed
-#> 0.002 0.000 0.002
+#> 0.002 0.000 0.001
## Simple example splitting a numeric vector into chunks of 200 and
## aggregating the values within the chunk using the `mean`. Due to the
diff --git a/reference/combinePeaks.html b/reference/combinePeaks.html
index eb9223fa..f0c2a9ad 100644
--- a/reference/combinePeaks.html
+++ b/reference/combinePeaks.html
@@ -43,7 +43,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/combinePeaksData.html b/reference/combinePeaksData.html
index ce3b87c3..3d179d7c 100644
--- a/reference/combinePeaksData.html
+++ b/reference/combinePeaksData.html
@@ -63,7 +63,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/combineSpectra.html b/reference/combineSpectra.html
index e4a14380..c8180202 100644
--- a/reference/combineSpectra.html
+++ b/reference/combineSpectra.html
@@ -141,7 +141,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -418,8 +418,8 @@ Examples#> 102 1 27.902 100
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
-#> Merge 2 Spectra into one [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
+#> Merge 2 Spectra into one [Wed Dec 18 13:26:49 2024]
## The new `Spectra` objects contains the union of spectra variables from
## both:
@@ -515,7 +515,7 @@ Examples#> 1 1 0.28 1
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
#>
#> $`1`
#> MSn data (Spectra) with 4 spectra in a MsBackendMemory backend:
@@ -527,7 +527,7 @@ Examples#> 4 1 1.396 5
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
#>
#> $`2`
#> MSn data (Spectra) with 3 spectra in a MsBackendMemory backend:
@@ -538,7 +538,7 @@ Examples#> 3 1 2.233 8
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
#>
#> $`3`
#> MSn data (Spectra) with 4 spectra in a MsBackendMemory backend:
@@ -550,7 +550,7 @@ Examples#> 4 1 3.349 12
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
#>
#> $`4`
#> MSn data (Spectra) with 4 spectra in a MsBackendMemory backend:
@@ -562,7 +562,7 @@ Examples#> 4 1 4.465 16
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
#>
#> $`5`
#> MSn data (Spectra) with 3 spectra in a MsBackendMemory backend:
@@ -573,7 +573,7 @@ Examples#> 3 1 5.302 19
#> ... 33 more variables/columns.
#> Processing:
-#> Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:26:46 2024]
+#> Switch backend from MsBackendMzR to MsBackendMemory [Wed Dec 18 13:26:49 2024]
#>
diff --git a/reference/compareSpectra.html b/reference/compareSpectra.html
index 836bc4da..c1137369 100644
--- a/reference/compareSpectra.html
+++ b/reference/compareSpectra.html
@@ -73,7 +73,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/countIdentifications.html b/reference/countIdentifications.html
index 87a4e232..b7cf565a 100644
--- a/reference/countIdentifications.html
+++ b/reference/countIdentifications.html
@@ -21,7 +21,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/estimatePrecursorIntensity.html b/reference/estimatePrecursorIntensity.html
index cb896d82..73815915 100644
--- a/reference/estimatePrecursorIntensity.html
+++ b/reference/estimatePrecursorIntensity.html
@@ -23,7 +23,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/estimatePrecursorMz.html b/reference/estimatePrecursorMz.html
index cb0c2475..a2b953e0 100644
--- a/reference/estimatePrecursorMz.html
+++ b/reference/estimatePrecursorMz.html
@@ -39,7 +39,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/filterFourierTransformArtefacts.html b/reference/filterFourierTransformArtefacts.html
index 073698a4..bc28a00f 100644
--- a/reference/filterFourierTransformArtefacts.html
+++ b/reference/filterFourierTransformArtefacts.html
@@ -29,7 +29,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -116,7 +116,7 @@ Examples#> Lazy evaluation queue: 1 processing step(s)
#> Processing:
#> Switch backend from MsBackendMzR to MsBackendDataFrame [Mon Nov 22 14:14:45 2021]
-#> Remove fast fourier artefacts. [Mon Dec 16 09:27:37 2024]
+#> Remove fast fourier artefacts. [Wed Dec 18 13:27:49 2024]
plotSpectra(fft_spectrum, xlim = c(264.5, 265.5), ylim = c(0, 5e6))
diff --git a/reference/filterMsLevel.html b/reference/filterMsLevel.html
index 608d5ddc..156b9d8b 100644
--- a/reference/filterMsLevel.html
+++ b/reference/filterMsLevel.html
@@ -29,7 +29,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -711,7 +711,7 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Filter: select MS level(s) 2 [Mon Dec 16 09:27:38 2024]
+#> Filter: select MS level(s) 2 [Wed Dec 18 13:27:50 2024]
## Filter the object keeping only MS2 spectra with an precursor m/z value
## between a specified range:
@@ -735,7 +735,7 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Filter: select spectra with a precursor m/z within [80, 90] [Mon Dec 16 09:27:38 2024]
+#> Filter: select spectra with a precursor m/z within [80, 90] [Wed Dec 18 13:27:50 2024]
## Filter the object to MS2 spectra with an precursor m/z matching a
## pre-defined value (given ppm and tolerance)
@@ -759,7 +759,7 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Filter: select spectra with precursor m/z matching 85 [Mon Dec 16 09:27:38 2024]
+#> Filter: select spectra with precursor m/z matching 85 [Wed Dec 18 13:27:50 2024]
## The `filterRanges()` function allows to filter a `Spectra` based on
## numerical ranges of any of its (numerical) spectra variables.
@@ -788,9 +788,9 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Filter: select spectra with a rtime within: [30, 350] [Mon Dec 16 09:27:38 2024]
-#> Filter: select spectra with a precursorMz within: [200, 500] [Mon Dec 16 09:27:38 2024]
-#> Filter: select spectra with a peaksCount within: [350, 600] [Mon Dec 16 09:27:38 2024]
+#> Filter: select spectra with a rtime within: [30, 350] [Wed Dec 18 13:27:50 2024]
+#> Filter: select spectra with a precursorMz within: [200, 500] [Wed Dec 18 13:27:50 2024]
+#> Filter: select spectra with a peaksCount within: [350, 600] [Wed Dec 18 13:27:50 2024]
## `filterRanges()` can also be used to filter a `Spectra` object with
## multiple ranges for the same `spectraVariable` (e.g, here `"rtime"`)
@@ -818,8 +818,8 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Filter: select spectra with a rtime within: [30, 100] [Mon Dec 16 09:27:38 2024]
-#> Filter: select spectra with a rtime within: [200, 300] [Mon Dec 16 09:27:38 2024]
+#> Filter: select spectra with a rtime within: [30, 100] [Wed Dec 18 13:27:51 2024]
+#> Filter: select spectra with a rtime within: [200, 300] [Wed Dec 18 13:27:51 2024]
## While `filterRanges()` filtered on numeric ranges, `filterValues()`
## allows to filter an object matching spectra variable values to user
@@ -851,8 +851,8 @@ Examples#> file(s):
#> PestMix1_DDA.mzML
#> Processing:
-#> Filter: select spectra with a rtime similar to: 350 [Mon Dec 16 09:27:38 2024]
-#> Filter: select spectra with a precursorMz similar to: 80 [Mon Dec 16 09:27:38 2024]
+#> Filter: select spectra with a rtime similar to: 350 [Wed Dec 18 13:27:51 2024]
+#> Filter: select spectra with a precursorMz similar to: 80 [Wed Dec 18 13:27:51 2024]
## -------- FILTER SPECTRA DATA --------
@@ -934,7 +934,7 @@ Examples#> Lazy evaluation queue: 1 processing step(s)
#> Processing:
#> Switch backend from MsBackendMzR to MsBackendDataFrame [Mon Nov 22 14:14:45 2021]
-#> Remove fast fourier artefacts. [Mon Dec 16 09:27:41 2024]
+#> Remove fast fourier artefacts. [Wed Dec 18 13:27:54 2024]
plotSpectra(fft_spectrum, xlim = c(264.5, 265.5), ylim = c(0, 5e6))
@@ -956,8 +956,8 @@ Examples#> Lazy evaluation queue: 2 processing step(s)
#> Processing:
#> Switch backend from MsBackendMzR to MsBackendDataFrame [Mon Nov 22 14:14:45 2021]
-#> Remove fast fourier artefacts. [Mon Dec 16 09:27:41 2024]
-#> Remove fast fourier artefacts. [Mon Dec 16 09:27:41 2024]
+#> Remove fast fourier artefacts. [Wed Dec 18 13:27:54 2024]
+#> Remove fast fourier artefacts. [Wed Dec 18 13:27:54 2024]
length(mz(fft_spectrum_filtered)[[1]])
#> [1] 297
plotSpectra(fft_spectrum_filtered, xlim = c(264.5, 265.5), ylim = c(0, 5e6))
diff --git a/reference/filterPeaksRanges.html b/reference/filterPeaksRanges.html
index 95f77367..f8ee5504 100644
--- a/reference/filterPeaksRanges.html
+++ b/reference/filterPeaksRanges.html
@@ -77,7 +77,7 @@
Spectra
- 1.17.3
+ 1.17.4
@@ -220,7 +220,7 @@ Examples#> ... 16 more variables/columns.
#> Lazy evaluation queue: 1 processing step(s)
#> Processing:
-#> Filter: remove peaks based on user-provided ranges for 1 variables [Mon Dec 16 09:27:43 2024]
+#> Filter: remove peaks based on user-provided ranges for 1 variables [Wed Dec 18 13:27:56 2024]
## The Spectra object has still the same length and spectra variables
length(res)
@@ -256,7 +256,7 @@ Examples#> ... 16 more variables/columns.
#> Lazy evaluation queue: 1 processing step(s)
#> Processing:
-#> Filter: select peaks based on user-provided ranges for 2 variables [Mon Dec 16 09:27:43 2024]
+#> Filter: select peaks based on user-provided ranges for 2 variables [Wed Dec 18 13:27:56 2024]
length(res)
#> [1] 2
diff --git a/reference/hidden_aliases.html b/reference/hidden_aliases.html
index feecdd97..addc223f 100644
--- a/reference/hidden_aliases.html
+++ b/reference/hidden_aliases.html
@@ -7,7 +7,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/index.html b/reference/index.html
index a31e6d92..6570f80e 100644
--- a/reference/index.html
+++ b/reference/index.html
@@ -7,7 +7,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/joinPeaks.html b/reference/joinPeaks.html
index 86dffd5c..5f318a2f 100644
--- a/reference/joinPeaks.html
+++ b/reference/joinPeaks.html
@@ -69,7 +69,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/neutralLoss.html b/reference/neutralLoss.html
index 1fe7707e..bc61bb3f 100644
--- a/reference/neutralLoss.html
+++ b/reference/neutralLoss.html
@@ -55,7 +55,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/plotMzDelta.html b/reference/plotMzDelta.html
index 4042ff80..13e4f632 100644
--- a/reference/plotMzDelta.html
+++ b/reference/plotMzDelta.html
@@ -51,7 +51,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/processingChunkSize.html b/reference/processingChunkSize.html
index e57d6a1c..a2942b21 100644
--- a/reference/processingChunkSize.html
+++ b/reference/processingChunkSize.html
@@ -89,7 +89,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/spectra-plotting.html b/reference/spectra-plotting.html
index 1d44a7d0..55af896c 100644
--- a/reference/spectra-plotting.html
+++ b/reference/spectra-plotting.html
@@ -31,7 +31,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/spectraData.html b/reference/spectraData.html
index d9eb8528..71ba0349 100644
--- a/reference/spectraData.html
+++ b/reference/spectraData.html
@@ -27,7 +27,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/reference/spectraVariableMapping.html b/reference/spectraVariableMapping.html
index d7648ce5..c2cf357a 100644
--- a/reference/spectraVariableMapping.html
+++ b/reference/spectraVariableMapping.html
@@ -21,7 +21,7 @@
Spectra
- 1.17.3
+ 1.17.4
diff --git a/search.json b/search.json
index 90fcf6e4..6262b7d2 100644
--- a/search.json
+++ b/search.json
@@ -1 +1 @@
-[{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Creating new `MsBackend` classes","text":"vignette briefly describes MsBackend class used Spectra package represent provide Mass Spectrometry (MS) data illustrates new backend class can created tested validity. Contributions vignette (content correction typos) requests additional details information highly welcome (ideally via pull requests github issues).","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"what-is-a-msbackend","dir":"Articles","previous_headings":"","what":"What is a MsBackend?","title":"Creating new `MsBackend` classes","text":"Spectra package separates code analysis MS data code needed import, represent provide data. former implemented Spectra class main object users use analyses. Spectra object relies -called backend provide MS data. MsBackend virtual class defines API new backend classes need implement order used Spectra object. Spectra object contains implementation MsBackend within @backend slot provides MS data Spectra object. data management thus hidden user. addition separation allows define new, alternative, data representations integrate seamlessly Spectra-based data analysis workflow. concept extension -memory -disk data representations MSnbase package (Gatto, Gibb, Rainer 2020).","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"conventions-and-definitions","dir":"Articles","previous_headings":"What is a MsBackend?","what":"Conventions and definitions","title":"Creating new `MsBackend` classes","text":"General conventions MS data Spectra : One Spectra object supposed contain MS (spectral) data multiple MS spectra. m/z values within spectrum expected sorted increasingly. Missing values (NA) m/z values supported. Properties spectrum called spectra variables. backends can define properties, minimum required set spectra variables must provided backend (even values empty). core spectra variables listed (along expected data type) coreSpectraVariables() function. dataStorage dataOrigin two special spectra variables define spectrum data stored data derived (loaded, data origin). expected typecharacter need defined backend (.e., can empty missing). MsBackend implementations can also represent purely read-data resources. case data accessor methods need implemented data replacement methods. Whether backend read-can set @readonly slot virtual MsBackend class (isReadOnly() function can used retrieve value slot). default @readonly = FALSE thus data replacement method listed section Data replacement methods implemented. read-backends (@readonly = TRUE) methods section Required methods need implemented. Backends can also partially read-, MsBackendMzR. backend allows example change spectra variables, peaks data (.e. m/z intensity values). Also, backends purely read-resources extend MsBackendCached Spectra package enable support modifying (adding) spectra variables. changes spectra variables internally cached MsBackendCached without need propagating underlying data resource (see example MsBackendMassbankSql MsBackendMassbank package).","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"notes-on-parallel-processing","dir":"Articles","previous_headings":"What is a MsBackend?","what":"Notes on parallel processing","title":"Creating new `MsBackend` classes","text":"parallel processing, Spectra splits backend based defined factor processes parallel (serial SerialParam used). splitting factor can defined Spectra setting parameter processingChunkSize. Alternatively, backendParallelFactor() function backend can also suggest factor /used splitting parallel processing. default implementation backendParallelFactor() return empty factor (factor()) hence suggesting preferred splitting. backendParallelFactor() MsBackendMzR hand returns factor based data files data stored (.e. based dataStorage MS data). Besides parallel processing, chunk-wise processing can also reduce memory demand operations, peak data current chunk needs realized memory.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"api","dir":"Articles","previous_headings":"","what":"API","title":"Creating new `MsBackend` classes","text":"MsBackend class defines core methods implemented MS backend well optional methods default implementations might implemented new backend don’t necessarily . functions described sections Required methods Optional methods, respectively. create new backend class extending virtual MsBackend needs implemented. example create thus simple class data.frame contain general spectral properties (spectra variables) two slots m/z intensity values. stored NumericList objects since m/z intensity values expected type numeric allow store data multiple spectra single backend object. also define simple constructor function returns empty instance new class. 3 slots spectraVars, mz intensity used store MS data, row spectraVars data one spectrum columns different spectra variables (.e. additional properties spectrum retention time MS level) element mz intensity numeric m/z intensity values respective spectrum. ideally also add basic validity function ensures data OK. function simply checks number rows spectraVars slot matches length mz intensity slot. can now create instance new class MsBackendTest() function. Note backend class necessarily need contain data like one example. Backends MsBackendMzR example retrieve data fly raw MS data files MsBackendSql MsBackendSql SQL database.","code":"library(Spectra) library(IRanges) setClass(\"MsBackendTest\", contains = \"MsBackend\", slots = c( spectraVars = \"data.frame\", mz = \"NumericList\", intensity = \"NumericList\" ), prototype = prototype( spectraVars = data.frame(), mz = NumericList(compress = FALSE), intensity = NumericList(compress = FALSE) )) MsBackendTest <- function() { new(\"MsBackendTest\") } setValidity(\"MsBackendTest\", function(object) { if (length(object@mz) != length(object@intensity) || length(object@mz) != nrow(object@spectraVars)) return(\"length of 'mz' and 'intensity' has to match the number of \", \"rows of 'spectraVars'\") NULL }) ## Class \"MsBackendTest\" [in \".GlobalEnv\"] ## ## Slots: ## ## Name: spectraVars mz intensity readonly version ## Class: data.frame NumericList NumericList logical character ## ## Extends: \"MsBackend\" MsBackendTest() ## An object of class \"MsBackendTest\" ## Slot \"spectraVars\": ## data frame with 0 columns and 0 rows ## ## Slot \"mz\": ## NumericList of length 0 ## ## Slot \"intensity\": ## NumericList of length 0 ## ## Slot \"readonly\": ## [1] FALSE ## ## Slot \"version\": ## [1] \"0.1\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"required-methods","dir":"Articles","previous_headings":"API","what":"Required methods","title":"Creating new `MsBackend` classes","text":"Methods listed section must implemented new class extending MsBackend. Methods ideally also implemented order listed . Also, strongly advised write dedicated unit tests newly implemented method function already development.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"datastorage","dir":"Articles","previous_headings":"API > Required methods","what":"dataStorage()","title":"Creating new `MsBackend` classes","text":"dataStorage spectra variable spectrum provides information data stored. dataStorage() method therefor return character vector length equal number spectra backend object information. backends data storage information can simple string \"memory\" \"database\" specify data spectrum stored within object database, respectively. Backend classes keep subset MS data memory need load data data files upon request use spectra variable store keep track original data file spectrum. example MsBackendMzR backend retrieves MS data --fly original data file(s) whenever m/z intensity values requested backend. Calling dataStorage() MsBackendMzR returns thus names originating files. example backend define simple dataStorage() method simply returns column \"dataStorage\" @svars (character).","code":"setMethod(\"dataStorage\", \"MsBackendTest\", function(object) { as.character(object@spectraVars$dataStorage) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"length","dir":"Articles","previous_headings":"API > Required methods","what":"length()","title":"Creating new `MsBackend` classes","text":"length() expected return single integer total number spectra available backend class. example backend simply return number rows data.frame stored @spectraVars slot.","code":"setMethod(\"length\", \"MsBackendTest\", function(x) { nrow(x@spectraVars) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"backendinitialize","dir":"Articles","previous_headings":"API > Required methods","what":"backendInitialize()","title":"Creating new `MsBackend` classes","text":"backendInitialize() method expected called creating instance backend class prepare (initialize) backend cases means MS data loaded. method can take parameters needed backend get loaded/initialized data (can file names load data, database connection object(s) containing data). backendInitialize() usually also special spectra variables dataStorage dataOrigin set. define backendInitialize() method takes arguments data.frame spectra variables two lists m/z intensity values spectrum. addition adding data object, function also defined dataStorage dataOrigin spectra variables. purpose two variables provide information data stored (memory example) data originating. dataOrigin example allow specify original data files individual spectra derive. can now create instance backend class fill data. thus first define MS data pass backendInitialize() method. method works compliant MsBackend API (requirement input parameters backendInitialize() method), good practice backends supposed support replacing data, add optional additional parameter data allow passing complete MS data (including m/z intensity values) function DataFrame. simplify implementation replacement methods addition also allow change backend Spectra using setBackend() new backend. thus re-implement backendInitialize() method supporting also initialize backend data frame also implement helper function checks spectra variables correct data type. function used check input data new backendInitialize() method. create backend updated backendInitialize(). backendInitialize() method implemented backend class expects user provide full MS data. however always case. backendInitialize() method MsBackendMzR backend takes example file names raw mzML, mzXML CDF files input initializes backend importing part data . Also backends defined MsBackendMgf r Biocpkg(\"MsBackendMsp\") packages work way thus allow import MS data specific file formats. backendInitialize() method backend defined MsBackendSql hand takes connection database containing data input performs sanity checks data load data backend. subsequent data access handled methods backend class SQL calls database. purpose backendInitialize() method initialize prepare data way can accessed Spectra object (initialized backend class). Whether data loaded backendInitialize() method memory simply referenced within backend class matter long backend able provide data accessor methods. Note also backendInitialize() function ideally also perform data sanity checks (e.g. whether spectra variables correct data type etc).","code":"setMethod( \"backendInitialize\", \"MsBackendTest\", function(object, svars, mz, intensity) { if (!is.data.frame(svars)) stop(\"'svars' needs to be a 'data.frame' with spectra variables\") if (is.null(svars$dataStorage)) svars$dataStorage <- \"\" if (is.null(svars$dataOrigin)) svars$dataOrigin <- \"\" object@spectraVars <- svars object@mz <- NumericList(mz, compress = FALSE) object@intensity <- NumericList(intensity, compress = FALSE) validObject(object) object }) ## A data.frame with spectra variables. svars <- data.frame(msLevel = c(1L, 2L, 2L), rtime = c(1.2, 1.3, 1.4)) ## m/z values for each spectrum. mzs <- list(c(12.3, 13.5, 16.5, 17.5), c(45.1, 45.2), c(64.4, 123.1, 124.1)) ## intensity values for each spectrum. ints <- list(c(123.3, 153.6, 2354.3, 243.4), c(100, 80.1), c(12.3, 35.2, 100)) ## Create and initialize the backend be <- backendInitialize(MsBackendTest(), svars = svars, mz = mzs, intensity = ints) be ## An object of class \"MsBackendTest\" ## Slot \"spectraVars\": ## msLevel rtime dataStorage dataOrigin ## 1 1 1.2 ## 2 2 1.3 ## 3 2 1.4 ## ## Slot \"mz\": ## NumericList of length 3 ## [[1]] 12.3 13.5 16.5 17.5 ## [[2]] 45.1 45.2 ## [[3]] 64.4 123.1 124.1 ## ## Slot \"intensity\": ## NumericList of length 3 ## [[1]] 123.3 153.6 2354.3 243.4 ## [[2]] 100 80.1 ## [[3]] 12.3 35.2 100 ## ## Slot \"readonly\": ## [1] FALSE ## ## Slot \"version\": ## [1] \"0.1\" #' Helper function to check if core spectra variables have the correct #' data type. #' #' @param x `data.frame` with the data for spectra variables. #' #' @param name `character` defining the column names (spectra variables) of `x` #' for which the correct data type should be evaluated. .sv_valid_data_type <- function(x, name = colnames(x)) { sv <- coreSpectraVariables()[names(coreSpectraVariables()) %in% name] for (i in seq_along(sv)) { if (!is(x[, names(sv[i])], sv[i])) stop(\"Spectra variabe \\\"\", names(sv[i]), \"\\\" is not of type \", sv[i], call. = FALSE) } TRUE } setMethod( \"backendInitialize\", \"MsBackendTest\", function(object, svars, mz, intensity, data) { if (!missing(data)) { svars <- as.data.frame( data[, !colnames(data) %in% c(\"mz\", \"intensity\")]) if (any(colnames(data) == \"mz\")) mz <- data$mz if (any(colnames(data) == \"intensity\")) intensity <- data$intensity } if (!is.data.frame(svars)) stop(\"'svars' needs to be a 'data.frame' with spectra variables\") if (is.null(svars$dataStorage)) svars$dataStorage <- \"\" if (is.null(svars$dataOrigin)) svars$dataOrigin <- \"\" .sv_valid_data_type(svars) object@spectraVars <- svars object@mz <- NumericList(mz, compress = FALSE) object@intensity <- NumericList(intensity, compress = FALSE) validObject(object) object }) ## Create and initialize the backend be <- backendInitialize(MsBackendTest(), svars = svars, mz = mzs, intensity = ints) be ## An object of class \"MsBackendTest\" ## Slot \"spectraVars\": ## msLevel rtime dataStorage dataOrigin ## 1 1 1.2 ## 2 2 1.3 ## 3 2 1.4 ## ## Slot \"mz\": ## NumericList of length 3 ## [[1]] 12.3 13.5 16.5 17.5 ## [[2]] 45.1 45.2 ## [[3]] 64.4 123.1 124.1 ## ## Slot \"intensity\": ## NumericList of length 3 ## [[1]] 123.3 153.6 2354.3 243.4 ## [[2]] 100 80.1 ## [[3]] 12.3 35.2 100 ## ## Slot \"readonly\": ## [1] FALSE ## ## Slot \"version\": ## [1] \"0.1\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"spectravariables","dir":"Articles","previous_headings":"API > Required methods","what":"spectraVariables()","title":"Creating new `MsBackend` classes","text":"spectraVariables() method return character vector names available spectra variables backend. backend class support defining providing spectra variables, MsBackend class must provide also core spectra variables (correct data type). Since data file formats provide values spectra variables can however also NA (exception spectra variable \"dataStorage\"). coreSpectraVariables() function returns full list mandatory spectra variables along expected data type. typical spectraVariables() method MsBackend class thus implemented similarly one MsBackendTest test backend: return union core spectra variables names available spectra variables within backend object.","code":"coreSpectraVariables() ## msLevel rtime acquisitionNum ## \"integer\" \"numeric\" \"integer\" ## scanIndex mz intensity ## \"integer\" \"NumericList\" \"NumericList\" ## dataStorage dataOrigin centroided ## \"character\" \"character\" \"logical\" ## smoothed polarity precScanNum ## \"logical\" \"integer\" \"integer\" ## precursorMz precursorIntensity precursorCharge ## \"numeric\" \"numeric\" \"integer\" ## collisionEnergy isolationWindowLowerMz isolationWindowTargetMz ## \"numeric\" \"numeric\" \"numeric\" ## isolationWindowUpperMz ## \"numeric\" setMethod(\"spectraVariables\", \"MsBackendTest\", function(object) { union(names(coreSpectraVariables()), colnames(object@spectraVars)) }) spectraVariables(be) ## [1] \"msLevel\" \"rtime\" ## [3] \"acquisitionNum\" \"scanIndex\" ## [5] \"mz\" \"intensity\" ## [7] \"dataStorage\" \"dataOrigin\" ## [9] \"centroided\" \"smoothed\" ## [11] \"polarity\" \"precScanNum\" ## [13] \"precursorMz\" \"precursorIntensity\" ## [15] \"precursorCharge\" \"collisionEnergy\" ## [17] \"isolationWindowLowerMz\" \"isolationWindowTargetMz\" ## [19] \"isolationWindowUpperMz\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"spectradata","dir":"Articles","previous_headings":"API > Required methods","what":"spectraData()","title":"Creating new `MsBackend` classes","text":"spectraData() method return full spectra data within backend DataFrame object (defined S4Vectors package). second parameter columns allows define names spectra variables returned DataFrame. row data frame represent one spectrum, column spectra variable. Columns \"mz\" \"intensity\" (requested) contain NumericList m/z intensity values spectra. DataFrame must provide values (even NA) requested spectra variables backend (including core spectra variables). now first problem toy backend class, since keep spectra variable data simple data.frame without constraints required columns etc. simple solution (also used backend classes Spectra package) fill missing spectra variables --fly returned DataFrame. thus define simple helper function adds columns missing values (correct data type) core spectra variables available within backend result. next implement spectraData() method uses helper function fill eventually missing core spectra variables. Note also function return DataFrame even single column. alternative, also initialize @spectraVars data frame within backendInitialize() method adding columns spectra variables provided user require data frame always contains core spectra variables. Extracting spectra data (single spectra variables full data) might thus efficient --fly initialization eventual missing spectra variables, backend class also larger memory footprint even spectra variables missing values spectra need stored within object. can now use spectraData() either extract full spectra data backend, data selected spectra variables.","code":"#' @description Add columns with missing core spectra variables. #' #' @param x `data.frame` or `DataFrame` with some spectra variables. #' #' @param core_vars `character` with core spectra variable names that should #' be added to `x` if not already present. #' .fill_core_variables <- function(x, core_vars = names(coreSpectraVariables())) { fill_vars <- setdiff(core_vars, colnames(x)) core_type <- coreSpectraVariables() n <- nrow(x) if (length(fill_vars)) { fill <- lapply(fill_vars, function(z) { rep(as(NA, core_type[z]), n) }) names(fill) <- fill_vars x <- cbind(x, as.data.frame(fill)) } x } setMethod( \"spectraData\", \"MsBackendTest\", function(object, columns = spectraVariables(object)) { if (!all(columns %in% spectraVariables(object))) stop(\"Some of the requested spectra variables are not available\") ## Add m/z and intensity values to the result res <- DataFrame(object@spectraVars) res$mz <- object@mz res$intensity <- object@intensity ## Fill with eventually missing core variables res <- .fill_core_variables( res, intersect(columns, names(coreSpectraVariables()))) res[, columns, drop = FALSE] }) ## Full data spectraData(be) ## DataFrame with 3 rows and 19 columns ## msLevel rtime acquisitionNum scanIndex mz ## ## 1 1 1.2 NA NA 12.3,13.5,16.5,... ## 2 2 1.3 NA NA 45.1,45.2 ## 3 2 1.4 NA NA 64.4,123.1,124.1 ## intensity dataStorage dataOrigin centroided smoothed ## ## 1 123.3, 153.6,2354.3,... NA NA ## 2 100.0, 80.1 NA NA ## 3 12.3, 35.2,100.0 NA NA ## polarity precScanNum precursorMz precursorIntensity precursorCharge ## ## 1 NA NA NA NA NA ## 2 NA NA NA NA NA ## 3 NA NA NA NA NA ## collisionEnergy isolationWindowLowerMz isolationWindowTargetMz ## ## 1 NA NA NA ## 2 NA NA NA ## 3 NA NA NA ## isolationWindowUpperMz ## ## 1 NA ## 2 NA ## 3 NA ## Selected variables spectraData(be, c(\"rtime\", \"mz\", \"centroided\")) ## DataFrame with 3 rows and 3 columns ## rtime mz centroided ## ## 1 1.2 12.3,13.5,16.5,... NA ## 2 1.3 45.1,45.2 NA ## 3 1.4 64.4,123.1,124.1 NA ## Only missing core spectra variables spectraData(be, c(\"centroided\", \"polarity\")) ## DataFrame with 3 rows and 2 columns ## centroided polarity ## ## 1 NA NA ## 2 NA NA ## 3 NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"peaksdata","dir":"Articles","previous_headings":"API > Required methods","what":"peaksData()","title":"Creating new `MsBackend` classes","text":"peaksData() method extracts MS peaks data backend, includes m/z intensity values MS peak spectrum. expected returned List numerical matrices columns matrix requested peaks variables (default \"mz\" \"intensity\") one spectrum. Backends must provide least two peaks variables. implement peaksData() method backend. need loop @mz @intensity slots merge m/z intensity spectrum matrix. Also, simplicity reasons, accept c(\"mz\", \"intensity\") columns parameter. expected default behavior MsBackend, general columns parameter thought allow user specify peaks variables returned matrix. method can now extract peaks data backend. peaksData() method used many data analysis functions Spectra object extract MS data, thus ideally method implemented efficient way. backend need loop lists m/z intensity values obviously ideal. Thus, storing m/z intensity values separate slots done backend might ideal. MsBackendMemory backend example stores MS data already list matrices results efficient peaksData() method (comes also larger overhead adding, replacing checking MS data). Note also backend needs provide m/z intensity values, additional peak variables also supported. MsBackendMemory class example allows store provide additional peak variables can added additional columns returned matrix. case default peaksVariables() method also overwritten list additionally available variables columns parameter peaksData() method allow selection additional peaks variables (addition required \"mz\" \"intensity\" variables).","code":"setMethod( \"peaksData\", \"MsBackendTest\", function(object, columns = c(\"mz\", \"intensity\")) { if (length(columns) != 2 && columns != c(\"mz\", \"intensity\")) stop(\"'columns' supports only \\\"mz\\\" and \\\"intensity\\\"\") mapply(mz = object@mz, intensity = object@intensity, FUN = cbind, SIMPLIFY = FALSE, USE.NAMES = FALSE) }) peaksData(be) ## [[1]] ## mz intensity ## [1,] 12.3 123.3 ## [2,] 13.5 153.6 ## [3,] 16.5 2354.3 ## [4,] 17.5 243.4 ## ## [[2]] ## mz intensity ## [1,] 45.1 100.0 ## [2,] 45.2 80.1 ## ## [[3]] ## mz intensity ## [1,] 64.4 12.3 ## [2,] 123.1 35.2 ## [3,] 124.1 100.0"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"extractbyindex-and","dir":"Articles","previous_headings":"API > Required methods","what":"extractByIndex() and [","title":"Creating new `MsBackend` classes","text":"extractByIndex() [ methods allows subset MsBackend objects. operation expected reduce MsBackend object selected spectra. methods must also support duplication (e.g. [c(1, 1, 1)] extraction arbitrary order (e.g. [c(3, 1, 5, 3)]). methods subset object, extractByIndex() supports subset integer index, [, compliant base R implementation, support subset indices logical vectors. error thrown indices bounds, method also support returning empty backend [integer()]. Note MsCoreUtils::i2index function can used check correct input (convert input integer index). extractByIndex() method used data operation analysis methods Spectra objects, [ intended used end user (needed). implement extractByIndex() backend: [ need defined default implementation base MsBackend exists. can now subset backend last two spectra. extracting second spectrum multiple times.","code":"setMethod(\"extractByIndex\", c(\"MsBackendTest\", \"ANY\"), function(object, i) { object@spectraVars <- object@spectraVars[i, ] object@mz <- object@mz[i] object@intensity <- object@intensity[i] object }) a <- extractByIndex(be, 2:3) spectraData(a) ## DataFrame with 2 rows and 19 columns ## msLevel rtime acquisitionNum scanIndex mz ## ## 1 2 1.3 NA NA 45.1,45.2 ## 2 2 1.4 NA NA 64.4,123.1,124.1 ## intensity dataStorage dataOrigin centroided smoothed polarity ## ## 1 100.0, 80.1 NA NA NA ## 2 12.3, 35.2,100.0 NA NA NA ## precScanNum precursorMz precursorIntensity precursorCharge collisionEnergy ## ## 1 NA NA NA NA NA ## 2 NA NA NA NA NA ## isolationWindowLowerMz isolationWindowTargetMz isolationWindowUpperMz ## ## 1 NA NA NA ## 2 NA NA NA a <- be[c(2, 2, 2)] spectraData(a) ## DataFrame with 3 rows and 19 columns ## msLevel rtime acquisitionNum scanIndex mz intensity ## ## 2 2 1.3 NA NA 45.1,45.2 100.0, 80.1 ## 2.1 2 1.3 NA NA 45.1,45.2 100.0, 80.1 ## 2.2 2 1.3 NA NA 45.1,45.2 100.0, 80.1 ## dataStorage dataOrigin centroided smoothed polarity precScanNum ## ## 2 NA NA NA NA ## 2.1 NA NA NA NA ## 2.2 NA NA NA NA ## precursorMz precursorIntensity precursorCharge collisionEnergy ## ## 2 NA NA NA NA ## 2.1 NA NA NA NA ## 2.2 NA NA NA NA ## isolationWindowLowerMz isolationWindowTargetMz isolationWindowUpperMz ## ## 2 NA NA NA ## 2.1 NA NA NA ## 2.2 NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"backendmerge","dir":"Articles","previous_headings":"API > Required methods","what":"backendMerge()","title":"Creating new `MsBackend` classes","text":"backendMerge() method merges (combines) MsBackend objects (type!) single instance. test backend thus need combine values @spectraVars, @mz @intensity slots. support also merging data.frames different set columns use MsCoreUtils::rbindFill() function instead simple rbind() (function joins data frames making union available columns). , implementation requires 3 loops might efficient - allows merge backends type MsBackendTest.","code":"setMethod(\"backendMerge\", \"MsBackendTest\", function(object, ...) { res <- object object <- unname(c(object, ...)) res@mz <- do.call(c, lapply(object, function(z) z@mz)) res@intensity <- do.call(c, lapply(object, function(z) z@intensity)) res@spectraVars <- do.call(MsCoreUtils::rbindFill, lapply(object, function(z) z@spectraVars)) validObject(res) res }) a <- backendMerge(be, be[2], be) a ## An object of class \"MsBackendTest\" ## Slot \"spectraVars\": ## msLevel rtime dataStorage dataOrigin ## 1 1 1.2 ## 2 2 1.3 ## 3 2 1.4 ## 21 2 1.3 ## 11 1 1.2 ## 22 2 1.3 ## 31 2 1.4 ## ## Slot \"mz\": ## NumericList of length 7 ## [[1]] 12.3 13.5 16.5 17.5 ## [[2]] 45.1 45.2 ## [[3]] 64.4 123.1 124.1 ## [[4]] 45.1 45.2 ## [[5]] 12.3 13.5 16.5 17.5 ## [[6]] 45.1 45.2 ## [[7]] 64.4 123.1 124.1 ## ## Slot \"intensity\": ## NumericList of length 7 ## [[1]] 123.3 153.6 2354.3 243.4 ## [[2]] 100 80.1 ## [[3]] 12.3 35.2 100 ## [[4]] 100 80.1 ## [[5]] 123.3 153.6 2354.3 243.4 ## [[6]] 100 80.1 ## [[7]] 12.3 35.2 100 ## ## Slot \"readonly\": ## [1] FALSE ## ## Slot \"version\": ## [1] \"0.1\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"section","dir":"Articles","previous_headings":"API > Required methods","what":"$","title":"Creating new `MsBackend` classes","text":"$ method expected extract single spectra variable backend. Parameter name allow name spectra variable return. MsBackend must support extracting core spectra variables method (even data might available variable). example implementation make use spectraData() method, efficient implementations might available well (require first subset/create DataFrame full data subset ). Also, $ method check requested spectra variable available throw error otherwise. can now extract MS levels core spectra variable available within backend. also m/z values","code":"setMethod(\"$\", \"MsBackendTest\", function(x, name) { spectraData(x, columns = name)[, 1L] }) be$msLevel ## [1] 1 2 2 be$precursorMz ## [1] NA NA NA be$mz ## NumericList of length 3 ## [[1]] 12.3 13.5 16.5 17.5 ## [[2]] 45.1 45.2 ## [[3]] 64.4 123.1 124.1"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"lengths","dir":"Articles","previous_headings":"API > Required methods","what":"lengths()","title":"Creating new `MsBackend` classes","text":"lengths() method expected return integer vector (length number spectra backend) total number peaks per spectrum. MsBackendTest can simply use lengths() method m/z intensity values . can now get peaks count per spectrum:","code":"setMethod(\"lengths\", \"MsBackendTest\", function(x, use.names = FALSE) { lengths(x@mz, use.names = use.names) }) lengths(be) ## [1] 4 2 3"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isempty","dir":"Articles","previous_headings":"API > Required methods","what":"isEmpty()","title":"Creating new `MsBackend` classes","text":"isEmpty() method expected return spectrum information whether empty, .e. contain MS peaks (hence m/z intensity values). result method logical length equal number spectra represented backend TRUE indicating whether spectrum empty FALSE otherwise. implementation isEmpty() method use lenghts() method defined returns number MS peaks per spectrum.","code":"setMethod(\"isEmpty\", \"MsBackendTest\", function(x) { lengths(x) == 0L }) isEmpty(be) ## [1] FALSE FALSE FALSE"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"acquisitionnum","dir":"Articles","previous_headings":"API > Required methods","what":"acquisitionNum()","title":"Creating new `MsBackend` classes","text":"Extract acquisitionNum core spectra variable. method expected return integer vector length spectra represented backend. backend simply re-use spectraData() method.","code":"setMethod(\"acquisitionNum\", \"MsBackendTest\", function(object) { spectraData(object, \"acquisitionNum\")[, 1L] }) acquisitionNum(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"centroided","dir":"Articles","previous_headings":"API > Required methods","what":"centroided()","title":"Creating new `MsBackend` classes","text":"Extract spectrum information whether contains centroided data. method expected return logical vector length spectra represented backend.","code":"setMethod(\"centroided\", \"MsBackendTest\", function(object) { spectraData(object, \"centroided\")[, 1L] }) centroided(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"collisionenergy","dir":"Articles","previous_headings":"API > Required methods","what":"collisionEnergy()","title":"Creating new `MsBackend` classes","text":"Extract spectrum collision energy applied generate fragment spectrum. method expected return numeric vector length spectra represented backend (NA_real_ spectra information available, MS1 spectra).","code":"setMethod(\"collisionEnergy\", \"MsBackendTest\", function(object) { spectraData(object, \"collisionEnergy\")[, 1L] }) collisionEnergy(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"dataorigin","dir":"Articles","previous_headings":"API > Required methods","what":"dataOrigin()","title":"Creating new `MsBackend` classes","text":"Extract data origin spectra variable spectrum. spectra variable can used store origin spectra. method expected return character vector length equal number spectra represented backend.","code":"setMethod(\"dataOrigin\", \"MsBackendTest\", function(object) { spectraData(object, \"dataOrigin\")[, 1L] }) dataOrigin(be) ## [1] \"\" \"\" \"\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"intensity","dir":"Articles","previous_headings":"API > Required methods","what":"intensity()","title":"Creating new `MsBackend` classes","text":"Extract intensity values spectrum backend. result expected NumericList length equal number spectra represented backend. test backend can simply return @intensity slot since data already stored within NumericList.","code":"setMethod(\"intensity\", \"MsBackendTest\", function(object) { object@intensity }) intensity(be) ## NumericList of length 3 ## [[1]] 123.3 153.6 2354.3 243.4 ## [[2]] 100 80.1 ## [[3]] 12.3 35.2 100"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isolationwindowlowermz","dir":"Articles","previous_headings":"API > Required methods","what":"isolationWindowLowerMz()","title":"Creating new `MsBackend` classes","text":"Extract core spectra variable isolationWindowLowerMz backend. information usually provided spectrum raw mzML files. method expected return numeric vector length equal number spectra represented backend.","code":"setMethod(\"isolationWindowLowerMz\", \"MsBackendTest\", function(object) { spectraData(object, \"isolationWindowLowerMz\")[, 1L] }) isolationWindowLowerMz(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isolationwindowtargetmz","dir":"Articles","previous_headings":"API > Required methods","what":"isolationWindowTargetMz()","title":"Creating new `MsBackend` classes","text":"Extract core spectra variable isolationWindowTargetMz backend. information usually provided spectrum raw mzML files. method expected return numeric vector length equal number spectra represented backend.","code":"setMethod(\"isolationWindowTargetMz\", \"MsBackendTest\", function(object) { spectraData(object, \"isolationWindowTargetMz\")[, 1L] }) isolationWindowTargetMz(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isolationwindowuppermz","dir":"Articles","previous_headings":"API > Required methods","what":"isolationWindowUpperMz()","title":"Creating new `MsBackend` classes","text":"Extract core spectra variable isolationWindowUpperMz backend. information usually provided spectrum raw mzML files. method expected return numeric vector length equal number spectra represented backend.","code":"setMethod(\"isolationWindowUpperMz\", \"MsBackendTest\", function(object) { spectraData(object, \"isolationWindowUpperMz\")[, 1L] }) isolationWindowUpperMz(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"mslevel","dir":"Articles","previous_headings":"API > Required methods","what":"msLevel()","title":"Creating new `MsBackend` classes","text":"Extract MS level spectrum backend. method expected return integer length equal number spectra represented backend.","code":"setMethod(\"msLevel\", \"MsBackendTest\", function(object) { spectraData(object, \"msLevel\")[, 1L] }) msLevel(be) ## [1] 1 2 2"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"mz","dir":"Articles","previous_headings":"API > Required methods","what":"mz()","title":"Creating new `MsBackend` classes","text":"Extract m/z values spectrum backend. result expected NumericList length equal number spectra represented backend. Also, m/z values expected ordered increasingly element (spectrum).","code":"setMethod(\"mz\", \"MsBackendTest\", function(object) { object@mz }) mz(be) ## NumericList of length 3 ## [[1]] 12.3 13.5 16.5 17.5 ## [[2]] 45.1 45.2 ## [[3]] 64.4 123.1 124.1"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"polarity","dir":"Articles","previous_headings":"API > Required methods","what":"polarity()","title":"Creating new `MsBackend` classes","text":"Extract polarity core spectra variable spectrum backend. method expected return integer length equal number spectra represented backend. Negative positive polarity expected encoded 0L 1L, respectively.","code":"setMethod(\"polarity\", \"MsBackendTest\", function(object) { spectraData(object, \"polarity\")[, 1L] }) polarity(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"precscannum","dir":"Articles","previous_headings":"API > Required methods","what":"precScanNum()","title":"Creating new `MsBackend` classes","text":"Extract acquisition number precursor spectrum. method expected return integer length equal number spectra represented backend. MS1 spectra (acquisition number precursor provided) NA_integer_ returned.","code":"setMethod(\"precScanNum\", \"MsBackendTest\", function(object) { spectraData(object, \"precScanNum\")[, 1L] }) precScanNum(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"precursorcharge","dir":"Articles","previous_headings":"API > Required methods","what":"precursorCharge()","title":"Creating new `MsBackend` classes","text":"Extract charge precursor spectrum. method expected return integer length equal number spectra represented backend. MS1 spectra (charge precursor provided) NA_integer_ returned.","code":"setMethod(\"precursorCharge\", \"MsBackendTest\", function(object) { spectraData(object, \"precursorCharge\")[, 1L] }) precursorCharge(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"precursorintensity","dir":"Articles","previous_headings":"API > Required methods","what":"precursorIntensity()","title":"Creating new `MsBackend` classes","text":"Extract intensity precursor spectrum. method expected return numeric length equal number spectra represented backend. MS1 spectra (precursor intensity fragment spectrum provided) NA_real_ returned.","code":"setMethod(\"precursorIntensity\", \"MsBackendTest\", function(object) { spectraData(object, \"precursorIntensity\")[, 1L] }) precursorIntensity(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"precursormz","dir":"Articles","previous_headings":"API > Required methods","what":"precursorMz()","title":"Creating new `MsBackend` classes","text":"Extract precursor m/z spectrum. method expected return numeric length equal number spectra represented backend. MS1 spectra (precursor m/z fragment spectrum provided) NA_real_ returned.","code":"setMethod(\"precursorMz\", \"MsBackendTest\", function(object) { spectraData(object, \"precursorMz\")[, 1L] }) precursorMz(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"rtime","dir":"Articles","previous_headings":"API > Required methods","what":"rtime()","title":"Creating new `MsBackend` classes","text":"Extract retention time spectrum. method expected return numeric length equal number spectra represented backend.","code":"setMethod(\"rtime\", \"MsBackendTest\", function(object) { spectraData(object, \"rtime\")[, 1L] }) rtime(be) ## [1] 1.2 1.3 1.4"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"scanindex","dir":"Articles","previous_headings":"API > Required methods","what":"scanIndex()","title":"Creating new `MsBackend` classes","text":"Extract scan index core spectra variable. scan index represents relative index spectrum within respective raw data file can different acquisitionNum (index spectrum recorded MS instrument). method expected return integer length equal number spectra represented backend.","code":"setMethod(\"scanIndex\", \"MsBackendTest\", function(object) { spectraData(object, \"scanIndex\")[, 1L] }) scanIndex(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"smoothed","dir":"Articles","previous_headings":"API > Required methods","what":"smoothed()","title":"Creating new `MsBackend` classes","text":"Extract smoothed core spectra variable indicates whether spectrum smoothed. variable supported backward compatibility seldomly used. method expected return logical length equal number spectra represented backend.","code":"setMethod(\"smoothed\", \"MsBackendTest\", function(object) { spectraData(object, \"smoothed\")[, 1L] }) smoothed(be) ## [1] NA NA NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"spectranames","dir":"Articles","previous_headings":"API > Required methods","what":"spectraNames()","title":"Creating new `MsBackend` classes","text":"spectraNames() can used extract (optional) names (IDs) individual spectra backend, NULL set. test backend can use rownames @spectraVars slot store spectra names. methods need implemented valid read-MsBackend class running test object described section Testing validity backend produce errors. backends support also data replacement also methods listed next section need implemented.","code":"setMethod(\"spectraNames\", \"MsBackendTest\", function(object) { rownames(object@spectraVars) }) spectraNames(be) ## [1] \"1\" \"2\" \"3\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"tic","dir":"Articles","previous_headings":"API > Required methods","what":"tic()","title":"Creating new `MsBackend` classes","text":"tic() method return total ion count (.e. sum intensities) spectrum. information usually also provided raw MS data files, can also calculated fly data. parameter initial (default TRUE) allows define whether provided original tic returned (initial = TRUE) whether tic calculated actual data (initial = FALSE). original tic values usually provided spectra variable \"totIonCurrent\". Thus, initial = TRUE, implementation return value spectra variable avaialble NA . can now either return original (initial) TIC (available). calculate TIC based actual intensity values.","code":"setMethod(\"tic\", \"MsBackendTest\", function(object, initial = TRUE) { if (initial) { if (any(spectraVariables(object) == \"totIonCurrent\")) spectraData(object, \"totIonCurrent\")[, 1L] else rep(NA_real_, length(object)) } else vapply(intensity(object), sum, numeric(1), na.rm = TRUE) }) tic(be) ## [1] NA NA NA tic(be, initial = FALSE) ## [1] 2874.6 180.1 147.5"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"data-replacement-methods","dir":"Articles","previous_headings":"API","what":"Data replacement methods","title":"Creating new `MsBackend` classes","text":"stated general description, MsBackend implementations can also purely read-resources allowing just access data, replace data. Thus, strictly required implement methods, fully functional backend suggested (much possible). backend purely read-MS data resource might even extend MsBackendCached backend defined Spectra package provides mechanism cache (spectra variable) data data.frame within object. MsBackendMassbankSql implemented MsBackendMassbank package extends example backend thus allows modifying spectra variables without changing original data MassBank SQL database.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"spectradata-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"spectraData<-","title":"Creating new `MsBackend` classes","text":"spectraData<- method allow replace data within backend. method take DataFrame full data input value expected replace full data within backend, .e. spectra variables well peak data. Also, importantly, number spectra calling spectraData<- method object . implementation can make use optional parameter data added backendInitialize() method allows fill MsBackendTest object full data. test new method extract full spectra data, add additional column (spectra variable) replace data .","code":"setReplaceMethod(\"spectraData\", \"MsBackendTest\", function(object, value) { if (!inherits(value, \"DataFrame\")) stop(\"'value' is expected to be a 'DataFrame'\") if (length(object) && length(object) != nrow(value)) stop(\"'value' has to be a 'DataFrame' with \", length(object), \" rows\") object <- backendInitialize(MsBackendTest(), data = value) object }) d <- spectraData(be) d$new_col <- c(\"a\", \"b\", \"c\") spectraData(be) <- d be$new_col ## [1] \"a\" \"b\" \"c\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"intensity-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"intensity<-","title":"Creating new `MsBackend` classes","text":"intensity<- method allow replace intensity values spectra backend. method expected replace values intensities, must change number intensities (hence peaks) spectrum (done peaksData<- method allows replace intensity m/z values time). value method ideally NumericList ensure intensity values indeed numeric. addition method implement also simple helper function checks correct length value. data replacement method needs check function thus reduces code duplication. now use method replace intensities backend modified intensities.","code":".match_length <- function(x, y) { if (length(x) != length(y)) stop(\"Length of 'value' has to match the length of 'object'\") } setReplaceMethod(\"intensity\", \"MsBackendTest\", function(object, value) { .match_length(object, value) if (!(is.list(value) || inherits(value, \"NumericList\"))) stop(\"'value' has to be a list or NumericList\") if (!all(lengths(value) == lengths(mz(object)))) stop(\"lengths of 'value' has to match the number of peaks per spectrum\") if (!inherits(value, \"NumericList\")) value <- NumericList(value, compress = FALSE) object@intensity <- value object }) intensity(be) ## NumericList of length 3 ## [[1]] 123.3 153.6 2354.3 243.4 ## [[2]] 100 80.1 ## [[3]] 12.3 35.2 100 intensity(be) <- intensity(be) - 10 intensity(be) ## NumericList of length 3 ## [[1]] 113.3 143.6 2344.3 233.4 ## [[2]] 90 70.1 ## [[3]] 2.3 25.2 90"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"mz-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"mz<-","title":"Creating new `MsBackend` classes","text":"mz<- method allow replace m/z values spectra backend. implementation can intensity<- method. m/z values within spectrum need increasingly ordered. thus also check case provided m/z values. take advantage efficient .unsorted() implementation NumericList already available, faster e.g. calling vapply(mz(), .unsorted, logical(1)).","code":"setReplaceMethod(\"mz\", \"MsBackendTest\", function(object, value) { .match_length(object, value) if (!(is.list(value) || inherits(value, \"NumericList\"))) stop(\"'value' has to be a list or NumericList\") if (!all(lengths(value) == lengths(mz(object)))) stop(\"lengths of 'value' has to match the number of peaks per spectrum\") if (!inherits(value, \"NumericList\")) value <- NumericList(value, compress = FALSE) if (any(is.unsorted(value))) stop(\"m/z values need to be increasingly sorted within each spectrum\") object@mz <- value object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"peaksdata-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"peaksData<-","title":"Creating new `MsBackend` classes","text":"peaksData<- allow replace peaks data (m/z intensity values) spectra backend. contrast mz<- intensity<- methods method also support changing number peaks per spectrum (e.g. due filtering). Parameter value list matrix objects columns \"mz\" \"intensity\". length list match number spectra backend. implementation backend class need loop list extract m/z intensity values assign @mz @intensity slots. Using peaksData<- method can now also example remove peaks.","code":"setReplaceMethod(\"peaksData\", \"MsBackendTest\", function(object, value) { if (!(is.list(value) || inherits(value, \"SimpleList\"))) stop(\"'value' has to be a list-like object\") .match_length(object, value) object@mz <- NumericList(lapply(value, \"[\", , \"mz\"), compress = FALSE) object@intensity <- NumericList(lapply(value, \"[\", , \"intensity\"), compress = FALSE) validObject(object) object }) pd <- peaksData(be) ## Remove the first peak from the first spectrum pd[[1L]] <- pd[[1L]][-1L, ] lengths(be) ## [1] 4 2 3 peaksData(be) <- pd lengths(be) ## [1] 3 2 3"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"section-1","dir":"Articles","previous_headings":"API > Data replacement methods","what":"$<-","title":"Creating new `MsBackend` classes","text":"$<- method allow replace values spectra variables also add additional spectra variables backend. replacement methods, length() value match number spectra represented backend. can now replace example existing spectra variables: even add new spectra variables. Replacement methods core spectra variables can implemented similarly.","code":"setReplaceMethod(\"$\", \"MsBackendTest\", function(x, name, value) { .match_length(x, value) if (name == \"mz\") { mz(x) <- value } else if (name == \"intensity\") { intensity(x) <- value } else { x@spectraVars[[name]] <- value } .sv_valid_data_type(x@spectraVars, name) x }) msLevel(be) ## [1] 1 2 2 be$msLevel <- c(2L, 1L, 2L) msLevel(be) ## [1] 2 1 2 be$new_var <- c(\"a\", \"b\", \"c\") be$new_var ## [1] \"a\" \"b\" \"c\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"selectspectravariables","dir":"Articles","previous_headings":"API > Data replacement methods","what":"selectSpectraVariables()","title":"Creating new `MsBackend` classes","text":"selectSpectraVariables() function allow reduce information within backend (parameter object) selected spectra variables (parameter spectraVariables). equivalent subset columns/variables. core spectra variables, specified parameter spectraVariables, values expected removed (since core spectra variables expected available even defined within backend). implementation backend remove columns @spectraVars data frame defined spectraVariables parameter. Special care given \"mz\" \"intensity\" spectra variables: selected, @mz @intensity slots initialized empty NumericList (length matching number spectra). Note also backends might throw error spectra variable required backend removed (\"dataStorage\" MsBackendMzR backend, required backend allow retrieval m/z intensity values). can now use selectSpectraVariables() remove example spectra variable \"new_var\" added . spectra variable \"new_var\" now longer available. Note however still core spectra variables listed, even selected spectraVariables parameter. variables (\"dataOrigin\") still listed spectraVariables(be2), actual values removed: \"mz\" \"intensitity\" selected, m/z intensity values get removed.","code":"setMethod( \"selectSpectraVariables\", \"MsBackendTest\", function(object, spectraVariables = spectraVariables(object)) { keep <- colnames(object@spectraVars) %in% spectraVariables object@spectraVars <- object@spectraVars[, keep, drop = FALSE] if (!any(spectraVariables == \"mz\")) object@mz <- NumericList(vector(\"list\", length(object)), compress = FALSE) if (!any(spectraVariables == \"intensity\")) object@intensity <- NumericList(vector(\"list\", length(object)), compress = FALSE) validObject(object) object }) be2 <- be be2 <- selectSpectraVariables(be2, c(\"msLevel\", \"rtime\", \"mz\", \"intensity\", \"dataStorage\")) spectraVariables(be2) ## [1] \"msLevel\" \"rtime\" ## [3] \"acquisitionNum\" \"scanIndex\" ## [5] \"mz\" \"intensity\" ## [7] \"dataStorage\" \"dataOrigin\" ## [9] \"centroided\" \"smoothed\" ## [11] \"polarity\" \"precScanNum\" ## [13] \"precursorMz\" \"precursorIntensity\" ## [15] \"precursorCharge\" \"collisionEnergy\" ## [17] \"isolationWindowLowerMz\" \"isolationWindowTargetMz\" ## [19] \"isolationWindowUpperMz\" dataOrigin(be) ## [1] \"\" \"\" \"\" dataOrigin(be2) ## [1] NA NA NA be2 <- selectSpectraVariables(be2, c(\"msLevel\", \"rtime\", \"dataStorage\")) mz(be2) ## NumericList of length 3 ## [[1]] numeric(0) ## [[2]] numeric(0) ## [[3]] numeric(0) intensity(be2) ## NumericList of length 3 ## [[1]] numeric(0) ## [[2]] numeric(0) ## [[3]] numeric(0)"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"centroided-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"centroided<-","title":"Creating new `MsBackend` classes","text":"Replace value centroided core spectra variable. provided data type must logical. re-use function .sv_valid_data_type defined backendInitialize() check correct data type core spectra variables. Alternatively, also simply re-use $<- replacement method . make whole code base backend cleaner replacing adding spectra variables handled single central function.","code":"setReplaceMethod(\"centroided\", \"MsBackendTest\", function(object, value) { object@spectraVars[[\"centroided\"]] <- value .sv_valid_data_type(object@spectraVars, \"centroided\") object }) setReplaceMethod(\"centroided\", \"MsBackendTest\", function(object, value) { object$centroided <- value object }) centroided(be) <- c(TRUE, FALSE, TRUE) centroided(be) ## [1] TRUE FALSE TRUE"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"collisionenergy-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"collisionEnergy<-","title":"Creating new `MsBackend` classes","text":"Replace values collision energy. Parameter value type numeric.","code":"setReplaceMethod(\"collisionEnergy\", \"MsBackendTest\", function(object, value) { object$collisionEnergy <- value object }) collisionEnergy(be) <- c(NA_real_, 20.0, 20.0) collisionEnergy(be) ## [1] NA 20 20"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"dataorigin-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"dataOrigin<-","title":"Creating new `MsBackend` classes","text":"Replace values data origin spectra variable. Parameter value type character.","code":"setReplaceMethod(\"dataOrigin\", \"MsBackendTest\", function(object, value) { object$dataOrigin <- value object }) dataOrigin(be) ## [1] \"\" \"\" \"\" dataOrigin(be) <- c(\"unknown\", \"file a\", \"file b\") dataOrigin(be) ## [1] \"unknown\" \"file a\" \"file b\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"datastorage-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"dataStorage<-","title":"Creating new `MsBackend` classes","text":"Replace values data storage spectra variable. Parameter value type character. Since backend really make use spectra variable, can accept character value. backends, example need load data --fly data files, spectra variable used store name data files hence need perform additional checks within replacement function.","code":"setReplaceMethod(\"dataStorage\", \"MsBackendTest\", function(object, value) { object$dataStorage <- value object }) dataStorage(be) ## [1] \"\" \"\" \"\" dataStorage(be) <- c(\"\", \"\", \"\") dataStorage(be) ## [1] \"\" \"\" \"\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isolationwindowlowermz-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"isolationWindowLowerMz<-","title":"Creating new `MsBackend` classes","text":"Replace values isolation window lower m/z spectra variable. Parameter value type numeric (NA_real_ missing values supported, e.g. MS1 spectra).","code":"setReplaceMethod( \"isolationWindowLowerMz\", \"MsBackendTest\", function(object, value) { object$isolationWindowLowerMz <- value object }) isolationWindowLowerMz(be) <- c(NA_real_, 245.3, NA_real_) isolationWindowLowerMz(be) ## [1] NA 245.3 NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isolationwindowtargetmz-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"isolationWindowTargetMz<-","title":"Creating new `MsBackend` classes","text":"Replace values isolation window target m/z spectra variable. Parameter value type numeric (NA_real_ missing values supported, e.g. MS1 spectra).","code":"setReplaceMethod( \"isolationWindowTargetMz\", \"MsBackendTest\", function(object, value) { object$isolationWindowTargetMz <- value object }) isolationWindowTargetMz(be) <- c(NA_real_, 245.4, NA_real_) isolationWindowTargetMz(be) ## [1] NA 245.4 NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isolationwindowuppermz-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"isolationWindowUpperMz<-","title":"Creating new `MsBackend` classes","text":"Replace values isolation window upper m/z spectra variable. Parameter value type numeric (NA_real_ missing values supported, e.g. MS1 spectra).","code":"setReplaceMethod( \"isolationWindowUpperMz\", \"MsBackendTest\", function(object, value) { object$isolationWindowUpperMz <- value object }) isolationWindowUpperMz(be) <- c(NA_real_, 245.5, NA_real_) isolationWindowUpperMz(be) ## [1] NA 245.5 NA"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"mslevel-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"msLevel<-","title":"Creating new `MsBackend` classes","text":"Replace MS level spectra backend. Parameter value type integer. Missing values (NA_integer_) supported.","code":"setReplaceMethod(\"msLevel\", \"MsBackendTest\", function(object, value) { object$msLevel <- value object }) msLevel(be) ## [1] 2 1 2 msLevel(be) <- c(1L, 1L, 2L) msLevel(be) ## [1] 1 1 2"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"polarity-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"polarity<-","title":"Creating new `MsBackend` classes","text":"Replace values polarity spectra variables. Parameter value type integer ideally also use standard encoding 0L 1L negative positive polarity (NA_integer missing). Thus, implementation also make sure input parameter contains expected values (although strictly required).","code":"setReplaceMethod(\"polarity\", \"MsBackendTest\", function(object, value) { if (!all(value %in% c(0, 1, NA))) stop(\"'polarity' should be encoded as 0L (negative), 1L (positive) \", \"with missing values being NA_integer_\") object$polarity <- value object }) polarity(be) <- c(0L, 0L, 0L) polarity(be) ## [1] 0 0 0"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"rtime-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"rtime<-","title":"Creating new `MsBackend` classes","text":"Replace retention times spectra represented backend. Parameter value must type numeric. Also, although strict requirement, retention times ideally ordered increasingly per sample unit seconds.","code":"setReplaceMethod(\"rtime\", \"MsBackendTest\", function(object, value) { object$rtime <- value object }) rtime(be) ## [1] 1.2 1.3 1.4 rtime(be) <- rtime(be) + 2 rtime(be) ## [1] 3.2 3.3 3.4"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"smoothed-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"smoothed<-","title":"Creating new `MsBackend` classes","text":"Replace spectra variable smoothed indicates whether data smoothing operation performed spectra. Parameter value must type logical.","code":"setReplaceMethod(\"smoothed\", \"MsBackendTest\", function(object, value) { object$smoothed <- value object }) smoothed(be) <- rep(TRUE, 3) smoothed(be) ## [1] TRUE TRUE TRUE"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"spectranames-","dir":"Articles","previous_headings":"API > Data replacement methods","what":"spectraNames<-","title":"Creating new `MsBackend` classes","text":"Replace names individual spectras within backend. names, colnames rownames, spectraNames expected type character. backend implementation store spectra names rownames @spectraVars data frame.","code":"setReplaceMethod(\"spectraNames\", \"MsBackendTest\", function(object, value) { rownames(object@spectraVars) <- value object }) spectraNames(be) <- c(\"a\", \"b\", \"c\") spectraNames(be) ## [1] \"a\" \"b\" \"c\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"optional-methods","dir":"Articles","previous_headings":"API","what":"Optional methods","title":"Creating new `MsBackend` classes","text":"Default implementations methods available MsBackend classes, thus methods don’t implemented new backend. backends, depending data represented accessed within , different implementations might however efficient.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"backendbpparam","dir":"Articles","previous_headings":"API > Optional methods","what":"backendBpparam()","title":"Creating new `MsBackend` classes","text":"backendBpparam() method supposed evaluate whether provided (default) parallel processing setup supported backend. Backends support parallel processing return SerialParam() instead. default implementation shown .","code":"setMethod(\"backendBpparam\", signature = \"MsBackend\", function(object, BPPARAM = bpparam()) { ## Return SerialParam() instead to disable parallel processing BPPARAM })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"backendparallelfactor","dir":"Articles","previous_headings":"API > Optional methods","what":"backendParallelFactor()","title":"Creating new `MsBackend` classes","text":"backendParallelFactor() allows backend suggest preferred way backend split parallel processing. See also notes parallel processing information. default implementation returns factor() (.e. factor length 0) hence suggesting splitting:","code":"setMethod(\"backendParallelFactor\", \"MsBackend\", function(object, ...) { factor() })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"backendrequiredspectravariables","dir":"Articles","previous_headings":"API > Optional methods","what":"backendRequiredSpectraVariables()","title":"Creating new `MsBackend` classes","text":"backendRequiredSpectraVariables() method can implemented backend needs specific spectra variables work. default implementation : implementation MsBackendMzR returns c(\"dataStorage\", \"scanIndex\") backend needs two spectra variables load MS data --fly original data files.","code":"setMethod(\"backendRequiredSpectraVariables\", \"MsBackend\", function(object, ...) { character() })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"dropnaspectravariables","dir":"Articles","previous_headings":"API > Optional methods","what":"dropNaSpectraVariables()","title":"Creating new `MsBackend` classes","text":"dropNaSpectraVariables() supposed allow removing spectra variables data set (storage) contain missing values (.e. value spectra variable spectrum NA). function intended reduce memory requirements backends MsBackendMzR load values core spectra variables original data files, even values NA. Removing missing values backend can hence reduce size memory backend without data loss (methods extracting core spectra variables supposed always return NA values even data available - cases NA values supposed created --fly. default implementation shown .","code":"setMethod(\"dropNaSpectraVariables\", \"MsBackend\", function(object) { svs <- spectraVariables(object) svs <- svs[!(svs %in% c(\"mz\", \"intensity\"))] spd <- spectraData(object, columns = svs) keep <- !vapply1l(spd, function(z) all(is.na(z))) selectSpectraVariables(object, c(svs[keep], \"mz\", \"intensity\")) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"isreadonly","dir":"Articles","previous_headings":"API > Optional methods","what":"isReadOnly()","title":"Creating new `MsBackend` classes","text":"isReadOnly() expected return logical(1) either TRUE FALSE indicating whether backend supports replacing data . default implementation shown .","code":"setMethod(\"isReadOnly\", \"MsBackend\", function(object) { object@readonly })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"peaksvariables","dir":"Articles","previous_headings":"API > Optional methods","what":"peaksVariables()","title":"Creating new `MsBackend` classes","text":"peaksVariables() expected return character vector names peaks variables (.e. information properties individual mass peaks) available backend. default implementation MsBackend returns default c(\"mz\", \"intensity\"). method implemented backends (eventually) also provide additional peaks variables. default implementation shown .","code":"setMethod(\"peaksVariables\", \"MsBackend\", function(object) { c(\"mz\", \"intensity\") })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"uniquemslevels","dir":"Articles","previous_headings":"API > Optional methods","what":"uniqueMsLevels()","title":"Creating new `MsBackend` classes","text":"method return unique MS level(s) spectra within backend. default implementation shown . method thus retrieves first MS levels spectra calls unique() . Database-based backends might avoid eventually heavy operation selecting unique MS levels directly using SQL call.","code":"setMethod(\"uniqueMsLevels\", \"MsBackend\", function(object, ...) { unique(msLevel(object)) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"precursormz-","dir":"Articles","previous_headings":"API > Optional methods","what":"precursorMz<-","title":"Creating new `MsBackend` classes","text":"Replace values precursor m/z spectra variable. Parameter value type numeric (NA_real_ missing values supported, e.g. MS1 spectra). default implementation uses $<- method:","code":"setReplaceMethod(\"precursorMz\", \"MsBackend\", function(object, ..., value) { object$precursorMz <- value object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"ioncount","dir":"Articles","previous_headings":"API > Optional methods","what":"ionCount()","title":"Creating new `MsBackend` classes","text":"ionCount() method return numeric (length equal number spectra represented backend) sum intensities within spectrum. empty spectra NA_real_ returned. method default implementation method.","code":"setMethod(\"ionCount\", \"MsBackend\", function(object) { vapply1d(intensity(object), sum, na.rm = TRUE) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"iscentroided","dir":"Articles","previous_headings":"API > Optional methods","what":"isCentroided()","title":"Creating new `MsBackend` classes","text":"method return information spectrum whether centroided. contrast centroided() method heuristic approach used. default implementation shown .","code":"setMethod(\"isCentroided\", \"MsBackend\", function(object, ...) { vapply1l(peaksData(object), .peaks_is_centroided) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"reset","dir":"Articles","previous_headings":"API > Optional methods","what":"reset()","title":"Creating new `MsBackend` classes","text":"special method backends may implement support, don’t necessary . method called reset,Spectra method supposed restore data original state. default implementation MsBackend shown simply returns backend -. MsBackendSql backend MsBackendSql package contrast re-initializes data using data database.","code":"setMethod(\"reset\", \"MsBackend\", function(object) { object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"export","dir":"Articles","previous_headings":"API > Optional methods","what":"export()","title":"Creating new `MsBackend` classes","text":"method export data MsBackend. method called export,Spectra method passes second argument function. export,MsBackend implementation thus expected take Spectra object second argument data taken exported. Implementation method optional. implementation method MsBackendMzR backend shown . See alternatively also MsBackendMgf package implementation MsBackendMgf backend.","code":"setMethod(\"export\", \"MsBackendMzR\", function(object, x, file = tempfile(), format = c(\"mzML\", \"mzXML\"), copy = FALSE, BPPARAM = bpparam()) { l <- length(x) file <- sanitize_file_name(file) if (length(file) == 1) file <- rep_len(file, l) if (length(file) != l) stop(\"Parameter 'file' has to be either of length 1 or \", length(x), \", i.e. 'length(x)'.\", call. = FALSE) f <- factor(file, levels = unique(file)) tmp <- bpmapply(.write_ms_data_mzR, split(x, f), levels(f), MoreArgs = list(format = format, copy = copy), BPPARAM = BPPARAM) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"split","dir":"Articles","previous_headings":"API > Optional methods","what":"split()","title":"Creating new `MsBackend` classes","text":"split() method allow split MsBackend list MsBackend objects. default implementation shown .","code":"setMethod(\"split\", \"MsBackend\", function(x, f, drop = FALSE, ...) { split.default(x, f, drop = drop, ...) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"supportssetbackend","dir":"Articles","previous_headings":"API > Optional methods","what":"supportsSetBackend()","title":"Creating new `MsBackend` classes","text":"Whether MsBackend supports setBackend() method allows change backend Spectra object one another backend. support setBackend() backend needs parameter data backendInitialize() method allows initialized DataFrame containing full spectra data. default implementation shown .","code":"setMethod(\"supportsSetBackend\", \"MsBackend\", function(object, ...) { !isReadOnly(object) })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterdataorigin","dir":"Articles","previous_headings":"API > Optional methods","what":"filterDataOrigin()","title":"Creating new `MsBackend` classes","text":"filter* methods expected take MsBackend subset based criteria. also [ method used perform subset operation, methods might allow efficient ways subset data e.g. performing operation within database dedicated SQL call. default implementation available every filter function thus method needs implemented data storage/representation within backend allow efficient operation. filter methods expected return subset backend (.e. instance backend class , less spectra). filterDataOrigin() subset backend spectra dataOrigin spectra variable matching values provided dataOrigin parameter. default implementation MsBackend shown .","code":"setMethod(\"filterDataOrigin\", \"MsBackend\", function(object, dataOrigin = character()) { if (length(dataOrigin)) { object <- object[dataOrigin(object) %in% dataOrigin] if (is.unsorted(dataOrigin)) object[order(match(dataOrigin(object), dataOrigin))] else object } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterdatastorage","dir":"Articles","previous_headings":"API > Optional methods","what":"filterDataStorage()","title":"Creating new `MsBackend` classes","text":"Similar filterDataOrigin(), filterDataStorage() subset backend spectra dataStorage spectra variable matching values provided dataStorage parameter.","code":"setMethod(\"filterDataStorage\", \"MsBackend\", function(object, dataStorage = character()) { if (length(dataStorage)) { object <- object[dataStorage(object) %in% dataStorage] if (is.unsorted(dataStorage)) object[order(match(dataStorage(object), dataStorage))] else object } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filteremptyspectra","dir":"Articles","previous_headings":"API > Optional methods","what":"filterEmptySpectra()","title":"Creating new `MsBackend` classes","text":"filterEmptySpectra() remove empty spectra (.e. spectra without mass peaks) backend. method expected return subset backend. default implementation MsBackend shown .","code":"setMethod(\"filterEmptySpectra\", \"MsBackend\", function(object, ...) { if (!length(object)) return(object) object[as.logical(lengths(object))] })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterisolationwindow","dir":"Articles","previous_headings":"API > Optional methods","what":"filterIsolationWindow()","title":"Creating new `MsBackend` classes","text":"filterIsolationWindow() filters backend spectra provided mz value within isolationWindowLowerMz() isolationWindowUpperMz(). parameter mz defining target m/z expected numeric length 1. default implementation MsBackend shown .","code":"setMethod(\"filterIsolationWindow\", \"MsBackend\", function(object, mz = numeric(), ...) { if (length(mz)) { if (length(mz) > 1) stop(\"'mz' is expected to be a single m/z value\") keep <- which(isolationWindowLowerMz(object) <= mz & isolationWindowUpperMz(object) >= mz) object[keep] } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filtermslevel","dir":"Articles","previous_headings":"API > Optional methods","what":"filterMsLevel()","title":"Creating new `MsBackend` classes","text":"filterMsLevel() method expected reduce backend spectra provided MS level(s). Parameter msLevel integer (length). default implementation MsBackend shown .","code":"setMethod(\"filterMsLevel\", \"MsBackend\", function(object, msLevel = integer()) { if (length(msLevel)) { object[msLevel(object) %in% msLevel] } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterpolarity","dir":"Articles","previous_headings":"API > Optional methods","what":"filterPolarity()","title":"Creating new `MsBackend` classes","text":"filterPolarity() method expected subset backend spectra matching provided polarity (polarities). Parameter polarity integer (length). default implementation MsBackend shown .","code":"setMethod(\"filterPolarity\", \"MsBackend\", function(object, polarity = integer()) { if (length(polarity)) object[polarity(object) %in% polarity] else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterprecursormzrange","dir":"Articles","previous_headings":"API > Optional methods","what":"filterPrecursorMzRange()","title":"Creating new `MsBackend` classes","text":"filterPrecursorMzRange() method filters backend spectra precursorMz provided m/z range (parameter mz). method previously named filterPrecursorMz(). Parameter mz expected numeric length 2 defining lower upper limit precursor m/z range. default implementation MsBackend shown .","code":"library(MsCoreUtils) ## ## Attaching package: 'MsCoreUtils' ## The following objects are masked from 'package:Spectra': ## ## bin, entropy, smooth ## The following object is masked from 'package:stats': ## ## smooth setMethod(\"filterPrecursorMzRange\", \"MsBackend\", function(object, mz = numeric()) { if (length(mz)) { mz <- range(mz) keep <- which(between(precursorMz(object), mz)) object[keep] } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterprecursormzvalues","dir":"Articles","previous_headings":"API > Optional methods","what":"filterPrecursorMzValues()","title":"Creating new `MsBackend` classes","text":"filterPrecursorMzValues() method filters backend spectra m/z values matching provided m/z value(s). Parameters ppm tolerance (expected numeric length 1) allow define conditions relaxed matching. Parameter mz numeric (length). default implementation MsBackend shown . .values_match_mz function used function defined :","code":"setMethod(\"filterPrecursorMzValues\", \"MsBackend\", function(object, mz = numeric(), ppm = 20, tolerance = 0) { if (length(mz)) { object[.values_match_mz(precursorMz(object), mz = mz, ppm = ppm, tolerance = tolerance)] } else object }) .values_match_mz <- function(x, mz, ppm = 20, tolerance = 0) { o <- order(x, na.last = NA) cmn <- common(x[o], sort(mz), tolerance = tolerance, ppm = ppm, duplicates = \"keep\", .check = FALSE) sort(o[cmn]) }"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterprecursorcharge","dir":"Articles","previous_headings":"API > Optional methods","what":"filterPrecursorCharge()","title":"Creating new `MsBackend` classes","text":"filterPrecursorCharge() method filters backend spectra matching precursor charge. Parameter z defining requested precursor charge integer (length). default implementation MsBackend shown .","code":"setMethod(\"filterPrecursorCharge\", \"MsBackend\", function(object, z = integer()) { if (length(z)) { keep <- which(precursorCharge(object) %in% z) object[keep] } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterprecursorscan","dir":"Articles","previous_headings":"API > Optional methods","what":"filterPrecursorScan()","title":"Creating new `MsBackend` classes","text":"filterPrecursorScan() method filters backend parent (e.g. MS1) children scans (e.g. MS2) acquisition number acquisitionNum. Parameter f defines backend split (default original data file) avoid selecting spectra different samples/files. default implementation MsBackend shown .","code":"setMethod(\"filterPrecursorScan\", \"MsBackend\", function(object, acquisitionNum = integer(), f = dataOrigin(object)) { if (length(acquisitionNum) && length(f)) { if (!is.factor(f)) f <- factor(f, exclude = character()) keep <- unsplit(lapply(split(object, f = f), function(z, an) { .filterSpectraHierarchy(acquisitionNum(z), precScanNum(z), an) }, an = acquisitionNum), f = f) object[keep] } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"filterrt","dir":"Articles","previous_headings":"API > Optional methods","what":"filterRt()","title":"Creating new `MsBackend` classes","text":"filterRt() method filters backend spectra retention time provided rt range. Parameter rt expected numeric length 2 defining lower upper bound range. Parameter msLevel. (note . name parameter!) can optionally used restrict filtering selected MS levels (.e. RT filter applied spectra selected MS levels spectra different MS level returned well). default implementation MsBackend shown .","code":"setMethod(\"filterRt\", \"MsBackend\", function(object, rt = numeric(), msLevel. = uniqueMsLevels(object)) { if (length(rt)) { rt <- range(rt) sel_ms <- msLevel(object) %in% msLevel. sel_rt <- between(rtime(object), rt) & sel_ms object[sel_rt | !sel_ms] } else object })"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"implementation-notes","dir":"Articles","previous_headings":"API","what":"Implementation notes","title":"Creating new `MsBackend` classes","text":"tutorial implemented simple -memory MsBackend scratch. many real-life situation might however better extend pre-defined backend classes Spectra package avoid duplicating functionality. good starting point might MsBackendMemory backend -memory data representation, MsBackendCached backends retrieve data inherently read-resources (database connection raw data files) still need support adding spectra variables changing values spectra variables. Similarly, purpose backend import export data specific format, MsBackendMemory might extended single method (backendInitialize()) need implemented new class: new backendInitialize() call code import data new file format store within available slots MsBackendMemory object. Examples backends provided MsBackendMgf MsBackendMsp classes.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"testing-the-validity-of-the-backend","dir":"Articles","previous_headings":"","what":"Testing the validity of the backend","title":"Creating new `MsBackend` classes","text":"Spectra package provides set unit tests allow check backend compliance MsBackend. load test suite call tests. tests performed variable current workspace (case instance MsBackendTest class).","code":"library(testthat) test_suite <- system.file(\"test_backends\", \"test_MsBackend\", package = \"Spectra\") test_dir(test_suite, stop_on_failure = TRUE)"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/MsBackend.html","id":"session-information","dir":"Articles","previous_headings":"","what":"Session information","title":"Creating new `MsBackend` classes","text":"","code":"sessionInfo() ## R Under development (unstable) (2024-12-10 r87437) ## Platform: x86_64-pc-linux-gnu ## Running under: Ubuntu 24.04.1 LTS ## ## Matrix products: default ## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0 ## ## locale: ## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C ## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 ## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 ## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C ## [9] LC_ADDRESS=C LC_TELEPHONE=C ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C ## ## time zone: UTC ## tzcode source: system (glibc) ## ## attached base packages: ## [1] stats4 stats graphics grDevices utils datasets methods ## [8] base ## ## other attached packages: ## [1] MsCoreUtils_1.19.0 IRanges_2.41.2 Spectra_1.17.3 ## [4] BiocParallel_1.41.0 S4Vectors_0.45.2 BiocGenerics_0.53.3 ## [7] generics_0.1.3 BiocStyle_2.35.0 ## ## loaded via a namespace (and not attached): ## [1] cli_3.6.3 knitr_1.49 rlang_1.1.4 ## [4] xfun_0.49 ProtGenerics_1.39.0 textshaping_0.4.1 ## [7] clue_0.3-66 jsonlite_1.8.9 htmltools_0.5.8.1 ## [10] ragg_1.3.3 sass_0.4.9 rmarkdown_2.29 ## [13] evaluate_1.0.1 jquerylib_0.1.4 MASS_7.3-61 ## [16] fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4 ## [19] bookdown_0.41 BiocManager_1.30.25 cluster_2.1.8 ## [22] compiler_4.5.0 codetools_0.2-20 fs_1.6.5 ## [25] htmlwidgets_1.6.4 MetaboCoreUtils_1.15.0 systemfonts_1.1.0 ## [28] digest_0.6.37 R6_2.5.1 parallel_4.5.0 ## [31] bslib_0.8.0 tools_4.5.0 pkgdown_2.1.1.9000 ## [34] cachem_1.1.0 desc_1.4.3"},{"path":[]},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra-large-scale.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Large-scale data handling and processing with Spectra","text":"Spectra package supports handling processing also large mass spectrometry (MS) data sets. dedicated backends, load MS data requested/needed, memory demand can minimized. Examples backends MsBackendMzR MsBackendOfflineSql (defined MsBackendSql package). addition, Spectra supports chunk-wise data processing, hence parts data loaded memory processed time. document provide information large scale data can best processed Spectra package.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra-large-scale.html","id":"memory-requirements-of-different-data-representations","dir":"Articles","previous_headings":"","what":"Memory requirements of different data representations","title":"Large-scale data handling and processing with Spectra","text":"Spectra package separates functionality process analyze MS data (implemented Spectra class) code defines MS data stored. latter, different implementations MsBackend class available, either optimized performance (MsBackendMemory MsBackendDataFrame) low memory requirement (MsBackendMzR, MsBackendOfflineSql implemented MsBackendSql package, smallest possible memory footprint enables also analysis large data sets). load MS data 4 test files Spectra using MsBackendMzR backend. resulting Spectra uses MsBackendMzR data representation. backend load general spectra data memory full MS data (.e., m/z intensity values individual mass peaks) loaded requested needed. contrast -memory backend, memory footprint backend thus lower. create Spectra keeps full data memory changing backend MsBackendMemory backend compare sizes objects. Keeping full data memory requires thus considerably memory. next disable parallel processing Spectra allow unbiased estimation memory usage.","code":"library(Spectra) #' Define the file names from which to import the data fls <- c( system.file(\"TripleTOF-SWATH\", \"PestMix1_DDA.mzML\", package = \"msdata\"), system.file(\"TripleTOF-SWATH\", \"PestMix1_SWATH.mzML\", package = \"msdata\"), system.file(\"sciex\", \"20171016_POOL_POS_1_105-134.mzML\", package = \"msdata\"), system.file(\"sciex\", \"20171016_POOL_POS_3_105-134.mzML\", package = \"msdata\")) #' Creating a Spectra object representing the MS data sps_mzr <- Spectra(fls, source = MsBackendMzR()) sps_mzr ## MSn data (Spectra) with 18463 spectra in a MsBackendMzR backend: ## msLevel rtime scanIndex ## ## 1 1 0.231 1 ## 2 1 0.351 2 ## 3 1 0.471 3 ## 4 1 0.591 4 ## 5 1 0.711 5 ## ... ... ... ... ## 18459 1 258.636 927 ## 18460 1 258.915 928 ## 18461 1 259.194 929 ## 18462 1 259.473 930 ## 18463 1 259.752 931 ## ... 33 more variables/columns. ## ## file(s): ## PestMix1_DDA.mzML ## PestMix1_SWATH.mzML ## 20171016_POOL_POS_1_105-134.mzML ## ... 1 more files sps_mem <- setBackend(sps_mzr, MsBackendMemory()) print(object.size(sps_mzr), units = \"MB\") ## 5.2 Mb print(object.size(sps_mem), units = \"MB\") ## 140.1 Mb #' Disable parallel processing globally register(SerialParam())"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra-large-scale.html","id":"chunk-wise-and-parallel-processing","dir":"Articles","previous_headings":"","what":"Chunk-wise and parallel processing","title":"Large-scale data handling and processing with Spectra","text":"Operations peaks data time memory demanding tasks. generally apply function , modify m/z /intensity values. Among functions example functions filter, remove combine mass peaks (filterMzRange(), filterIntensity() combinePeaks()) functions perform calculations peaks data (bin() pickPeaks()) also functions provide information , summarize spectra (lengths() ionCount()). functions, peaks data needs present memory -disk backends, MsBackendMzR, need thus first import data data storage. However, loading full peaks data memory might possible large data sets. Loading processing data smaller chunks however reduce memory demand hence allow process also data sets. MsBackendMzR MsBackendHdf5Peaks backends data automatically split processed data storage files. backends chunk-wise processing can enabled defining processingChunkSize Spectra, .e. number spectra peaks data loaded processed iteration. processingChunkFactor() function can used evaluate data split. use function evaluate chunk-wise processing performed two Spectra objects. Spectra -memory backend empty factor() returned, thus, chunk-wise processing performed. next evaluate whether Spectra MsBackendMzR -disk backend use chunk-wise processing. data thus split processed original file, data imported. next specifically define chunk-size Spectra processingChunkSize() function. setting chunk size, also Spectra -memory backend use chunk-wise processing. repeat Spectra object: Spectra MsBackendMzR backend now split data equally sized arbitrary chunks longer original data file. Setting processingChunkSize thus overrides splitting suggested backend. set processingChunkSize, operation involving peaks data default performed chunk-wise manner. Thus, calling ionCount() Spectra now split data chunks 3000 spectra sum intensities (per spectrum) chunk chunk. chunk-wise processing reduces memory demand operations, splitting merging data results can negatively impact performance. Thus, small data sets Spectra -memory backends generally benefit type processing. computationally intense operation hand, chunk-wise processing advantage, chunks can () processed parallel (depending parallel processing setup). Note chunk-wise processing affects functions involve actual peak data. Subset operations reduce number spectra (filterRt() [) bypass mechanism applied immediately data. evaluation chunk-wise processing see also issue Spectra github repository.","code":"processingChunkFactor(sps_mem) ## factor() ## Levels: processingChunkFactor(sps_mzr) |> table() ## ## /__w/_temp/Library/msdata/TripleTOF-SWATH/PestMix1_DDA.mzML ## 7602 ## /__w/_temp/Library/msdata/TripleTOF-SWATH/PestMix1_SWATH.mzML ## 8999 ## /__w/_temp/Library/msdata/sciex/20171016_POOL_POS_1_105-134.mzML ## 931 ## /__w/_temp/Library/msdata/sciex/20171016_POOL_POS_3_105-134.mzML ## 931 processingChunkSize(sps_mem) <- 3000 processingChunkFactor(sps_mem) |> table() ## ## 1 2 3 4 5 6 7 ## 3000 3000 3000 3000 3000 3000 463 processingChunkSize(sps_mzr) <- 3000 processingChunkFactor(sps_mzr) |> table() ## ## 1 2 3 4 5 6 7 ## 3000 3000 3000 3000 3000 3000 463 tic <- ionCount(sps_mem)"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra-large-scale.html","id":"notes-and-suggestions-for-parallel-or-chunk-wise-processing","dir":"Articles","previous_headings":"","what":"Notes and suggestions for parallel or chunk-wise processing","title":"Large-scale data handling and processing with Spectra","text":"Estimating memory usage R tends difficult, MS data sets 100 samples whenever processing tends take longer expected suggested enable chunk-wise processing (already used, MsBackendMzR). Spectra uses BiocParallel package parallel processing. parallel processing setup can configured globally registering preferred setup using register() function (e.g. register(SnowParam(4)) use socket-based parallel processing Windows using 4 different R processes). Parallel processing can disabled setting register(SerialParam()). Chunk-wise processing default run parallel, depending configured parallel processing setup. Parallel processing (also chunk-wise processing) computational overhead, data needs split merged. Thus, operations data sets avoiding mechanism can efficient (e.g. -memory backends small data sets).","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra-large-scale.html","id":"spectra-functions-supporting-or-using-parallel-processing","dir":"Articles","previous_headings":"","what":"Spectra functions supporting or using parallel processing","title":"Large-scale data handling and processing with Spectra","text":"functions allow configure parallel processing using dedicated parameter allows define split data parallel (chunk-wise) processing. functions : applyProcessing(): parameter f (defaults processingChunkFactor(object)) can used define split process data parallel. combineSpectra(): parameter p (defaults x$dataStorage) defines data split processed parallel. estimatePrecursorIntensity(): parameter f (defaults dataOrigin(x)) defines splitting processing. represent original data files spectra data derives . intensity(): parameter f (defaults processingChunkFactor(object)) defines data split parallel processing. mz(): parameter f (defaults processingChunkFactor(object)) defines data split parallel processing. peaksData(): parameter f (defaults processingChunkFactor(object)) defines data split parallel processing. setBackend(): parameter f (defaults processingChunkFactor(object)) defines data split parallel processing. Functions perform chunk-wise (parallel) processing natively, .e., based processingChunkFactor: containsMz(). containsNeutralLoss(). ionCount(). isCentroided(). isEmpty().","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra-large-scale.html","id":"session-information","dir":"Articles","previous_headings":"","what":"Session information","title":"Large-scale data handling and processing with Spectra","text":"","code":"sessionInfo() ## R Under development (unstable) (2024-12-10 r87437) ## Platform: x86_64-pc-linux-gnu ## Running under: Ubuntu 24.04.1 LTS ## ## Matrix products: default ## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0 ## ## locale: ## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C ## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 ## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 ## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C ## [9] LC_ADDRESS=C LC_TELEPHONE=C ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C ## ## time zone: UTC ## tzcode source: system (glibc) ## ## attached base packages: ## [1] stats4 stats graphics grDevices utils datasets methods ## [8] base ## ## other attached packages: ## [1] Spectra_1.17.3 BiocParallel_1.41.0 S4Vectors_0.45.2 ## [4] BiocGenerics_0.53.3 generics_0.1.3 BiocStyle_2.35.0 ## ## loaded via a namespace (and not attached): ## [1] jsonlite_1.8.9 compiler_4.5.0 BiocManager_1.30.25 ## [4] Rcpp_1.0.13-1 Biobase_2.67.0 parallel_4.5.0 ## [7] cluster_2.1.8 jquerylib_0.1.4 systemfonts_1.1.0 ## [10] IRanges_2.41.2 textshaping_0.4.1 yaml_2.3.10 ## [13] fastmap_1.2.0 R6_2.5.1 ProtGenerics_1.39.0 ## [16] knitr_1.49 htmlwidgets_1.6.4 MASS_7.3-61 ## [19] bookdown_0.41 desc_1.4.3 bslib_0.8.0 ## [22] rlang_1.1.4 cachem_1.1.0 xfun_0.49 ## [25] fs_1.6.5 MsCoreUtils_1.19.0 sass_0.4.9 ## [28] cli_3.6.3 pkgdown_2.1.1.9000 ncdf4_1.23 ## [31] digest_0.6.37 mzR_2.41.1 MetaboCoreUtils_1.15.0 ## [34] lifecycle_1.0.4 clue_0.3-66 evaluate_1.0.1 ## [37] codetools_0.2-20 ragg_1.3.3 rmarkdown_2.29 ## [40] tools_4.5.0 htmltools_0.5.8.1"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Description and usage of Spectra objects","text":"Spectra package provides scalable flexible infrastructure represent, retrieve handle mass spectrometry (MS) data. Spectra object provides user single standardized interface access manipulate MS data supporting, concept exchangeable backends, large variety different ways store retrieve mass spectrometry data. backends range mzML/mzXML/CDF files, simple flat files, database systems. vignette provides general examples descriptions Spectra package. Additional information tutorials available, SpectraTutorials, MetaboAnnotationTutorials, also (Rainer et al. 2022). information handle (parallel) process large-scale data sets see Large-scale data handling processing Spectra vignette.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"installation","dir":"Articles","previous_headings":"","what":"Installation","title":"Description and usage of Spectra objects","text":"package can installed BiocManager package. install BiocManager use install.packages(\"BiocManager\") , , BiocManager::install(\"Spectra\") install Spectra.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"general-usage","dir":"Articles","previous_headings":"","what":"General usage","title":"Description and usage of Spectra objects","text":"Mass spectrometry data Spectra objects can thought list individual spectra, spectrum set variables associated . Besides core spectra variables (MS level retention time) arbitrary number optional variables can assigned spectrum. core spectra variables accessor method guaranteed value returned (NA information available). core variables data type (alphabetically ordered): acquisitionNum integer(1): index acquisition spectrum MS run. centroided logical(1): whether spectrum profile centroid mode. collisionEnergy numeric(1): collision energy used create MSn spectrum. dataOrigin character(1): origin spectrum’s data, e.g. mzML file read. dataStorage character(1): (current) storage location spectrum data. value depends backend used handle provide data. -memory backend like MsBackendDataFrame \"\", -disk backend MsBackendHdf5Peaks name HDF5 file spectrum’s peak data stored. intensity numeric: intensity values spectrum’s peaks. isolationWindowLowerMz numeric(1): lower m/z isolation window (MSn) spectrum measured. isolationWindowTargetMz numeric(1): target m/z isolation window (MSn) spectrum measured. isolationWindowUpperMz numeric(1): upper m/z isolation window (MSn) spectrum measured. msLevel integer(1): MS level spectrum. mz numeric: m/z values spectrum’s peaks. polarity integer(1): polarity spectrum (0 1 representing negative positive polarity, respectively). precScanNum integer(1): scan (acquisition) number precursor MSn spectrum. precursorCharge integer(1): charge precursor MSn spectrum. precursorIntensity numeric(1): intensity precursor MSn spectrum. precursorMz numeric(1): m/z precursor MSn spectrum. rtime numeric(1): retention time spectrum. scanIndex integer(1): index spectrum within (raw) file. smoothed logical(1): whether spectrum smoothed. details individual variables getter/setter function see help Spectra (?Spectra). Also note variables suggested, required characterize spectrum. Also, make sense MSn, MS1 spectra.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"creating-spectra-objects","dir":"Articles","previous_headings":"General usage","what":"Creating Spectra objects","title":"Description and usage of Spectra objects","text":"simplest way create Spectra object defining DataFrame corresponding spectra data (using corresponding spectra variable names column names) passing Spectra constructor function. create object set 3 spectra providing MS level, olarity also additional annotations ID HMDB (human metabolome database) name. m/z intensity values spectrum provided list numeric values. Alternatively, possible import spectra data mass spectrometry raw files mzML/mzXML CDF format. create Spectra object two mzML files define use MsBackendMzR backend store data (note requires mzR package installed). backend, specifically designed raw MS data, keeps subset spectra variables memory reading m/z intensity values original data files demand. See section Backends details backends properties. Spectra object sps_sciex allows now access spectra data 1862 MS1 spectra uses MsBackendMzR backend (Spectra object sps created previous code block uses default MsBackendMemory).","code":"library(Spectra) spd <- DataFrame( msLevel = c(2L, 2L, 2L), polarity = c(1L, 1L, 1L), id = c(\"HMDB0000001\", \"HMDB0000001\", \"HMDB0001847\"), name = c(\"1-Methylhistidine\", \"1-Methylhistidine\", \"Caffeine\")) ## Assign m/z and intensity values. spd$mz <- list( c(109.2, 124.2, 124.5, 170.16, 170.52), c(83.1, 96.12, 97.14, 109.14, 124.08, 125.1, 170.16), c(56.0494, 69.0447, 83.0603, 109.0395, 110.0712, 111.0551, 123.0429, 138.0662, 195.0876)) spd$intensity <- list( c(3.407, 47.494, 3.094, 100.0, 13.240), c(6.685, 4.381, 3.022, 16.708, 100.0, 4.565, 40.643), c(0.459, 2.585, 2.446, 0.508, 8.968, 0.524, 0.974, 100.0, 40.994)) sps <- Spectra(spd) sps ## MSn data (Spectra) with 3 spectra in a MsBackendMemory backend: ## msLevel rtime scanIndex ## ## 1 2 NA NA ## 2 2 NA NA ## 3 2 NA NA ## ... 18 more variables/columns. fls <- dir(system.file(\"sciex\", package = \"msdata\"), full.names = TRUE) sps_sciex <- Spectra(fls, source = MsBackendMzR()) sps_sciex ## MSn data (Spectra) with 1862 spectra in a MsBackendMzR backend: ## msLevel rtime scanIndex ## ## 1 1 0.280 1 ## 2 1 0.559 2 ## 3 1 0.838 3 ## 4 1 1.117 4 ## 5 1 1.396 5 ## ... ... ... ... ## 1858 1 258.636 927 ## 1859 1 258.915 928 ## 1860 1 259.194 929 ## 1861 1 259.473 930 ## 1862 1 259.752 931 ## ... 33 more variables/columns. ## ## file(s): ## 20171016_POOL_POS_1_105-134.mzML ## 20171016_POOL_POS_3_105-134.mzML"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"accessing-spectrum-data","dir":"Articles","previous_headings":"General usage","what":"Accessing spectrum data","title":"Description and usage of Spectra objects","text":"detailed Spectra objects can contain arbitrary number properties spectrum (called spectra variables). available variables can listed spectraVariables() method: two Spectra contain different set variables: besides \"msLevel\", \"polarity\", \"id\" \"name\", specified Spectra object sps, contains variables \"rtime\", \"acquisitionNum\" \"scanIndex\". part core variables defining spectrum accessor methods exist. use msLevel() rtime() access MS levels retention times spectra sps. specify retention times spectra sps thus NA returned . Spectra object sps_sciex contains many variables, extracted mzML files. extract retention times first spectra object. Note addition accessor functions also possible use $ extract specific spectra variable. extract name compounds sps can use sps$name, , extract MS levels sps$msLevel. also replace specific spectra variables using either dedicated method $. specify spectra sps represent centroided data. $ operator can also used add arbitrary new spectra variables Spectra object. add SPLASH key spectra. new spectra variable now listed additional variable result spectraVariables() function can directly access content sps$splash. spectrum can different number mass peaks, consisting mass--charge (m/z) associated intensity value. can extracted mz() intensity() functions, return list numeric values. Peak data can also extracted peaksData() function returns list numerical matrices peak variables m/z intensity values. peak variables available Spectra object can determined peaksVariables() function. can passed peaksData() function parameter columns extract peak variables interest. default peaksData() extracts m/z intensity values. Note get result using () method coerce Spectra object list SimpleList: spectraData() function returns DataFrame full data spectrum (except m/z intensity values), selected spectra variables (can specified columns parameter). extract spectra data variables \"msLevel\", \"id\" \"name\". Spectra one-dimensional objects storing spectra, even different files samples, single list. Specific variables thus used define originating file extracted sample measured. data origin spectrum can extracted dataOrigin() function. sps, Spectra created DataFrame, NA specify data origin: dataOrigin sps_sciex, Spectra initialized data mzML files, contrast, returns originating file names: current data storage location spectrum can retrieved dataStorage variable, return arbitrary string Spectra use -memory backend file data stored -disk backends: Certain backends (MsBackendMemory MsBackendDataFrame) support also additional peaks variables. present, must already present backend gets initialized. future dedicated function allowing add peaks variables available. thus first extract full data (including peaks variables) sps spectra object add column \"peak_anno\" peak annotations individual peak. Importantly, peak variables, value needs assigned individual peak, even NA (lengths() new peak variable must match lengths() mz intensity, .e. number peaks per spectrum). parameter peaksVariables() (currently available backendInitialize() method MsBackendMemory MsBackendDataFrame) allows define columns input data contain peaks variables (case \"mz\", \"intensity\" additional \"peak_anno\" column). Full peak data can extracted peaksData() function second parameter columns allowing define peak variables return. extract peak data second spectrum. can also use peaksData() function extract values individual peak variables. Peak variables can also extracted using $ method: Similar spectra variables also possible replace values existing peaks variables using $<- function.","code":"spectraVariables(sps) ## [1] \"msLevel\" \"rtime\" ## [3] \"acquisitionNum\" \"scanIndex\" ## [5] \"dataStorage\" \"dataOrigin\" ## [7] \"centroided\" \"smoothed\" ## [9] \"polarity\" \"precScanNum\" ## [11] \"precursorMz\" \"precursorIntensity\" ## [13] \"precursorCharge\" \"collisionEnergy\" ## [15] \"isolationWindowLowerMz\" \"isolationWindowTargetMz\" ## [17] \"isolationWindowUpperMz\" \"id\" ## [19] \"name\" spectraVariables(sps_sciex) ## [1] \"msLevel\" \"rtime\" ## [3] \"acquisitionNum\" \"scanIndex\" ## [5] \"dataStorage\" \"dataOrigin\" ## [7] \"centroided\" \"smoothed\" ## [9] \"polarity\" \"precScanNum\" ## [11] \"precursorMz\" \"precursorIntensity\" ## [13] \"precursorCharge\" \"collisionEnergy\" ## [15] \"isolationWindowLowerMz\" \"isolationWindowTargetMz\" ## [17] \"isolationWindowUpperMz\" \"peaksCount\" ## [19] \"totIonCurrent\" \"basePeakMZ\" ## [21] \"basePeakIntensity\" \"ionisationEnergy\" ## [23] \"lowMZ\" \"highMZ\" ## [25] \"mergedScan\" \"mergedResultScanNum\" ## [27] \"mergedResultStartScanNum\" \"mergedResultEndScanNum\" ## [29] \"injectionTime\" \"filterString\" ## [31] \"spectrumId\" \"ionMobilityDriftTime\" ## [33] \"scanWindowLowerLimit\" \"scanWindowUpperLimit\" msLevel(sps) ## [1] 2 2 2 rtime(sps) ## [1] NA NA NA head(rtime(sps_sciex)) ## [1] 0.280 0.559 0.838 1.117 1.396 1.675 sps$name ## [1] \"1-Methylhistidine\" \"1-Methylhistidine\" \"Caffeine\" sps$msLevel ## [1] 2 2 2 sps$centroided <- TRUE centroided(sps) ## [1] TRUE TRUE TRUE sps$splash <- c( \"splash10-00di-0900000000-037d24a7d65676b7e356\", \"splash10-00di-0900000000-03e99316bd6c098f5d11\", \"splash10-000i-0900000000-9af60e39c843cb715435\") mz(sps) ## NumericList of length 3 ## [[1]] 109.2 124.2 124.5 170.16 170.52 ## [[2]] 83.1 96.12 97.14 109.14 124.08 125.1 170.16 ## [[3]] 56.0494 69.0447 83.0603 109.0395 110.0712 111.0551 123.0429 138.0662 195.0876 intensity(sps) ## NumericList of length 3 ## [[1]] 3.407 47.494 3.094 100 13.24 ## [[2]] 6.685 4.381 3.022 16.708 100 4.565 40.643 ## [[3]] 0.459 2.585 2.446 0.508 8.968 0.524 0.974 100 40.994 peaksVariables(sps) ## [1] \"mz\" \"intensity\" pks <- peaksData(sps) pks[[1]] ## mz intensity ## [1,] 109.20 3.407 ## [2,] 124.20 47.494 ## [3,] 124.50 3.094 ## [4,] 170.16 100.000 ## [5,] 170.52 13.240 as(sps, \"SimpleList\") ## List of length 3 spectraData(sps, columns = c(\"msLevel\", \"id\", \"name\")) ## DataFrame with 3 rows and 3 columns ## msLevel id name ## ## 1 2 HMDB0000001 1-Methylhistidine ## 2 2 HMDB0000001 1-Methylhistidine ## 3 2 HMDB0001847 Caffeine dataOrigin(sps) ## [1] NA NA NA head(basename(dataOrigin(sps_sciex))) ## [1] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## [3] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## [5] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" dataStorage(sps) ## [1] \"\" \"\" \"\" head(basename(dataStorage(sps_sciex))) ## [1] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## [3] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## [5] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## Extract the full data from a spectrum spd <- spectraData(sps, columns = union(spectraVariables(sps), peaksVariables(sps))) ## Add a new column with a *annotation* for each peak spd$peak_anno <- list(c(\"a\", NA_character_, \"b\", \"c\", \"d\"), c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\"), c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\")) ## lengths have to match: lengths(spd$peak_anno) ## [1] 5 7 9 lengths(spd$mz) ## [1] 5 7 9 sps2 <- Spectra(spd, backend = MsBackendMemory(), peaksVariables = c(\"mz\", \"intensity\", \"peak_anno\")) peaksVariables(sps2) ## [1] \"mz\" \"intensity\" \"peak_anno\" peaksData(sps2, columns = peaksVariables(sps2))[[2L]] ## mz intensity peak_anno ## 1 83.10 6.685 a ## 2 96.12 4.381 b ## 3 97.14 3.022 c ## 4 109.14 16.708 d ## 5 124.08 100.000 e ## 6 125.10 4.565 f ## 7 170.16 40.643 g ## Peak annotations for the first spectrum peaksData(sps2, \"peak_anno\")[[1L]] ## peak_anno ## 1 a ## 2 ## 3 b ## 4 c ## 5 d ## Peak annotations for the second spectrum peaksData(sps2, \"peak_anno\")[[2L]] ## peak_anno ## 1 a ## 2 b ## 3 c ## 4 d ## 5 e ## 6 f ## 7 g sps2$peak_anno ## [[1]] ## [1] \"a\" NA \"b\" \"c\" \"d\" ## ## [[2]] ## [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" ## ## [[3]] ## [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" \"h\" \"i\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"filtering-aggregating-and-merging-spectra-data","dir":"Articles","previous_headings":"General usage","what":"Filtering, aggregating and merging spectra data","title":"Description and usage of Spectra objects","text":"Various functions available filter, subset merge Spectra objects. can generally subdivided functions subset filter spectra data operations filter mass peak data. third category function allows aggregate data within Spectra merge combine multiple Spectra objects one. Functions various categories described following subsections. Please refer function’s documentation details information.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"filter-spectra-data","dir":"Articles","previous_headings":"General usage > Filtering, aggregating and merging spectra data","what":"Filter spectra data","title":"Description and usage of Spectra objects","text":"functions comprise subset operations reduce total number spectra Spectra object well filter functions reduce content Spectra’s spectra data (.e. content spectraVariables()). functions thus don’t change affect mass peaks data Spectra’s individual spectra. [: operation reduce Spectra object selected elements. dropNaSpectraVariables(): drops spectraVariables() contain missing values. function returns Spectra object number elements, eventually fewer spectra variables. filterAcquisitionNum(): retains spectra certain acquisition numbers. filterDataOrigin(): subsets spectra specific origins. filterDataStorage(): subsets spectra certain data storage files. filterEmptySpectra(): removes spectra without mass peaks. filterIsolationWindow(): keeps spectra provided mz isolation window (m/z range). filterMsLevel(): filters MS level. filterPolarity(): filters polarity. filterPrecursorCharge(): retains (MSn) spectra specified precursor charge(s). filterPrecursorIsotopes(): identifies precursor ions (fragment spectra) represent isotopes molecule. spectra groups spectrum monoisotopic precursor ion returned. MS1 spectra returned without filtering. filterPrecursorMaxIntensity(): filters spectra keeping, groups spectra similar precursor m/z, one spectrum highest precursor intensity. MS1 spectra returned without filtering. filterPrecursorMzRange(): retains (MSn) spectra precursor m/z within provided m/z range. filterPrecursorMzValues((): retains (MSn) spectra precursor m/z value matching provided value(s) considering also tolerance ppm. filterPrecursorScan(): retains (parent children) scans acquisition number. filterRanges(): filters Spectra object based (multiple) user defined numeric ranges one available (numeric) spectra variables. filterRt(): filters based retention time range. filterValues(): filters Spectra object based similarities numeric values one available spectra variables. selectSpectraVariables(): reduces (spectra) data within object selected spectra variables.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"filter-or-aggregate-mass-peak-data","dir":"Articles","previous_headings":"General usage > Filtering, aggregating and merging spectra data","what":"Filter or aggregate mass peak data","title":"Description and usage of Spectra objects","text":"function filter aggregate mass peak data (peaksData()) spectrum Spectra without changing total number spectra. combinePeaks(): groups peaks within spectrum based similarity m/z values combines single peak per peak group. deisotopeSpectra(): deisotopes individual spectrum keeping monoisotopic peak peaks groups potential isotopologues. filterFourierTransformArtefacts(): removes (Orbitrap) fast fourier transform artifact peaks spectra. filterIntensity(): filter spectrum keeping peaks intensities meeting certain criteria. filterMzRange(): filters mass peaks keeping (removing) m/z within provided m/z range. filterMzValues(): filters mass peaks within spectrum keeping (removing) m/z matching provided value(s). filterPeaksRanges(): filters mass peaks using set range-based filters numeric spectra peaks variables. filterPrecursorPeaks(): removes peaks either m/z value matching precursor m/z respective spectrum (parameter mz = \"==\") peaks m/z value larger equal precursor m/z (parameter mz = \">=\"). reduceSpectra(): filters individual spectra keeping largest peak groups peaks similar m/z values.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"merging-aggregating-and-splitting","dir":"Articles","previous_headings":"General usage > Filtering, aggregating and merging spectra data","what":"Merging, aggregating and splitting","title":"Description and usage of Spectra objects","text":"c(): combine several Spectra single Spectra object. combineSpectra(): allows combine MS data sets spectra single spectrum per set. Thus, instead filtering data, function aggregates . joinSpectraData(): merge DataFrame existing spectra data. split(): splits Spectra object based provided grouping factor.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"examples-and-use-cases-for-filter-operations","dir":"Articles","previous_headings":"General usage > Filtering, aggregating and merging spectra data","what":"Examples and use cases for filter operations","title":"Description and usage of Spectra objects","text":"example, use filterValues() function retain spectra base peak m/z close 100 (+/- 30 ppm) retention time around 230 (+/- 5 s). , demonstrate usage filterRanges() function filter spectra based ranges values variables base peak m/z, peak count, retention time. one spectrum matches ranges. Another option filterValues() filterRanges() use parameter match = \"\", retains spectra match one conditions instead match . Let’s run code change match parameter time: can see many spectra passed filtering step time. example use specific functions select spectra measured second mzML file subsequently filter retain spectra measured 175 189 seconds measurement run. addition, Spectra support also subsetting [. perform filtering [ -based subsetting. equivalent using filter function shown , added benefit filtering recorded processing slot. Note use filter functions might efficient backends, depending implementation, (e.g. database-based backends translate filter function SQL condition perform subsetting already within database). Multiple Spectra objects can also combined single Spectra c() concatenateSpectra() function. resulting Spectra object contain union spectra variables individual objects. combine Spectra object sps additional object containing another MS2 spectrum Caffeine. Next combine two objects. resulting object contains now data 4 MS2 spectra union spectra variables objects. second object additional spectra variable instrument present sps spectra object thus get value NA variable. Sometimes spectra variables might required (e.g. also many empty). might specifically interesting also Spectra containing data large experiments, can significantly reduce object’s size memory. cases selectSpectraVariables() function can used retain specified spectra variables.","code":"sps_sub <- filterValues(sps_sciex, spectraVariables = c(\"basePeakMZ\", \"rtime\"), values = c(123.089, 230), tolerance = c(0,5), ppm = c(30, 0), match = \"all\") length(sps_sub) ## [1] 72 sps_ranges <- filterRanges(sps_sciex, spectraVariables = c(\"basePeakMZ\",\"peaksCount\", \"rtime\"), ranges = c(123.09,124, 3500, 3520, 259, 260), match = \"all\") length(sps_ranges) ## [1] 1 sps_ranges <- filterRanges(sps_sciex, spectraVariables = c(\"basePeakMZ\", \"peaksCount\", \"rtime\"), ranges = c(123.09, 124, 3500, 3520, 259, 260), match = \"any\") length(sps_ranges) ## [1] 473 fls <- unique(dataOrigin(sps_sciex)) file_2 <- filterDataOrigin(sps_sciex, dataOrigin = fls[2]) length(file_2) ## [1] 931 sps_sub <- filterRt(file_2, rt = c(175, 189)) length(sps_sub) ## [1] 50 sps_sciex[sps_sciex$dataOrigin == fls[2] & sps_sciex$rtime >= 175 & sps_sciex$rtime <= 189] ## MSn data (Spectra) with 50 spectra in a MsBackendMzR backend: ## msLevel rtime scanIndex ## ## 1 1 175.212 628 ## 2 1 175.491 629 ## 3 1 175.770 630 ## 4 1 176.049 631 ## 5 1 176.328 632 ## ... ... ... ... ## 46 1 187.768 673 ## 47 1 188.047 674 ## 48 1 188.326 675 ## 49 1 188.605 676 ## 50 1 188.884 677 ## ... 33 more variables/columns. ## ## file(s): ## 20171016_POOL_POS_3_105-134.mzML sps_sciex |> filterDataOrigin(fls[2]) |> filterRt(c(175, 189)) ## MSn data (Spectra) with 50 spectra in a MsBackendMzR backend: ## msLevel rtime scanIndex ## ## 1 1 175.212 628 ## 2 1 175.491 629 ## 3 1 175.770 630 ## 4 1 176.049 631 ## 5 1 176.328 632 ## ... ... ... ... ## 46 1 187.768 673 ## 47 1 188.047 674 ## 48 1 188.326 675 ## 49 1 188.605 676 ## 50 1 188.884 677 ## ... 33 more variables/columns. ## ## file(s): ## 20171016_POOL_POS_3_105-134.mzML ## Processing: ## Filter: select data origin(s) /__w/_temp/Library/msdata/sciex/20171016_POOL_POS_3_105-134.mzML [Mon Dec 16 09:28:27 2024] ## Filter: select retention time [175..189] on MS level(s) 1 [Mon Dec 16 09:28:27 2024] caf_df <- DataFrame(msLevel = 2L, name = \"Caffeine\", id = \"HMDB0001847\", instrument = \"Agilent 1200 RRLC; Agilent 6520 QTOF\", splash = \"splash10-0002-0900000000-413259091ba7edc46b87\", centroided = TRUE) caf_df$mz <- list(c(110.0710, 138.0655, 138.1057, 138.1742, 195.9864)) caf_df$intensity <- list(c(3.837, 32.341, 0.84, 0.534, 100)) caf <- Spectra(caf_df) sps <- concatenateSpectra(sps, caf) sps ## MSn data (Spectra) with 4 spectra in a MsBackendMemory backend: ## msLevel rtime scanIndex ## ## 1 2 NA NA ## 2 2 NA NA ## 3 2 NA NA ## 4 2 NA NA ## ... 20 more variables/columns. ## Processing: ## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024] spectraVariables(sps) ## [1] \"msLevel\" \"rtime\" ## [3] \"acquisitionNum\" \"scanIndex\" ## [5] \"dataStorage\" \"dataOrigin\" ## [7] \"centroided\" \"smoothed\" ## [9] \"polarity\" \"precScanNum\" ## [11] \"precursorMz\" \"precursorIntensity\" ## [13] \"precursorCharge\" \"collisionEnergy\" ## [15] \"isolationWindowLowerMz\" \"isolationWindowTargetMz\" ## [17] \"isolationWindowUpperMz\" \"id\" ## [19] \"name\" \"splash\" ## [21] \"instrument\" sps$instrument ## [1] NA ## [2] NA ## [3] NA ## [4] \"Agilent 1200 RRLC; Agilent 6520 QTOF\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"data-manipulations","dir":"Articles","previous_headings":"General usage","what":"Data manipulations","title":"Description and usage of Spectra objects","text":"analyses require manipulation mass peak data (.e. m/z /intensity values). One example remove peaks spectrum intensity lower certain threshold. perform operation replaceIntensitiesBelow() function replace peak intensities 10 spectrum sps value 0. result intensities 10 set 0 peaks. Zero-intensity peaks (peaks missing intensities) can removed filterIntensity() function specifying lower required intensity level optionally also upper intensity limit. filterIntensity() supports also user-provided function passed parameter intensity allow e.g. remove peaks smaller median peak intensity spectrum. See examples ?filterIntensity help page details. Note data manipulations Spectra objects immediately applied peak data. added called processing queue applied time peak data accessed (peaksData(), mz() intensity() functions). Thanks processing queue data manipulation operations also possible read-backends (e.g. mzML-file based backends database-based backends). information number processing steps can seen (next Lazy evaluation queue). possible add also custom functions processing queue Spectra object. function must take peaks matrix first argument, ... function definition must return peaks matrix (peaks matrix numeric two-column matrix first column containing peaks’ m/z values second corresponding intensities). define function divides intensities peak value can passed argument y. Object sps_2 now 3 processing steps lazy evaluation queue. Calling intensity() object now return intensities half intensities original objects sps. Alternatively define function returns maximum peak spectrum (note: use unname() function remove names results): spectrum sps_2 thus contains single peak. parameter spectraVariables addProcessing() function allows addition define spectra variables passed (addition peaks matrix) user-provided function. enable example calculate neutral loss spectra Spectra subtracting precursor m/z m/z spectrum (note also dedicated neutralLoss() function perform operation efficiently). tool example precursor m/z values defined, thus first set arbitrary values. define function neutral_loss calculates difference precursor m/z fragment peak’s m/z. addition need ensure peaks resulting spectra ordered (delta) m/z values. Note , order able access precursor m/z spectrum within function, add parameter function name spectrum variable want access (case precursorMz). call addProcessing() spectraVariables = \"precursorMz\" specify spectra variable passed along function. can see, precursor m/z subtracted m/z respective spectrum. better version function, calculates neutral loss spectra MS level 2 spectra neutral_loss function . Since accessing also spectrum’s MS level call addProcessing() adding also spectra variable msLevel spectraVariables parameter. Note however msLevel spectra variable default renamed spectrumMsLevel prior passing function. thus use parameter called spectrumMsLevel neutral_loss function instead msLevel. Using concept also possible provide spectrum-specific user-defined value processing function. variable simply added first new spectra variable Spectra object variable passed along function way passed precursor m/z function . Another example spectra processing potentially helpful spectral matching reference fragment spectra libraries function removes fragment peaks m/z matching precursor m/z spectrum. define function takes peaks matrix precursor m/z input evaluates closest() function MsCoreUtils whether spectrum contains peaks m/z value matching one precursor (given tolerance ppm). returned peaks matrix contains peaks except matching precursor m/z. can now add processing step Spectra object. result, peaks matching precursor m/z (tolerance = 0.1 ppm = 0) removed. reference, original peak matrices shown . Note can also perform relaxed matching m/z values passing different value tolerance function: Since data manipulations change original intensity m/z values, possible restore original data. can done reset() function empty lazy evaluation queue call reset() method storage backend. call reset() sps_2 object hence restore data original state. Finally, Spectra use writeable backend, MsBackendMemory, MsBackendDataFrame MsBackendHdf5Peaks, possible apply processing queue peak data write back data storage applyProcessing() function. use make data manipulations peak data sps_rep object persistent. applyProcessing() lazy evaluation queue contained 2 processing steps, applied peak data written data storage. Note calling reset() applyProcessing() can longer restore data.","code":"sps_rep <- replaceIntensitiesBelow(sps, threshold = 10, value = 0) intensity(sps_rep) ## NumericList of length 4 ## [[1]] 0 47.494 0 100 13.24 ## [[2]] 0 0 0 16.708 100 0 40.643 ## [[3]] 0 0 0 0 0 0 0 100 40.994 ## [[4]] 0 32.341 0 0 100 sps_rep <- filterIntensity(sps_rep, intensity = c(0.1, Inf)) intensity(sps_rep) ## NumericList of length 4 ## [[1]] 47.494 100 13.24 ## [[2]] 16.708 100 40.643 ## [[3]] 100 40.994 ## [[4]] 32.341 100 sps_rep ## MSn data (Spectra) with 4 spectra in a MsBackendMemory backend: ## msLevel rtime scanIndex ## ## 1 2 NA NA ## 2 2 NA NA ## 3 2 NA NA ## 4 2 NA NA ## ... 20 more variables/columns. ## Lazy evaluation queue: 2 processing step(s) ## Processing: ## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024] ## Signal <= 10 in MS level(s) 2 set to 0 [Mon Dec 16 09:28:27 2024] ## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Mon Dec 16 09:28:27 2024] ## Define a function that takes a matrix as input, divides the second ## column by parameter y and returns it. Note that ... is required in ## the function's definition. divide_intensities <- function(x, y, ...) { x[, 2] <- x[, 2] / y x } ## Add the function to the procesing queue sps_2 <- addProcessing(sps_rep, divide_intensities, y = 2) sps_2 ## MSn data (Spectra) with 4 spectra in a MsBackendMemory backend: ## msLevel rtime scanIndex ## ## 1 2 NA NA ## 2 2 NA NA ## 3 2 NA NA ## 4 2 NA NA ## ... 20 more variables/columns. ## Lazy evaluation queue: 3 processing step(s) ## Processing: ## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024] ## Signal <= 10 in MS level(s) 2 set to 0 [Mon Dec 16 09:28:27 2024] ## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Mon Dec 16 09:28:27 2024] intensity(sps_2) ## NumericList of length 4 ## [[1]] 23.747 50 6.62 ## [[2]] 8.354 50 20.3215 ## [[3]] 50 20.497 ## [[4]] 16.1705 50 intensity(sps_rep) ## NumericList of length 4 ## [[1]] 47.494 100 13.24 ## [[2]] 16.708 100 40.643 ## [[3]] 100 40.994 ## [[4]] 32.341 100 max_peak <- function(x, ...) { unname(x[which.max(x[, 2]), , drop = FALSE]) } sps_2 <- addProcessing(sps_rep, max_peak) lengths(sps_2) ## [1] 1 1 1 1 intensity(sps_2) ## NumericList of length 4 ## [[1]] 100 ## [[2]] 100 ## [[3]] 100 ## [[4]] 100 sps_rep$precursorMz <- c(170.5, 170.5, 195.1, 195.1) neutral_loss <- function(x, precursorMz, ...) { x[, \"mz\"] <- precursorMz - x[, \"mz\"] x[order(x[, \"mz\"]), , drop = FALSE] } sps_3 <- addProcessing(sps_rep, neutral_loss, spectraVariables = \"precursorMz\") mz(sps_rep) ## NumericList of length 4 ## [[1]] 124.2 170.16 170.52 ## [[2]] 109.14 124.08 170.16 ## [[3]] 138.0662 195.0876 ## [[4]] 138.0655 195.9864 mz(sps_3) ## NumericList of length 4 ## [[1]] -0.0200000000000102 0.340000000000003 46.3 ## [[2]] 0.340000000000003 46.42 61.36 ## [[3]] 0.0123999999999853 57.0338 ## [[4]] -0.886400000000009 57.0345 neutral_loss <- function(x, spectrumMsLevel, precursorMz, ...) { if (spectrumMsLevel == 2L) { x[, \"mz\"] <- precursorMz - x[, \"mz\"] x <- x[order(x[, \"mz\"]), , drop = FALSE] } x } sps_3 <- addProcessing(sps_rep, neutral_loss, spectraVariables = c(\"msLevel\", \"precursorMz\")) mz(sps_3) ## NumericList of length 4 ## [[1]] -0.0200000000000102 0.340000000000003 46.3 ## [[2]] 0.340000000000003 46.42 61.36 ## [[3]] 0.0123999999999853 57.0338 ## [[4]] -0.886400000000009 57.0345 library(MsCoreUtils) ## ## Attaching package: 'MsCoreUtils' ## The following objects are masked from 'package:Spectra': ## ## bin, entropy, smooth ## The following object is masked from 'package:stats': ## ## smooth remove_precursor <- function(x, precursorMz, tolerance = 0.1, ppm = 0, ...) { if (!is.na(precursorMz)) { keep <- is.na(closest(x[, \"mz\"], precursorMz, tolerance = tolerance, ppm = ppm, .check = FALSE)) x[keep, , drop = FALSE] } else x } sps_4 <- addProcessing(sps_rep, remove_precursor, spectraVariables = \"precursorMz\") peaksData(sps_4) |> as.list() ## [[1]] ## mz intensity ## [1,] 124.20 47.494 ## [2,] 170.16 100.000 ## ## [[2]] ## mz intensity ## [1,] 109.14 16.708 ## [2,] 124.08 100.000 ## [3,] 170.16 40.643 ## ## [[3]] ## mz intensity ## [1,] 138.0662 100 ## ## [[4]] ## mz intensity ## [1,] 138.0655 32.341 ## [2,] 195.9864 100.000 peaksData(sps_rep) |> as.list() ## [[1]] ## mz intensity ## [1,] 124.20 47.494 ## [2,] 170.16 100.000 ## [3,] 170.52 13.240 ## ## [[2]] ## mz intensity ## [1,] 109.14 16.708 ## [2,] 124.08 100.000 ## [3,] 170.16 40.643 ## ## [[3]] ## mz intensity ## [1,] 138.0662 100.000 ## [2,] 195.0876 40.994 ## ## [[4]] ## mz intensity ## [1,] 138.0655 32.341 ## [2,] 195.9864 100.000 sps_4 <- addProcessing(sps_rep, remove_precursor, tolerance = 0.6, spectraVariables = \"precursorMz\") peaksData(sps_4) |> as.list() ## [[1]] ## mz intensity ## [1,] 124.2 47.494 ## ## [[2]] ## mz intensity ## [1,] 109.14 16.708 ## [2,] 124.08 100.000 ## ## [[3]] ## mz intensity ## [1,] 138.0662 100 ## ## [[4]] ## mz intensity ## [1,] 138.0655 32.341 ## [2,] 195.9864 100.000 sps_2_rest <- reset(sps_2) intensity(sps_2_rest) ## NumericList of length 4 ## [[1]] 3.407 47.494 3.094 100 13.24 ## [[2]] 6.685 4.381 3.022 16.708 100 4.565 40.643 ## [[3]] 0.459 2.585 2.446 0.508 8.968 0.524 0.974 100 40.994 ## [[4]] 3.837 32.341 0.84 0.534 100 intensity(sps) ## NumericList of length 4 ## [[1]] 3.407 47.494 3.094 100 13.24 ## [[2]] 6.685 4.381 3.022 16.708 100 4.565 40.643 ## [[3]] 0.459 2.585 2.446 0.508 8.968 0.524 0.974 100 40.994 ## [[4]] 3.837 32.341 0.84 0.534 100 length(sps_rep@processingQueue) ## [1] 2 sps_rep <- applyProcessing(sps_rep) length(sps_rep@processingQueue) ## [1] 0 sps_rep ## MSn data (Spectra) with 4 spectra in a MsBackendMemory backend: ## msLevel rtime scanIndex ## ## 1 2 NA NA ## 2 2 NA NA ## 3 2 NA NA ## 4 2 NA NA ## ... 20 more variables/columns. ## Processing: ## Merge 2 Spectra into one [Mon Dec 16 09:28:27 2024] ## Signal <= 10 in MS level(s) 2 set to 0 [Mon Dec 16 09:28:27 2024] ## Remove peaks with intensities outside [0.1, Inf] in spectra of MS level(s) 2. [Mon Dec 16 09:28:27 2024] ## ...1 more processings. Use 'processingLog' to list all."},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"visualizing-spectra","dir":"Articles","previous_headings":"General usage","what":"Visualizing Spectra","title":"Description and usage of Spectra objects","text":"Spectra package provides following functions visualize spectra data: - plotSpectra(): plot spectrum Spectra panel. - plotSpectraOverlay(): plot multiple spectra plot. use plotSpectra() plot 4 spectra sps object using names (provided spectra variable \"name\") plot titles. also possible label individual peaks plot. use m/z value peak label. example define function accesses information spectrum (z) returns character peak text used label. Parameters labelSrt, labelPos labelOffset define rotation label text position relative x y coordinates peak. plots rather busy peaks m/z values overplotted. define label function indicate m/z peaks intensity higher 30. Sometimes might interest plot multiple spectra plot (e.g. directly compare peaks multiple spectra). can done plotSpectraOverlay() use create overlay-plot 4 example spectra, using different color spectrum. Lastly, plotSpectraMirror() allows plot two spectra mirror plot ideal visualize spectra comparison results. plot spectrum 1-Methylhistidine one Caffeine. upper panel shows spectrum 1-Methylhistidine, lower one Caffeine. None peaks two spectra match. plot two spectra 1-Methylhistidine two Caffeine matching peaks ppm 50. See also ?plotSpectra plotting options examples.","code":"plotSpectra(sps, main = sps$name) plotSpectra(sps, main = sps$name, labels = function(z) format(mz(z)[[1L]], digits = 4), labelSrt = -30, labelPos = 2, labelOffset = 0.1) mzLabel <- function(z) { z <- peaksData(z)[[1L]] lbls <- format(z[, \"mz\"], digits = 4) lbls[z[, \"intensity\"] < 30] <- \"\" lbls } plotSpectra(sps, main = sps$name, labels = mzLabel, labelSrt = -30, labelPos = 2, labelOffset = 0.1) cols <- c(\"#E41A1C80\", \"#377EB880\", \"#4DAF4A80\", \"#984EA380\") plotSpectraOverlay(sps, lwd = 2, col = cols) legend(\"topleft\", col = cols, legend = sps$name, pch = 15) plotSpectraMirror(sps[1], sps[3]) par(mfrow = c(1, 2)) plotSpectraMirror(sps[1], sps[2], main = \"1-Methylhistidine\", ppm = 50) plotSpectraMirror(sps[3], sps[4], main = \"Caffeine\", ppm = 50)"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"aggregating-spectra-data","dir":"Articles","previous_headings":"General usage","what":"Aggregating spectra data","title":"Description and usage of Spectra objects","text":"Spectra package provides combineSpectra() function allows aggregate multiple spectra single one. main parameters function f, defines sets spectra combined, FUN, allows define function performs actual aggregation. default aggregation function combinePeaksData() (see ?combinePeaksData details) combines multiple spectra single spectrum peaks input spectra (additional paramter peaks = \"union\"), peaks present certain proportion input spectra (parameter peaks = \"intersect\"; parameter minProp allows define minimum required proportion spectra peak needs present. important mention , default, function combines mass peaks spectra similar m/z value single, representative mass peak aggregating intensities one. avoid resulting intensity affected potential noise peaks might advised first clean individual mass spectra using e.g. combinePeaks() reduceSpectra() functions first aggregate mass peaks within individual spectrum. example use combineSpectra() combine spectra 1-methylhistidine caffeine single spectrum compound. use spectra variable $name, contains names compounds, define spectra grouped together. result, 4 spectra got aggregated two. default, peaks present spectra reported. alternative, specifying peaks = \"intersect\" minProp = 1, combine spectra keeping peaks present input spectra. results thus single peak 1-methylhistidine none caffeine - ? reason difference peaks’ m/z values larger default tolerance used peak grouping (defaults combinePeaksData() tolerance = 0 ppm = 0). however already see previous section reported peaks’ m/z values larger measurement error (likely fragment spectra measured different instruments different precision). Thus, next increase tolerance ppm parameters group also peaks larger difference m/z values. Whether real analysis OK large tolerance however questionable. Note: m/z intensity reported aggregated spectra can defined parameters intensityFun mzFun combinePeaksData() (see ?combinePeaksData information). combinePeaksData() function indeed helpful combine peaks different spectra, combineSpectra() function addition also allow us provide , custom, peak aggregation function. simple example, instead combining spectra, like select one input spectra representative spectrum grouped input spectra. combineSpectra() supports function takes list peak matrices input returns single peak matrix output. thus define function calculates total signal (TIC) input peak matrix, returns one peak matrix largest TIC. can now use function combineSpectra() select compound spectrum largest TIC.","code":"sps_agg <- combineSpectra(sps, f = sps$name) plotSpectra(sps_agg, main = sps_agg$name) sps_agg <- combineSpectra(sps, f = sps$name, peaks = \"intersect\", minProp = 1) plotSpectra(sps_agg, main = sps_agg$name) sps_agg <- combineSpectra(sps, f = sps$name, peaks = \"intersect\", minProp = 1, tolerance = 0.2) plotSpectra(sps_agg, main = sps_agg$name) #' function to select and return the peak matrix with the largest tic from #' the provided list of peak matrices. maxTic <- function(x, ...) { tic <- vapply(x, function(z) sum(z[, \"intensity\"], na.rm = TRUE), numeric(1)) x[[which.max(tic)]] } sps_agg <- combineSpectra(sps, f = sps$name, FUN = maxTic) plotSpectra(sps_agg, main = sps_agg$name)"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"comparing-spectra","dir":"Articles","previous_headings":"General usage","what":"Comparing spectra","title":"Description and usage of Spectra objects","text":"Spectra can compared compareSpectra() function, allows calculate similarities spectra using variety methods. compareSpectra() implements similarity scoring two-step approach: first peaks pair spectra compared matched (mapped) similarity score calculated . MAPFUN parameter compareSpectra() defines function match (map) peaks spectra parameter FUN specifies function calculate similarity. default, compareSpectra() uses MAPFUN = joinPeaks (see ?joinPeaks description alternative options) FUN = ndotproduct (normalized dot-product spectra similarity score). Parameters configure functions can passed compareSpectra() additional parameter (e.g. ppm define m/z-relative tolerance peak matching joinPeaks()). calculate pairwise similarities spectra sps accepting 50 ppm difference peaks’ m/z values considered matching. resulting matrix provides similarity scores pairwise comparison. expected, first two last two spectra similar, albeit moderately, spectra 1-Methylhistidine don’t share similarity Caffeine. Similarities Spectra objects can calculated calls form compareSpectra(, b) b two Spectra objects compare. result n x m matrix returned n (rows) spectra m (columns) spectra b. similarity calculated default (normalized) dot-product, also similarity scores can used instead. Either one metrics provided MsCoreUtils used (see ?MsCoreUtils::distance list available options) external user-provided similarity scoring function. example, use spectral entropy similarity score introduced (Y et al. 2021) provided msentropy package. Since msentropy_similarity() function performs also mapping peaks compared spectra internally (along spectra cleaning), disable compareSpectra() function using MAPFUN = joinPeaksNone. configure similarity scoring can pass additional parameters msentropy_similarity() (see ?msentropy_similarity) compareSpectra() call. use ms2_tolerance_in_ppm = 50 set tolerance m/z-relative peak matching (equivalent ppm = 50 used ) ms2_tolerance_in_da = -1 disable absolute tolerance matching. Note also GNPS-like scores can calculated MAPFUN = joinPeaksGnps FUN = MsCoreUtils::gnps. additional information examples see also (Rainer et al. 2022) SpectraTutorials tutorial. Another way comparing spectra bin spectra cluster based similar intensity values. Spectra binning ensures binned m/z values comparable across spectra. bin spectra using bin size 0.1 (.e. peaks m/z smaller 0.1 aggregated one binned peak. , explicitly set zero.rm = FALSE retain bins generated function, including intensity zero. spectra now number m/z values. intensity values however 0 (original spectra peak respective m/z bin present). ’re next creating intensity matrix Spectra object, row one spectrum columns representing binned m/z values. can now identify columns (m/z bins) 0s across spectra remove . associated m/z values bins can extracted mz() binned Spectra object. use column names intensity matrix. intensity matrix now example used cluster spectra based peak intensities. expected, first 2 last 2 spectra similar clustered together.","code":"compareSpectra(sps, ppm = 50) ## 1 2 3 4 ## 1 1.0000000 0.1380817 0.0000000 0.0000000 ## 2 0.1380817 1.0000000 0.0000000 0.0000000 ## 3 0.0000000 0.0000000 1.0000000 0.1817149 ## 4 0.0000000 0.0000000 0.1817149 1.0000000 library(msentropy) ## Loading required package: Rcpp compareSpectra(sps, MAPFUN = joinPeaksNone, FUN = msentropy_similarity, ms2_tolerance_in_ppm = 50, ms2_tolerance_in_da = -1) ## 1 2 3 4 ## 1 1.0000000 0.3002225 0.0000000 0.0000000 ## 2 0.3002225 1.0000000 0.0000000 0.0000000 ## 3 0.0000000 0.0000000 1.0000000 0.5144764 ## 4 0.0000000 0.0000000 0.5144764 1.0000000 sps_bin <- Spectra::bin(sps, binSize = 0.1, zero.rm = FALSE) lengths(sps_bin) ## [1] 1400 1400 1400 1400 intensity(sps_bin) ## NumericList of length 4 ## [[1]] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [[2]] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ## [[3]] 0.459 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 40.994 0 0 0 0 0 0 0 0 0 ## [[4]] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 intmat <- do.call(rbind, intensity(sps_bin)) zeros <- colSums(intmat) == 0 intmat <- intmat[, !zeros] intmat ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] ## [1,] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 3.407 0.000 0.000 0.000 ## [2,] 0.000 0.000 0.000 6.685 4.381 3.022 0.000 16.708 0.000 0.000 0.000 0.000 ## [3,] 0.459 2.585 2.446 0.000 0.000 0.000 0.508 0.000 0.000 8.968 0.524 0.974 ## [4,] 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 3.837 0.000 0.000 ## [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] ## [1,] 0 47.494 3.094 0.000 0.000 0.000 100.000 13.24 0.000 0 ## [2,] 100 0.000 0.000 4.565 0.000 0.000 40.643 0.00 0.000 0 ## [3,] 0 0.000 0.000 0.000 100.000 0.000 0.000 0.00 40.994 0 ## [4,] 0 0.000 0.000 0.000 32.341 1.374 0.000 0.00 0.000 100 colnames(intmat) <- mz(sps_bin)[[1L]][!zeros] heatmap(intmat)"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"exporting-spectra","dir":"Articles","previous_headings":"General usage","what":"Exporting spectra","title":"Description and usage of Spectra objects","text":"Spectra data can exported export() method. method takes Spectra supposed exported backend (parameter backend) used export data additional parameters export function backend. backend thus defines format exported file. Note however MsBackend classes might support data export. backend classes currently supporting data export format : - MsBackendMzR (Spectra package): export data mzML mzXML format. Can export custom, user specified spectra variables. - MsBackendMgf (MsBackendMgf package): exports data Mascot Generic Format (mgf). Exports spectra variables individual spectrum fields mgf file. - MsBackendMsp (MsBackendMsp): exports data NIST MSP format. - MsBackendMassbank (MsBackendMassbank) exports data Massbank text file format. example use MsBackendMzR export spectra variable sps mzML file. thus pass data, backend used export file name result file (temporary file) export() function (see also help page export,MsBackendMzR function additional supported parameters). evaluate spectra variables exported, load exported data identify spectra variables original file exported (defined variables mzML standard). additional variables thus exported. data export performed handled depends also used backend. MsBackendMzR example exports spectra default single file (specified file parameter), allows also specify individual spectrum Spectra file exported (parameter file thus length equal number spectra). example export spectrum 1 3 one file spectra 2 4 another. realistic use case mzML export export MS data processing, smoothing (using smooth() function) centroiding (using pickPeaks() function) raw profile-mode MS data.","code":"fl <- tempfile() export(sps, MsBackendMzR(), file = fl) ## Writing file file1fd57b32f0f7...OK sps_im <- Spectra(backendInitialize(MsBackendMzR(), fl)) spectraVariables(sps)[!spectraVariables(sps) %in% spectraVariables(sps_im)] ## [1] \"id\" \"name\" \"splash\" \"instrument\" fls <- c(tempfile(), tempfile()) export(sps, MsBackendMzR(), file = fls[c(1, 2, 1, 2)]) ## Writing file file1fd5713b4525...OK ## Writing file file1fd51d89ecd...OK"},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"changing-backends","dir":"Articles","previous_headings":"General usage","what":"Changing backends","title":"Description and usage of Spectra objects","text":"previous sections learned already Spectra object can use different backends actual data handling. also possible change backend Spectra different one setBackend() function. example change (MsBackendMzR) backend sps_sciex object MsBackendMemory backend enable use data even without need keep original mzML files. change backend sps_sciex -memory MsBackendMemory backend. call full peak data imported original mzML files object. obviously impact object’s size, now much larger . dataStorage spectrum variable now changed, dataOrigin still keeps information originating files:","code":"print(object.size(sps_sciex), units = \"Mb\") ## 0.4 Mb sps_sciex <- setBackend(sps_sciex, MsBackendMemory()) sps_sciex ## MSn data (Spectra) with 1862 spectra in a MsBackendMemory backend: ## msLevel rtime scanIndex ## ## 1 1 0.280 1 ## 2 1 0.559 2 ## 3 1 0.838 3 ## 4 1 1.117 4 ## 5 1 1.396 5 ## ... ... ... ... ## 1858 1 258.636 927 ## 1859 1 258.915 928 ## 1860 1 259.194 929 ## 1861 1 259.473 930 ## 1862 1 259.752 931 ## ... 33 more variables/columns. ## Processing: ## Switch backend from MsBackendMzR to MsBackendMemory [Mon Dec 16 09:28:33 2024] print(object.size(sps_sciex), units = \"Mb\") ## 53.2 Mb head(dataStorage(sps_sciex)) ## [1] \"\" \"\" \"\" \"\" \"\" \"\" head(basename(dataOrigin(sps_sciex))) ## [1] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## [3] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\" ## [5] \"20171016_POOL_POS_1_105-134.mzML\" \"20171016_POOL_POS_1_105-134.mzML\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"backends","dir":"Articles","previous_headings":"","what":"Backends","title":"Description and usage of Spectra objects","text":"Backends allow use different backends store mass spectrometry data providing via Spectra class unified interface use data. abstraction -disk -memory data modes MSnbase (Gatto, Gibb, Rainer 2020). Spectra package defines set example backends object extending base MsBackend class used instead. default backends : MsBackendMemory: default backend store data memory. Due design MsBackendMemory provides fast access peaks matrices (using peaksData() function) also optimized fast access spectra variables subsetting. Since data kept memory, backend relatively large memory footprint (depending data) thus suggested large MS experiments. MsBackendDataFrame: mass spectrometry data stored (-memory) DataFrame. Keeping data memory guarantees high performance also, depending number mass peaks spectrum, much higher memory footprint. MsBackendMzR: backend keeps general spectra variables memory relies mzR package read mass peaks (m/z intensity values) original MS files -demand. MsBackendHdf5Peaks: similar MsBackendMzR backend reads peak data -demand disk spectra variables kept memory. peak data stored Hdf5 files guarantees scalability. mentioned backends support changing spectra variables, except MsBackendMzR support changing m/z intensity values mass peaks. example load data single mzML file use MsBackendHdf5Peaks backend data storage. hdf5path parameter allows us specify storage location HDF5 file. (possibly incomplete) list R packages providing additional backends add support additional data types storage options provided : MsBackendCompDb (package CompoundDb): provides access spectra data (spectra peaks variables) CompDb database. small memory footprint data (except precursor m/z values) retrieved --fly database. MsBackendHmdbXml (package MsbackendHmdb): allows import MS data xml files Human Metabolome Database (HMDB). Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendMassbank (package MsBackendMassbank): allows import/export data MassBank text file format. Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendMassbankSql (package MsBackendMassbank): allows directly connect MassBank SQL database retrieve MS data variables. minimal memory footprint data retrieved --fly SQL database. MsBackendMetaboLights (package r BiocStyle::Biocpkg(\"MsBackendMetaboLights\")): retrieves caches MS data files MetaboLights repository. MsBackendMgf: (package MsBackendMgf): support import/export mass spectrometry files mascot generic format (MGF). MsBackendMsp: (package MsBackendMsp): allows import/export data NIST MSP format. Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendRawFileReader (package MsBackendRawFileReader): implements backend reading MS data Thermo Fisher Scientific’s raw data files using manufacturer’s NewRawFileReader .Net libraries. package generalizes functionality introduced rawrr package, see also (Kockmann Panse 2021). MsBackendSql (package MsBackendSql): stores MS data SQL database thus minimal memory footprint. MsBackendTimsTof (package MsBackendTimsTof: allows import data Bruker TimsTOF raw data files (using opentimsr R package). MsBackendWeizMass (package MsBackendWeizMass: allows access MS data WeizMass MS/MS spectral databases.","code":"library(msdata) fl <- proteomics(full.names = TRUE)[5] sps_tmt <- Spectra(fl, backend = MsBackendHdf5Peaks(), hdf5path = tempdir()) head(basename(dataStorage(sps_tmt))) ## [1] \"TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.h5\" ## [2] \"TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.h5\" ## [3] \"TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.h5\" ## [4] \"TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.h5\" ## [5] \"TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.h5\" ## [6] \"TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.mzML.h5\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"handling-very-large-data-sets","dir":"Articles","previous_headings":"","what":"Handling very large data sets","title":"Description and usage of Spectra objects","text":"Spectra package designed support also efficient processing large data sets. functionality require keep full MS data memory (specifically, peaks data, .e., m/z intensity values, represent largest chunk data MS experiments). functions however peaks data needs loaded memory. One example lengths() function determine number peaks per spectra calculated (fly) evaluating number rows peaks matrix. Backends MsBackendMzR perform default data processing separately (eventually parallel) data file thus safe call functions Spectra object backend. backends (MsBackendSql MsBackendMassbankSql) however advised process data chunk-wise manner using spectrapply() function parameter chunkSize. split original Spectra object chunks size chunkSize applies function separately chunk. way data one chunk eventually loaded memory iteration enabling process also large Spectra objects computers limited hardware resources. Instead lengths(sps) call, number peaks per spectra also determined (less memory demanding way) spectrapply(sps, lengths, chunkSize = 5000L). way peak data 5000 spectra time loaded memory.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"serializing-saving-moving-and-loading-serialized-spectra-objects","dir":"Articles","previous_headings":"","what":"Serializing (saving), moving and loading serialized Spectra objects","title":"Description and usage of Spectra objects","text":"Serializing re-loading variables/objects analysis using e.g. save() load() functions common many workflows, especially tasks computationally intensive take long time. Sometimes serialized objects might even moved one computer (file system) another. operations unproblematic Spectra objects -memory backends MsBackendMemory MsBackendDataFrame, keep data memory, however break -disk backends MsBackendMzR file path original data files identical. thus suggested (size MS data respectively available system memory allows ) change backend Spectra objects MsBackendMemory serializing object save(). Spectra objects MsBackendMzR alternative option eventually update/adapt path directory containing raw (e.g. mzML) data files: assuming data files available computers, path directory containing can updated dataStorageBasePath<- function allowing thus move/copy serialized Spectra objects computers file systems. example workflow : files .mzML, b.mzML stored directory /data/mzML/ one computer. get loaded Spectra object MsBackendMzR serialized file .RData. Assuming file gets now copied another computer (data available folder /data/mzML/) loaded load(). Spectra object valid MsBackendMzR can longer access MS data original data files. Assuming user also copied data files .mzML b.mzML, folder /some_other_folder/, base storage path object need adapted match directory data files available second computer: pointing now storage path new storage location data files, Spectra object also usable second computer.","code":"A <- Spectra(c(\"/data/mzML/a.mzML\", \"/data/mzML/b.mzML\")) save(A, file = \"A.RData\") load(\"A.RData\") dataStorageBasePath(A) <- \"/some_other_folder\""},{"path":"https://rformassspectrometry.github.io/Spectra/articles/Spectra.html","id":"session-information","dir":"Articles","previous_headings":"","what":"Session information","title":"Description and usage of Spectra objects","text":"","code":"sessionInfo() ## R Under development (unstable) (2024-12-10 r87437) ## Platform: x86_64-pc-linux-gnu ## Running under: Ubuntu 24.04.1 LTS ## ## Matrix products: default ## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0 ## ## locale: ## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C ## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 ## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 ## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C ## [9] LC_ADDRESS=C LC_TELEPHONE=C ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C ## ## time zone: UTC ## tzcode source: system (glibc) ## ## attached base packages: ## [1] stats4 stats graphics grDevices utils datasets methods ## [8] base ## ## other attached packages: ## [1] msdata_0.47.0 msentropy_0.1.4 Rcpp_1.0.13-1 ## [4] MsCoreUtils_1.19.0 Spectra_1.17.3 BiocParallel_1.41.0 ## [7] S4Vectors_0.45.2 BiocGenerics_0.53.3 generics_0.1.3 ## [10] BiocStyle_2.35.0 ## ## loaded via a namespace (and not attached): ## [1] jsonlite_1.8.9 compiler_4.5.0 BiocManager_1.30.25 ## [4] Biobase_2.67.0 rhdf5filters_1.19.0 parallel_4.5.0 ## [7] cluster_2.1.8 jquerylib_0.1.4 systemfonts_1.1.0 ## [10] IRanges_2.41.2 textshaping_0.4.1 yaml_2.3.10 ## [13] fastmap_1.2.0 R6_2.5.1 ProtGenerics_1.39.0 ## [16] knitr_1.49 htmlwidgets_1.6.4 MASS_7.3-61 ## [19] bookdown_0.41 desc_1.4.3 bslib_0.8.0 ## [22] rlang_1.1.4 cachem_1.1.0 xfun_0.49 ## [25] fs_1.6.5 sass_0.4.9 cli_3.6.3 ## [28] Rhdf5lib_1.29.0 pkgdown_2.1.1.9000 ncdf4_1.23 ## [31] digest_0.6.37 mzR_2.41.1 MetaboCoreUtils_1.15.0 ## [34] rhdf5_2.51.1 lifecycle_1.0.4 clue_0.3-66 ## [37] evaluate_1.0.1 codetools_0.2-20 ragg_1.3.3 ## [40] rmarkdown_2.29 tools_4.5.0 htmltools_0.5.8.1"},{"path":[]},{"path":"https://rformassspectrometry.github.io/Spectra/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"RforMassSpectrometry Package Maintainer. Maintainer. Laurent Gatto. Author. Johannes Rainer. Author. Sebastian Gibb. Author. Philippine Louail. Author. Jan Stanstrup. Contributor. Nir Shahaf. Contributor. Mar Garcia-Aloy. Contributor.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Rainer J, Vicini , Salzer L, Stanstrup J, Badia JM, Neumann S, Stravs MA, Verri Hernandes V, Gatto L, Gibb S Wittin M. Modular Expandable Ecosystem Metabolomics Data Annotation R Metabolites 2022, 12, 173. https://doi.org/10.3390/metabo12020173","code":"@Article{, title = {A Modular and Expandable Ecosystem for Metabolomics Data Annotation in R}, author = {Johannes Rainer and Andrea Vicini and Liesa Salzer and Jan Stanstrup and Josep M. Badia and Steffen Neumann and Michael A. Stravs and Vinicius {Verri Hernandes} and Laurent Gatto and Sebastian Gibb and Michael Witting}, journal = {Metabolites}, year = {2022}, doi = {10.3390/metabo12020173}, url = {https://www.mdpi.com/2218-1989/12/2/173}, volume = {12}, pages = {173}, }"},{"path":"https://rformassspectrometry.github.io/Spectra/index.html","id":"low-level-infrastructure-to-handle-ms-spectra","dir":"","previous_headings":"","what":"Spectra Infrastructure for Mass Spectrometry Data","title":"Spectra Infrastructure for Mass Spectrometry Data","text":"Spectra package defines efficient infrastructure storing handling mass spectrometry spectra functionality subset, process, visualize compare spectra data. provides different implementations (backends) store mass spectrometry data. comprise backends tuned fast data access processing backends large data sets ensuring small memory footprint. (possibly incomplete) list available backends (along link R package providing ) shown : MsBackendCompDb (package CompoundDb: provides access spectra data (spectra peaks variables) CompDb database. small memory footprint data (except precursor m/z values) retrieved --fly database. MsBackendDataFrame (package: Spectra): alternative MsBackendMemory also keeping data memory, supporting S4 objects spectra variables data stored internally DataFrame. MsBackendHdf5Peaks (package: Spectra): -disk backend similar MsBackendMzR, peaks data stored HDF5 files (general spectra variables kept memory). MsBackendHmdbXml (package MsbackendHmdb): allows import MS data xml files Human Metabolome Database (HMDB). Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendMassbank (package MsBackendMassbank): allows import/export data MassBank text file format. Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendMassbankSql (package MsBackendMassbank): allows directly connect MassBank SQL database retrieve MS data variables. minimal memory footprint data retrieved --fly SQL database. MsBackendMemory (package: Spectra): default backend keeps data memory. Optimized fast processing. MsBackendMetaboLights (package MsBackendMetaboLights): retrieves caches MS data files MetaboLights. MsBackendMgf (package MsBackendMgf): allows import/export data mascot generic format (MGF). Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendMsp (package MsbackendMsp): allows import/export data NIST MSP format. Extends MsBackendDataFrame keeps thus data, import, memory. MsBackendMzR (package: Spectra): using mzR package supports import MS data mzML, mzXML CDF files. backend keeps general spectra variables memory retrieves peaks data (m/z intensity values) --fly original data files. backend thus smaller memory footprint compared -memory backends. MsBackendOfflineSql (package MsBackendSql): stores MS data SQL database thus minimal memory footprint. , contrast MsBackendSql, keep active SQL database connection can thus support parallel processing. MsBackendRawFileReader (package MsBackendRawFileReader): implements backend reading MS data Thermo Fisher Scientific’s raw data files using manufacturer’s NewRawFileReader .Net libraries. package generalizes functionality introduced rawrr package. MsBackendSql (package MsBackendSql): stores MS data SQL database thus minimal memory footprint. MsBackendTimsTof (package MsBackendTimsTof: allows import data Bruker TimsTOF raw data files (using opentimsr R package). MsBackendWeizMass (package MsBackendWeizMass: allows access MS data WeizMass MS/MS spectral databases. information see package homepage.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Spectra Infrastructure for Mass Spectrometry Data","text":"package can installed ","code":"install.packages(\"BiocManager\") BiocManager::install(\"Spectra\")"},{"path":"https://rformassspectrometry.github.io/Spectra/index.html","id":"contributions","dir":"","previous_headings":"","what":"Contributions","title":"Spectra Infrastructure for Mass Spectrometry Data","text":"Contributions highly welcome follow contribution guidelines. Also, please check coding style guidelines RforMassSpectrometry vignette importantly, follow code conduct.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":null,"dir":"Reference","previous_headings":"","what":"Mass spectrometry data backends — MsBackend","title":"Mass spectrometry data backends — MsBackend","text":"Note classes described meant used directly end-users material man page aimed package developers. MsBackend virtual class defines different backend needs provide. MsBackend objects provide access mass spectrometry data. backends can classified -memory -disk backends, depending data, .e spectra (m/z intensities) spectra annotation (MS level, charge, polarity, ...) stored. Typically, -memory backends keep data memory ensuring fast data access, -disk backends store (parts ) data disk retrieve demand. Backend functions implementation notes new backend classes section documents API backend must implement. Currently available backends : MsBackendMemory MsBackendDataFrame: store data memory. MsBackendMemory optimized accessing processing peak data (.e. numerical matrices m/z intensity values) MsBackendDataFrame keeps data DataFrame. MsBackendMzR: stores m/z intensities -disk raw data files (typically mzML mzXML) spectra annotation information (header) memory DataFrame. backend requires mzR package. MsBackendHdf5Peaks: stores m/z intensities -disk custom hdf5 data files remaining spectra variables memory (DataFrame). backend requires rhdf5 package. See details individual backends.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Mass spectrometry data backends — MsBackend","text":"","code":"# S4 method for class 'MsBackend' backendBpparam(object, BPPARAM = bpparam()) # S4 method for class 'MsBackend' backendInitialize(object, ...) # S4 method for class 'list' backendMerge(object, ...) # S4 method for class 'MsBackend' backendMerge(object, ...) # S4 method for class 'MsBackend' backendParallelFactor(object, ...) # S4 method for class 'MsBackend' export(object, ...) # S4 method for class 'MsBackend' acquisitionNum(object) # S4 method for class 'MsBackend' peaksData(object, columns = c(\"mz\", \"intensity\")) # S4 method for class 'MsBackend' peaksVariables(object) # S4 method for class 'MsBackend,dataframeOrDataFrameOrmatrix' cbind2(x, y = data.frame(), ...) # S4 method for class 'MsBackend' centroided(object) # S4 method for class 'MsBackend' centroided(object) <- value # S4 method for class 'MsBackend' collisionEnergy(object) # S4 method for class 'MsBackend' collisionEnergy(object) <- value # S4 method for class 'MsBackend' dataOrigin(object) # S4 method for class 'MsBackend' dataOrigin(object) <- value # S4 method for class 'MsBackend' dataStorage(object) # S4 method for class 'MsBackend' dataStorage(object) <- value # S4 method for class 'MsBackend' dropNaSpectraVariables(object) # S4 method for class 'MsBackend,ANY' extractByIndex(object, i) # S4 method for class 'MsBackend,missing' extractByIndex(object, i) # S4 method for class 'MsBackend' filterAcquisitionNum(object, n, file, ...) # S4 method for class 'MsBackend' filterDataOrigin(object, dataOrigin = character()) # S4 method for class 'MsBackend' filterDataStorage(object, dataStorage = character()) # S4 method for class 'MsBackend' filterEmptySpectra(object, ...) # S4 method for class 'MsBackend' filterIsolationWindow(object, mz = numeric(), ...) # S4 method for class 'MsBackend' filterMsLevel(object, msLevel = integer()) # S4 method for class 'MsBackend' filterPolarity(object, polarity = integer()) # S4 method for class 'MsBackend' filterPrecursorMzRange(object, mz = numeric()) # S4 method for class 'MsBackend' filterPrecursorMz(object, mz = numeric()) # S4 method for class 'MsBackend' filterPrecursorMzValues(object, mz = numeric(), ppm = 20, tolerance = 0) # S4 method for class 'MsBackend' filterPrecursorCharge(object, z = integer()) # S4 method for class 'MsBackend' filterPrecursorScan(object, acquisitionNum = integer(), f = dataOrigin(object)) # S4 method for class 'MsBackend' filterRanges( object, spectraVariables = character(), ranges = numeric(), match = c(\"all\", \"any\") ) # S4 method for class 'MsBackend' filterRt(object, rt = numeric(), msLevel. = uniqueMsLevels(object)) # S4 method for class 'MsBackend' filterValues( object, spectraVariables = character(), values = numeric(), ppm = 0, tolerance = 0, match = c(\"all\", \"any\") ) # S4 method for class 'MsBackend' intensity(object) # S4 method for class 'MsBackend' intensity(object) <- value # S4 method for class 'MsBackend' ionCount(object) # S4 method for class 'MsBackend' isCentroided(object, ...) # S4 method for class 'MsBackend' isEmpty(x) # S4 method for class 'MsBackend' isolationWindowLowerMz(object) # S4 method for class 'MsBackend' isolationWindowLowerMz(object) <- value # S4 method for class 'MsBackend' isolationWindowTargetMz(object) # S4 method for class 'MsBackend' isolationWindowTargetMz(object) <- value # S4 method for class 'MsBackend' isolationWindowUpperMz(object) # S4 method for class 'MsBackend' isolationWindowUpperMz(object) <- value # S4 method for class 'MsBackend' isReadOnly(object) # S4 method for class 'MsBackend' length(x) # S4 method for class 'MsBackend' msLevel(object) # S4 method for class 'MsBackend' msLevel(object) <- value # S4 method for class 'MsBackend' mz(object) # S4 method for class 'MsBackend' mz(object) <- value # S4 method for class 'MsBackend' lengths(x, use.names = FALSE) # S4 method for class 'MsBackend' polarity(object) # S4 method for class 'MsBackend' polarity(object) <- value # S4 method for class 'MsBackend' precScanNum(object) # S4 method for class 'MsBackend' precursorCharge(object) # S4 method for class 'MsBackend' precursorIntensity(object) # S4 method for class 'MsBackend' precursorMz(object) # S4 method for class 'MsBackend' precursorMz(object, ...) <- value # S4 method for class 'MsBackend' peaksData(object) <- value # S4 method for class 'MsBackend' reset(object) # S4 method for class 'MsBackend' rtime(object) # S4 method for class 'MsBackend' rtime(object) <- value # S4 method for class 'MsBackend' scanIndex(object) # S4 method for class 'MsBackend' selectSpectraVariables(object, spectraVariables = spectraVariables(object)) # S4 method for class 'MsBackend' smoothed(object) # S4 method for class 'MsBackend' smoothed(object) <- value # S4 method for class 'MsBackend' spectraData(object, columns = spectraVariables(object)) # S4 method for class 'MsBackend' spectraData(object) <- value # S4 method for class 'MsBackend' spectraNames(object) # S4 method for class 'MsBackend' spectraNames(object) <- value # S4 method for class 'MsBackend' spectraVariables(object) # S4 method for class 'MsBackend,ANY' split(x, f, drop = FALSE, ...) # S4 method for class 'MsBackend' supportsSetBackend(object, ...) # S4 method for class 'MsBackend' tic(object, initial = TRUE) # S4 method for class 'MsBackend' x[i, j, ..., drop = FALSE] # S4 method for class 'MsBackend' x$name # S4 method for class 'MsBackend' x$name <- value # S4 method for class 'MsBackend' x[[i, j, ...]] # S4 method for class 'MsBackend' x[[i, j, ...]] <- value # S4 method for class 'MsBackend' uniqueMsLevels(object, ...) # S4 method for class 'MsBackend' dataStorageBasePath(object) # S4 method for class 'MsBackend' dataStorageBasePath(object) <- value MsBackendDataFrame() # S4 method for class 'MsBackendDataFrame' backendInitialize(object, data, peaksVariables = c(\"mz\", \"intensity\"), ...) MsBackendHdf5Peaks() MsBackendMemory() # S4 method for class 'MsBackendMemory' backendInitialize(object, data, peaksVariables = c(\"mz\", \"intensity\"), ...) MsBackendMzR()"},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Mass spectrometry data backends — MsBackend","text":"object Object extending MsBackend. BPPARAM backendBpparam(): parameter object BiocParallel package defining parallel processing setup. Defaults BPPARAM = bpparam(). See BiocParallel::bpparam() information. ... Additional arguments. columns spectraData() accessor: optional character column names (spectra variables) included returned DataFrame. default, columns returned. peaksData() accessor: optional character requested columns individual matrix returned list. Defaults peaksVariables(object) depends peaks variables backend provides. x Object extending MsBackend. y cbind2(): data.frame DataFrame spectra variables added backend. number rows y order match number spectra order x. value replacement value <- methods. See individual method description expected data type. [: integer, logical character subset object. n filterAcquisitionNum(): integer acquisition numbers filter . file filterFile(): index name file(s) data subsetted. export(): character length 1 equal number spectra. dataOrigin filterDataOrigin(): character define spectra keep. filterAcquisitionNum(): optionally specify filtering occur spectra selected dataOrigin. dataStorage filterDataStorage(): character define spectra keep. filterAcquisitionNum(): optionally specify filtering occur spectra selected dataStorage. mz filterIsolationWindow(): numeric(1) m/z value filter object. filterPrecursorMzRange(): numeric(2) lower upper m/z boundary. filterPrecursorMzValues(): numeric m/z value(s) filter object. msLevel integer defining MS level spectra function applied. filterMsLevel(): MS level object subsetted. polarity filterPolarity(): integer specifying polarity subset object. ppm filterPrecursorMzValues(): numeric(1) m/z-relative maximal acceptable difference m/z considered matching. See MsCoreUtils::closest() details. filterValues(): numeric length allowing define maximal accepted difference user input values spectraVariables values. equal length value provided parameter spectraVariables, ppm[1] recycled. tolerance filterPrecursorMzValues(): numeric(1) maximal absolute acceptable difference m/z value considered matching. See MsCoreUtils::closest() details. filterValues(): numeric accepted tolerance values spectra variables. Defaults tolerance = 0. equal length value provided parameter spectraVariables, tolerance[1] recycled. z filterPrecursorCharge(): integer() precursor charges used filter. acquisitionNum filterPrecursorScan(): integer acquisition number spectra object subsetted. f factor defining grouping split x. See split(). filterPrecursorScan(): factor defining original data files spectra derive avoid selecting spectra different samples/files. Defaults f = dataOrigin(object). spectraVariables selectSpectraVariables(): character names spectra variables backend subsetted. filterRanges() filterValues(): character vector specifying column(s) spectraData(object) filter data correspond names spectra variables used filtering. ranges filterRanges(): numeric vector paired values (upper lower boundary) define ranges filter object. paired values need order spectraVariables parameter (see ). match filterRanges() filterValues(): character(1) defining whether condition match provided ranges/values (match = \"\"; default), (match = \"\") spectra retained. rt filterRt(): numeric(2) defining retention time range used subset/filter object. msLevel. msLevel . values filterValues(): numeric vector define values filter object. values needs length parameter spectraVariables order. use.names lengths(): whether spectrum names used. drop [: considered. initial tic(): logical(1) whether initially reported total ion current reported, whether total ion current (re)calculated actual data (initial = FALSE). j [: supported. name $ $<-: name spectra variable return set. data backendInitialize(): DataFrame spectrum metadata/data. parameter can empty MsBackendMzR backends needs provided MsBackendDataFrame backends. peaksVariables backendInitialize() MsBackendMemory: character specifying columns provided data contain peaks variables (.e. information individual mass peaks). Defaults peaksVariables = c(\"mz\", \"intensity\"). \"mz\" \"intensity\" always specified.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Mass spectrometry data backends — MsBackend","text":"See documentation respective function.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"implementation-notes","dir":"Reference","previous_headings":"","what":"Implementation notes","title":"Mass spectrometry data backends — MsBackend","text":"Backends extending MsBackend must implement methods (listed ). Developers new MsBackends follow MsBackendMemory implementation. ensure new implementation conform MsBackend definition, developers included test suites provided package unit test setup. variable created package's \"testthat.R\" file represents (initialized) instance developed backend. path test suites defined test_suite <- system.file(\"test_backends\", \"test_MsBackend\", package = \"Spectra\") followed test_dir(test_suite) run test files directory. Individual unit test files run test_file(file.path(test_suite, \"test_spectra_variables.R\"), stop_on_failure = TRUE) (note without stop_on_failure = TRUE tests fail silently) . Adding code packages \"testthat.R\" file ensures tests checking validity MsBackend instance defined Spectra package also run newly develped backend class. MsBackend defines following slots: @readonly: logical(1) whether backend supports writing/replacing m/z intensity values. Backends extending MsBackend must implement methods (listed ). Developers new MsBackends follow MsBackendDataFrame implementation. MsBackendCached() backend provides caching mechanism allow read backends add change spectra variables. backend used , meant extended. See MsBackendCached() details. MsBackend defines following slots: @readonly: logical(1) whether backend supports writing/replacing m/z intensity values.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"backend-functions","dir":"Reference","previous_headings":"","what":"Backend functions","title":"Mass spectrometry data backends — MsBackend","text":"New backend classes must extend base MsBackend class implement following methods (see MsBackend vignette detailed description examples): [: subset backend. subsetting element (row/) allowed. Parameter support integer indices logical throw error bounds. MsCoreUtils::i2index used check input . = integer() empty backend returned. Implementation method optional, default calls extractByIndex() method (implemented main subsetting method). $, $<-: access set/add single spectrum variable (column) backend. Using value NULL allow deleting specified spectra variable. error thrown spectra variable available. [[, [[<-: access set/add single spectrum variable (column) backend. default implementation uses $, thus methods implemented new classes extending MsBackend. acquisitionNum(): returns acquisition number spectrum. Returns integer length equal number spectra (NA_integer_ available). backendBpparam(): return parallel processing setup supported backend class. function can used higher level function evaluate whether provided parallel processing setup (default one returned bpparam()) supported backend. Backends supporting parallel processing (e.g. contain connection database can shared across processes) extend method return SerialParam() hence disable parallel processing () methods functions. See also backendParallelFactor() function provide preferred splitting backend parallel processing. backendInitialize(): initialises backend. method supposed called rights creating instance backend class prepare backend (e.g. set data memory backend read spectra header data MsBackendMzR backend). Parameters can defined freely backend, depending needed initialize backend. however suggested also support parameter data can used submit full spectra data DataFrame backend. allow backend also usable setBackend() function Spectra. Note eventually (read-backends) also supportsSetBackend method need implemented return TRUE. backendInitialize() method also ensure correctly set spectra variable dataStorage. backendMerge(): merges (combines) MsBackend objects single instance. objects merged type (e.g. MsBackendDataFrame()). backendParallelFactor(): returns factor defining optimal (preferred) way backend can split parallel processing used peak data accessor data manipulation functions. default implementation returns factor length 0 (factor()) providing thus default splitting. backendParallelFactor() MsBackendMzR hand returns factor(dataStorage(object)) hence suggesting split object data file. backendRequiredSpectraVariables(): returns character spectra variable names mandatory specific backend. default returns empty character(). implementation MsBackendMzR returns c(\"dataStorage\", \"scanIndex\") two spectra variables required load MS data --fly. method needs implemented backend requires specific variables defined. dataOrigin(): gets character length equal number spectra object data origin spectrum. e.g. mzML file data read. dataStorage(): gets character length equal number spectra object data storage spectrum. Note missing values (NA_character_) supported dataStorage. dataStorageBasePath(), dataStorageBasePath<-: gets sets common *base* path directory containing data files. supported, function expected return (accept) characterof length 1. backends (example theMsBackendMemorywill support function anddataStorageBasePath()returnNA_character_. MsBackendMzR, function allows get change path directory containing original data files, required e.g. serialized MsBackendMzR` instance gets copied another computer file system. dropNaSpectraVariables(): removes spectra variables (.e. columns object's spectraData contain missing values (NA). Note columns NAs removed, spectraData() call dropNaSpectraVariables() might still show columns containing NA values core spectra variables. cbind2(): allows appends multiple new spectra variables backend . values new spectra variables order spectra x. Replacing existing spectra variables supported function. controlled way adding spectra variables, joinSpectraData() used. centroided(), centroided<-: gets sets centroiding information spectra. centroided() returns logical vector length equal number spectra TRUE spectrum centroided, FALSE profile mode NA undefined. See also isCentroided() estimating spectrum data whether spectrum centroided. value centroided<- either single logical logical length equal number spectra object. collisionEnergy(), collisionEnergy<-: gets sets collision energy spectra object. collisionEnergy() returns numeric length equal number spectra (NA_real_ present/defined), collisionEnergy<- takes numeric length equal number spectra object. export(): exports data Spectra class file. method called export,Spectra method passes second argument function. export,MsBackend implementation thus expected take Spectra class second argument data exported. Taking data Spectra class ensures also eventual data manipulations (cached Spectra's lazy evaluation queue) applied prior export - possible MsBackend class. example implementation export() method MsBackendMzR backend supports export data mzML mzXML format. See documentation MsBackendMzR class information. extractByIndex(): function subset backend selected elements defined provided index. Similar [, method allow extracting (subset) data order. contrast [, however, expected integer ([ also support logical eventually character). apparently redundant [, methods avoids package namespace errors/problems can result implementations [ found R (can happen sometimes parallel processing using BiocParallel::SnowParam()). method used internally Spectra extract/subset backend. Implementation method mandatory. filterAcquisitionNum(): filters object keeping spectra matching provided acquisition numbers (argument n). dataOrigin dataStorage also provided, object subsetted spectra acquisition number equal n spectra matching dataOrigin dataStorage values retaining spectra. filterDataOrigin(): filters object retaining spectra matching provided dataOrigin. Parameter dataOrigin type character needs match exactly data origin value spectra subset. filterDataOrigin() return data ordered provided dataOrigin parameter, .e. dataOrigin = c(\"2\", \"1\") provided, spectra resulting object ordered accordingly (first spectra data origin \"2\" \"1\"). Implementation method optional since default implementation MsBackend available. filterDataStorage(): filters object retaining spectra matching provided dataStorage. Parameter dataStorage type character needs match exactly data storage value spectra subset. filterDataStorage() return data ordered provided dataStorage parameter, .e. dataStorage = c(\"2\", \"1\") provided, spectra resulting object ordered accordingly (first spectra data storage \"2\" \"1\"). Implementation method optional since default implementation MsBackend available. filterEmptySpectra(): removes empty spectra (.e. spectra without peaks). Implementation method optional since default implementation MsBackend available. filterFile(): retains data files matching file index file name provided parameter file. filterIsolationWindow(): retains spectra contain mz isolation window m/z range (.e. isolationWindowLowerMz <= mz isolationWindowUpperMz >= mz. Implementation method optional since default implementation MsBackend available. filterMsLevel(): retains spectra MS level msLevel. Implementation method optional since default implementation MsBackend available. filterPolarity(): retains spectra polarity polarity. Implementation method optional since default implementation MsBackend available. filterPrecursorMzRange() (previously filterPrecursorMz): retains spectra precursor m/z within provided m/z range. Implementation method optional since default implementation MsBackend available. filterPrecursorMzValues(): retains spectra precursor m/z matching provided m/z values (given ppm tolerance). Implementation method optional since default implementation MsBackend available. filterPrecursorCharge(): retains spectra defined precursor charge(s). Implementation method optional since default implementation MsBackend available. filterPrecursorScan(): retains parent (e.g. MS1) children scans (e.g. MS2) acquisition number acquisitionNum. Parameter f supposed define origin spectra (.e. original data file) ensure related spectra file/sample selected retained. Implementation method optional since default implementation MsBackend available. filterRanges(): allows filtering Spectra object based user defined numeric ranges (parameter ranges) one available spectra variables object (spectra variable names can specified parameter spectraVariables). Spectra value spectra variable within defined range retained. multiple ranges/spectra variables defined, match parameter can used specify whether conditions (match = \"\"; default) conditions must match (match = \"\"; spectra values within provided ranges retained). Implementation method optional since default implementation MsBackend available. filterRt(): retains spectra MS level msLevel retention times within (>=) rt[1] (<=) rt[2]. Implementation method optional since default implementation MsBackend available. filterValues(): allows filtering Spectra object based similarities numeric values one spectraVariables(object) (parameter spectraVariables) provided values (parameter values) given acceptable differences (parameters tolerance ppm). multiple values/spectra variables defined, match parameter can used specify whether conditions (match = \"\"; default) conditions must match (match = \"\"; spectra values within provided ranges retained). Implementation method optional since default implementation MsBackend available. intensity(): gets intensity values spectra. Returns IRanges::NumericList() numeric vectors (intensity values spectrum). length list equal number spectra object. intensity<-: replaces intensity values. value list (IRanges::NumericList()) length equal number spectra number values within list element identical number peaks spectrum (.e. lengths(x)). Note just writeable backends support method. ionCount(): returns numeric sum intensities spectrum. spectrum empty (see isEmpty()), NA_real_ returned. isCentroided(): heuristic approach assessing spectra object profile centroided mode. function takes qtl th quantile top peaks, calculates difference adjacent m/z value returns TRUE first quartile greater k. (See Spectra:::.peaks_is_centroided code.) isEmpty(): checks whether spectrum object empty (.e. contain peaks). Returns logical vector length equal number spectra. isolationWindowLowerMz(), isolationWindowLowerMz<-: gets sets lower m/z boundary isolation window. isolationWindowTargetMz(), isolationWindowTargetMz<-: gets sets target m/z isolation window. isolationWindowUpperMz(), isolationWindowUpperMz<-: gets sets upper m/z boundary isolation window. isReadOnly(): returns logical(1) whether backend read allow also write/update data. length(): returns number spectra object. lengths(): gets number peaks (m/z-intensity values) per spectrum. Returns integer vector (length equal number spectra). empty spectra, 0 returned. msLevel(): gets spectra's MS level. Returns integer vector (length equal number spectra) MS level spectrum (NA_integer_ available). msLevel<-: replaces spectra's MS level. mz(): gets mass--charge ratios (m/z) spectra. Returns IRanges::NumericList() length equal number spectra, element numeric vector m/z values one spectrum. mz<-: replaces m/z values. value list length equal number spectra number values within list element identical number peaks spectrum (.e. lengths(x)). Note just writeable backends support method. polarity(), polarity<-: gets sets polarity spectrum. polarity() returns integer vector (length equal number spectra), 0 1 representing negative positive polarities, respectively. polarity<- expects integer vector length 1 equal number spectra. precursorCharge(), precursorIntensity(), precursorMz(), precScanNum(), precAcquisitionNum(): get charge (integer), intensity (numeric), m/z (numeric), scan index (integer) acquisition number (interger) precursor MS level 2 spectra object. Returns vector length equal number spectra object. NA reported MS1 spectra precursor information available. peaksData() returns list spectras' peak data, .e. m/z intensity values peak variables. length list equal number spectra object. element list two-dimensional array (matrix data.frame) columns depending provided columns parameter (default \"mz\" \"intensity\", depends backend's available peaksVariables). empty spectrum, matrix (data.frame) 0 rows columns according columns returned. optional parameter columns, supported backend, allows define peak variables returned numeric peak matrix. default c(\"mz\", \"intensity\") used. peaksData<- replaces peak data (m/z intensity values) backend. method expects list two dimensional arrays (matrix data.frame) columns representing peak variables. existing peaks data expected replaced new values. length list match number spectra object. Note writeable backends need support method. peaksVariables(): lists available variables mass peaks. Default peak variables \"mz\" \"intensity\" (backends need support provide), backends might provide additional variables. variables expected returned (requested) peaksData() function. reset() backend (supported). method called backend reset,Spectra method supposed restore data original state (see reset,Spectra details). function returns reset backend. default implementation MsBackend returns backend -. rtime(), rtime<-: gets sets retention times spectrum (seconds). rtime() returns numeric vector (length equal number spectra) retention time spectrum. rtime<- expects numeric vector length equal number spectra. scanIndex(): returns integer vector scan index spectrum. represents relative index spectrum within file. Note can different acquisitionNum() spectrum index spectrum reported mzML file. selectSpectraVariables(): reduces information within backend selected spectra variables. suggested remove values \"dataStorage\" variable, since might required backends work properly (MsBackendMzR). smoothed(),smoothed<-: gets sets whether spectrum smoothed. smoothed() returns logical vector length equal number spectra. smoothed<- takes logical vector length 1 equal number spectra object. spectraData(), spectraData<-: gets sets general spectrum metadata (annotation, also called header). spectraData() returns DataFrame, spectraData<- expects DataFrame number rows spectra object. Note spectraData() return full data, .e. also m/z intensity values (list SimpleList columns \"mz\" \"intensity\". spectraNames(): returns character vector names spectra object NULL set. spectraNames<- allows set spectra names (object read-). spectraVariables(): returns character vector available spectra variables (columns, fields attributes) available object. return spectra variables present object, also \"mz\" \"intensity\" (default returned spectraVariables,Spectra method). split(): splits backend list backends (depending parameter f). default method MsBackend uses split.default(), thus backends extending MsBackend necessarily need implement method. supportsSetBackend(): whether MsBackend supports Spectra setBackend() function. MsBackend support setBackend() needs parameter called data backendInitialize() method support receiving spectra data DataFrame another backend initialize backend data. general read-backends support setBackend() hence, default implementation supportsSetBackend() returns !isReadOnly(object). read-backend support setBackend() initialized DataFrame implementation method backend defined returns TRUE (see also MsBackend vignette details examples). tic(): gets total ion current/count (sum signal spectrum) spectra object. default, value reported original raw data file returned. empty spectrum, NA_real_ returned. uniqueMsLevels(): gets unique MS levels spectra object. default implementation calls unique(msLevel(object)) efficient implementations defined specific backends.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"subsetting-and-merging-backend-classes","dir":"Reference","previous_headings":"","what":"Subsetting and merging backend classes","title":"Mass spectrometry data backends — MsBackend","text":"Backend classes must support (implement) [ method subset object. method support subsetting spectra (rows, ) return MsBackend class. Backends extending MsBackend also implement backendMerge() method support combining backend instances (backend classes type merged). Merging follow following rules: whole spectrum data various objects merged. resulting merged object contain union individual objects' spectra variables (columns/fields), eventually missing variables one object filled NA.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"in-memory-data-backends","dir":"Reference","previous_headings":"","what":"In-memory data backends","title":"Mass spectrometry data backends — MsBackend","text":"MsBackendMemory MsBackendDataFrame: MsBackendMemory MsBackendDataFrame objects keep MS data memory thus ideal fast data processing. Due large memory footprint however suited large scale experiments. two backends store data different. MsBackendDataFrame stores data DataFrame thus supports also S4-classes spectra variables. Also, sepratate access m/z intensity values (.e. using mz() intensity() methods) faster MsBackendDataFrame. MsBackendMemory hand, due way data organized internally, provides much faster access full peak data (.e. numerical matrices m/z intensity values). Also subsetting access spectra variable (except \"mz\" \"intensity\") fastest MsBackendMemory. Thus, use cases, MsBackendMemory provides higher performance flexibility MsBackendDataFrame thus preferred. See also issue 246 performance comparison. New objects can created MsBackendMemory() MsBackendDataFrame() function, respectively. backends can subsequently initialized backendInitialize() method, taking DataFrame (data.frame) (full) MS data first parameter data. second parameter peaksVariables allows define columns data contain peak variables m/z intensity values individual peaks per spectrum. default parameter peaksVariables = c(\"mz\", \"intensity\"). Note supported provide either \"mz\" \"intensity\", provided, need present data frame. Alternatively, function also supports data frame without m/z intensity values, case Spectra without mass peaks created. Suggested columns DataFrame : \"msLevel\": integer MS levels spectra. \"rt\": numeric retention times spectra. \"acquisitionNum\": integer acquisition number spectrum. \"scanIndex\": integer index scan/spectrum within mzML/mzXML/CDF file. \"dataOrigin\": character defining data origin. \"dataStorage\": character indicating grouping spectra different e.g. input files. Note missing values supported. \"centroided\": logical whether spectrum centroided. \"smoothed\": logical whether spectrum smoothed. \"polarity\": integer polarity information spectra. \"precScanNum\": integer specifying index (MS1) spectrum containing precursor (MS2) spectrum. \"precursorMz\": numeric m/z value precursor. \"precursorIntensity\": numeric intensity value precursor. \"precursorCharge\": integer charge precursor. \"collisionEnergy\": numeric collision energy. \"mz\": IRanges::NumericList() numeric vectors representing m/z values spectrum. \"intensity\": IRanges::NumericList() numeric vectors representing intensity values spectrum. Additional columns allowed . peaksData() function MsBackendMemory MsBackendDataFrame returns list numeric matrix default (parameter columns = c(\"mz\", \"intensity\")). peak variables requested, list data.frame returned (ensuring m/z intensity values always numeric).","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"msbackendmzr-on-disk-ms-data-backend","dir":"Reference","previous_headings":"","what":"MsBackendMzR, on-disk MS data backend","title":"Mass spectrometry data backends — MsBackend","text":"MsBackendMzR keeps limited amount data memory, spectra data (m/z intensity values) fetched raw files -demand. backend uses mzR package data import retrieval hence requires package installed. Also, can used import represent data stored mzML, mzXML CDF files. MsBackendMzR backend extends MsBackendDataFrame backend using DataFrame keep spectra variables (except m/z intensity) memory. New objects can created MsBackendMzR() function can subsequently filled data calling backendInitialize() passing file names input data files argument files. backend provides export() method export data Spectra mzML mzXML format. definition function : export(object, x, file = tempfile(), format = c(\"mzML\", \"mzXML\"), copy = FALSE) parameters : object: instance MsBackendMzR class. x: Spectra object exported. file: character (full) output file name(s). length 1 equal length(x). single file specified, spectra exported file. Alternatively possible specify spectrum x name file exported (hence file length equal length(x)). format: character(1), either \"mzML\" \"mzXML\" defining output file format. copy: logical(1) whether general file information copied original MS data files. works x uses MsBackendMzR backend dataOrigin(x) contains original MS data file names. BPPARAM: parallel processing settings. See examples Spectra vignette details examples. MsBackendMzR ignores parameter columns peaksData() function returns always m/z intensity values.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"msbackendhdf-peaks-on-disk-ms-data-backend","dir":"Reference","previous_headings":"","what":"MsBackendHdf5Peaks, on-disk MS data backend","title":"Mass spectrometry data backends — MsBackend","text":"MsBackendHdf5Peaks keeps, similar MsBackendMzR, peak data (.e. m/z intensity values) custom data files (HDF5 format) disk remaining spectra variables kept memory. backend supports updating writing manipulated peak data data files. New objects can created MsBackendHdf5Peaks() function can subsequently filled data calling object's backendInitialize() method passing desired file names HDF5 data files along spectra variables form DataFrame (see MsBackendDataFrame expected format). optional parameter hdf5path allows specify folder HDF5 data files stored . provided, added path submitted file names (parameter files). default backendInitialize() store peak data single HDF5 file name provided parameter files. store peak data across several HDF5 files data contain column \"dataStorage\" defines grouping spectra/peaks files: peaks spectra value \"dataStorage\" saved HDF5 file. parameter files omitted, value dataStorage used file name (replacing file ending \".h5\". specify file names, files' length match number unique elements \"dataStorage\". details see examples Spectra() help page. MsBackendHdf5Peaks ignores parameter columns peaksData() function returns always m/z intensity values.","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Mass spectrometry data backends — MsBackend","text":"Johannes Rainer, Sebastian Gibb, Laurent Gatto, Philippine Louail","code":""},{"path":"https://rformassspectrometry.github.io/Spectra/reference/MsBackend.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Mass spectrometry data backends — MsBackend","text":"","code":"## The MsBackend class is a virtual class and can not be instantiated ## directly. Below we define a new backend class extending this virtual ## class MsBackendDummy <- setClass(\"MsBackendDummy\", contains = \"MsBackend\") MsBackendDummy() #> An object of class \"MsBackendDummy\" #> Slot \"readonly\": #> [1] FALSE #> #> Slot \"version\": #> [1] \"0.1\" #> ## This class inherits now all methods from `MsBackend`, all of which ## however throw an error. These methods would have to be implemented ## for the new backend class. try(mz(MsBackendDummy())) #> Error in .local(object, ...) : Not implemented for MsBackendDummy. ## See `MsBackendDataFrame` as a reference implementation for a backend ## class (in the *R/MsBackendDataFrame.R* file). ## MsBackendDataFrame ## ## The `MsBackendDataFrame` uses a `S4Vectors::DataFrame` to store all MS ## data. Below we create such a backend by passing a `DataFrame` with all ## data to it. data <- DataFrame(msLevel = c(1L, 2L, 1L), scanIndex = 1:3) data$mz <- list(c(1.1, 1.2, 1.3), c(1.4, 54.2, 56.4, 122.1), c(15.3, 23.2)) data$intensity <- list(c(3, 2, 3), c(45, 100, 12.2, 1), c(123, 12324.2)) ## Backends are supposed to be created with their specific constructor ## function be <- MsBackendDataFrame() be #> MsBackendDataFrame with 0 spectra ## The `backendInitialize()` method initializes the backend filling it with ## data. This method can take any parameters needed for the backend to ## get loaded with the data (e.g. a file name from which to load the data, ## a database connection or, in this case, a data frame containing the data). be <- backendInitialize(be, data) be #> MsBackendDataFrame with 3 spectra #> msLevel rtime scanIndex #> #> 1 1 NA 1 #> 2 2 NA 2 #> 3 1 NA 3 #> ... 16 more variables/columns. ## Data can be accessed with the accessor methods msLevel(be) #> [1] 1 2 1 mz(be) #> NumericList of length 3 #> [[1]] 1.1 1.2 1.3 #> [[2]] 1.4 54.2 56.4 122.1 #> [[3]] 15.3 23.2 ## Even if no data was provided for all spectra variables, its accessor ## methods are supposed to return a value. precursorMz(be) #> [1] NA NA NA ## The `peaksData()` method is supposed to return the peaks of the spectra as ## a `list`. peaksData(be) #> [[1]] #> mz intensity #> [1,] 1.1 3 #> [2,] 1.2 2 #> [3,] 1.3 3 #> #> [[2]] #> mz intensity #> [1,] 1.4 45.0 #> [2,] 54.2 100.0 #> [3,] 56.4 12.2 #> [4,] 122.1 1.0 #> #> [[3]] #> mz intensity #> [1,] 15.3 123.0 #> [2,] 23.2 12324.2 #> ## List available peaks variables peaksVariables(be) #> [1] \"mz\" \"intensity\" ## Use columns to extract specific peaks variables. Below we extract m/z and ## intensity values, but in reversed order to the default. peaksData(be, columns = c(\"intensity\", \"mz\")) #> [[1]] #> intensity mz #> [1,] 3 1.1 #> [2,] 2 1.2 #> [3,] 3 1.3 #> #> [[2]] #> intensity mz #> [1,] 45.0 1.4 #> [2,] 100.0 54.2 #> [3,] 12.2 56.4 #> [4,] 1.0 122.1 #> #> [[3]] #> intensity mz #> [1,] 123.0 15.3 #> [2,] 12324.2 23.2 #> ## List available spectra variables (i.e. spectrum metadata) spectraVariables(be) #> [1] \"msLevel\" \"rtime\" #> [3] \"acquisitionNum\" \"scanIndex\" #> [5] \"mz\" \"intensity\" #> [7] \"dataStorage\" \"dataOrigin\" #> [9] \"centroided\" \"smoothed\" #> [11] \"polarity\" \"precScanNum\" #> [13] \"precursorMz\" \"precursorIntensity\" #> [15] \"precursorCharge\" \"collisionEnergy\" #> [17] \"isolationWindowLowerMz\" \"isolationWindowTargetMz\" #> [19] \"isolationWindowUpperMz\" ## Extract precursor m/z, rtime, MS level spectra variables spectraData(be, c(\"precursorMz\", \"rtime\", \"msLevel\")) #> DataFrame with 3 rows and 3 columns #> precursorMz rtime msLevel #> #> 1 NA NA 1 #> 2 NA NA 2 #> 3 NA NA 1 ## MsBackendMemory ## ## The `MsBackendMemory` uses a more efficient internal data organization ## and allows also adding arbitrary additional peaks variables (annotations) ## Below we thus add a column \"peak_ann\" with arbitrary names/ids for each ## peak and add the name of this column to the `peaksVariables` parameter ## of the `backendInitialize()` method (in addition to `\"mz\"` and ## `\"intensity\"` that should **always** be specified. data$peak_ann <- list(c(\"a\", \"\", \"d\"), c(\"\", \"d\", \"e\", \"f\"), c(\"h\", \"i\")) be <- backendInitialize(MsBackendMemory(), data, peaksVariables = c(\"mz\", \"intensity\", \"peak_ann\")) be #> MsBackendMemory with 3 spectra #> msLevel rtime scanIndex #>