Relations and analysis
SpatialRelation is the generic structure for weighted associations between spatial elements. The RelationKind dispatch tokens select the algorithm used by analyze.
Relation kinds
SpatialOmics.RelationKind — Type
RelationKindAbstract supertype for relation-kind dispatch tokens.
Concrete subtypes — Membership, Proximity, KNN, Expression — are passed to analyze to select the algorithm, and stored in the resulting SpatialRelation to enable re-dispatch.
SpatialOmics.Membership — Type
Membership(; strict=false)
Membership{strict}Assignment of source observations to containing destination shapes.
strict=false(default): containment is tested by point-in-polygon for transcripts, or centroid-in-polygon for cell shapes.strict=true: full geometric containment is required.
See also
SpatialOmics.Proximity — Type
SpatialOmics.KNN — Type
SpatialOmics.Expression — Type
Expression()Relation kind for a cell × gene transcript count matrix.
Produced by analyze(Expression(), pts, cells), which assigns each transcript to the cell containing it and accumulates counts. The weights field is a Float32 matrix of shape (ncells × ngenes); var holds a named tuple with a :name column of gene names.
See also
Relations
SpatialOmics.SpatialRelation — Type
SpatialRelation{K<:RelationKind, W}Weighted relation between two named spatial elements.
The relation kind K determines the semantics: Expression is a bipartite cell × gene count matrix; Membership is a source-to-destination assignment; Proximity and KNN are graph structures.
src,dst: element names in the parent datasetsrc_ids,dst_ids:instance_idvectors identifying the rows/nodesweights: the relation data (Matrix{Float32}ornothing)obs: per-row metadata (Tables.jl-compatible)var: per-column metadata (forExpression: gene names via:name)kind: theRelationKindsingleton
Constructors
SpatialRelation(kind, src, dst, src_ids, dst_ids, weights=nothing; obs)
SpatialRelation(Expression(), src, src_ids, weights; obs, var)See also
SpatialOmics.nobs — Function
nobs(rel) → IntReturn the number of source observations (rows) in a SpatialRelation.
SpatialOmics.nvar — Function
SpatialOmics.var_names — Function
SpatialOmics.annotate — Function
annotate(rel, labels; key::Symbol) → SpatialRelationReturn a new SpatialRelation with labels added as column key in rel.obs.
Pure — does not modify rel. labels must have length equal to nobs(rel).
types = assign_cell_types(rel)
rel2 = annotate(rel, types; key=:cell_type)See also
Analysis
SpatialOmics.analyze — Function
analyze(kind, args...) → SpatialRelation
analyze(pts::SpatialPoints, cells::SpatialShapes) → Expression relation
analyze(src::SpatialShapes, dst::SpatialShapes) → Membership relation
analyze(rel::SpatialRelation{Expression}; k=30) → KNN relationCompute a spatial relation between elements.
Dispatch on the RelationKind token selects the algorithm:
analyze(Expression(), pts, cells)— count transcripts per gene per cell. Each transcript is assigned to the first containing cell (bounding-box pre-filter, then exact point-in-polygon). Returns an ncells × ngenes count matrix.analyze(Membership(), src, dst)— assign each point or shape insrcto the containing shape indst.strict=truerequires full containment; default uses centroid or point containment.analyze(KNN(k), rel)— k-nearest-neighbour graph on anExpressionrelation. Requiresusing NearestNeighbors.
The two-argument forms (pts, cells and src, dst) infer the kind from argument types and call the explicit form.
See also
SpatialOmics.distances — Function
distances(shapes_a, shapes_b) → Vector{Float32}
distances(shapes, roi) → Vector{Float32}Compute the minimum distance from each shape in shapes_a to the nearest shape in shapes_b (or to a SpatialROI boundary), using centroid-to-shape signed distance.
Returns a Float32 vector of length length(shapes_a).
See also
SpatialOmics.PointDensity — Type
PointDensityLazy density estimate descriptor for a SpatialPoints collection.
Produced by density(pts; resolution, feature). Passed to Makie plot verbs to render a rasterised kernel density map at display time.
See also
SpatialOmics.density — Function
density(pts; resolution=512, feature=nothing) → PointDensityCreate a lazy density estimate descriptor for pts.
resolution sets the output grid size (pixels along the longer axis). feature restricts density computation to a single feature label; nothing uses all points.
See also
SpatialOmics.ShapeColorView — Type
ShapeColorViewDisplay descriptor that pairs a SpatialShapes collection with per-shape color values from a SpatialRelation.
Passed to Makie's poly! to render shapes coloured by an expression or other quantitative measure.
See also