Computes spatial similarity of gene expression between two SpatialExperiments.
spatialSimilarity.RdThis function calculates the spatial similarity of gene expression patterns between two SpatialExperiment objects based on thresholding and fold-change criteria. Similarity is defined as the proportion of pixels where the fold change in gene expression falls within a specified range.
Usage
spatialSimilarity(
input,
t1 = NULL,
t2 = NULL,
minQuantile = 0.05,
minPixels = 0.1,
foldChange = 1,
assayName = NULL
)Arguments
- input
List of two SpatialExperiment objects. The first element corresponds to the first spatial experiment (`x`), and the second to the second spatial experiment (`y`). Similarity is computed as the proportion of pixels satisfying: `-b <= log2(y/x) <= b` for each gene, where `b = 1` as default
- t1
numeric: Gene expression threshold for the first spatial experiment (`x`). Only pixels with values greater than t1 or t2 are used to calculate similarity score. Default isNULL. If no value is supplied fort1, then each gene will have a threshold set as byminQuantile.- t2
numeric: Gene expression threshold for the second spatial experiment (`y`). Only pixels with values greater than t1 or t2 are used to calculate similarity score. Default isNULL. If no value is supplied fort2, then each gene will have a threshold set as byminQuantile.- minQuantile
numeric: Gene expression minimum quantile threshold to use ift1andt2are not supplied. Default is0.05.- minPixels
numeric: Pixels minimum threshold. If less than this percentage of pixels meet the gene expression minimum threshold, then a spatial similarity score is not calculated for this gene and the function returns `NA`. Default is0.1.- foldChange
numeric: Fold-change threshold defining similarity in gene expression across spatial locations. Default is1.- assayName
A character string or numeric specifying the assay in the Spatial Experiment to use. Default is
NULL. If no value is supplied forassayName, then the first assay is used as a default
Value
A list containing:
- similarityTable
A data frame with the following columns:
geneGene name.
percentSimilarityPercentage of similar pixels for the gene.
percentDissimilarityXPercentage of pixels for which log2(y/x) < -foldChange.
percentDissimilarityYPercentage of pixels for which log2(y/x) > foldChange.
similarPixelIDList of pixel IDs classified as similar.
dissimilarPixelIDXList of pixel IDs for log2(y/x) < -foldChange.
dissimilarPixelIDYList of pixel IDs for log2(y/x) > foldChange.
numPixelInThreshNumber of pixels above the threshold in both experiments.
pixelIDInThreshList of pixel IDs above the threshold.
numPixelOutThreshNumber of pixels below the threshold.
pixelIDOutThreshList of pixel IDs below the threshold.
t1Threshold value for this gene in first spatial experiment.
t2Threshold value for this gene in second spatial experiment.
- pixelLogTransformation
A data frame containing log-transformed fold-change values for each gene.
- parameters
A list of input parameters used in the computation.
Examples
data(speKidney)
##### Rasterize to get pixels at matched spatial locations #####
rastKidney <- SEraster::rasterizeGeneExpression(speKidney,
assay_name = 'counts', resolution = 0.2, fun = "mean",
BPPARAM = BiocParallel::MulticoreParam(), square = FALSE)
s <- spatialSimilarity(list(rastKidney$A, rastKidney$C))