生信人

找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

0

收听

12

听众

279

主题
发表于 2024-4-15 09:55:27 | 查看: 35| 回复: 0

背景

有了转录组数据,需要画出某基因相关通路的其他基因的表达热图,通路和基因的关系,从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列表,再输出保存。

收藏回复 显示全部楼层 道具 举报

您需要登录后才可以回帖 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|生信人

GMT+8, 2024-5-6 04:33 , Processed in 0.043888 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表