library(Seurat)
library(ggplot2)
library(openxlsx)
feature為metadata的colname中的某個屬性,按照該屬性的不同因子查找marker
MyMarker <- function(seurat_object,feature,path.out){
all_markers_list <- list()
for (cell_type in unique(seurat_object@meta.data[,match(feature,colnames(seurat_object@meta.data))])){
print(cell_type)
cell_names_vector <- rownames(seurat_object@meta.data)[which(seurat_object@meta.data[,match(feature,colnames(seurat_object@meta.data))]==cell_type)]
print(head(cell_names_vector))
try(cell_markers <- FindMarkers(seurat_object,ident.1=cell_names_vector,only.pos=TRUE))
all_markers_list[[cell_type]] <- cell_markers
}
write.xlsx(all_markers_list, file=paste(path.out,"all_cell_type_marker.xlsx",sep="/"), rowNames=TRUE,colNames=TRUE)
saveRDS(all_markers_list,file=paste(path.out,"all_markers_list.rds",sep="/"))
}
對不同的cell.type查找marker
MyMarker(seurat_object=seurat_object_filter_cluster_0.5,feature="cell.type",path.out=path_out)