跟着顶刊学习单细胞CD4T细胞功能基因集评分!
前言
之前的推文中,卡卡已经带大家学习了Pan-cancer T cell atlas links a cellular stress response state to immunotherapy resistance
文献中的CD8T细胞功能基因集评分,今天卡卡继续带大家学习这篇推文中的CD4T细胞功能基因集评分。往期推文如下:
回复20250411获取本期数据的CD4T细胞功能基因集评分!
先上图:

截屏2025-04-10 17.30.23.png
c, Heat map displaying expression of 16 curated gene signatures (as listed in Supplementary Table 6) across CD4+ T cell clusters.
实战
加载单细胞数据集
# 加载必要的库
library(Seurat)
library(tidyverse)
library(pheatmap)
library(scales) # 用于rescale函数
##这里加载自己的CD8T细胞处理好的Seurat对象即可
load("CD4_Obj.Rdata")
CD4_Obj$seurat_clusters=as.factor(CD4_Obj$seurat_clusters)
加载CD4T细胞功能基因集
library(scales)
# 设置输出路径
figurePath <- "./CD4_figures" # 输出图表的目录
dir.create(figurePath, showWarnings = FALSE, recursive = TRUE)
Idents(CD4_Obj) <- CD4_Obj$seurat_clusters
# 读取标记基因 - 正确处理宽格式CSV
CD4_markers <- read_csv("CD4-markers.csv", skip = 1) # 如果第一行是标题行,跳过它
# 将宽格式转换为标记基因列表
marker.list <- list()
for(col_name in colnames(CD4_markers)) {
# 提取非NA的基因
genes <- CD4_markers[[col_name]]
genes <- genes[!is.na(genes) & genes != ""]
# 替换列名中的特殊字符
clean_name <- gsub("/", ":", col_name)
# 添加到列表
if(length(genes) > 0) {
marker.list[[clean_name]] <- genes
}
}
基因集评分
CD4_Obj <- AddModuleScore(CD4_Obj,
features = marker.list,
ctrl = 5,
name = "FunctionScore")
for(i in 1:length(marker.list)) {
colnames([email protected])[colnames([email protected]) == paste0("FunctionScore", i)] <- names(marker.list)[i]
}
Idents(CD4_Obj) <- CD4_Obj$seurat_clusters
Differentiation <- c("Naive", "Activation:Effector function")
Function <- c("TCR signaling", "Cytotoxicity", "Cytokine:Cytokine receptor",
"Chemokine:Chemokine receptor", "Stress response", "Adhesion",
"IFN response", "Treg signature", "Costimulatory molecules")
Metabolism <- c("OXPHOS", "Glycolysis", "Lipid metabolism")
Apoptosis <- c("Pro-apoptosis", "Anti-apoptosis")
MarkerNameVector <- c(Differentiation, Function, Metabolism, Apoptosis)
FunctionScoreMatrix <- matrix(0,
ncol = length(unique(CD4_Obj$seurat_clusters)),
nrow = length(MarkerNameVector))
colnames(FunctionScoreMatrix) <- paste0("CD4_c", unique(CD4_Obj$seurat_clusters))
rownames(FunctionScoreMatrix) <- MarkerNameVector
for(ci in 1:ncol(FunctionScoreMatrix)) {
for(ri in 1:nrow(FunctionScoreMatrix)) {
FunctionVec <- as_tibble([email protected]) %>% pull(MarkerNameVector[ri])
fv <- mean(FunctionVec[CD4_Obj$seurat_clusters == unique(CD4_Obj$seurat_clusters)[ci]])
FunctionScoreMatrix[ri, ci] <- fv
}
}
热图绘制
FunctionScoreMatrix <- t(apply(FunctionScoreMatrix, 1, rescale, to=c(-1, 1)))
my.breaks <- c(seq(-1, 0, by=0.1), seq(0.1, 1, by=0.1))
my.colors <- c(
colorRampPalette(colors = c("#6DCCFD", "white"))(length(my.breaks)/2),
colorRampPalette(colors = c("white", "#FD9AA0"))(length(my.breaks)/2))
signatureType_row <- data.frame(Signature.type = c(
rep("Differentiation", length(Differentiation)),
rep("Function", length(Function)),
rep("Metabolism", length(Metabolism)),
rep("Apoptosis", length(Apoptosis))))
rownames(signatureType_row) <- MarkerNameVector
col_name_v <- paste0("CD4_c", c(1,3,8,7,9,10,2,6,4,11,0,5))
FunctionScoreMatrix <- FunctionScoreMatrix[, col_name_v]
pheatmap(FunctionScoreMatrix,
show_colnames = T,
show_rownames = T,
annotation_row = signatureType_row,
gaps_row = c(2, 11, 14),
cluster_rows = F,
cluster_cols = F,
breaks = my.breaks,
color = my.colors,
border_color = "NA",
fontsize = 8,
width = 5,
height = 3.8,
filename = file.path(figurePath, paste0("CD4_FunctionScore_heatmap.pdf")))
后续AI修整图片



截屏2025-04-10 17.30.23.png
结束语
卡卡学习这篇文献收获了很多内容,不仅是通路基因集的评分,里面的marker也可以收集当作自己去定义细胞亚型的基因。后台回复20250411获取本期数据的CD4T细胞功能基因集评分!
共有 0 条评论