API Reference
This page lists the public stGrads 2.0 functions. Arguments shown here are
the most important user-facing arguments; run ?function_name in R for the
complete help page and defaults.
Spatial pseudo-cells and transcriptomic aggregation
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
List with |
Aggregates spatially adjacent segmented units into pseudo-cells while preserving segment-level provenance. |
|
|
List with sparse counts and grouped metadata |
Aggregates counts by metadata groups without using spatial coordinates. |
|
|
Normalized matrix |
Performs sparse-friendly library-size normalization. |
|
|
Cell-by-program score matrix |
Scores deterministic marker programs from one or more gene sets. |
|
|
Numeric overlap score |
Combines two marker-program scores, including the minimum fuzzy intersection. |
stg_spatial_pseudocells() mapping output
The cell_map table has one row per retained original segment and includes:
Column |
Meaning |
|---|---|
|
Original segmented-unit identifier. |
|
Pseudo-cell receiving the segment. |
|
Sample-specific spatial grid identifier. |
|
Integer spatial-grid coordinates. |
|
Original segment centroid. |
|
Original sample or replicate identifiers. |
|
Original cell-type annotation, when supplied. |
The pseudo-cell-level metadata table contains n_segments,
x_centroid, y_centroid, grid_x, and grid_y. This makes it possible to
assign a CAF or NicheNet-related label to a pseudo-cell and project that label
back to every original segment.
Spatial coordinates and gradients
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
|
Extracts coordinates from metadata, Seurat images, or segmentation boundaries. |
|
|
Coordinate matrix |
Standardizes coordinate input for spatial calculations. |
|
|
Cell-level gradient table |
Computes spatial distance or decayed reference strength. |
|
|
Feature-level test table |
Tests transcriptomic association with a spatial gradient. |
|
|
Numeric weights |
Applies an exponential or user-defined spatial decay. |
|
|
Neighborhood counts and proportions |
Quantifies local cell-type composition. |
|
|
Interface distance table |
Quantifies distance to a tumor or epithelial interface. |
|
|
Barrier proxy table |
Summarizes stromal obstruction between spatial populations. |
Morphology and segmentation
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
Morphology table |
Computes cell-area and shape descriptors from segmentation polygons. |
|
|
Updated object or metadata |
Adds morphology features to a spatial object. |
|
|
Combined morphology table |
Combines cell and nuclear measurements. |
|
|
QC table |
Flags implausible or low-quality morphology. |
|
|
Atypia score table |
Summarizes morphology deviations within a reference group. |
|
|
Prepared morphology object |
Standardizes polygon and nucleus inputs for Visium HD analysis. |
RCTD mixed units and refinement
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
Normalized annotations |
Standardizes RCTD singlet and mixed-unit labels. |
|
|
Canonical pair labels |
Treats mixed pairs as undirected. |
|
|
Support table |
Tests whether both constituent singlet types occur nearby. |
|
|
Updated metadata/object |
Adds local support evidence to an object. |
|
|
Residual score table |
Measures expression beyond expected constituent signals. |
|
|
Ranked refinement table |
Integrates spatial, morphology, and transcriptomic evidence. |
|
|
Display class |
Labels enriched, depleted, zero-observed, or non-estimable pairs. |
Pair enrichment
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
ROI-level and condition-level tables |
Computes conditional heterotypic observed-to-expected pair enrichment. |
|
|
ggplot object |
Displays undirected pair enrichment as a triangular heatmap. |
The primary effect size is the unregularized ratio (O/E). The display-only value for an observed zero may use a finite pseudocount so that the heatmap can be colored, but the exact zero remains recorded in the output.
Publication-oriented plotting
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
ggplot theme |
Provides a consistent publication-oriented theme. |
|
|
ggplot object |
Displays cropped H&E context. |
|
|
ggplot object |
Plots segmentation polygons by class. |
|
|
ggplot object |
Maps a continuous feature onto polygons. |
|
|
ggplot object |
Displays mixed units and spatial support. |
|
|
ggplot object |
Maps a feature across spatial coordinates. |
Compatibility and data helpers
Function |
Main arguments |
Returns |
Description |
|---|---|---|---|
|
|
Matrix |
Reads Seurat v5 layers or Seurat v4 slots. |
|
|
Updated object |
Applies compatibility updates to older stGrads/Seurat objects. |
|
|
Character vector |
Standardizes HD cell identifiers. |
|
|
File path |
Returns the packaged demo H&E image path. |
|
|
List |
Reads HD scale-factor metadata. |
Legacy API
The original stGrads 0.1.x functions remain available for old scripts and RDS
workflows. New analyses should use the stg_* functions above whenever an
equivalent function exists.
FindPrimSpot(), CalcNearDis(), CalcNearDis_HD(), PlotNearDis(),
PlotStrengthDis(), PlotStrengthExpr(), PlotDisExpr(), PlotDisProp(),
CalcDRG(), PlotDRGs(), SeuLocation_StConvert(), and
calculate_distance() are retained for backward compatibility.