# CellTypist注释免疫细胞亚群

## 第一步 加载包

    1
    2
    3
    4
    5
    6
    7

    Sys.setenv(RETICULATE_PYTHON = "/opt/conda/envs/celltypist/bin/python3.8")
    library(reticulate)
    scanpy = import("scanpy")
    celltypist = import("celltypist")
    pandas <- import("pandas")
    numpy = import("numpy")
    py_config()

## 第二步 加载数据

    1
    2
    3

    library(Seurat)
    sce <- readRDS("~/upload/yy_zhang_data/scRNA-seq/pca.celltype.rds")
    Myeloid <- subset(sce, cell_type=='Myeloid')

## 第三步 seurat转scanpy

    1
    2
    3
    4
    5
    6
    7
    8
    9

    # 数据矩阵, scanpy与Seurat的行列定义相反
    adata.X = numpy$array(t(as.matrix(Myeloid[['RNA']]@counts)))
    # 对每个细胞的观察
    adata.obs = pandas$DataFrame(Myeloid@meta.data[colnames(Myeloid[['RNA']]@counts),])
    # 对基因矩阵的注释
    adata.var = pandas$DataFrame(data.frame(gene = rownames(Myeloid[['RNA']]@counts), row.names = rownames(Myeloid[['RNA']]@counts)))

    # 组装AnnData对象
    adata = scanpy$AnnData(X = adata.X, obs=adata.obs, var=adata.var)

## 第四步 进行预测

    1
    2
    3
    4
    5

    model = celltypist$models$Model$load(model = 'Immune_All_AddPIP.pkl')
    model$cell_types
    scanpy$pp$normalize_total(adata, target_sum=1e4)
    scanpy$pp$log1p(adata)
    predictions = celltypist$annotate(adata, model = 'Immune_All_AddPIP.pkl', majority_voting = T)

## 第五步 预测添加到seurat对象

    1

    Myeloid = AddMetaData(Myeloid, predictions$predicted_labels)

生信 分群
CellTypist注释免疫细胞亚群
https://occdn.limour.top/1541.html
Author
Limour
Posted on
February 22, 2022
Licensed under
通过conda安装纯净环境的SingleR Previous
通过conda安装纯净环境的CellTypist Next

#### Search

Keyword