非模式物種KEGG富集數(shù)據(jù)庫準(zhǔn)備(二)

一、KEGG數(shù)據(jù)下載

1、先進(jìn)入官網(wǎng):https://www.kegg.jp/

image.png

2、進(jìn)入KO (KEGG ORTHOLOGY) Database
image.png

3、點擊此處選擇物種
image.png

4、此處以斑馬魚為例,所以選擇dre
image.png

5、下載json文件到本地
image.png

二、json文件的處理

import json
import re
K_ko_dict = {}
with open(json, "r")as f:
    K_ko_file_content = json.load(f) 
for children_info in K_ko_file_content.get("children"):
    for next_children_info in children_info.get("children"):
        for third_children_info in next_children_info.get("children"):
            name_info = third_children_info.get("name")
            pathway_id = re.findall(r'PATH:(.*)]', name_info)
            pathway_name = re.findall(r'\d+\s(.*)\s\[', name_info)
            if pathway_id and pathway_name:
                K_ko_dict[pathway_id[0]+"\t"+pathway_name[0]] = []
                if third_children_info.get("children"):
                    for fourth_children_info in third_children_info.get("children"):
                        K_name = fourth_children_info.get("name").split(" ")[0]
                        gene_name = fourth_children_info.get("name").split(" ")[1]
                        gene_name=re.sub(';','',gene_name)
                        K_ko_dict[pathway_id[0]+"\t"+pathway_name[0]].append(K_name+'\t'+gene_name)
out=open(outfile,'w+')
out.write("pathway_gene_id\tgene_name\tpathway_id\tpathway_name\n")
key1=sorted(K_ko_dict.keys())
for key in key1:
    K_ko_dict[key].sort()
    for i in K_ko_dict[key]:
        out.write(i+'\t'+key+'\n')
out.close()

處理后的文件:
image.png

如果需要gene id 那么需要gtf文件,通過gene name轉(zhuǎn)化即可

注意:json.load(f) 若報錯:AttributeError: 'str' object has no attribute 'load',那么需要修改名稱,此處的f指向的名稱為json,與import json重復(fù),覆蓋了此處的名稱。因此會報錯

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容