10X空间转录组之空间临近通讯分析stlearn进阶版
新的一年,2022年,第一周,继cellphoneDB更新到3.0,辅助做空间生态位细胞通讯之后,stlearn也更新了其做空间转录组临近细胞通讯的分析教程,我们来看一下,看看有什么新颖的地方。
stLearn Cell-Cell Interaction Analysis
分析步骤
- Load known ligand-receptor gene pairs.
- Identify spots where significant interactions between these pairs occur.
- For each LR pair and each celltype-celltype combination,count the instances where neighbours of a signficant spot for that LR pair link two given cell types.
- Identify signficant interactions with p<.05 from cell type information permutation.
- Visualise the CCI results.
Ligand-Receptor Analysis
stLearn CCI pipeline的第一步是配体受体 (LR) 分析。该分析从候选配体-受体数据库中调用了显著的配体-受体相互作用spot。
import stlearn as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
加载数据并添加注释
# Loading raw data #
data = st.Read10X(data_dir)
data.var_names_make_unique()
st.add.image(adata=data,
imgpath=data_dir+"spatial/tissue_hires_nobg.png",
library_id="V1_Breast_Cancer_Block_A_Section_1", visium=True)
# Basic normalisation #
st.pp.filter_genes(data, min_cells=3)
st.pp.normalize_total(data) # NOTE: no log1p
# Adding the label transfer results, #
spot_mixtures = pd.read_csv(data_dir+'../../Brad/label_transfer_bc.csv', index_col=0, sep='\t')
labels = spot_mixtures.loc[:,'predicted.id'].values.astype(str)
spot_mixtures = spot_mixtures.drop(['predicted.id','prediction.score.max'],
axis=1)
spot_mixtures.columns = [col.replace('prediction.score.', '')
for col in spot_mixtures.columns]
# Note the format! #
print(labels)
print(spot_mixtures)
print('Spot mixture order correct?: ',
np.all(spot_mixtures.index.values==data.obs_names.values)) # Check is in correct order
# NOTE: using the same key in data.obs & data.uns
data.obs['cell_type'] = labels # Adding the dominant cell type labels per spot
data.obs['cell_type'] = data.obs['cell_type'].astype('category')
data.uns['cell_type'] = spot_mixtures # Adding the cell type scores
st.pl.cluster_plot(data, use_label='cell_type')
图片.png
- 对于上述细胞类型信息,注意这些结果是使用 Seurat 生成的。
- 不必有每个点的细胞类型分数; 可以仅使用离散的点标签运行。
- 但是,如果使用细胞类型分数运行,则需要将主要细胞类型添加到 adata.obs slot中,并使用与添加到 adata.uns slot中的细胞类型分数相同的key。
Running the Ligand-Receptor Analysis
# Loading the LR databases available within stlearn (from NATMI)
lrs = st.tl.cci.load_lrs(['connectomeDB2020_lit'], species='human')
print(len(lrs))
# Running the analysis #
st.tl.cci.run(data, lrs,
min_spots = 20, #Filter out any LR pairs with no scores for less than min_spots
distance=None, # None defaults to spot+immediate neighbours; distance=0 for within-spot mode
n_pairs=100, # Number of random pairs to generate; low as example, recommend ~10,000
n_cpus=4, # Number of CPUs for parallel. If None, detects & use all available.
)
lr_info = data.uns['lr_summary'] # A dataframe detailing the LR pairs ranked by number of significant spots.
print('\n', lr_info)
P-value adjustment
下面可以使用不同的方法调整 p 值; p 值已通过运行 st.tl.cci.run 进行校正。
st.tl.cci.adj_pvals(data, correct_axis='spot',
pval_adj_cutoff=0.05, adj_method='fdr_bh')
Visualise the overall ranking of LRs by significant spots
# Showing the rankings of the LR from a global and local perspective.
# Ranking based on number of significant hotspots.
st.pl.lr_summary(data, n_top=500)
st.pl.lr_summary(data, n_top=50, figsize=(10,3))
图片.png
Diagnostic plots
LR 分析的一个关键方面是在调用重要热点时控制 LR 表达水平和频率。
因此,诊断图应该显示 LR 对的热点与表达水平和表达频率之间几乎没有相关性。
st.pl.lr_diagnostics(data, figsize=(10,2.5))
图片.png
- 左图:LR 表达水平(non-zero spots average median expression of genes in the LR pair)与 LR 排名之间的关系。
- 右图:LR 表达频率(average proportion of zero spots for each gene in the LR pair)与 LR 排名之间的关系。
在这种情况下,LR 表达频率与显着点数之间存在弱相关性,表明应将 n_pairs 参数设置得更高以创建更准确的背景分布
st.pl.lr_n_spots(data, n_top=50, figsize=(11, 3),
max_text=100)
st.pl.lr_n_spots(data, n_top=500, figsize=(11, 3),
max_text=100)
图片.png
上面的箱线图在 y 轴上显示了每个 LR 的配体受体分数的点数,在 x 轴上显示了 LR 排名。 条形区域由显着(绿色)和非显着(蓝色)的点分层。
虽然与散点图相比,该图的趋势不是定量的,但似乎与更频繁的 LR 对和 LR 排名存在一些相关性; 再次表明上面的 n_pairs 参数应该设置得更高。
Biologic Plots
通过诊断图检查了是否仍然看到与技术因素的相关性,现在检查一下是否将top LR 对中基因的生物富集视为正在执行一些生物学推断的预后。
For this to work, it requires R installed with clusterProfiler, org.Mm.eg.db, and org.Hs.eg.db.
## Running the GO enrichment analysis ##
r_path = "/Library/Frameworks/R.framework/Resources"
st.tl.cci.run_lr_go(data, r_path)
st.pl.lr_go(data, lr_text_fp={'weight': 'bold', 'size': 10}, rot=15,
figsize=(12,3.65), n_top=15, show=False)
图片.png
Overall, we see some strong biological enrichment, indicating some potential pathways mediated by the top LR pairs.
LR Statistics Visualisations
best_lr = data.uns['lr_summary'].index.values[0]
stats = ['lr_scores', 'p_vals', 'p_adjs', '-log10(p_adjs)']
fig, axes = plt.subplots(ncols=len(stats), figsize=(16,6))
for i, stat in enumerate(stats):
st.pl.lr_result_plot(data, use_result=stat, use_lr=best_lr, show_color_bar=False, ax=axes[i])
axes[i].set_title(f'{best_lr} {stat}')
图片.png
fig, axes = plt.subplots(ncols=2, figsize=(8,6))
st.pl.lr_result_plot(data, use_result='-log10(p_adjs)', use_lr=best_lr, show_color_bar=False, ax=axes[0])
st.pl.lr_result_plot(data, use_result='lr_sig_scores', use_lr=best_lr, show_color_bar=False, ax=axes[1])
axes[0].set_title(f'{best_lr} -log10(p_adjs)')
axes[1].set_title(f'{best_lr} lr_sig_scores')
图片.png
LR Interpretation Visualisations
These visualisations are meant to help interpret the directionality of the cross-talk.
st.pl.lr_plot(data, best_lr, inner_size_prop=0.1, outer_mode='binary', pt_scale=5,
use_label=None, show_image=True,
sig_spots=False)
图片.png
st.pl.lr_plot(data, best_lr, outer_size_prop=1, outer_mode='binary', pt_scale=20,
use_label=None, show_image=True,
sig_spots=True)
图片.png
The receptor is in green, the ligand is in red. The inner-point is the receptor, the outter point is the ligand.
Help to see where and how heavily expressed ligands/receptors are.
Idea is receptor is on the cell surface, & ligand permeates out from the cell surface.
# All spots #
st.pl.lr_plot(data, best_lr,
inner_size_prop=0.04, middle_size_prop=.07, outer_size_prop=.4,
outer_mode='continuous', pt_scale=60,
use_label=None, show_image=True,
sig_spots=False)
图片.png
# Only significant spots #
st.pl.lr_plot(data, best_lr,
inner_size_prop=0.04, middle_size_prop=.07, outer_size_prop=.4,
outer_mode='continuous', pt_scale=60,
use_label=None, show_image=True,
sig_spots=True)
图片.png
This is only useful when zooming in and want to display cell information and direction of interaction at the same time.
st.pl.lr_plot(data, best_lr,
inner_size_prop=0.08, middle_size_prop=.3, outer_size_prop=.5,
outer_mode='binary', pt_scale=50,
show_image=True, arrow_width=10, arrow_head_width=10,
sig_spots=True, show_arrows=True)
图片.png
还可以可视化配体或受体与主要spot细胞类型同时表达/共表达的位置。
The outter spot shows the expression of ligand (red), the receptor (green), and coexpression (blue). The inner spot is coloured by the dominant spot cell type.
st.pl.lr_plot(data, best_lr,
inner_size_prop=0.08, middle_size_prop=.3, outer_size_prop=.5,
outer_mode='binary', pt_scale=150,
use_label='cell_type', show_image=True,
sig_spots=True)
图片.png
Predicting significant CCIs
With the establishment of significant areas of LR interaction, can now determine the significantly interacting cell types.
# Running the counting of co-occurence of cell types and LR expression hotspots #
st.tl.cci.run_cci(data, 'cell_type', # Spot cell information either in data.obs or data.uns
min_spots=3, # Minimum number of spots for LR to be tested.
spot_mixtures=True, # If True will use the label transfer scores,
# so spots can have multiple cell types if score>cell_prop_cutoff
cell_prop_cutoff=0.2, # Spot considered to have cell type if score>0.2
sig_spots=True, # Only consider neighbourhoods of spots which had significant LR scores.
n_perms=100 # Permutations of cell information to get background, recommend ~1000
)
Diagnostic plot: check interaction and cell type frequency correlation
The plot below should show little to no correlation if the number of permutations is adequate; otherwise recommend increasing n_perms above
st.pl.cci_check(data, 'cell_type')
图片.png
CCI Visualisations
随着细胞类型-细胞类型预测的完成,实施了一些可视化来探索 LR 对或每个独立对的交互情况。
CCI network
The below shows the stlearn version of a CCI network.
If you’re more comfortable with visualisations in R, it’s possible to save the adjacency matrix that generates this network from the anndata object and use visualisation functions from CellChat to make R-based visualisations.
# Visualising the no. of interactions between cell types across all LR pairs #
pos_1 = st.pl.ccinet_plot(data, 'cell_type', return_pos=True)
# Just examining the cell type interactions between selected pairs #
lrs = data.uns['lr_summary'].index.values[0:3]
for best_lr in lrs[0:3]:
st.pl.ccinet_plot(data, 'cell_type', best_lr, min_counts=2,
figsize=(10,7.5), pos=pos_1,
)
图片.png
CCI chord-plot
The chord-plot is really useful when visualising interactions between few cell types
st.pl.lr_chord_plot(data, 'cell_type')
for lr in lrs:
st.pl.lr_chord_plot(data, 'cell_type', lr)
图片.png
Heatmap Visualisations
LR-CCI-Map
We also impliment a number of heatmap visualisations so you can visualise individual celltype-celltype interactions across multiple LR pairs concurrently
# This will automatically select the top interacting CCIs and their respective LRs #
st.pl.lr_cci_map(data, 'cell_type', lrs=None, min_total=100, figsize=(20,4))
图片.png
# You can also put in your own LR pairs of interest #
st.pl.lr_cci_map(data, 'cell_type', lrs=lrs, min_total=100, figsize=(20,4))
图片.png
CCI Maps
This is a heatmap equivalent to the network diagrams and chordplots, it has more quantitative benefits.
The # of interactions refers to the number of times a spot with the reciever cell type expressed the ligand and the source cell type expressed the receptor in the same neighbourhood.
st.pl.cci_map(data, 'cell_type')
lrs = data.uns['lr_summary'].index.values[0:3]
for lr in lrs[0:3]:
st.pl.cci_map(data, 'cell_type', lr)
图片.png
Spatial cell type interactions
By combining the spatial LR analysis with the significant CCI from the CCI analysis, we can now visualise where in the tissue these cell types are interacting.
The recommended method for this is to plot the cell types, and overlay arrows indicating spots that express the ligand and spots that express the receptor.
This way can see - at spot level in the spatial context - where the different cell types interact and via a given ligand-receptor pair.
best_lr = lrs[0]
### This will plot with simple black arrows ####
st.pl.lr_plot(data, best_lr, outer_size_prop=1, outer_mode=None,
pt_scale=40, use_label='cell_type', show_arrows=True,
show_image=True, sig_spots=False, sig_cci=True,
arrow_head_width=4,
arrow_width=1, cell_alpha=.8
)
### This will colour the spot by the mean LR expression in the spots connected by arrow
st.pl.lr_plot(data, best_lr, outer_size_prop=1, outer_mode=None,
pt_scale=10, use_label='cell_type', show_arrows=True,
show_image=True, sig_spots=False, sig_cci=True,
arrow_head_width=4, arrow_width=2,
arrow_cmap='YlOrRd', arrow_vmax=1.5,
)
图片.png
Visualisation Tips
空间背景中的 CCI 非常高维且信息丰富。 上述可视化中的哪一个有用将取决于希望突出显示的生物学和关键方面。
增加的核心画图功能
st.pl.lr_summary(adata_processed, highlight_lrs=['GPC3_IGF1R'])
图片.png
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "-log10(p_adjs)")
图片.png
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "lr_sig_scores")
图片.png
Cell-cell interaction plots
st.pl.cluster_plot(adata_processed, use_label='cell_type')
st.pl.lr_chord_plot(adata_processed, 'cell_type', 'GPC3_IGF1R', figsize=(4,4))
图片.png
更新的相当可以
生活很好,有你更好