新的一年,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')
- 對于上述細胞類型信息,注意這些結果是使用 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))
Diagnostic plots
LR 分析的一個關鍵方面是在調用重要熱點時控制 LR 表達水平和頻率。
因此,診斷圖應該顯示 LR 對的熱點與表達水平和表達頻率之間幾乎沒有相關性。
st.pl.lr_diagnostics(data, figsize=(10,2.5))
- 左圖: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)
上面的箱線圖在 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)
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}')
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')
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)
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)
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)
# 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)
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)
還可以可視化配體或受體與主要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)
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')
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,
)
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)
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))
# 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))
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)
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,
)
Visualisation Tips
空間背景中的 CCI 非常高維且信息豐富。 上述可視化中的哪一個有用將取決于希望突出顯示的生物學和關鍵方面。
增加的核心畫圖功能
st.pl.lr_summary(adata_processed, highlight_lrs=['GPC3_IGF1R'])
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "-log10(p_adjs)")
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "lr_sig_scores")
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))
更新的相當可以
生活很好,有你更好