我想从Entrez Gene页面中删除Interactions表。Python Entrez词典中的字典返回值
Interactions表从Web服务器填充,当我试图在R中使用XML包时,我可以获得Entrez基因页面,但Interactions表体是空的(它尚未由Web服务器填充)。
处理R中的Web服务器问题可能是可以解决的(我很想看看它是如何实现的),但似乎Biopython是一条更简单的路径。
我下面的放在一起,这给了我什么,我想为例基因:
# Pull the Entrez gene page for MAP1B using Biopython
from Bio import Entrez
Entrez.email = "[email protected]"
handle = Entrez.efetch(db="gene", id="4131", retmode="xml")
record = Entrez.read(handle)
handle.close()
PPI_Entrez = []
PPI_Sym = []
# Find the Dictionary that contains the Interaction table
for x in range(1, len(record[0]["Entrezgene_comments"])):
if ('Gene-commentary_heading', 'Interactions') in record[0]["Entrezgene_comments"][x].items():
for y in range(0, len(record[0]["Entrezgene_comments"][x]['Gene-commentary_comment'])):
EntrezID = record[0]["Entrezgene_comments"][x]['Gene-commentary_comment'][y]['Gene-commentary_comment'][1]['Gene-commentary_source'][0]['Other-source_src']['Dbtag']['Dbtag_tag']['Object-id']['Object-id_id']
PPI_Entrez.append(EntrezID)
Sym = record[0]["Entrezgene_comments"][x]['Gene-commentary_comment'][y]['Gene-commentary_comment'][1]['Gene-commentary_source'][0]['Other-source_anchor']
PPI_Sym.append(Sym)
# Return the desired values: I want the Entrez ID and Gene symbol for each interacting protein
PPI_Entrez # Returns the EntrezID
PPI_Sym # Returns the gene symbol
此代码的工作,给我我想要的东西。但我认为它很丑,而且担心如果Entrez基因页面在格式上略有变化,它会破坏代码。尤其是,必须有一个更好的方法来提取所需的信息不是指定的完整路径,因为我做:
record[0]["Entrezgene_comments"][x]['Gene-commentary_comment'][y]['Gene-commentary_comment'][1]['Gene-commentary_source'][0]['Other-source_anchor']
但我无法弄清楚如何通过词典的词典搜索,而无需指定每个级别我想要下降。当我尝试像find()这样的函数时,它们会在下一级进行操作,但不会一直到底部。
是否有一个通配符符号,“//”的Python等价物,或者我可以用来在不指定完整路径的情况下转到['Object-id_id']的函数?其他建议更干净的代码也表示赞赏。
谢谢克里斯S!我曾经计划用Python编写脚本,然后从R做一个系统调用。但是这很容易(至少对我来说)。我并不知道Entrez Direct,但它很好地解决了Web服务器问题,并让我回到由Node解析而不是试图钻取Python Dictionaries。 – jamayfie 2014-12-08 18:55:56
在开始这个项目之前,我曾考虑过BioGrid,HERD等,但我喜欢NCBI将IntAct和BioGrid整理成一张桌子,如果可能,我想从那里开始。 – jamayfie 2014-12-08 19:01:41
我能得到公正的EntrezID通过指定相互作用蛋白:sapply(X,函数(x)的糊状(xpathSApply(X,” .//Gene-commentary_comment//..//Dbtag_db[.='GeneID']// ..//Object-id_id”,xmlValue),倒塌= “”)),如果你需要保存历史(esearch – jamayfie 2014-12-08 19:59:08