2
$\begingroup$

I've analyzed my scRNA-seq data and have a couple of Seurat clusters that show more than one cell type in each cluster. (for example, cluster 9 shows both NK and CD4 cells) How can I split a cluster into subclusters, based on the gene expression?

$\endgroup$

3 Answers 3

1
$\begingroup$

Increase the clustering resolution parameter to generate more (smaller) clusters, see FindClusters in the Seurat docs. Whether or not this will neatly, split your clusters into subclusters depends on your data, but normally one can easily separate CD4 and NK cells from PBMCs. See also the Clustree approach for determining the optimal resolution.

Alternatively/additionally use a cell type annotation approach that does not require clustering, e.g. Seurat V4 permits reference mapping and there are many other methods too

$\endgroup$
1
$\begingroup$

I've done sub-clustering a few times on my Seurat data sets. The approach I take is to subset the clusters that need to be clustered (i.e. using subset), carry out a clustering of only those cells, then transfer the subcluster labels back to the original dataset. Here's some rough code, which will need to be modified for your specific situation and code preferences:

data.sc[["main.cluster"]] <- Idents(data.sc);
clusterToSubset <- "B cells";
data.sub <- subset(data.sc, subset = main.cluster == clusterToSubset);
## ** [Cluster data.sub] **
Idents(data.sc) <- "main.cluster";
## This should work as long as cell order (i.e. column names) isn't changed
Idents(data.sc, cells=colnames(data.sc) %in% colnames(data.sub)) <- 
    paste0("Sub_", Idents(data.sub));
data.sc[["merged.cluster"]] <- Idents(data.sc);

This approach will work with multiple sub-clusters as well by changing the label that is pasted onto the sub-cluster idents:

data.sc[["main.cluster"]] <- Idents(data.sc);
clusterToSubset1 <- "B cells";
data.sub.1 <- subset(data.sc, subset = main.cluster == clusterToSubset1);
## ** [Cluster data.sub.1] **
clusterToSubset2 <- "T cells";
data.sub.2 <- subset(data.sc, subset = main.cluster == clusterToSubset2);
## ** [Cluster data.sub.2] **
Idents(data.sc) <- "main.cluster";
## This should work as long as cell order (i.e. column names) isn't changed
Idents(data.sc, cells=colnames(data.sc) %in% colnames(data.sub.1)) <- 
    paste0("Sub1_", Idents(data.sub.1));
Idents(data.sc, cells=colnames(data.sc) %in% colnames(data.sub.2)) <- 
    paste0("Sub2_", Idents(data.sub.2));
data.sc[["merged.cluster"]] <- Idents(data.sc);
$\endgroup$
0
0
$\begingroup$

Idents(data.sc, cells=colnames(data.sc) %in% colnames(data.sub.1)) gives the same output as Idents(data.sc, cells=colnames(data.sc) %in% colnames(data.sub.2)).

Both are returning the cellIDs of all cells.

The correct code to generate a list of colnames of data.sc is as follows:

Idents(data.sc, cells=colnames(data.sc)[colnames(data.sc) %in% colnames(data.sub.1)]) <- paste0("sub1_", Idents(data.sub.1))

However, you can directly add the new cluster names to a metadata column in the Seurat object using the following code:

## Set up new metadata column to store subcluster IDs later ##
data.sc$subcluster <- Idents(data.sc)

## subclustering steps (from a previous comment)##
data.sub.1 <- subset(data.sc, subset = seurat_clusters == 1)
data.sub.1 <- FindVariableFeatures(data.sub.1)
data.sub.1 <- ScaleData(data.sub.1)
data.sub.1 <- RunPCA(data.sub.1, verbose = FALSE)
data.sub.1 <- RunUMAP(data.sub.1, reduction = "pca", dims = 1:30)
data.sub.1 <- FindNeighbors(data.sub.1, reduction = "pca", dims = 1:30)
data.sub.1 <- FindClusters(data.sub.1, resolution = 0.5)

## merging the subclusster names back to original clusters ##
data.sc$subcluster[colnames(dta.sc)[colnames(data.sc) %in% colnames(data.sub.1)]] <- paste0("sub1_", data.sub.1$seurat_clusters)
```
$\endgroup$
1
  • $\begingroup$ If those two commands are producing the same output, it means that the subsets (i.e. data.sub.1 and data.sub.2) are identical, i.e. that the subsetting did not work properly. $\endgroup$
    – gringer
    Commented Oct 10, 2023 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.