这就是我想要做的。 我有一个基因名称列表,例如:[ITGB1、RELA、NFKBIA]
查找 biopython 中的帮助和 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 以获得我拥有的基因列表的序列。
谢谢,
最佳答案
首先是基因名eg: 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,则返回 ids 作为列表,它是 []。现在假设它返回列表中的 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'))
关于python - 使用biopython从entrez获取基因序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13557981/