鉴定不同分组间的差异表达基因

鉴定每一个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")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容