| Title: | Spatial Component Analysis for Spatial Sequencing Data |
|---|---|
| Description: | Spatial components offer tools for dimension reduction and spatially variable gene detection for high dimensional spatial transcriptomics data. Construction of a projection onto low-dimensional feature space of spatially dependent metagenes offers pre-processing to clustering, testing for spatial variability and denoising of spatial expression patterns. For more details, see Koehler et al. (2026) <doi:10.1093/bioinformatics/btag052>. |
| Authors: | David Köhler [aut, cre] (ORCID: <https://orcid.org/0009-0006-0027-4046>) |
| Maintainer: | David Köhler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-05-31 08:47:03 UTC |
| Source: | https://github.com/cran/SPACO |
create_SpaCoObject_from_KNN
create_SpaCoObject_from_KNN(SeuratObject, n = 10)create_SpaCoObject_from_KNN(SeuratObject, n = 10)
SeuratObject |
Seurat object to export kNN-graph from. |
n |
Number of neighbors to consider. |
Returns a SPaCoObject with the SCT data and the kNN-graph as neighborhood matrix.
computes smoothed gene profiles of genes present in the data.
denoise_profiles(SpaCoObject)denoise_profiles(SpaCoObject)
SpaCoObject |
Spaco object to compute profiles of. |
smoothed gene profiles in the SpaCoObject.
Plot denoised gene expression
denoised_projection_plot(SpaCoObject, feature = NULL)denoised_projection_plot(SpaCoObject, feature = NULL)
SpaCoObject |
SpacoObject with computed projections |
feature |
Gene for which to plot denoised projection |
returns a ggplot object with the denoised gene expression.
This function multiplies two matrices using the Eigen library, which provides fast linear algebra operations.
eigenMapMatMult(A, B)eigenMapMatMult(A, B)
A |
a matrix |
B |
a matrix |
the product of A and B
Plot gene expression
feature_plot(SpaCoObject, feature)feature_plot(SpaCoObject, feature)
SpaCoObject |
SpacoObject with computed projections |
feature |
Gene to plot |
returns a ggplot object with gene expression.
Read in 10x Visium spatial transcriptomics data
read_10x_for_spaco( data_dir, slice, filename, variable_features_n = variable_features_n, spatial_file = spatial_file, vars_to_regress = NULL )read_10x_for_spaco( data_dir, slice, filename, variable_features_n = variable_features_n, spatial_file = spatial_file, vars_to_regress = NULL )
data_dir |
Directory containing the H5 file specified by file name and the image data in a sub directory called spatial |
slice |
Name for the stored image of the tissue slice |
filename |
Filename of data to be read |
variable_features_n |
Number of most variable features to keep. |
spatial_file |
Name of csv file from which to read tissue positions. |
vars_to_regress |
Names of features to be regressed against using PercentageFeatureSet |
Retuns a ready to run SPaCoObject.
Set projections of Spaco Object
set_projection(SpaCoObject, data, neighborhood = SpaCoObject@neighbours)set_projection(SpaCoObject, data, neighborhood = SpaCoObject@neighbours)
SpaCoObject |
Fitted object of class |
data |
gene expression data matrix; p genes as columns, n loci as rows |
neighborhood |
neighborhood matrix of the new data. Must be of dimension n times n, where n is the number of columns of |
Returns the SpaCoObject with the updated data, neighborhood matrix, and projection matrix.
Wrapper to transform existing Seurat object into an SpaCoObject.
seurat_to_spaco(SeuratObject, assay = "SCT", n_image = 1, layer = "scale.data")seurat_to_spaco(SeuratObject, assay = "SCT", n_image = 1, layer = "scale.data")
SeuratObject |
Seurat object to export |
assay |
Assay to export from the Seurat object. Default is SCT assay. |
n_image |
Number of the image to export from Seurat object. Only relevant if Seurat object contains multiple images. Default is 1. |
layer |
Which layer to export data from. Default is scale.data. |
Returns a SpaCoObject with all slots filled necessary to perform the spatial component analysis.
SpaCo
SpaCo( SpaCoObject, PC_criterion = "percent", PC_value = 0.95, set_nspacs = NULL, nSim = 1000, nSpacQuantile = 0.05, reducedSpots = FALSE, nReduce = 1000 )SpaCo( SpaCoObject, PC_criterion = "percent", PC_value = 0.95, set_nspacs = NULL, nSim = 1000, nSpacQuantile = 0.05, reducedSpots = FALSE, nReduce = 1000 )
SpaCoObject |
Object of class |
PC_criterion |
criterion on which to select number of principal components for initial covariance matrix reconstruction; either "number" to select a number of PCs or "percent" to select number of PCs to explain specified amount of data variance |
PC_value |
Value to specify number of PCs or desired level of explained variance, see "PC_criterion" |
set_nspacs |
Boolean if number of relevant spacs is to be computed. Increases run time significantly |
nSim |
Number of simulations for computation of spac number |
nSpacQuantile |
Quantile to use as cutoff for spac number |
reducedSpots |
Should algorithm be run on a subset of spots? Default = FALSE |
nReduce |
Number of spots to sample to run algorithm on subset if |
Returns a SpaCoObject filled with the result of the spatial component analysis.
Plot SPaCo meta genes.
Spaco_plot(SpaCoObject, spac = 1)Spaco_plot(SpaCoObject, spac = 1)
SpaCoObject |
SpacoObject with computed projections |
spac |
component to plot |
returns a ggplot object with the meta gene expression.
Create a constructor function that creates an object of class SpaCoObject
SpaCoObject(neighbours, data, coordinates)SpaCoObject(neighbours, data, coordinates)
neighbours |
Binary matrix with weights describing if cells are to be considered neighbours or not depending on the defined distance. |
data |
Matrix with normalized and scaled gene counts. Rows as cells and genes as columns |
coordinates |
Matri with the cell coordinates on the slides. Rows and Columns in the 10x Visium case. |
Returns a SpaCoObject with the given slots filled
transfer computed spatial components to existing Seurat object.
spacs_to_seurat(SpaCoObject, SeuratObject, nSpacs = SpaCoObject@nSpacs)spacs_to_seurat(SpaCoObject, SeuratObject, nSpacs = SpaCoObject@nSpacs)
SpaCoObject |
SpaCoObject to export spatial components from. |
SeuratObject |
Seurat object to add spatial components to. |
nSpacs |
Number of Spacs which are to be projected on for dimension reduction |
Returns a Seurat Object with the spatial components projections in the dimensional reduction slot.
Filtering function to remove cells without neighbours in defined distance from existing Seurat object to be conformable with existing SpaCoObject.
subset_non_neighbour_cells(SpaCoObject, SeuratObject)subset_non_neighbour_cells(SpaCoObject, SeuratObject)
SpaCoObject |
SpaCoObject to integrate into Seurat object. |
SeuratObject |
Seurat object to be filtered. |
Returns a Seurat object with cells filtered to match SpaCoObject.
Compute the spatial variable genes of a SpaCoObject after runinng runSCA
SVGTest(SpaCoObject, adjustMethod = "holm")SVGTest(SpaCoObject, adjustMethod = "holm")
SpaCoObject |
SpaCoObject to compute spatially variable genes of. |
adjustMethod |
method for p-value adjustment. See p.adjust function. |
returns a data frame of spatial variable genes and their p-Values.