spatialDistanceHeatmap
spatialDistanceHeatmap ¶
spatialDistanceHeatmap(
data,
spatialDistance="spatial_distance",
phenotype="phenotype",
imageId="imageid",
log=False,
heatmapSummarize=True,
heatmapNaColor="grey",
heatmapCmap="vlag_r",
distanceFrom=None,
distanceTo=None,
subsetCol=None,
subsetValue=None,
fileName="spatial_distance_heatmap.pdf",
outputDir=None,
saveDir=None,
show=True,
returnData=False,
returnFig=False,
dpi=300,
transparent=False,
sdataTable=None,
**kwargs
)
Cell-type by cell-type distance matrix, as a heatmap.
Reads the per-cell distances that
sp.tl.spatialDistance writes to
uns[spatialDistance], averages them within each phenotype, and draws the
result. A reversed colormap is used by default so that near reads as warm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
spatialDistance
|
str
|
Key in |
'spatial_distance'
|
phenotype
|
str
|
Column in |
'phenotype'
|
imageId
|
str
|
Column in |
'imageid'
|
log
|
bool
|
Plot |
False
|
heatmapSummarize
|
bool
|
Accepted for signature compatibility with scimap; distances are always
averaged across images in the current implementation. Use |
True
|
heatmapNaColor
|
str
|
Colour for missing pairs. Accepted for signature compatibility. |
'grey'
|
heatmapCmap
|
str
|
Matplotlib colormap. |
'vlag_r'
|
distanceFrom
|
str | list
|
Keep only these phenotypes as rows — the cell types you are measuring from. |
None
|
distanceTo
|
str | list
|
Keep only these phenotypes as columns — the cell types you are measuring to. |
None
|
subsetCol
|
str
|
Column in |
None
|
subsetValue
|
str | list
|
Values of |
None
|
**kwargs
|
dict
|
Extra options. |
{}
|
fileName
|
str
|
File name for the saved figure. The extension decides the format. |
'spatial_distance_heatmap.pdf'
|
outputDir
|
str
|
Directory to save the figure in. When |
None
|
saveDir
|
str
|
Deprecated alias for |
None
|
show
|
bool
|
Call |
True
|
returnData
|
bool
|
Return the |
False
|
returnFig
|
bool
|
Return |
False
|
dpi
|
int
|
Resolution of the saved figure. |
300
|
transparent
|
bool
|
Save with a transparent background. |
False
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
None | DataFrame | tuple
|
|
Example
adata = sp.tl.spatialDistance(adata, phenotype="phenotype")
sp.pl.spatialDistanceHeatmap(adata, phenotype="phenotype")
# Only how far immune cells sit from tumour cells, in one image.
sp.pl.spatialDistanceHeatmap(
adata,
distanceFrom=["Treg", "NK cells"],
distanceTo=["ECAD+"],
subsetCol="imageid",
subsetValue="sample_1",
)