【问题标题】:how to get a specific protein sequence using entrez.efetch?如何使用 entrez.efetch 获取特定的蛋白质序列?
【发布时间】:2013-11-14 19:18:05
【问题描述】:

我正在尝试使用 Biopython 的 Entrez.fetch() 函数通过基因 id (GI) 号从 NCBI 获取蛋白质序列。

proteina = Entrez.efetch(db="protein", id= gi, rettype="gb", retmode="xml").

然后我使用以下方法读取数据:

proteinaXML = Entrez.read(proteina).

我可以打印结果,但是我不知道如何单独获得蛋白质序列

结果显示后,我可以手动到达蛋白质。或者我使用以下命令检查 XML 树:

proteinaXML[0]["GBSeq_feature-table"][2]["GBFeature_quals"][6]['GBQualifier_value'].

但是,根据提交的蛋白质的 GI,XML 树可能会有所不同。使这一过程难以稳健地自动化。

我的问题:是否可以只检索蛋白质序列,而不是整个 XML 树? 或者:如何从 XML 文件中提取蛋白质序列,因为 XML 文件的结构可能因蛋白质而异?

谢谢

【问题讨论】:

    标签: xml sequence bioinformatics biopython ncbi


    【解决方案1】:

    好点,XML 中的数据库条目确实因不同作者提交的蛋白质而异。

    我已经制定了一个算法来从 XML 树中“寻找”蛋白质序列:

    import os
    import sys
    from Bio import Entrez
    from Bio import SeqIO
    
    gi          = '1293613'         # example gene id                   
    Entrez.email= "you@email.com"   # Always tell NCBI who you are
    protina     = Entrez.efetch(db="protein", id=gi, retmode="xml") # fetch the xml
    protinaXML  = Entrez.read(protina)[0]
    
    seqs = []           # store candidate protein seqs
    def seqScan(xml):   # recursively collect protein seqs
        if str(type(xml))=="<class 'Bio.Entrez.Parser.ListElement'>":
            for ele in xml:
                seqScan(ele)
        elif str(type(xml))=="<class 'Bio.Entrez.Parser.DictionaryElement'>":
            for key in xml.keys():
                seqScan(xml[key])
        elif str(type(xml))=="<class 'Bio.Entrez.Parser.StringElement'>":
            #   v___THIS IS THE KEYWORD FILTER_____v
            if (xml.startswith('M') and len(xml))>10: # 1) all proteins start with M (methionine)
                seqs.append(xml)                      # 2) filters out authors starting with M
    
    seqScan(protinaXML) # run the recursive sequence collection
    print(seqs)         # print the goods!
    

    注意:在极少数情况下(取决于“关键字过滤器”),它可能会幽默地抓取不需要的字符串,例如以“M”开头的作者姓名,其缩写名称长度超过 10 个字符(下图):

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 2013-11-27
      • 1970-01-01
      • 2017-01-28
      • 2012-06-27
      • 2013-01-16
      • 1970-01-01
      • 2017-12-31
      • 2014-11-28
      • 2020-05-01
      相关资源
      最近更新 更多