+-
使用biopython从entrez获取基因序列
这就是我要做的.
我有一个基因名称列表,例如:[ITGB1,RELA,NFKBIA]

在biobio和entrez API教程中查找帮助时,我想到了:

x = ['ITGB1', 'RELA', 'NFKBIA']
for item in x:
    handle = Entrez.efetch(db="nucleotide", id=item ,rettype="gb")
    record = handle.read()
    out_handle = open('genes/'+item+'.xml', 'w') #to create a file with gene name
    out_handle.write(record)
    out_handle.close

但这总是出错.我发现如果id是数字id(尽管您必须将其放入字符串中才能使用’186972394′,所以:

handle = Entrez.efetch(db="nucleotide", id='186972394' ,rettype="gb")

这使我得到想要的信息,其中包括序列.

所以现在到问题:
如何搜索基因名称(因为我没有ID号)或如何轻松地将我的基因名称转换为ID以获取我拥有的基因列表的序列.

谢谢,

最佳答案
首先使用基因名称,例如:ATK1

item = 'ATK1'
animal = 'Homo sapien' 
search_string = item+"[Gene] AND "+animal+"[Organism] AND mRNA[Filter] AND RefSeq[Filter]"

现在我们有一个搜索字符串来查找ID

handle = Entrez.esearch(db="nucleotide", term=search_string)
record = Entrez.read(handleA)
ids = record['IdList']

如果没有找到ID,则返回ID作为列表.现在假设它返回列表中的1个项目.

seq_id = ids[0] #you must implement an if to deal with <0 or >1 cases
handle = Entrez.efetch(db="nucleotide", id=seq_id, rettype="fasta", retmode="text")
record = handleA.read()

这将为您提供一个fasta字符串,您可以将其保存到文件中

out_handle = open('myfasta.fasta', 'w')
out_handle.write(record.rstrip('\n'))
点击查看更多相关文章

转载注明原文:使用biopython从entrez获取基因序列 - 乐贴网