单细胞测序

空间转录组2022||空间数据反卷积RCTD分析:细胞类型鉴定

2022-11-19  本文已影响0人  信你个鬼

参考教程链接:

RCTD可以将单细胞类型或细胞类型混合分配到空间转录组spots上。RCTD 有三种模式:

每种模态都有一个对应的教程

今天先来学习Doublet mode: spatial transcriptomics vignette. Also, most other vignettes use doublet mode.

包安装

# install.packages("devtools")
devtools::install_github("dmcable/spacexr", build_vignettes = FALSE)
library(spacexr)
library(Matrix)

Introduction

稳健细胞类型分解(Robust Cell Type Decomposition,简称RCTD)是一种从空间转录组数据中学习细胞类型的统计方法。
在本次示例中,我们将为小脑Slide-seq数据集反卷积注释细胞类型。教程使用带注释的snRNA-seq小脑数据集定义细胞类型。
Note:参考也可以是单细胞数据集或细胞类型特定的bulkRNA-seq数据集。

数据预处理

RCTD需要两个数据:带有注释的单细胞转录组参考数据,需要反卷积注释的空间转录组数据。

reference数据

首先是单细胞参考数据集。reference使用RCTD包中Reference函数,这个函数需要三个参数:

reference可能来自各种数据类型,但需要将其加载到R环境中。

在本教程中,我们的reference作为两个csv文件存储在' reference /Vignette '文件夹中:

### Load in/preprocess your data, this might vary based on your file type
# directory for the reference
refdir <- system.file("extdata",'Reference/Vignette',package = 'spacexr') 
# load in counts matrix
counts <- read.csv(file.path(refdir,"dge.csv")) 
# Move first column to rownames
rownames(counts) <- counts[,1]
counts[,1] <- NULL
counts[1:4,1:4]


# load in meta_data (barcodes, clusters, and nUMI)
meta_data <- read.csv(file.path(refdir,"meta_data.csv")) 
head(meta_data)

# create cell_types named list
cell_types <- meta_data$cluster
names(cell_types) <- meta_data$barcode 
# convert to factor data type
cell_types <- as.factor(cell_types) 
head(cell_types)

# create nUMI named list
nUMI <- meta_data$nUMI
names(nUMI) <- meta_data$barcode 
head(nUMI)

### Create the Reference object
reference <- Reference(counts, cell_types, nUMI)
str(reference)

## Examine reference object (optional)
#observe Digital Gene Expression matrix
print(dim(reference@counts)) 
#> [1] 384 475

#number of occurences for each cell type
table(reference@cell_types) 

## Save RDS object (optional)
saveRDS(reference, file.path(refdir,'SCRef.rds'))

至此,reference已经构建好。

空间转录组数据

接下来,加载空间数据为SpatialRNA对象。SpatialRNA函数需要三个参数:

构建SpatialRNA有不同的方法,本教程为两个文件:

##=============================== 读取空间数据
# directory for sample Slide-seq dataset
datadir <- system.file("extdata",'SpatialRNA/Vignette',package = 'spacexr') 
counts <- read.csv(file.path(datadir,"MappedDGEForR.csv"))
rownames(counts) <- counts[,1]; counts[,1] <- NULL
counts[1:4,1:4]

coords <- read.csv(file.path(datadir,"BeadLocationsForR.csv"))
rownames(coords) <- coords$barcodes
coords$barcodes <- NULL
head(coords)

# In this case, total counts per pixel is nUMI
nUMI <- colSums(counts) 
head(nUMI)

### Create SpatialRNA object
puck <- SpatialRNA(coords, counts, nUMI)
str(puck)


### Create SpatialRNA object
puck <- SpatialRNA(coords, counts, nUMI)
str(puck)

## Examine SpatialRNA object (optional)
print(dim(puck@counts))

# histogram of log_2 nUMI
hist(log(puck@nUMI,2))

结果图:可以看到空间数据的每个像素中UMI的数值分布。


image-20221111222523662.png
print(head(puck@coords)) # start of coordinate data.frame
barcodes <- colnames(puck@counts) # pixels to be used (a list of barcode names). 

# This list can be restricted if you want to crop the puck e.g. 
# puck <- restrict_puck(puck, barcodes) provides a basic plot of the nUMI of each pixel
# on the plot:
p <- plot_puck_continuous(puck, barcodes, puck@nUMI, ylimit = c(0,round(quantile(puck@nUMI,0.9))), title ='plot of nUMI') 

结果图:使用x,y坐标展示每个像素中的UMI分布

image-20221111222947585.png

创建RCTD对象

使用create.RCTD函数创建。以下为几个有用的参数:

运行RCTD

可以使用run.RCTD函数,这个函数等价于:fitBulk,choose_sigma_c, andfitPixels这三个函数。doublet_mode可以选择上面提到的三种反卷积模式。

myRCTD <- create.RCTD(puck, reference, max_cores = 10)
myRCTD <- run.RCTD(myRCTD, doublet_mode = 'doublet')
str(myRCTD)

myRCTD结构:

image-20221112182253019.png

RCTD结果

RCTD结果保存在myRCTD对象中的@results中

results <- myRCTD@results

# normalize the cell type proportions to sum to 1.
norm_weights = normalize_weights(results$weights) 

#list of cell type names
cell_type_names <- myRCTD@cell_type_info$info[[2]] 
spatialRNA <- myRCTD@spatialRNA

## you may change this to a more accessible directory on your computer.
resultsdir <- 'RCTD_Plots' 
dir.create(resultsdir)

results$results_df结果示例如下:


image-20221112184204705.png

接下来对结果可视化绘图:

# make the plots 
# 绘制full_mode模式下每种细胞类型的可信权重 (saved as 
# 'results/cell_type_weights_unthreshold.pdf')
plot_weights(cell_type_names, spatialRNA, resultsdir, norm_weights) 

# 绘制full_mode模式下每种细胞类型的权重
# 这里每种细胞类型一幅图,点表示空间上的一个像素或者spot,颜色为权重 (saved as
# 'results/cell_type_weights.pdf')
plot_weights_unthreshold(cell_type_names, spatialRNA, resultsdir, norm_weights) 

# 绘制full_mode模式下每种细胞类型预测到的spots数 (saved as 
# 'results/cell_type_occur.pdf')
plot_cond_occur(cell_type_names, resultsdir, norm_weights, spatialRNA)

# 绘制doublet_mode模式下每种细胞类型的权重 (saved as 
# 'results/cell_type_weights_doublets.pdf')
plot_weights_doublet(cell_type_names, spatialRNA, resultsdir, results$weights_doublet, results$results_df) 

其中,绘制full_mode模式下每种细胞类型预测到的spots数结果图如下:

从这里可以看得出,空间数据预测出来的主要为细胞类型10,其次是18。


image-20221112192742832.png
# 所有细胞类型的map结果 (saved as 
# 'results/all_cell_types.pdf')
plot_all_cell_types(results$results_df, spatialRNA@coords, cell_type_names, resultsdir) 

所有细胞类型的map结果图:

image-20221112194400757.png

绘制doublets:

# doublets
# obtain a dataframe of only doublets
doublets <- results$results_df[results$results_df$spot_class == "doublet_certain",] 

# 绘制所有的doublets (saved as 
# 'results/all_doublets.pdf')
plot_doublets(spatialRNA, doublets, resultsdir, cell_type_names) 

# 对每种细胞类型绘制doublets (saved as 
# 'results/all_doublets_type.pdf')
plot_doublets_type(spatialRNA, doublets, resultsdir, cell_type_names) 

# a table of frequency of doublet pairs 
doub_occur <- table(doublets$second_type, doublets$first_type) 

# 绘制doublet出现的堆积柱状图 (saved as   
# 'results/doublet_stacked_bar.pdf')
plot_doub_occur_stack(doub_occur, resultsdir, cell_type_names) 

doublet_stacked_bar结果图:

image-20221112194946431.png

感觉这个软件的结果图不是很好看,可调整度也不高,我觉得跟教程的数据有关系,后面重新找个数据看看。

教程的空间数据是slide-seq的数据:


img

找了个10x Visium的文献来看看:

ref1:Cell2location maps fine-grained cell types in spatial transcriptomics ( https://doi.org/10.1038/s41587-021-01139-4 )

image-20221112222920831.png
上一篇下一篇

猜你喜欢

热点阅读