neighExp
neighExp ¶
neighExp(
data,
xCoordinate="X_centroid",
yCoordinate="Y_centroid",
zCoordinate=None,
method="radius",
radius=30,
knn=10,
imageId="imageid",
layer="raw",
log=True,
subset=None,
label="neighExp",
verbose=True,
outputDir=None,
streamData=False,
sdataTable=None,
)
Neighbourhood-weighted expression (spatial lag) for every cell.
For each cell, average the expression of its neighbours, producing a
cell x marker matrix in which each value describes the cell's surroundings.
Clustering it with cluster(mode="spatial") gives Recurrent Cellular
Neighbourhoods defined by expression rather than by cell type.
The neighbour weights are assembled directly as row/column/value arrays and
multiplied through a sparse matrix, so the lag is one csr_matrix product
rather than a loop over cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
xCoordinate
|
str
|
Column in |
'X_centroid'
|
yCoordinate
|
str
|
Column in |
'Y_centroid'
|
zCoordinate
|
str
|
Column in |
None
|
method
|
str
|
How neighbourhoods are defined. |
'radius'
|
radius
|
float
|
Neighbourhood radius in the units of the coordinate columns, normally
pixels. Used when |
30
|
knn
|
int
|
Number of nearest neighbours. Used when |
10
|
imageId
|
str
|
Column in |
'imageid'
|
layer
|
str
|
Which matrix to average. |
'raw'
|
log
|
bool
|
Apply |
True
|
subset
|
str
|
Process only this image. |
None
|
label
|
str
|
Key in |
'neighExp'
|
verbose
|
bool
|
Print progress messages. |
True
|
outputDir
|
str
|
Directory to write the updated object to. With |
None
|
streamData
|
bool
|
Run out of core against an |
False
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
adata |
AnnData | SpatialData | None
|
The updated object with the cell x marker lagged matrix in |
Example
adata = sp.tl.neighExp(adata, method="radius", radius=30, layer="raw")
# Cluster the environment rather than the cell.
adata = sp.tl.cluster(
adata, mode="spatial", layer="neighExp", method="kmeans", k=8,
label="expressionNeighbourhood",
)
sp.pl.spatialScatterPlot(adata, colorBy="expressionNeighbourhood", s=3)