# CellTypist_annotate **Repository Path**: mo_xinwu/cell-typist_annotate ## Basic Information - **Project Name**: CellTypist_annotate - **Description**: 使用 celltypist 进行单细胞细胞类型注释 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-07-16 - **Last Updated**: 2024-07-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # README 使用 CellTypist 进行细胞类型注释, 物种为人时适用, 非人物种要使用请将基因名转换成人的同源基因。 纠正: 能进行什么物种的注释主要看 model 文件是否适用, 模型的名称会包含来源(物种和组织), 进行模型选择时可以根据已有模型和实际情况进行选择。截止到 `2024-7` 共有 50 个可用的 model 涉及物种包括: - Human(人类) - Mouse(小鼠) - Cynomolgus Macaque(食蟹猕猴) - Rhesus Macaque(猕猴) - Pig(猪) ## 怎么看模型是否适用? 1. 物种是否匹配 2. 组织是否匹配 3. 模型中是否包含想要注释的细胞类型 ```python # 下载最新的模型, 截止到 2024-07-16 from celltypist import models models.download_models(force_update = True) # 查看模型路径 models.models_path # /public/home/lxw/.celltypist/data/models # 查看模型信息 model = models.Model.load(model = 'Adult_Pig_Hippocampus.pkl') model # CellTypist model with 13 cell types and 2576 features # date: 2023-07-14 21:40:10.051325 # details: cell types from the adult pig hippocampus # source: https://doi.org/10.1016/j.neuron.2021.10.036 # version: v1 # cell types: Astro, CA1 Sub, ..., nIPC # features: ND4, COX3, ..., LOC110256592 model.cell_types # array(['Astro', 'CA1 Sub', 'CA2-3', 'GC', 'InN', 'MC', 'NB', 'OPC', # 'Oligo', 'RGL', 'Vas', 'immune', 'nIPC'], dtype=object) ``` ## High 与 Low 模型的区别 有些情况下模型文件命名会存在 high / low 的字样, low 表示包含低层次(高分辨率)免疫细胞类型/亚型的所有组织组合模型, high 表示包含高层次(低分辨率)免疫细胞类型/亚型的所有组织组合模型。 ```python # -rw-r--r-- 1 lxw lxw 1.1M Jul 16 14:59 Immune_All_High.pkl # -rw-r--r-- 1 lxw lxw 2.7M Jul 16 14:59 Immune_All_Low.pkl from celltypist import models low = models.Model.load(model = 'Immune_All_Low.pkl') high = models.Model.load(model = 'Immune_All_High.pkl') low # CellTypist model with 98 cell types and 6639 features # date: 2022-07-16 00:20:42.927778 # details: immune sub-populations combined from 20 tissues of 18 studies # source: https://doi.org/10.1126/science.abl5197 # version: v2 # cell types: Age-associated B cells, Alveolar macrophages, ..., pDC precursor # features: A1BG, A2M, ..., ZYX high # CellTypist model with 32 cell types and 6639 features # date: 2022-07-16 08:53:00.959521 # details: immune populations combined from 20 tissues of 18 studies # source: https://doi.org/10.1126/science.abl5197 # version: v2 # cell types: B cells, B-cell lineage, ..., pDC precursor # features: A1BG, A2M, ..., ZYX ``` ## 软件安装 仅介绍 python 软件部分 ```python pip install celltypist pip install scanpy ``` ## 软件使用 1. model 数据下载 ```python from celltypist import models models.download_models(force_update = True) ``` 2. 加载并处理数据 - 不在 R 中进行调用 python 环境运行, 容易出现问题, 建议使用 scanpy 和 celltypist 进行数据处理和预测。 - 个人建议使用 cellranger 的输出结果 `filtered_feature_bc_matrix/` 或者 `filtered_feature_bc_matrix.h5` 文件。 ```bash /public/home/liss/software/Miniconda3/envs/CellTypist/bin/python SET_CellTypist.py -h # usage: python3 SET_CellTypist.py --infile filtered_feature_bc_matrix --type 10x_mtx --model model.pkl --metadata meta_data.txt --out_dir . # Options: # -h, --help Display this message # --infile Input file or file directory. # --type Input file format. # mtx is gene * cell matrix, # h5ad is scanpy object file, # 10x_mtx is cellranger outs filtered_feature_bc_matrix, # 10x_h5 is cellranger outs filtered_feature_bc_matrix.h5 # --model Model file used to predict the input cells, file suffix must be '.pkl' # --metadata meta data saved from Seurat object. # --out_dir output directory, default is current directory. # optional arguments: # -h, --help show this help message and exit # --infile INFILE Input file or file directory. # --type {mtx,h5ad,10x_mtx,10x_h5} # Input file format. mtx is gene * cell matrix, h5ad is scanpy obj file, 10x_mtx is cellranger outs filtered_feature_bc_matrix, 10x_h5 is filtered_feature_bc_matrix.h5 # --model MODEL Model file used to predict the input cells, file suffix must be '.pkl' # --metadata METADATA meta data saved from Seurat object. # --out_dir OUT_DIR output directory, default is current directory. ``` 参数说明: - `--infile` 输入文件或文件目录, 建议使用 `filtered_feature_bc_matrix` 文件夹。 - `--type` 输入文件格式, `mtx` 为 gene * cell 矩阵, `h5ad` 为 scanpy 对象文件, `10x_mtx` 为 cellranger 输出的 `filtered_feature_bc_matrix` 文件, `10x_h5` 为 `filtered_feature_bc_matrix.h5` 文件。 - `--model` 模型文件, 用于预测输入细胞的细胞类型, 文件后缀必须为 `.pkl`。 - `--metadata` `Seurat` 对象的 `meta data`, 仅用于细胞进行过滤, 该文件的第一列必须为 `barcode` 。 - `--out_dir` 输出目录, 默认为当前目录。 3. 全流程 仅使用 `project.rdata` 文件, 从该文件中提取 `expression matrix` 和 `meta data`, 并调用 `SET_CellTypist.py` 进行预测。 ```bash /public/home/liss/software/Miniconda3/envs/scextool/bin/Rscript SET_CellTypist.R -h # usage: Rscript --project_sob project.rdata --model Immune_All_Low.pkl --out_dir . # optional arguments: # -h, --help show this help message and exit # --project_sob PROJECT_SOB # Input file saved by Seurat object. # --model MODEL Model file used to predict the input cells, file # suffix must be '.pkl' # --out_dir OUT_DIR Output file path. ``` 参数说明: - `--project_sob` `Seurat` 对象保存的文件, 以 `project` 记。 - `--model` 模型文件, 用于预测输入细胞的细胞类型, 文件后缀为 `.pkl`。 - `--out_dir` 输出目录, 默认为当前目录。 ## 个人建议 1. 不用 `SET_CellTypist.R` 脚本进行分析。虽然其运行简单, 但其运行速度较慢, 尤其对多样本整合后的文件, 保存 `expression matrix` 和 `meta data` 耗时较长。 2. 画图可能出现不适用。可能出现图不全、比例不协调等问题。建议只使用 `SET_CellTypist.py` 拿到 `Celltypist_CellType_Labels.csv` 预测结果, 自行绘图, 确保交付图片可用。