Seurat Clustering - Cluster Numbers from 1 instead of 0
1
0
Entering edit mode
2.7 years ago
David_emir ▴ 460

Hi All,

I am analysing Single-cell RNAseq data with Seurat. When I cluster my samples using "FindClusters", Seurat starts cluster labels from 0 (Zero) instead of 1. is there a way where I can ask Seurat to start cluster numbers from 1 instead of 0?

Dave.

RNA-Seq seurat Cluster numbering • 11k views
0
Entering edit mode

I've subsetted out a couple of clusters from a project of mine, but I'm trying to plug the numeric hole in my data. Is there a way to change the numbering of a Seurat cluster from, say, 10 to 9? Thanks!

2
Entering edit mode
2.7 years ago

The newer versions of Seurat start with 1 instead of 0. However, since the clusters are stored as a column in a data.frame, it's easy to change them as necessary.

 seurat_object$seurat_clusters <- as.factor(as.numeric(as.character(seurat_object$seurat_clusters)) + 1)

0
Entering edit mode

Thanks a lot for your kind help, but when I run this code, my seurat clusters are starting from 2 instead of 1. please have a look

> alldata$seurat_clusters <- as.factor(as.numeric(alldata$seurat_clusters) + 1)
> cbind(table(alldata\$seurat_clusters))
[,1]
2  2334
3  2086
4  2077
5  1961

0
Entering edit mode

I updated the code so it should work now. This was caused by as.numeric returning the factor levels instead of the the values.

0
Entering edit mode

Thanks a lot for your help, i am now able to get seurat clusters from 0 , but when i plot the UMAP or TSNE or PCA all labels still show from '0'th cluster.

DimPlot(alldata, reduction = "UMAP_on_CCA", label=T)

1
Entering edit mode

Try specifying which metadata column to use explicitly.

You can either set the identities.

Idents(alldata) <- "seurat_clusters"


Or you can specify what to use in the plotting function.

DimPlot(alldata, reduction = "UMAP_on_CCA", label=T, group.by="seurat_clusters")

0
Entering edit mode

Thanks a lot, this really works like a charm. Have a great day ahead.