4.1 导读

数据统计,大部分功能包括一下:

  • 细胞比例分析
  • 细胞比例异质性分析
  • 分组之间差异分析
  • 基因表达异质性分析

4.2 细胞比例分析

  • 统计各个样本之间cluster 以及 cell type 变化 ```python fig, axes = plt.subplots(1, 2 ,figsize=(10,5) , gridspec_kw={‘width_ratios’: [1, 5 ], ‘wspace’: 0.3}) list_conditions = [“T”,”N”] temp = adata_all.obs.groupby( [‘sample’,’cell_type’]).size().groupby(level=0).apply(lambda x: 100 x / float(x.sum())).unstack() temp.loc[list_conditions].plot(kind=’bar’, stacked=True, width=0.9, ax=axes[0] ) axes[0].grid(None) axes[0].get_legend().remove() axes[0].set_ylabel(‘Precentage celltype’) mask = adata_all.obs[‘sample’].isin(list_conditions) temp = adata_all[mask].obs.groupby( [‘sample’,’louvain_2’]).size().groupby(level=0).apply(lambda x: 100 x / float(x.sum())).unstack() temp.plot(kind=’bar’, stacked=True, ax=axes[1], width=0.9 )

axes[1].grid(None) axes[1].legend(loc=’upper right’, bbox_to_anchor=(1.5, 1), frameon=False)#, labels=[‘celltype’+x for x in adata_sub.obs[‘louvain’].unique() ]) axes[1].get_legend().remove() axes[1].set_ylabel(‘Precentage cluster’)

  1. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/2605407/1638253792958-41fccecd-b002-44ef-a358-893fa7872d7b.png#align=left&display=inline&height=358&id=ue8cb4807&margin=%5Bobject%20Object%5D&name=image.png&originHeight=715&originWidth=1385&size=72984&status=done&style=none&width=693)
  2. > 示例样本没有分组信息,如果有分组信息可以统计多个维度的数据。
  3. - 细胞比例异质性分析
  4. > 样本之间某一类细胞比例差异,如:`T``N`样本之间`B细胞`差异。由于每个样本只有一个数据,无法直接通过分组算`p-value`。由别的数据代替,请悉知。
  5. ```python
  6. sns.set_style("ticks")
  7. x = "samples"
  8. y_list = "B"
  9. order = ['N', 'T']
  10. x_num = 0
  11. y_num = 0
  12. ax = sns.boxplot(data=temp2, x=x, y=y_list, order=order,hue=x,)
  13. add_stat_annotation(ax, data=temp2, x=x, y=y_list, order=order,
  14. box_pairs=[("N", "T")],
  15. test='Wilcoxon', text_format='star', loc='inside', verbose=3)

image.png

同理 分组也是类似方法画图

  • 基因表达异质性

    计算每个细胞中基因的表达分数 如:IL4R基因

  1. sc.tl.score_genes(adata_all,gene_list=["IL4R"],score_name="IL4R_score")
  2. adata_all.obs.IL4R_score

image.pngimage.png

  1. sns.set_style("ticks")
  2. f = plt.figure(figsize=(10, 6))
  3. x = "sample"
  4. order = ['T', 'N']
  5. ax = sns.boxplot(data=adata_all.obs, x=x, y='IL4R_score', order=order)
  6. add_stat_annotation(ax, data=adata_all.obs, x=x, y='IL4R_score', order=order,
  7. box_pairs=[("T", "N")],
  8. test='t-test_ind', text_format='star', loc='inside', verbose=3)
  9. ax.tick_params(axis='both', labelsize=13)
  10. plt.setp(ax.artists,fill=False)
  11. handles, labels = ax.get_legend_handles_labels()
  12. legend1 = plt.legend(handles[0:3], order,bbox_to_anchor=(1.05, 1),
  13. loc=2, borderaxespad=0.)
  14. plt.setp(plt.gca().get_legend().get_texts(), fontsize='12')
  15. f.set_size_inches(10,7)

image.png

  • 基因表达分析

    某一个基因在 某一类细胞 中的表达情况。如:IL4R 在每个样本中的表达统计图。

  1. sc.pl.umap(adata_all[adata_all.obs["sample"].isin(["T"])], color=['IL4R'], color_map="Blues")
  2. sc.pl.umap(adata_all[adata_all.obs["sample"].isin(["N"])], color=['IL4R'], color_map="Greens")

image.pngimage.png

该示例中既有提取数据案例,也有图示例子。

image.png