'dsp_test' identifies differential spatial pattern (DSP) genes between conditions from spatially-resolved transcriptomics data, provided spatial clusters are available.
Usage
dsp_test(
spe,
design = NULL,
cluster_col,
sample_col,
condition_col,
min_counts = 20,
min_non_zero_spots = 10,
min_pct_cells = 0.5,
filter_gene = FALSE,
filter_cluster = TRUE,
verbose = FALSE
)
Arguments
- spe
SpatialExperiment or SingleCellExperiment.
- design
Matrix or array. Numeric design matrix for a regression-like model created by `model.matrix` function.
- cluster_col
Character. Column name of spatial clusters in
colData(spe)
.- sample_col
Character. Column name of sample ids in
colData(spe)
. Sample ids must be either a factor or character.- condition_col
Character. Column name of condition ids in
colData(spe)
.- min_counts
Numeric. Minimum number of counts per sample (across all spots) for a gene to be analyzed.
- min_non_zero_spots
Numeric. Minimum number of non-zero spots per sample, for a gene to be analyzed.
- min_pct_cells
Numeric. Minimum percentage of cells required for each cluster to be included in the analysis across the specified conditions. Default value is 0.5 (i.e., 0.5% of total cells per cluster per condition).
- filter_gene
Logical. If TRUE,
dsp_test
filters genes by requiring them to be expressed in at least 'min_non_zero_spots' cells and have at least 'min_counts' counts per sample across all locations.- filter_cluster
Logical. When set to TRUE,
dsp_test
excludes clusters that are insufficiently represented in the dataset. Only clusters meeting the 'min_pct_cells' threshold (i.e., containing at least the specified percentage of cells across all conditions) will be retained for analysis.- verbose
Logical. If TRUE,
svg_test
returns two more results: 'DGEGLM' and 'DGELRT' objects contain full statistics from 'edgeR::glmFit' and 'edgeR::glmLRT'.
Value
A list of results:
- "gene_results": a dataframe contains main edgeR test results;
- "estimated_y": a DGEList object contains the estimated common dispersion, which can later be used to speed-up calculation when testing individual clusters.
- "glmFit" (only if verbose = TRUE
): a DGEGLM object contains full statistics from "edgeR::glmFit".
- "glmLRT" (only if verbose = TRUE
): a DGELRT object contains full statistics from "edgeR::glmLRT".
Examples
## Load the example multi-sample multi-group spe object
spe <- muSpaData::Wei22_example()
#> see ?muSpaData and browseVignettes('muSpaData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> require(“SpatialExperiment”)
# Fit the model via \code{\link{dsp_test}} function.
set.seed(123)
results_dsp <- dsp_test(spe = spe,
cluster_col = "Banksy_smooth",
sample_col = "sample_id",
condition_col = "condition",
verbose = FALSE)
#> Using 'dsp_test' for spatial variable pattern genes detection.
#> Filter low quality clusters:
#> Cluster levels to keep: 0, 1, 2, 3, 4
#> Design model: row names represent sample names, followed by underscores and cluster names.
#> (Intercept) condition20DPI condition2DPI cluster_id1 cluster_id2
#> 2DPI_1_0 1 0 1 0 0
#> 2DPI_2_0 1 0 1 0 0
#> cluster_id3 cluster_id4 condition20DPI:cluster_id1
#> 2DPI_1_0 0 0 0
#> 2DPI_2_0 0 0 0
#> condition2DPI:cluster_id1 condition20DPI:cluster_id2
#> 2DPI_1_0 0 0
#> 2DPI_2_0 0 0
#> condition2DPI:cluster_id2 condition20DPI:cluster_id3
#> 2DPI_1_0 0 0
#> 2DPI_2_0 0 0
#> condition2DPI:cluster_id3 condition20DPI:cluster_id4
#> 2DPI_1_0 0 0
#> 2DPI_2_0 0 0
#> condition2DPI:cluster_id4
#> 2DPI_1_0 0
#> 2DPI_2_0 0
# dsp_test returns of an object:
# "gene_results": a dataframe contains main edgeR test results.
# We visualize differential results:
head(results_dsp, 3)
#> gene_id logFC.condition20DPI.cluster_id1
#> AMEX60DD014721 AMEX60DD014721 -0.07170723
#> AMEX60DD045083 AMEX60DD045083 0.08759059
#> AMEX60DD011151 AMEX60DD011151 -0.97377297
#> logFC.condition2DPI.cluster_id1 logFC.condition20DPI.cluster_id2
#> AMEX60DD014721 -0.3898784 -0.8510223
#> AMEX60DD045083 0.5418637 -1.3377605
#> AMEX60DD011151 -2.1019048 0.1861520
#> logFC.condition2DPI.cluster_id2 logFC.condition20DPI.cluster_id3
#> AMEX60DD014721 0.8526301 -0.8328237
#> AMEX60DD045083 1.1226997 0.2478193
#> AMEX60DD011151 0.4671347 -0.4011555
#> logFC.condition2DPI.cluster_id3 logFC.condition20DPI.cluster_id4
#> AMEX60DD014721 -0.9450830 0.22287797
#> AMEX60DD045083 1.2666344 -0.99648014
#> AMEX60DD011151 0.4086612 -0.01634095
#> logFC.condition2DPI.cluster_id4 logCPM LR PValue
#> AMEX60DD014721 0.2085777 9.344907 100.69288 3.081052e-18
#> AMEX60DD045083 -0.7969334 7.505402 97.72697 1.243325e-17
#> AMEX60DD011151 0.1810959 7.959492 85.69149 3.472538e-15
#> FDR
#> AMEX60DD014721 1.540526e-14
#> AMEX60DD045083 3.108313e-14
#> AMEX60DD011151 5.787563e-12