Spatial¶
spatial_distribution¶
-
spatialtis.
spatial_distribution
(adata, groupby=None, method='nns', pval=0.01, r=10, resample=500, quad=(10, 10), type_key=None, centroid_key=None, export=True, export_key=None, return_df=False, mp=None)[source]¶ Cell distribution pattern
There are three type of distribution pattern (0 if no cells)
random (1)
regular (2)
cluster (3)
Three methods are provided
Variance-to-mean ratio (vmr): Index of Dispersion
Quadratic statistics (quad): Morisita’s index of dispersion
Nearest neighbors search (nns): Clark and Evans aggregation index
Random
Regular
Cluster
Index of dispersion: ID
ID = 1
ID < 1
ID > 1
Morisita’s index of dispersion: I
I = 1
I < 1
I > 1
Clark and Evans aggregation index: R
R = 1
R < 1
R > 1
- Parameters
adata – AnnData object to perform analysis
groupby – How your experiments data grouped, (Default: spatialtis.CONFIG.EXP_OBS)
method – Options are “vmr”, “quad”, and “nns”
pval – The p-value threshold to determine significance
r – Only use when method=”vmr”, diameter of sample window
resample – Only use when method=”vmr”, the number of random permutations to perform
quad – Only use when method=”quad”, how to perform rectangle tessellation
type_key – The key to store cell types in AnnData.obs (Default: spatialtis.CONFIG.CELL_TYPE_KEY)
centroid_key – The key to store cell centroid in AnnData.obs (Default: spatialtis.CONFIG.CENTROID_KEY)
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
mp – Whether to enable parallel processing (Default: spatialtis.CONFIG.MULTI_PROCESSING)
“quad” is quadratic statistic, it cuts a ROI into few rectangles, quad=(10,10) means the ROI will have 10*10 grid.
spatial_heterogeneity¶
-
spatialtis.
spatial_heterogeneity
(adata, groupby=None, method='leibovici', base=None, d=None, cut=None, compare=None, type_key=None, centroid_key=None, export=True, export_key=None, return_df=False, mp=None)[source]¶ Evaluate tissue heterogeneity based on entropy
Entropy describes the amount of information.
Shannon entropy (No spatial info included): To compare the difference within a group (eg. different samples from same tumor), Kullback–Leibler divergences for each sample within the group are computed, smaller value indicates less difference within group.
Leibovici entropy: You can specific the distance threshold to determine co-occurrence events.
Altieri entropy: You can specific the distance interval to determine co-occurrence events.
- Parameters
adata – AnnData object to perform analysis
groupby – How your experiments data grouped, (Default: spatialtis.CONFIG.EXP_OBS)
method – Options are “shannon”, “leibovici” and “altieri”
base – The log base
d – The distance threshold to determine co-occurrence events (method=”leibovici”)
cut – Distance interval (method=”altieri”)
compare – Compute Kullback-Leibler divergences based on which level
type_key – The key to store cell types in AnnData.obs (Default: spatialtis.CONFIG.CELL_TYPE_KEY)
centroid_key – The key to store cell centroid in AnnData.obs (Default: spatialtis.CONFIG.CENTROID_KEY)
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
mp – Whether to enable parallel processing (Default: spatialtis.CONFIG.MULTI_PROCESSING)
hotspot¶
-
spatialtis.
hotspot
(adata, groupby=None, type_key=None, centroid_key=None, selected_types=None, search_level=1, grid_size=50, pval=0.01, export=True, export_key=None, return_df=False, mp=None)[source]¶ -
- Parameters
adata – AnnData object to perform analysis
groupby – How your experiments data grouped, (Default: spatialtis.CONFIG.EXP_OBS)
selected_types – Select interested cell types to perform analysis
search_level – How deep the search level to reach
grid_size – Length of the side of square grid
pval – The p-value threshold to determine significance
type_key – The key to store cell types in AnnData.obs (Default: spatialtis.CONFIG.CELL_TYPE_KEY)
centroid_key – The key to store cell centroid in AnnData.obs (Default: spatialtis.CONFIG.CENTROID_KEY)
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
mp – Whether to enable parallel processing (Default: spatialtis.CONFIG.MULTI_PROCESSING)
Neighbors¶
-
class
spatialtis.
Neighbors
(adata, geom='shape', *, groupby=None, type_key=None, shape_key=None, centroid_key=None)[source]¶ Storage object for cell relationship
- Parameters
adata – AnnData object to perform analysis
geom – How to resolve cell data, as “point” or “shape”
groupby – How your experiments data grouped, (Default: spatialtis.CONFIG.EXP_OBS)
type_key – The key to store cell types in AnnData.obs (Default: spatialtis.CONFIG.CELL_TYPE_KEY)
shape_key – The key to store cell shape in AnnData.obs (Default: spatialtis.CONFIG.SHAPE_KEY)
centroid_key – The key to store cell centroid in AnnData.obs (Default: spatialtis.CONFIG.CENTROID_KEY)
-
find_neighbors
(expand=None, scale=None)[source]¶ To find the neighbors of each cell
- Parameters
expand – If the cell has shape, it means how much units to expand each cell; If the cell is point, it’s the search radius;
scale – How much to scale each cell, only if cell has shape
-
export_neighbors
(export_key=None)[source]¶ Export computed neighbors
Export to AnnData.obs. The neighbors relationship are stored in dict, the value is index of cell in each ROI Correspond to the order in AnnData object
- Parameters
export_key (Optional[str]) – The name of key used to stored the exported result
neighborhood_analysis¶
-
spatialtis.
neighborhood_analysis
(n, method='pval', resample=500, pval=0.01, order=True, export=True, export_key=None, return_df=False)[source]¶ Profiling cell-cell interaction using permutation test
Neighborhood analysis tells you the relationship between different type of cells
Association (1)
Avoidance (-1)
No relationship (0)
This method is implemented in Rust, it executes in parallel automatically.
- Parameters
n – A spatialtis.Neighbors object, neighbors are already computed
method – Options are “pval” and “zscore”
resample – Number of times to perform resample
pval – The p-value threshold to determine significance
order – if False, (Cell_A, Cell_B) and (Cell_B, Cell_A) are the same interaction.
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
See also
spatial_enrichment_analysis¶
-
spatialtis.
spatial_enrichment_analysis
(n, threshold=None, layers_key=None, selected_markers=None, marker_key=None, resample=500, pval=0.01, export=True, export_key=None, return_df=False)[source]¶ Profiling markers co-expression using permutation test
Similar to neighborhood analysis which tells you the relationship between different type of cells. This analysis tells you the spatial relationship between markers.
This method is implemented in Rust, it executes in parallel automatically.
- Parameters
n – A spatialtis.Neighbors object, neighbors are already computed
threshold – The expression level to determine whether a marker is positive
layers_key – The layer in anndata to perform analysis
selected_markers – Select interested markers to perform analysis
marker_key – The key to store markers in AnnData.var (Default: spatialtis.CONFIG.MARKER_KEY)
resample – Number of times to perform resample
pval – The p-value threshold to determine significance
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
See also
communities¶
-
spatialtis.
communities
(n, partition_type=None, export=True, export_key=None, return_df=False, **kwargs)[source]¶ Leidenalg algorithm for communities detection
- Parameters
n – A spatialtis.Neighbors object, neighbors are already computed
partition_type – The leidenalg partition type
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
**kwargs – Pass to leidenalg.find_partition
exp_neighcells¶
-
spatialtis.
exp_neighcells
(n, std=2.0, marker_key=None, export=True, export_key=None, return_df=False, mp=None, **kwargs)[source]¶ Find the neighbor cells’ influence on marker expression
Random forest regressor is built to estimate the occurrence of different types of neighbor cells on cell’s gene expression level. Y is the gene expression, normalize by mean. X is the number of different cell types. For example: for cell type A with gene T 700, the neighbors of cells are type A 3, type B 2, type C 5 then Y = 700, X = (3, 2, 5)
A reasonable std should be set, the marker expression need to have certain degree of variance.
- Parameters
n – A spatialtis.Neighbors object, neighbors are already computed
std – Standard deviation, threshold to filter out markers that are not variant enough
marker_key – The key to store markers in AnnData.var (Default: spatialtis.CONFIG.MARKER_KEY)
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
mp – Whether to enable parallel processing (Default: spatialtis.CONFIG.MULTI_PROCESSING)
**kwargs – Pass to sklearn.ensemble.RandomForestRegressor (Default: random_state=0)
exp_neighexp¶
-
spatialtis.
exp_neighexp
(n, score=0.5, marker_key=None, export=True, export_key=None, return_df=False, mp=None, **kwargs)[source]¶ Find the neighbor marker influence on marker expression after exp_neighcell
- Parameters
n – A spatialtis.Neighbors object, neighbors are already computed
score – Threshold to filter out markers are less importance
marker_key – The key to store markers in AnnData.var (Default: spatialtis.CONFIG.MARKER_KEY)
export – Whether export the result to AnnData.uns
export_key – The name of key used to stored the exported result
return_df – Whether to return the result dataframe
mp – Whether to enable parallel processing (Default: spatialtis.CONFIG.MULTI_PROCESSING)
**kwargs – Pass to sklearn.ensemble.RandomForestRegressor (Default: random_state=0)