10X空間轉錄組之空間臨近通訊分析stlearn進階版

新的一年,2022年,第一周,繼cellphoneDB更新到3.0,輔助做空間生態位細胞通訊之后,stlearn也更新了其做空間轉錄組臨近細胞通訊的分析教程,我們來看一下,看看有什么新穎的地方。

stLearn Cell-Cell Interaction Analysis

分析步驟

    1. Load known ligand-receptor gene pairs.
    1. Identify spots where significant interactions between these pairs occur.
    1. 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.
    1. Identify signficant interactions with p<.05 from cell type information permutation.
    1. 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
更新的相當可以

生活很好,有你更好

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,001評論 6 537
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,786評論 3 423
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 176,986評論 0 381
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,204評論 1 315
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,964評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,354評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,410評論 3 444
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,554評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,106評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,918評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,093評論 1 371
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,648評論 5 362
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,342評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,755評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,009評論 1 289
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,839評論 3 395
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,107評論 2 375

推薦閱讀更多精彩內容