Stu*_*nce 3 python biopython ncbi
这就是我想做的。我有一个基因名称列表,例如:[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
Run Code Online (Sandbox Code Playgroud)
但这一直出错。我发现如果 id 是数字 id(尽管您必须将其放入字符串中才能使用,“186972394”),那么:
handle = Entrez.efetch(db="nucleotide", id='186972394' ,rettype="gb")
Run Code Online (Sandbox Code Playgroud)
这让我得到了我想要的信息,其中包括序列。
现在的问题是: 我如何搜索基因名称(因为我没有 ID 号)或轻松地将我的基因名称转换为 id 以获取我拥有的基因列表的序列。
谢谢你,
首先是基因名称,例如:ATK1
item = 'ATK1'
animal = 'Homo sapien'
search_string = item+"[Gene] AND "+animal+"[Organism] AND mRNA[Filter] AND RefSeq[Filter]"
Run Code Online (Sandbox Code Playgroud)
现在我们有一个搜索字符串来搜索 ids
handle = Entrez.esearch(db="nucleotide", term=search_string)
record = Entrez.read(handleA)
ids = record['IdList']
Run Code Online (Sandbox Code Playgroud)
如果没有找到 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()
Run Code Online (Sandbox Code Playgroud)
这将为您提供一个 fasta 字符串,您可以将其保存到文件中
out_handle = open('myfasta.fasta', 'w')
out_handle.write(record.rstrip('\n'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6750 次 |
| 最近记录: |