-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcelltype_annotation
More file actions
33 lines (26 loc) · 944 Bytes
/
celltype_annotation
File metadata and controls
33 lines (26 loc) · 944 Bytes
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
## SingleR (R)
library(Seurat)
library(SingleR)
library(celldex)
library(SummarizedExperiment)
ref <- celldex::HumanPrimaryCellAtlasData()
data <- readRDS("object.rds")
seurat_obj <- UpdateSeuratObject(object = data)
seurat_obj <- NormalizeData(seurat_obj)
seurat_obj <- ScaleData(seurat_obj)
results <- SingleR(test = as.SingleCellExperiment(seurat_obj), ref = ref, labels = ref$label.main)
# Add annotations to the object
seurat_obj$singlr_labels <- results$labels
--------------------------------------------------------------------------
## CellTypist (python)
import os
import scanpy as sc
import pandas as pd
import celltypist
from celltypist import models
adata = sc.read('object.h5ad')
model = models.Model.load(model = 'Immune_All_Low.pkl')
predictions = celltypist.annotate(adata, model = 'Immune_All_Low.pkl', majority_voting = True)
predictions.predicted_labels
# Add annotations to the object
adata = predictions.to_adata()