这就是我想做的。我有一个基因的列表,例如: 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来获得我所拥有的基因列表的序列。
谢谢,
发布于 2012-12-02 04:33:36
首先使用基因名称例如: ATK1
item = 'ATK1'
animal = 'Homo sapien'
search_string = item+"[Gene] AND "+animal+"[Organism] AND mRNA[Filter] AND RefSeq[Filter]"现在我们有一个搜索字符串来搜索ids。
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'))发布于 2012-11-26 02:58:16
在本教程的8.3节中,似乎有一个函数允许您搜索术语并获取相应的ID(我对这个库一无所知,对生物学的了解更少,因此这可能是完全错误的:)。
>>> handle = Entrez.esearch(db="nucleotide",term="Cypripedioideae[Orgn] AND matK[Gene]")
>>> record = Entrez.read(handle)
>>> record["Count"]
'25'
>>> record["IdList"]
['126789333', '37222967', '37222966', '37222965', ..., '61585492']据我所知,id引用了esearch函数返回的实际ID号(在响应的IdList属性中)。但是,如果使用term关键字,则可以运行搜索并获取匹配项的ID。完全未经测试,但假设搜索支持布尔运算符(它看起来像AND工作),您可以尝试使用以下查询:
>>> handle = Entrez.esearch(db="nucleotide",term="ITGB1[Gene] OR RELA[Gene] OR NFKBIA[Gene]")
>>> record = Entrez.read(handle)
>>> record["IdList"]
# Hopefully your ids here...要生成要插入的术语,可以执行如下操作:
In [1]: l = ['ITGB1', 'RELA', 'NFKBIA']
In [2]: ' OR '.join('%s[Gene]' % i for i in l)
Out[2]: 'ITGB1[Gene] OR RELA[Gene] OR NFKBIA[Gene]'然后,可以将record["IdList"]转换为以逗号分隔的字符串,并通过以下方式将其传递给原始查询中的id参数:
In [3]: r = ['1234', '5678', '91011']
In [4]: ids = ','.join(r)
In [5]: ids
Out[5]: '1234,5678,91011'https://stackoverflow.com/questions/13557981
复制相似问题