【单细胞】sc.pp.normalize_per_cell和sc.pp.normalize_total()函数

文章介绍了Scanpy库中的sc.pp.normalize_per_cell()和sc.pp.normalize_total()函数,这两个函数用于对细胞的计数矩阵进行归一化操作。在最新版本中,normalize_total()替代了normalize_per_cell()。示例展示了如何使用这些函数以及log1p()进行数据处理。归一化计算涉及对每个细胞的所有基因计数值求和,然后基于这些总和进行调整,以达到标准化的目的。

1 功能

  sc.pp.normalize_per_cell()和sc.pp.normalize_total()功能是一致的。在最新的Scanpy中sc.pp.normalize_total()替代了sc.pp.normalize_per_cell(),具体的情况见参考文献【2】。这个函数的功能就是对细胞的计数矩阵进行归一化操作。

2 例子

import numpy as np
import scanpy as sc

x = np.array([[1, 2, 3],
              [2, 3, 4],
              [1, 1, 3],
              [0, 2, 10]])
adata = sc.AnnData(x)
adata.raw = adata.copy(
ValueError Traceback (most recent call last) Cell In[16], line 5 2 model = models.Model.load('Immune_All_Low.pkl') 4 # 执行自动注释 ----> 5 predictions = celltypist.annotate( 6 scRNA_data, 7 model=model, 8 majority_voting=True, # 启用多数投票算法提升精度 9 mode='best_match' # 输出最可能细胞类型 10 ) 12 # 整合结果到AnnData对象 13 scRNA_data.obs['predicted_label'] = predictions.predicted_labels File ~/.local/lib/python3.12/site-packages/celltypist/annotate.py:83, in annotate(filename, model, transpose_input, gene_file, cell_file, mode, p_thres, majority_voting, over_clustering, use_GPU, min_prop) 81 lr_classifier = model if isinstance(model, Model) else Model.load(model) 82 #construct Classifier class ---> 83 clf = classifier.Classifier(filename = filename, model = lr_classifier, transpose = transpose_input, gene_file = gene_file, cell_file = cell_file) 84 #predict 85 predictions = clf.celltype(mode = mode, p_thres = p_thres) File ~/.local/lib/python3.12/site-packages/celltypist/classifier.py:311, in Classifier.__init__(self, filename, model, transpose, gene_file, cell_file) 309 if (self.adata.X[:1000].min() < 0) or (self.adata.X[:1000].max() > 9.22): 310 if not self.adata.raw: --> 311 raise ValueError( 312 "🛑 Invalid expression matrix in `.X`, expect log1p normalized expression to 10000 counts per cell") 313 elif (self.adata.raw.X[:1000].min() < 0) or (self.adata.raw.X[:1000].max() > 9.22): 314 raise ValueError( 315 "🛑 Invalid expression matrix in both `.X` and `.raw.X`, expect log1p normalized expression to 10000 counts per cell") ValueError: 🛑 Invalid expression matrix in `.X`, expect log1p normalized expression to 10000 counts per cell
最新发布
06-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值