10X空间转录组-----空间高变基因检测之SpatialDE

今天我们来学习一下简单的基础知识,空间高变基因,之前呢,已经分享过Seurat内置的方法计算高变基因,文章在10X空间转录组之基因的空间表达模式,其实有关10X空间转录组计算空间层面的高变基因,还有有很多值得挖掘的分析内容,今天我们来看看另外一个方法,SpatialDE,一个python模块,如何检测空间高变基因及意义。

SpatialDE 是一种以非线性和非参数方式识别显着依赖于空间坐标的基因的方法。

此外,SpatialDE 提供自动表达组织学,这是一种将基因分组为常见空间模式的方法

The key features of method are

  • Unsupervised - No need to define spatial regions(无监督)
  • Non-parametric and non-linear expression patterns
  • Automatic histology based on spatially coexpressed genes(空间共表达)
  • Extremely fast - Transcriptome wide tests takes only a few minutes on normal computers(计算快)

我们来看看范例

加载

import pandas as pd

rcParams['axes.spines.right'] = False
rcParams['axes.spines.top'] = False

import NaiveDE
import SpatialDE

例如,让我们使用 Stahl 等人 2016 年发表的数据集来研究小鼠嗅球中空间依赖性基因表达。使用作者的方法,可以一次对组织切片上的数百个位置进行采样,并测量基因表达 通过以无偏的全转录组方式进行测序。

counts = pd.read_csv('Analysis/MouseOB/data/Rep11_MOB_0.csv', index_col=0)
counts = counts.T[counts.sum(0) >= 3].T  # Filter practically unobserved genes

print(counts.shape)
counts.iloc[:5, :5]
图片.png
sample_info = pd.read_csv('Analysis/MouseOB/MOB_sample_info.csv', index_col=0)
counts = counts.loc[sample_info.index]  # Align count matrix with metadata table

sample_info.head(5)
图片.png
figsize(6, 4)
plt.scatter(sample_info['x'], sample_info['y'], c='k');
plt.axis('equal');
图片.png

方法假设噪声正态分布,但我们使用的数据来自表达式计数,并且根据经验似乎遵循负二项式分布。 我们使用 Anscombe 的技术将数据近似转换为正态分布噪声。

其次,空间样本的文库大小或测序深度会影响每个基因的表达。 在执行空间测试之前,我们使用线性回归来解释这种影响。

norm_expr = NaiveDE.stabilize(counts.T).T
resid_expr = NaiveDE.regress_out(sample_info, norm_expr.T, 'np.log(total_counts)').T

为了这个例子,让我们只对 1000 个随机基因进行测试。 这应该只需要几秒钟。 通过我们非常快速的实施,测试所有 14,000 个基因大约需要 10 分钟。

sample_resid_expr = resid_expr.sample(n=1000, axis=1, random_state=1)

X = sample_info[['x', 'y']]
results = SpatialDE.run(X, sample_resid_expr)

The result will be a DataFrame with P-values and other relevant values for each gene.

The most important columns are

  • g - The name of the gene
  • pval - The P-value for spatial differential expression
  • qval - Signifance after correcting for multiple testing
  • l - A parameter indicating the distance scale a gene changes expression over
results.head().T
图片.png
results.sort_values('qval').head(10)[['g', 'l', 'qval']]
图片.png

我们检测到一些空间差异表达的基因,例如 Cck 和 Ptn。

可视化这些基因的一种简单方法是绘制上述 x 和 y 坐标,但让颜色对应于表达水平。

figsize(10, 3)
for i, g in enumerate(['Kcnh3', 'Pcp4', 'Igfbp2']):
    plt.subplot(1, 3, i + 1)
    plt.scatter(sample_info['x'], sample_info['y'], c=norm_expr[g]);
    plt.title(g)
    plt.axis('equal')

    
    plt.colorbar(ticks=[]);
图片.png

For reference, we can compare these to genes which are not spatially DE

results.sort_values('qval').tail(10)[['g', 'l', 'qval']]
图片.png
figsize(10, 3)
for i, g in enumerate(['Myo9b', 'Sc4mol', 'Phf11b']):
    plt.subplot(1, 3, i + 1)
    plt.scatter(sample_info['x'], sample_info['y'], c=norm_expr[g]);
    plt.title(g)
    plt.axis('equal')

    
    plt.colorbar(ticks=[]);
图片.png

在正则差异表达分析中,我们通常通过所谓的火山图来研究显着性和效应大小之间的关系。 在我们的案例中,我们没有折叠变化的概念,但我们可以研究由空间变化解释的方差分数。

figsize(5, 4)
plt.yscale('log')

plt.scatter(results['FSV'], results['qval'], c='black')

plt.axhline(0.05, c='black', lw=1, ls='--');

plt.gca().invert_yaxis();
plt.xlabel('Fraction spatial variance')
plt.ylabel('Adj. P-value');
图片.png

自动表达组织学

To perform automatic expression histology (AEH), the genes should be filtered by SpatialDE significance. For this example, let us use a very weak threshold. But in typical use, filter by qval < 0.05

sign_results = results.query('qval < 0.5')
sign_results['l'].value_counts()
histology_results, patterns = SpatialDE.aeh.spatial_patterns(X, resid_expr, sign_results, C=3, l=1.8, verbosity=1)
figsize(10, 3)
for i in range(3):
    plt.subplot(1, 3, i + 1)
    plt.scatter(sample_info['x'], sample_info['y'], c=patterns[i]);
    plt.axis('equal')
    plt.title('Pattern {} - {} genes'.format(i, histology_results.query('pattern == @i').shape[0] ))
    plt.colorbar(ticks=[]);
图片.png

空间基因模式

for i in histology_results.sort_values('pattern').pattern.unique():
    
    print('Pattern {}'.format(i))
    print(', '.join(histology_results.query('pattern == @i').sort_values('membership')['g'].tolist()))
    print()
图片.png

其实空间高变基因,最后也是落在了基因功能和异质性上,甚至涉及到细胞之间的通讯,需要深入的挖掘

生活很好,等你超越

你可能感兴趣的:(10X空间转录组-----空间高变基因检测之SpatialDE)