Accessing SpaMTP Annotation Resources

Introduction

SpaMTPdb separates versioned RaMP and metabolite annotation resources from the SpaMTP software package. This keeps the software package small while allowing analyses to record and reproduce the exact database snapshot used.

Each resource is an independent serialised object, so an analysis downloads only the components it needs. Resource versions are immutable: future RaMP releases are added as new versions rather than replacing the RaMP 3.0.7 snapshot.

library(SpaMTPdb)
resources <- spaMTPdbResources(version = "latest")
resources[c("resource", "version", "category", "default")]
#>             resource version  category default
#> 1         chem_props   3.0.7      core    TRUE
#> 2          source_df   3.0.7      core    TRUE
#> 3            analyte   3.0.7      core    TRUE
#> 4  analytehaspathway   3.0.7      core    TRUE
#> 5            pathway   3.0.7      core    TRUE
#> 6   ramp_db_metadata   3.0.7      core    TRUE
#> 7          ramp_hmdb   3.0.7  topology    TRUE
#> 8          ramp_kegg   3.0.7  topology    TRUE
#> 9      ramp_reactome   3.0.7  topology    TRUE
#> 10  ramp_wikipathway   3.0.7  topology    TRUE
#> 11           hmdb_db   3.0.7    legacy   FALSE
#> 12          chebi_db   3.0.7    legacy   FALSE
#> 13      lipidmaps_db   3.0.7    legacy   FALSE
#> 14           gnps_db   3.0.7    legacy   FALSE
#> 15    filtered_fmp10   3.0.7    legacy   FALSE
#> 16   smiles_features   3.0.7 structure   FALSE

Where the resources are stored

The processed resource files are published on Zenodo and described by metadata for AnnotationHub. The manifest records, for every resource, the download location together with the size and MD5 checksum used to verify a retrieved file.

The same Zenodo version family can also host native experimental RDS used by SpaMTPData. Publication is coordinated through SpaMTPdb’s maintainer recipes, but the experimental resources stay in SpaMTPData’s registry and ExperimentHub metadata. Sharing the physical host does not merge the two packages or put experiments into the annotation database bundle. The original RaMP 3.0.7 snapshot keeps its fixed URL; later collection versions have their own URLs.

resources[c("resource", "file_name", "bytes", "md5")]
#>             resource             file_name    bytes
#> 1         chem_props        chem_props.rds 12925616
#> 2          source_df         source_df.rds  9200960
#> 3            analyte           analyte.rds  1205108
#> 4  analytehaspathway analytehaspathway.rds  1614224
#> 5            pathway           pathway.rds  1933008
#> 6   ramp_db_metadata  ramp_db_metadata.rds     1348
#> 7          ramp_hmdb         ramp_hmdb.rds  1207536
#> 8          ramp_kegg         ramp_kegg.rds   242076
#> 9      ramp_reactome     ramp_reactome.rds  1826696
#> 10  ramp_wikipathway  ramp_wikipathway.rds   198088
#> 11           hmdb_db           hmdb_db.rds  7120008
#> 12          chebi_db          chebi_db.rds  7846184
#> 13      lipidmaps_db      lipidmaps_db.rds  1971128
#> 14           gnps_db           gnps_db.rds    74628
#> 15    filtered_fmp10    filtered_fmp10.rds    54756
#> 16   smiles_features   smiles_features.rds  4252016
#>                                 md5
#> 1  42865f00ea7445f72bcd2f66b2b315a9
#> 2  5cc8fc44c759ba103f39c0f53b9dc438
#> 3  e694b953ad4b61276132273a7eb4f26b
#> 4  2225c0f057cbd716f184d337627f672d
#> 5  054f527072d3d29d4ff56c5b5e27ede5
#> 6  98e12612f051f8f48388371b2070d851
#> 7  1fd1e7814bd6fd3a8815445a1d60143c
#> 8  c400509696d779a962cd0b4360620900
#> 9  a5d64439c1f6b8717fb517fbb1bc70b4
#> 10 8c6cc59150f60d999f3ab13f97f42904
#> 11 33a3340519c217543ec87e94bc31be91
#> 12 126bba31fad002fe8bc243db26e0e9a8
#> 13 9be73b858dc1b4332f8bbf84f8e14460
#> 14 558a90f94380801038ee9a40dec8d37f
#> 15 a7ca0cd5a5b507f09fcd2eca8ffb856a
#> 16 f492e18843643ef17b037b91f7988ecb

spaMTPdbResource() resolves a resource in four steps, taking the first that succeeds:

  1. a staged local directory, for development and reproducible database builds;
  2. an existing download cache that passes its size and checksum checks;
  3. the matching AnnotationHub record;
  4. the immutable Zenodo source URL recorded in the manifest.

The final step means the package remains usable before the Hub records are published, and every file retrieved that way is checked against its recorded size and MD5 checksum before use.

Inspecting resources without downloading

Passing metadata = TRUE returns the registry row and never touches the network:

chem_props_metadata <- spaMTPdbResource(
  "chem_props",
  version = "3.0.7",
  metadata = TRUE
)
chem_props_metadata[c("resource", "version", "rows", "columns", "bytes")]
#>     resource version   rows columns    bytes
#> 1 chem_props   3.0.7 289754      11 12925616

The pruned RaMP chemical table and the derived structure features remain separate. SpaMTP’s annotation engine loads and joins the second table by the chemical table’s iso_smiles to the structure table’s smiles column when structure-aware ionisation scoring is requested:

smiles_features_metadata <- spaMTPdbResource(
  "smiles_features",
  version = "3.0.7",
  metadata = TRUE
)
smiles_features_metadata[c("resource", "version", "rows", "columns")]
#>           resource version   rows columns
#> 16 smiles_features   3.0.7 284818      36

Retrieving a resource

Omit metadata = TRUE to retrieve and cache the R object. The evaluated example uses an explicitly synthetic local fixture, so package checks need no network connection. verify = FALSE is appropriate only for this deliberate fixture; it must not be used to call modified data an official RaMP snapshot.

ramp_db_metadata <- local({
  directory <- tempfile("spamtpdb-demo-")
  dir.create(directory)
  on.exit(unlink(directory, recursive = TRUE))
  saveRDS(list(synthetic = TRUE, label = "tutorial fixture"),
    file.path(directory, "ramp_db_metadata.rds"))
  spaMTPdbResource("ramp_db_metadata", local_dir = directory,
    offline = TRUE, verify = FALSE)
})
str(ramp_db_metadata, max.level = 1)
#> List of 2
#>  $ synthetic: logi TRUE
#>  $ label    : chr "tutorial fixture"

Larger resources are retrieved the same way. The chemical property table backs the indexed MS1 annotation engine:

chem_props <- spaMTPdbResource("chem_props", version = "3.0.7")

Downloads are cached, so repeated calls in an analysis resolve from disk. Use cache_dir to override the default user cache returned by tools::R_user_dir().

Retrieving a coherent bundle

spaMTPdbBundle() returns several resources from one database version, which keeps identifiers consistent across an analysis:

bundle <- spaMTPdbBundle(
  resources = c("chem_props", "pathway"),
  version = "3.0.7",
  metadata = TRUE
)
vapply(bundle, function(row) row$title, character(1))
#>                  chem_props                     pathway 
#> "SpaMTPdb_chem_props_3.0.7"    "SpaMTPdb_pathway_3.0.7"

Working from a staged directory

Package developers and reproducible database builds can stage the resources locally and bypass both the Hub and Zenodo entirely:

options(SpaMTPdb.resource_dir = "/path/to/SpaMTPdb-resources/3.0.7")
core <- spaMTPdbBundle()

Local files are verified against the registry by default. Setting offline = TRUE uses local files or a verified cache, and errors when neither is available rather than attempting a network connection.

The three-package workflow

SpaMTPdb supplies versioned annotation tables, SpaMTPData supplies experiment resources and a small spaMTPExampleData() SpatialExperiment, and SpaMTP performs analysis using native Bioconductor containers. These data packages do not import the software package or Seurat. The executable three-package example is in SpaMTP’s SpaMTP_Companion_Workflow vignette.

The submission API uses spaMTPdbResource(), spaMTPdbResources(), spaMTPdbBundle() and spaMTPdbVersion(). Update the companion packages together with SpaMTP when replacing historical PascalCase calls.

Recording the version used

spaMTPdbVersion() reports the available snapshots, newest first. Recording this value alongside an analysis makes the annotation step reproducible:

spaMTPdbVersion()
#> [1] "3.0.7"

Session information

sessionInfo()
#> R version 4.6.1 (2026-06-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.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.32.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: Etc/UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] SpaMTPdb_0.99.4  BiocStyle_2.41.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] rappdirs_0.3.4       sass_0.4.10          generics_0.1.4      
#>  [4] BiocVersion_3.24.0   RSQLite_3.53.3       digest_0.6.39       
#>  [7] magrittr_2.0.5       evaluate_1.0.5       fastmap_1.2.0       
#> [10] blob_1.3.0           AnnotationHub_4.3.2  jsonlite_2.0.0      
#> [13] AnnotationDbi_1.75.2 DBI_1.3.0            BiocManager_1.30.27 
#> [16] httr_1.4.9           Biostrings_2.81.9    httr2_1.3.0         
#> [19] jquerylib_0.1.4      cli_3.6.6            crayon_1.5.3        
#> [22] rlang_1.3.0          XVector_0.53.0       dbplyr_2.6.0        
#> [25] Biobase_2.73.2       bit64_4.8.6          cachem_1.1.0        
#> [28] yaml_2.3.12          BiocBaseUtils_1.15.1 otel_0.2.0          
#> [31] tools_4.6.1          memoise_2.0.1        dplyr_1.2.1         
#> [34] filelock_1.0.3       BiocGenerics_0.59.12 curl_8.0.0          
#> [37] png_0.1-9            buildtools_1.0.0     vctrs_0.7.3         
#> [40] R6_2.6.1             stats4_4.6.1         BiocFileCache_3.3.0 
#> [43] lifecycle_1.0.5      Seqinfo_1.3.2        KEGGREST_1.53.6     
#> [46] S4Vectors_0.51.10    IRanges_2.47.5       bit_4.6.0           
#> [49] pkgconfig_2.0.3      bslib_0.12.0         pillar_1.11.1       
#> [52] glue_1.8.1           xfun_0.61            tibble_3.3.1        
#> [55] tidyselect_1.2.1     sys_3.4.3            knitr_1.52          
#> [58] htmltools_0.5.9      rmarkdown_2.32       maketools_1.3.2     
#> [61] compiler_4.6.1