你是否為各種各樣的空間轉(zhuǎn)錄組數(shù)據(jù)類型而眼花繚亂?你是否想要復(fù)現(xiàn)文章中的分析而倒在了數(shù)據(jù)讀入?你是否希望學(xué)習(xí)空間轉(zhuǎn)錄組數(shù)據(jù)分析卻又無從下手?
今天,我們就和大家一起來學(xué)習(xí)多種類型空間轉(zhuǎn)錄組數(shù)據(jù)的讀取,邁開空間轉(zhuǎn)錄組數(shù)據(jù)分析的第一步。
當(dāng)前常見的基于空間條形碼和NGS測序的空間組轉(zhuǎn)錄組技術(shù)包括10x Visium、華大基因的Stereo-seq和Broad研究所的Slide-seq等,每種空間轉(zhuǎn)錄組技術(shù)都有特有的基因表達矩陣文件,格式各異。下面,我們就依次來介紹上述3種空間轉(zhuǎn)錄組技術(shù)的數(shù)據(jù)讀取。
10x Visium
10x Visium是目前使用最廣泛的空間組學(xué)技術(shù),Visium數(shù)據(jù)經(jīng)SpaceRanger處理,生成類似如下結(jié)構(gòu)的輸出文件:

在Seurat中,使用
Load10X_Spatial()函數(shù)加載10x Visium數(shù)據(jù),該函數(shù)讀入SpaceRanger的輸出,并返回一個Seurat對象,該對象既包含基因表達數(shù)據(jù),也包含組織切片的相關(guān)圖像。例:
library(Seurat)
library(ggplot2)
obj <- Load10X_Spatial('/path/spaceranger_output/',
filename = "filtered_feature_bc_matrix.h5",
assay = "Spatial",
slice = "slice1",
filter.matrix = TRUE
)
obj
plot <- SpatialFeaturePlot(obj, features = "nCount_Spatial") + theme(legend.position = "right")
plot
An object of class Seurat
32285 features across 2797 samples within 1 assay
Active assay: Spatial (32285 features, 0 variable features)
1 image present: slice1

這樣我們就成功導(dǎo)入了1個10x Visium的空間轉(zhuǎn)錄組數(shù)據(jù)。
如果你習(xí)慣使用Python進行數(shù)據(jù)處理,我們也可以用scanpy來讀入Visium數(shù)據(jù)。scanpy使用scanpy.read_visium()函數(shù)導(dǎo)入Visium數(shù)據(jù)為anndata格式。
例:
import scanpy as sc
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
adata = sc.read_visium('/path/spaceranger_output/',
count_file='filtered_feature_bc_matrix.h5',
load_images=True)
adata
sc.pp.calculate_qc_metrics(adata, inplace=True)
sc.pl.spatial(adata, img_key='hires', color="n_genes_by_counts")
AnnData object with n_obs × n_vars = 2797 × 32285
obs: 'in_tissue', 'array_row', 'array_col'
var: 'gene_ids', 'feature_types', 'genome'
uns: 'spatial'
obsm: 'spatial'

在這里還遇到一個具有借鑒意義的bug。我從10x官網(wǎng)的公開數(shù)據(jù)中下載了數(shù)據(jù)用來測試,該數(shù)據(jù)是由SpaceRanger v2.0處理的。在使用sc.read_visium讀入時,會提示“OSError: Could not find '\path\spatial\tissue_positions_list.csv'”。原因是從SpaceRanger v2.0開始,此文件已重命名為“tissue_positions.csv”并包含標(biāo)題行。如果你的數(shù)據(jù)也是由SpaceRanger v2.0產(chǎn)生的,那么注意使用scanpy 1.9.4以上版本進行分析。
Stereo-seq
Stereo-seq是由華大基因開發(fā)的具有亞細胞分辨率的空間轉(zhuǎn)錄組技術(shù),測序reads通過SAW流程分析產(chǎn)生表達矩陣,由同樣由華大開發(fā)的Python包stereopy進行讀取。Stereo-seq的基因表達矩陣格式如下:

使用stereopy包中的stereo.io.read_gem()讀取矩陣為StereoExpData格式。
例:
import stereo as st
import warnings
warnings.filterwarnings('ignore')
data_path = '/path/Mouse_brain.gem'
data = st.io.read_gem(
file_path=data_path,
bin_type='bins',
bin_size=50,
is_sparse=True,
)
data.tl.cal_qc()
data.plt.spatial_scatter()
StereoExpData object with n_cells X n_genes = 38741 X 26177
bin_type: bins
bin_size: 50
offset_x = 3225
offset_y = 6175
cells: ['cell_name']
genes: ['gene_name']

通過stereopy讀取后,可將StereoExpData轉(zhuǎn)換為anndata從而使用scanpy進行分析,而anndata的h5ad文件又可以進一步轉(zhuǎn)化為rds(https://github.com/STOmics/stereopy/blob/dev/docs/source/_static/annh5ad2rds.R)從而便于使用Seurat進行分析。
#Scanpy
adata = st.io.stereo_to_anndata(data,flavor='scanpy',output='scanpy_out.h5ad')
#Seurat
data.tl.cal_qc()
adata = st.io.stereo_to_anndata(data,flavor='seurat',output='seurat_out.h5ad')
Slide-seq
Slide-seq由Broad研究所開發(fā),數(shù)據(jù)經(jīng)由Slide-seq tools流程處理。從目前已公開的數(shù)據(jù)來看,Slide-seq的結(jié)果文件類型多樣,各個公開數(shù)據(jù)庫中下載到的Slide-seq數(shù)據(jù)類型都有差別,但其主要數(shù)據(jù)由1個基因表達矩陣和1個beads矩陣構(gòu)成,兩個文件可能為分別的兩個文本文件或整合為loom格式文件等。
Seurat官方給出的讀入方法是:首先使用CreateSeuratObject將表達矩陣讀入,然后將坐標(biāo)信息附加至SeuratObject中。
例:
library(Seurat)
library(ggplot2)
slideCount <- '/path/Slide-seq/MappedDGEForR.csv'
slideBead <- '/path/Slide-seq/BeadLocationsForR.csv'
bead <- ReadSlideSeq(slideBead, assay = 'Spatial')
count <- read.table(slideCount, header = TRUE, sep=',', row.names='Row')
obj <- CreateSeuratObject(count, assay ="Spatial")
bead <- bead[Cells(x = obj)]
obj[["slice1"]] <- bead
plot <- SpatialFeaturePlot(obj, features = "nCount_Spatial") + theme(legend.position = "right")
plot

至此,三種空間轉(zhuǎn)錄組技術(shù)所產(chǎn)生的數(shù)據(jù)就可以被讀入R或Python中進行后續(xù)的數(shù)據(jù)分析,后續(xù)我們也將繼續(xù)從0開始,帶大家一起學(xué)習(xí)單細胞/空間轉(zhuǎn)錄組的分析方法。
參考資料:
https://satijalab.org/seurat/articles/spatial_vignette
https://scanpy-tutorials.readthedocs.io/en/latest/spatial/basic-analysis.html
https://stereopy.readthedocs.io/en/latest/Tutorials/IO.html
https://patrickcnmartin.github.io/Vesalius/articles/Vesalius_Analysis/Vesalius_analysis.html
https://squidpy.readthedocs.io/en/latest/notebooks/tutorials/tutorial_read_spatial.html