PyDESeq2
Python版的DESeq2已上线,以后就可以使用Python来做差异分析了。目前文章还在bioRxiv。我来简单尝尝鲜。
安装
使用mamba或者conda来新建一个虚拟环境,然后使用pip安装。
mamba create -n pydeseq2 python
mamba activate pydeseq2
pip install pydeseq2
用法
作为Python版的DESeq2, 用法和R里差不多。
数据读取
count_file = "test_counts.csv"
condition_file = "test_clinical.csv"
counts_df = pd.read_csv(count_file, index_col=0).T
condition_df = pd.read_csv(condition_file, index_col=0)
数据集是一个100个样本,每个样本10个基因的小测试集。而其中50个样本属于条件A,另50个样本属于条件B。
>>> counts_df.shape
(100, 10)
>>> counts_df.head()
gene1 gene2 gene3 gene4 gene5 gene6 gene7 gene8 gene9 gene10
sample1 12 22 2 187 15 2 13 57 56 6
sample2 10 6 20 99 55 0 35 96 43 1
sample3 0 28 3 96 38 2 9 54 27 14
sample4 7 28 10 170 16 10 17 38 18 16
sample5 2 31 5 126 23 2 19 53 31 18
>>> condition_df
condition
sample1 A
sample2 A
sample3 A
sample4 A
sample5 A
... ...
sample96 B
sample97 B
sample98 B
sample99 B
sample100 B
[100 rows x 1 columns]
构建DeseqDataSet 对象
和DESeq2类似
# 构建DeseqDataSet 对象
dds = DeseqDataSet(counts_df, condition_df, design_factor="condition")
# 离散度和log fold-change评估.
dds.deseq2()
# Fitting size factors...
# ... done in 0.00 seconds.
# Fitting dispersions...
# ... done in 0.64 seconds.
# Fitting dispersion trend curve...
# ... done in 0.03 seconds.
# Fitting MAP dispersions...
# ... done in 0.63 seconds.
# Fitting LFCs...
# ... done in 0.66 seconds.
# Refitting 0 outliers.
统计分析
差异表达统计检验分析
res = DeseqStats(dds)
# 执行统计分析并返回结果
res_df = res.summary()
结果如下
>>> res_df
baseMean log2FoldChange lfcSE stat pvalue padj
gene1 10.306788 1.007045 0.225231 4.471161 7.779603e-06 2.593201e-05
gene2 24.718815 -0.059670 0.165606 -0.360311 7.186146e-01 7.186146e-01
gene3 4.348135 -0.166592 0.325445 -0.511891 6.087275e-01 6.763639e-01
gene4 98.572300 -2.529204 0.136752 -18.494817 2.273125e-76 2.273125e-75
gene5 38.008562 1.236663 0.151824 8.145377 3.781028e-16 1.890514e-15
gene6 4.734285 0.212656 0.304487 0.698408 4.849222e-01 6.061527e-01
gene7 30.011855 -0.445855 0.150575 -2.961017 3.066249e-03 5.110415e-03
gene8 59.330642 0.372080 0.118911 3.129070 1.753603e-03 3.507207e-03
gene9 46.779546 0.547280 0.124922 4.380966 1.181541e-05 2.953853e-05
gene10 11.963156 0.494775 0.229494 2.155940 3.108836e-02 4.441194e-02
最后
PyDESeq2目前主要的核心功能差异分析已完成,虽然相比DESeq2而言还在起步阶段, 不过很明显可以发现Python的组学分析生态正逐渐完善~
参考
标签:...,01,df,seconds,使用,PyDESeq2,condition From: https://www.cnblogs.com/huanping/p/17001567.html