forked from swbioinf/scRNAseq_Workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-08-singleR.Rmd
More file actions
executable file
·73 lines (50 loc) · 2.53 KB
/
04-08-singleR.Rmd
File metadata and controls
executable file
·73 lines (50 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# (PART) Futher Analysis {-}
# SingleR {#singler}
```{r results='hide', message=FALSE, warning=FALSE}
#install.packages("BiocManager")
#BiocManager::install(c("SingleCellExperiment","SingleR","celldex"),ask=F)
library(SingleCellExperiment)
library(SingleR)
library(celldex)
```
In this workshop we have focused on the Seurat package. However, there is another whole ecosystem of R packages for single cell analysis within Bioconductor. We won't go into any detail on these packages in this workshop, but there is good material describing the object type online : [OSCA](https://robertamezquita.github.io/orchestratingSingleCellAnalysis/data-infrastructure.html).
For now, we'll just convert our Seurat object into an object called SingleCellExperiment. Some popular packages from Bioconductor that work with this type are Slingshot, Scran, Scater.
```{r}
sce <- as.SingleCellExperiment(seurat_object)
sce
```
We will now use a package called SingleR to label each cell. SingleR uses a reference data set of cell types with expression data to infer the best label for each cell. A convenient collection of cell type reference is in the `celldex` package which currently contains the follow sets:
```{r}
ls('package:celldex')
```
In this example, we'll use the `HumanPrimaryCellAtlasData` set, which contains high-level, and fine-grained label types. Lets download the reference dataset
```{r}
# This too is a sce object,
# colData is equivalent to seurat's metadata
ref.set <- celldex::HumanPrimaryCellAtlasData()
```
The "main" labels.
```{r}
unique(ref.set$label.main)
```
An example of the types of "fine" labels.
```{r}
head(unique(ref.set$label.fine))
```
Now we'll label our cells using the SingleCellExperiment object, with the above reference set.
```{r}
pred.cnts <- SingleR::SingleR(test = sce, ref = ref.set, labels = ref.set$label.main)
```
Keep any types that have more than 10 cells to the label, and put those labels back on our Seurat object and plot our on our umap.
<!-- previously this used first.lables, which no longer seems to exist in pred.cnts -->
<!-- labels and pruned labels are identical in this data -->
```{r}
lbls.keep <- table(pred.cnts$labels)>10
seurat_object$SingleR.labels <- ifelse(lbls.keep[pred.cnts$labels], pred.cnts$labels, 'Other')
DimPlot(seurat_object, reduction='umap_harmony', group.by='SingleR.labels')
```
Compare cell labels by different annotation methods:
```{r}
DimPlot(seurat_object,group.by = "RNA_snn_res.0.5",reduction = "umap_harmony")
DimPlot(seurat_object,group.by = "cell",reduction = "umap_harmony")
```