Thanks! That's a really good way to do what I intended to,
For me, however, I gave up and decided to just put the cluster into the object name as opposed to a column,
cluster_index <- levels(counts_all@active.ident) # counts_all is my main Seurat object
for(i in cluster_index) {
name <- paste0("counts_", i)
clustersubset <- subset(counts_all, idents=i, slot="counts")
assign(name, as.data.frame(clustersubset@assays$RNA@counts))
rm(name, clustersubset)
}
Why not start with
data_transcripts_seurat@assays$SCT@counts?Something like:
If you need the cells to be rows, you can use the
t()function:Thanks! That's a much better way to do it. Could you please also provide guidance on how the cluster assignment can also be transferred (correctly) to this dataframe?
what does
data_transcripts_seurat@active.identget you? Shouldn't those be the cluster assignments per cell? [Disclaimer: I do not use Seurat, so I'm basing this off your initial code]Hi, yes I think it is! I did not realise this before (also very new to Seurat, and transcriptomics in general). How can I add this to
counts.df? Is it with theattributesfunction?Also, should I be concerned about the order of cells being different in
counts.dfanddata_transcripts_seurat@active.ident? Are there ways to make sure they are matched?