pre01-scrublet检测双细胞
回想起来自己从事生物相关的研究已经大概15年了,从研究生进入实验室也有10年时间,陆续从硕士,博士到博后,研究地点也从化学学院,到药学院再到医院科室。自己做的研究是“干-湿”实验结合的,发表的成果也是各自一半,但是综合起来还是生物信息分析的文章发表的影响因子高一些。到现在由于工作场所频繁发生变化,反而没有稳定的场所做实验,所以愈发的在生物信息方面下较多的功夫。因此我对这十几年来的生信研究进行总结,希望帮助新手克服生物信息陡峭的学习曲线,当然我自己也不是科班出身的,也希望与你一起交流学习。所有的内容均是以自己的实验数据(会明确下载地址给读者)操作来进行,避免某些在demo运行很好却在自己的环境中出现bug的情况。最后一点,现在通讯太发达了,欢迎大家与我微信:cll7658直接交流共同进步。
参考 单细胞数据质控-双细胞预测-scrublet使用教程 – 简书下载数据并且解压
wget http://cf.10xgenomics.com/samples/cell-exp/2.1.0/pbmc8k/pbmc8k_filtered_gene_bc_matrices.tar.gz tar xfz pbmc8k_filtered_gene_bc_matrices.tar.gz
然后使用python环境进行运算
# 载入包 %matplotlib inline import scrublet as scr import scipy.io import matplotlib.pyplot as plt import numpy as np import os import pandas as pd plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['font.sans-serif'] = 'Arial' plt.rc('font', size=14) plt.rcParams['pdf.fonttype'] = 42 # 读取下载的数据,将counts数据读成上次朋友数据。cell作为行,基因作为列 input_dir = '/Users/yuanzan/Desktop/doublets/filtered_gene_bc_matrices/GRCh38/' counts_matrix = scipy.io.mmread(input_dir + '/matrix.mtx').T.tocsc() genes = np.array(scr.load_genes(input_dir + '/genes.tsv', delimiter='\t', column=1)) out_df = pd.read_csv(input_dir + '/barcodes.tsv', header = None, index_col=None, names=['barcode']) print('Counts matrix shape: {} rows, {} columns'.format(counts_matrix.shape[0], counts_matrix.shape[1])) print('Number of genes in gene list: {}'.format(len(genes))) # Counts matrix shape: 8381 rows, 33694 columns # Number of genes in gene list: 33694 # 初始化Scrublet对象 scrub = scr.Scrublet(counts_matrix, expected_doublet_rate=0.06) # 计算doublet score doublet_scores, predicted_doublets = scrub.scrub_doublets(min_counts=2, min_cells=3, min_gene_variability_pctl=85, n_prin_comps=30) # 绘制doublet score分布直方图 scrub.call_doublets(threshold=0.25) # 画doublet score直方图 scrub.plot_histogram() # 降维可视化 # 降维计算 print('Running UMAP...') scrub.set_embedding('UMAP', scr.get_umap(scrub.manifold_obs_, 10, min_dist=0.3)) print('Done.') # UMAP可视化 scrub.plot_embedding('UMAP', order_points=True) # doublets占比 print (scrub.detected_doublet_rate_) # 0.043789523923159525 # 把doublets预测结果保存到文件,后续用Seurat等软件处理的时候可以导入doublets的预测结果对barcode进行筛选。
下载笔记地址:blog/scrublet_basics.ipynb at 3288d2b414b7303a0bc6026409097a0c3051e223 · seqyuan/blog · GitHub
最后,如果感兴趣请加微信:cll7658,如果你有觉得比较重要的讨论即可。
请关注“恒诺新知”微信公众号,感谢“R语言“,”数据那些事儿“,”老俊俊的生信笔记“,”冷🈚️思“,“珞珈R”,“生信星球”的支持!
标签:单细胞测序