neighLDA
neighLDA ¶
neighLDA(
data,
xCoordinate="X_centroid",
yCoordinate="Y_centroid",
zCoordinate=None,
phenotype="phenotype",
neighbor_method="radius",
radius=30,
knn=10,
imageId="imageid",
numMotifs=10,
randomState=0,
subset=None,
inferenceMode="phenotype_driven",
layer=None,
subsetMarker=None,
streamData=False,
verbose=True,
label="neighLDA",
outputDir=None,
sdataTable=None,
**kwargs
)
Latent Dirichlet Allocation motifs over neighbourhood composition.
Each cell's neighbourhood becomes a bag of cell-type "words"; LDA then finds
numMotifs latent topics over those documents. Every cell gets a probability
distribution over motifs instead of a single label, so tissue regions that are
genuinely mixtures come out as mixtures.
uns[label] holds the per-cell motif weights and
uns[label + "_probability"] the full probability matrix. Cluster the weights
with cluster(mode="spatial") if you do want discrete neighbourhoods in the
end.
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
|
phenotype
|
str
|
Column in |
'phenotype'
|
neighbor_method
|
str
|
|
'radius'
|
radius
|
float
|
Neighbourhood radius for |
30
|
knn
|
int
|
Neighbour count for |
10
|
imageId
|
str
|
Column in |
'imageid'
|
numMotifs
|
int
|
Number of latent motifs to fit. This is the main thing to tune: too few and distinct neighbourhoods merge, too many and they fragment. |
10
|
randomState
|
int
|
Seed for LDA. Fix it for reproducible motifs. |
0
|
subset
|
str
|
Process only this image. |
None
|
inferenceMode
|
str
|
|
'phenotype_driven'
|
layer
|
str
|
Which matrix to read for |
None
|
subsetMarker
|
list
|
Restrict |
None
|
label
|
str
|
Key in |
'neighLDA'
|
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
|
**kwargs
|
dict
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
adata |
AnnData | SpatialData | None
|
The updated object with |
Example
adata = sp.tl.neighLDA(
adata, phenotype="phenotype", neighbor_method="radius", radius=50,
numMotifs=10, label="ldaRadius50",
)
adata.uns["ldaRadius50"].head()
# Turn the soft motifs into discrete neighbourhoods.
adata = sp.tl.cluster(
adata, mode="spatial", layer="ldaRadius50", method="kmeans", k=6,
label="rcn",
)