Hi, I have been trying to use SingleR to annotate the cell type per cluster. I used my Seurat object from integration analysis and the code was:
ref <- ImmGenData()
pred <- SingleR(as.SingleCellExperiment(seurat.integrated), ref, labels=ref$label.main, clusters=Idents(seurat.integrated))
But, when I checked rownames(pred)
, it still showed the name of each cell, not the cluster ids that I input in the function.
Also, when I checked with table(pred$labels)
, it also showed the number of a single cell per cell type.
Could anyone help me get the cluster-wise annotation results (the code above only provided me a single-cell wise annotation results)?
Any advice will be greatly appreciated. Thank you!
Thanks Friederike for your reply! The output of head(pred) looks exactly same as you described. It's rowname is the cell barcode and it has 5 columns: scores, first.labels, tuning scores, labels, pruned. labels as described in the vignette. And I was wondering where the cluster information was saved in "pred." When I tried
table(predicted=pred$labels, cluster=rownames(pred))
, it showed each cell barcode becauserownames(pred)
was still the cell barcode and I assume it was supposed to be cluster ids... Do you see any problem here? I really appreciate your input..The cluster IDs are part of the metadata of your Seurat object, I assume. SingleR simply gives you an additional entry for the metadata, i.e. for any given cell you now know which cell type it is most similar to. Just as you (presumably) know the cluster membership for any given cell. I don't typically interact with Seurat objects, so I can't tell you how to properly extract the cluster membership from your Seurat object, but that's essentially what you'll need to do if you want your
table
command to work.Thanks once again, Friederike. I can extract the cluster membership from my Seurat object by running
Idents(seurat.integrated)
, so I thoughtclusters=Idents(seurat.integrated)
in SingleR function that I wrote in my post could do the job to create additional entry for the cluster membership in "pred." But, unfortunately, "pred" didn't have a column for the cluster membership after the run. Then, do you know whatclusters=Idents(seurat.integrated)
in SingleR function is supposed to do? I am confused now..Hi, from the manual pages, it states:
Further:
In your example, 'test' is
as.SingleCellExperiment(seurat.integrated)
. Perhaps just pass the actual expression matrix. By passing a SingleCellExperiment, it may be overlooking whatever you have passed toclusters
- not sure.