Basic Analysis in SptialTis¶
SpatialTis provides some basic analysis
Cell Components
Cell Density
Cell Morphology
Cell Co-occurrence
To run the following analysis, you need to Download the data.
[1]:
import warnings
warnings.filterwarnings("ignore", category=FutureWarning)
[2]:
import anndata as ad
data = ad.read_h5ad("../data/imc_data.h5ad")
data
[2]:
AnnData object with n_obs × n_vars = 1776974 × 38
obs: 'area', 'eccentricity', 'islet_id', 'centroid', 'image', 'case', 'slide', 'part', 'group', 'stage', 'cell_cat', 'cell_type'
var: 'markers'
[3]:
import spatialtis as st
import spatialtis.plotting as sp
from spatialtis import CONFIG
CONFIG.EXP_OBS = ["stage", "case", "part", "image"]
CONFIG.CELL_TYPE_KEY = "cell_type"
CONFIG.MARKER_KEY = "markers"
CONFIG.CENTROID_KEY = "centroid"
Cell Components¶
Used to calculate the fractions of cells.
[4]:
st.cell_components(data)
⏳ Cell Components
📦 Added to AnnData, uns: 'cell_components'
⏱ 488ms
[4]:
We can visualize it, the default is static rendering.
[5]:
islets_cells = ['gamma', 'delta', 'alpha', 'beta',]
colors = ["#7aafde","#1b65b0","#fc7f71","#db060b"][::-1]
sp.cell_components(data,
["stage", "case"],
selected_types=islets_cells,
group_order={'stage':['Non-diabetic', 'Onset', 'Long-duration'],
'case':[6126,6134,6386,6278,6362,6414,6228,6380,6418,6180,6089,6264]},
palette=colors,
size=(5, 3.5),
title="Cell components of Islet cells",
yaxis_title="% of cell type")
[5]:
Alternatively, you can pass use="interactive"
to used bokeh, put your mouse on it to see extra information.
[6]:
sp.cell_components(data,
["stage", "case"],
use="interactive",
selected_types=islets_cells[::-1],
group_order={'stage':['Non-diabetic', 'Onset', 'Long-duration'],
'case':[6126,6134,6386,6278,6362,6414,6228,6380,6418,6180,6089,6264]},
palette=colors,
title="Cell components of Islet cells",
yaxis_title="% of cell type")
[6]:
Cell Density¶
Used to calculate the density of cells
[7]:
st.cell_density(data, ratio=0.001)
⏳ Cell Density
📦 Added to AnnData, uns: 'cell_density'
⏱ 20s29ms
[7]:
[8]:
sp.cell_density(data, ['stage'], selected_types=['alpha', 'beta', 'gamma', 'delta'],
group_order={'stage':['Non-diabetic', 'Onset', 'Long-duration'],},
size=(4, 3))
[8]:
Cell Co-occurrence¶
To determine whether two cells will occur in the same ROI
[9]:
st.cell_co_occurrence(data)
⏳ Cell Co-occurrence
📦 Added to AnnData, uns: 'co_occurrence'
⏱ 853ms
[9]:
[10]:
sp.cell_co_occurrence(data, xtickslabel_rotation=90)
[10]:
[11]:
sp.cell_co_occurrence(data, ['stage'], use="heatmap")
[11]:
Cell Morphology¶
The distribution of one of your cell’s morphology metrics, if your morphology information is available.
Here we can get the cell’s eccentricity.
[12]:
st.cell_morphology(data, metric_key="eccentricity")
⏳ Cell Morphology
📦 Added to AnnData, uns: 'morphology'
⏱ 4s360ms
[12]:
[13]:
sp.cell_morphology(data, ['stage', 'part'], selected_types=islets_cells, size=(8, 3))
[13]:
[14]: