Entering edit mode
17 months ago
shamza
•
0
Hey I am trying to subset only the clusters of my interest by the following command
diff2 <- subset(merged_seurat_filtered, idents = c(0:16),)
There are 21 clusters in total and I want to omit the last 4 clusters from my Seurat object, but when I run the above command it gives me the following.
table(diff2$seurat_clusters)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
9288 8539 8342 7552 6088 4697 4645 4251 3857 3621 3144 3045 2241 1460 1446 591 505 0
18 19 20
0 0 0
the diff2 object is retaining all the clusters and just removes all the cells but I am trying to retain only 0:16 clusters which should look something like this
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
9288 8539 8342 7552 6088 4697 4645 4251 3857 3621 3144 3045 2241 1460 1446 591 505
Does anyone know what mistake I am making?
idents
is probably a factor so even though you've removed cells with those level values, the factor level still remains. Don't worry about it.Could it be that idents needs a character string instead of integers? Also, you have an extra comma in your call after c(0:16).
I usually use select to choose which columns to keep, but not sure if this subset function is specific to seurat ( I am completely unfamiliar with it)? I am thinking of what I use from base R.
Edit: after looking at the seurat function, I think what Ram said makes sense. I think with your command you are selecting cells (not clusters) with Ident = 1 to 16, which is why the cluster columns are still there. For example, you could subset this object with cells that have gene expression > 3, and wouldn't expect any columns to drop, just the cells. At least as far as I understand.
You're close. The
subset
function serves a similar functionality as the base, but since the Seurat object is an S3 object, it subsets based on a slot instead of on a column like it would a data frame. However, the slot contains a factor and the factor is not re-created with new levels, hence the 0 values for levels that existed before subsetting.