今天我們來學習一下簡單的基礎知識帖世,空間高變基因休蟹,之前呢,已經分享過Seurat內置的方法計算高變基因日矫,文章在10X空間轉錄組之基因的空間表達模式赂弓,其實有關10X空間轉錄組計算空間層面的高變基因,還有有很多值得挖掘的分析內容哪轿,今天我們來看看另外一個方法盈魁,SpatialDE,一個python模塊窃诉,如何檢測空間高變基因及意義杨耙。
SpatialDE 是一種以非線性和非參數方式識別顯著依賴于空間坐標的基因的方法赤套。
此外,SpatialDE 提供自動表達組織學珊膜,這是一種將基因分組為常見空間模式的方法
The key features of method are
- Unsupervised - No need to define spatial regions(無監(jiān)督)
- 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 年發(fā)表的數據集來研究小鼠嗅球中空間依賴性基因表達。使用作者的方法辅搬,可以一次對組織切片上的數百個位置進行采樣唯沮,并測量基因表達 通過以無偏的全轉錄組方式進行測序。
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
方法假設噪聲正態(tài)分布堪遂,但我們使用的數據來自表達式計數,并且根據經驗似乎遵循負二項式分布萌庆。 我們使用 Anscombe 的技術將數據近似轉換為正態(tài)分布噪聲溶褪。
其次,空間樣本的文庫大小或測序深度會影響每個基因的表達践险。 在執(zhí)行空間測試之前猿妈,我們使用線性回歸來解釋這種影響。
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
其實空間高變基因旧蛾,最后也是落在了基因功能和異質性上莽龟,甚至涉及到細胞之間的通訊,需要深入的挖掘
生活很好蚜点,等你超越