鉴定每一个cluster分组间的差异基因
- group.by为分组属性,
- metadata中的列名,
- group.1,group.2,为属性中的两个水平
- split为拆分的类群
- tag 自己命名,数据的标签
FindDiffGene <- function(seurat.object,group_by,group.1,group.2,split,path.out,tag){
markers_up_all <- FindMarkers(seurat.object, ident.1 = group.1, ident.2 = group.2, group.by = group_by, only.pos=TRUE,logfc.threshold = 0.1,assay="RNA")
markers_down_all <- FindMarkers(seurat.object, ident.1 = group.2, ident.2 = group.1, group.by = group_by, only.pos=TRUE,logfc.threshold = 0.1,assay="RNA")
seurat_object_list <- SplitObject(seurat.object, split.by = split)
markers_list_up <- list()
markers_list_down <- list()
for (i in names(seurat_object_list)){
markers_up <- FindMarkers(seurat_object_list[[i]], ident.1 = group.1,ident.2 = group.2, group.by = group_by, only.pos=TRUE,logfc.threshold = 0.1,assay="RNA")
markers_list_up[[i]] <- markers_up
markers_down <- FindMarkers(seurat_object_list[[i]], ident.1 = group.2,ident.2 = group.1, group.by = group_by, only.pos=TRUE,logfc.threshold = 0.1,assay="RNA")
markers_list_down[[i]] <- markers_down
}
names(markers_list_up) <- paste("up",names(seurat_object_list),sep="_")
names(markers_list_down) <- paste("down",names(seurat_object_list),sep="_")
markers_list <- c(markers_list_up,markers_list_down)
markers_list[["up_all"]] <- markers_up_all
markers_list[["down_all"]] <- markers_down_all
markers_list_filter <- lapply(markers_list,function(x){x_filter <- x[x$p_val < 0.05,];return(x_filter)})
saveRDS(markers_list_filter,file=paste0(path.out,"/",tag,'_sample_type_markers_list.rds'))
write.xlsx(markers_list_filter,file = paste0(path.out,"/",tag,'_sample_type_markers_list.xlsx'),row.names=T,sep='\t',overwrite=T)
return(markers_list_filter)
}
加载数据
比较每个cell_type中(split="cell_type"),DOX和GMP之间的差异基因,DOX和GMP储存在“sample_type”属性中
FindDiffGene(seurat.object=seurat_object_cluster_define,group_by="sample_type",group.1="DOX",group.2="GMP",split="cell_type",path.out=path_debatch_marker,tag="DOX")