利用MetaNeighbor验证重复性和跨物种分群

进行跨物种研究时,我们经常需要进行注释结果的比较和归类,或者同一物种不同样本之间的注释验证。R语言中有一个包就可以利用直观的热图展示这一需求。

导入包和环境

R 复制代码
library(Seurat)
library(ggplot2)
library(MetaNeighbor)
library(SingleCellExperiment)
library(dplyr)

导入数据

这里以海豚和两个公开人的PFC脑区单细胞转录组数据为例

R 复制代码
hm <- readRDS('human_sci_EXN.rds')
DefaultAssay(hm) <- 'RNA'
[email protected]$species <- 'human'
hm2 <- readRDS('human_2_EXN.rds')
DefaultAssay(hm2) <- 'RNA'
[email protected]$species <- 'human'
dp <- readRDS('dolphin_PFC_EXN.rds')
DefaultAssay(dp) <- 'RNA'
[email protected]$species <- 'dolphin'

创建比较对象

R 复制代码
# 确保Idents已经正确设置
Idents(hm) <- [email protected]$cellType_layer
Idents(hm2) <- [email protected]$subclass.v2
Idents(dp) <- [email protected]$sub2

# 提取表达矩阵和元数据
exprs_hm <- GetAssayData(hm)
exprs_hm2 <- GetAssayData(hm2)
exprs_dp <- GetAssayData(dp)

meta_hm <- [email protected]
meta_hm2 <- [email protected]
meta_dp <- [email protected]

# 提取共有基因
common_genes <- Reduce(intersect, list(rownames(exprs_hm),rownames(exprs_hm2), rownames(exprs_dp)))

# 提取共有基因表达矩阵
exprs_hm_common <- exprs_hm[common_genes, ]
exprs_hm2_common <- exprs_hm2[common_genes, ]
exprs_dp_common <- exprs_dp[common_genes, ]

# 合并表达矩阵
combined_exprs <- cbind(exprs_hm_common, exprs_hm2_common, exprs_dp_common)

# 创建一个新的列数据框,确保使用Idents作为cell_type
new_colData <- data.frame(
  study_id = c(rep('human', ncol(exprs_hm_common)),rep('human2', ncol(exprs_hm2_common)), rep('dolphin', ncol(exprs_dp_common))),
  cell_type = c(Idents(hm), Idents(hm2), Idents(dp))
)

# 创建 SingleCellExperiment 对象
sce_combined <- SingleCellExperiment(assays = list(RNA = combined_exprs), colData = new_colData)

# 检查合并后的对象
sce_combined

检查所有细胞分群比例

R 复制代码
table(sce_combined$cell_type)

相似性分析

R 复制代码
# 选择高可变基因
var_genes <- variableGenes(dat = sce_combined, exp_labels = sce_combined$study_id)

# 运行相似性分析
celltype_NV <- MetaNeighborUS(var_genes = var_genes,
                              dat = sce_combined,
                              study_id = sce_combined$study_id,
                              cell_type = sce_combined$cell_type,
                              fast_version = TRUE)
# 检查前几行
head(celltype_NV)

可视化

R 复制代码
png("heatmap_integrated_3.png", width = 24, height = 24, units = "in", res = 300) 
plotHeatmapPretrained(aurocs = celltype_NV, cex = 1.5, margins = c(25, 25))
dev.off()
相关推荐
kngines2 小时前
【PostgreSQL数据分析实战:从数据清洗到可视化全流程】电商数据分析案例-9.4 可视化报告输出
postgresql·数据分析·ipywidgets·pg_cron·gmv·商品交易总额
kngines8 小时前
【PostgreSQL数据分析实战:从数据清洗到可视化全流程】8.4 数据故事化呈现(报告结构设计/业务价值提炼)
postgresql·数据分析·趋势预测模型·移动平均·cpa·生存分析模型·归因模型
QFIUNE8 小时前
数据分析之药物-基因-代谢物
数据挖掘·数据分析
qq_4369621812 小时前
奥威BI:AI+BI深度融合,重塑智能AI数据分析新标杆
人工智能·数据挖掘·数据分析
kngines15 小时前
【PostgreSQL数据分析实战:从数据清洗到可视化全流程】6.1 客户分群分析(RFM模型构建)
数据库·postgresql·数据分析·rfm模型·客户分群
元亓亓亓15 小时前
LeetCode热题100--54.螺旋矩阵--中等
算法·leetcode·矩阵
大势智慧16 小时前
12.模方ModelFun工具-立面修整
信息可视化·数据挖掘·数据分析·软件需求·三维建模
Expecto017 小时前
因子分析——数学原理及R语言代码
算法·r语言·统计学·多元统计分析
kngines18 小时前
【PostgreSQL数据分析实战:从数据清洗到可视化全流程】8.2 高级可视化技巧(热力图/桑基图/地理地图)
postgresql·数据分析·热力图·桑基图·地理地图·路径分析·转化漏斗
小羊在奋斗19 小时前
【今日三题】ISBN号码(模拟) / kotori和迷宫(BFS最短路) / 矩阵最长递增路径(dfs)
矩阵·深度优先·宽度优先