我想从Entrez Gene页面上抓取交互作用表。在
Interactions表是从web服务器填充的,当我试图在R中使用XML包时,我可以得到Entrez gene页面,但是Interactions表体是空的(它没有被web服务器填充)。在
在R中处理web服务器问题可能是可以解决的(我很想知道如何解决),但是Biopython似乎是一条更简单的途径。在
我把下面的内容放在一起,这就给了我想要的一个示例基因:
# Pull the Entrez gene page for MAP1B using Biopython
from Bio import Entrez
Entrez.email = "jamayfie@vasci.umass.edu"
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基因页面的格式稍有改变,就会破坏代码。特别是,必须有一种比指定完整路径更好的方法来提取所需信息,正如我所做的:
^{pr2}$但是我不知道如何在字典中搜索,而不指定我要下降的每一级。当我尝试find()之类的函数时,它们会在下一级操作,但不会一直操作到底部。在
是否有一个通配符、Python等价的“/”或一个函数,我可以使用它在不命名完整路径的情况下访问['Object-id_id']?其他关于更清洁的代码的建议也值得赞赏。在
我不确定Python中的xpath,但是如果代码有效,那么我就不必担心删除完整的路径或者Entrez Gene XML是否会改变。由于您第一次尝试R,您可以使用直接下面的Entrez系统调用或像rentrez这样的包来获取XML。在
接下来,获取表中http://www.ncbi.nlm.nih.gov/gene/4131#interactions处的行对应的节点
^{pr2}$先试试简单的东西
一些标记,如text、refs、source和dates应该很容易解析
我不确定表中列出的注释或产品、交互体和其他基因是如何存储在XML中的,但我在这里为每个节点提供了一到三个符号和三个ID。在
最后,因为我认为Entrez基因只是完整地复制了BioGrid,所以你也可以试试这些网站。Biogrid有一个非常简单的Rest服务,但是您必须注册一个密钥。在
相关问题 更多 >
编程相关推荐