生信喵 发表于 2024-4-15 09:55:27

使用python语言获取KEGG数据库基因与通路

# 背景

有了转录组数据,需要画出某基因相关通路的其他基因的表达热图,通路和基因的关系,从KEGG数据库中获得。
通过Python语言批量获取总结。

# 代码

```
from bioservices.kegg import KEGG
import pandas as pd

k = KEGG()
data_autophagy = k.get("mmu04140")
dic_data_autophagy = k.parse(data_autophagy)

# 提取路径信息和基因信息,自己写
pathway_id = "mmu04140"
pathway_name = dic_data_autophagy.get("NAME", "Autophagy - animal - Mus musculus (house mouse)")

# 假设GENE信息在返回的字典中以'GENE'为键
genes_dict = dic_data_autophagy.get("GENE", {})

# 分割基因ID和描述信息,创建记录列表
records = []
for gene_id, description in genes_dict.items():
    # 分割基因描述,以保持'GeneID'和'Description'分离
    records.append({
      "PathwayID": pathway_id,
      "PathwayName": pathway_name,
      "GeneID": gene_id,
      "Description": description
    })

# 将记录列表转换为DataFrame
df_genes = pd.DataFrame(records)

# 输出到Excel
output_path = r'D:\tmp\2\kegg_genes_autophagy.xlsx'
df_genes.to_excel(output_path, index=False)
```

# 小结

这个代码简单统计了mmu04140一条通路的基因情况,后续需要改进为多个通路循环获取,新增到df_genes列表,再输出保存。
页: [1]
查看完整版本: 使用python语言获取KEGG数据库基因与通路