How cemos-mannheim/molecular works
Project Type and Purpose
• This is an R package ("moleculaR") that provides a computational framework for spatial probabilistic mapping of metabolites in mass-spectrometry imaging (MSI).
• It includes both (a) a library of core R functions (under R/) for data import, processing, statistical mapping, and visualization, and (b) two Shiny-based web-apps (under inst/shiny/) for interactive GUI deployment (example-app and package-app).
• It comes with built-in example data, uses the SwissLipids database, ingests METASPACE annotations, and supports deployment via Shiny Server.
File-Structure Analysis
• Top-level “R/” directory: contains ~40 .R files (core algorithmic modules: data import, normalization, spatial window creation, probability mapping, plotting, Shiny launcher).
• “inst/shiny/”: two Shiny apps (example-app.R and package-app.R) plus static “www” assets.
• “data/”: preprocessed example RData.
• “vignettes/”: R Markdown walk-throughs illustrating package usage.
• “renv/” + renv.lock: reproducible environment for dependencies.
• Standard R package metadata: DESCRIPTION, NAMESPACE, man/ Rd docs.
README Insights
• Core tech: R, Shiny, renv.
• Data sources: SwissLipids DB (bundled), METASPACE (via REST / file import).
• Features: FDR-verified probabilistic maps (MPMs), collective projection maps (CPPMs), spatial and statistical ops, interactive GUI.
• Deployment: local Shiny Server, standalone web-apps.
• User Interface
– Web Browser (interacts via HTTP)
– Shiny Web GUI (example-app & package-app)
• Presentation Layer
– Shiny Server (optional) or local R session with runShiny()
• Application Layer (core package functions)
– Data Import Module (readCentrData.R, readSingleSpect.R, manualSpatstatImport.R)
– Database Module (loadSwissDB.R, downloadExData.R, recreateExData.R)
– Processing Engine
· Preprocessing & Filtering (filterPeaks.R, filterDuplicates.R, normalizeIntensity.R, transformIntensity.R)
· Spatial Window & Matrix Generation (createSpatialWindow.R, createSparseMat.R)
· Statistical Mapping (estimateFwhm.R, gaussWeight.R, probMap.R, moleculaR.R)
– Visualization Module (plotting-functions.R, focusPlot.R, plotImg.R, plot.molProbMap.R)
– Batch & Simulation Utilities (batchAnalyteSearch.R, simulation-functions.R)
• Data Layer
– Local Example Data (data/processed-example-Data.RData)
– External METASPACE Annotations (inst/extdata/*.txt, .csv, .tsv)
– SwissLipids DB (inst/extdata/swisslipids-speciesOnly-sep2020.tsv)
• Environment & Deployment
– renv-managed R library (renv/)
– Dependencies: Shiny, terra (GDAL), MALDIquantForeign/XML (Suggests), others from DESCRIPTION
1. User → Browser → (HTTP) → Shiny Web GUI
2. Shiny Web GUI → invokes core functions via runShiny()/Shiny Server
3. Data Import Module ↔ External Data Layer (SwissLipids + METASPACE files)
4. Processing Engine consumes imported data → outputs spatial point patterns & probability scores
5. Visualization Module reads processed objects → renders interactive/ static plots → Shiny UI
6. Batch & Simulation utilities operate on core modules similarly
7. renv ensures reproducible dependency resolution for all modules
c. Architectural Patterns & Principles
• Modular separation of concerns: data import, processing, visualization, deployment
• MVC-style pattern within Shiny: UI (ui.R sections in example-app/package-app), Server (core function calls), Model (R objects representing MSI data)
• Dependency management & reproducibility via renv
• Stateless web layer: Shiny session encapsulates user state
d. Key Technologies & Frameworks
• R (language)
• Shiny (web framework)
• renv (dependency management)
• terra (spatial raster support, GDAL)
• MALDIquantForeign/XML (optional)
• SwissLipids & METASPACE data interfaces