比这篇新的文章:
从NCBI下载基因序列
比这篇旧的文章: 生成华容道所有可求解的开局含镜像263977种,不含镜像132156种
作者: wisdom_love, 点击1088次, 评论(0), 收藏者(0), , 打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: 生成华容道所有可求解的开局含镜像263977种,不含镜像132156种
从NCBI下载基因序列
语言: Python, 标签: 无 2008/10/30发布 1年前更新作者: wisdom_love, 点击1088次, 评论(0), 收藏者(0), , 打分:
Python语言: 从NCBI下载基因序列
01 #!/usr/bin/env python
02 # -*- coding:utf-8 -*-
03 '''
04 读取文件(每行一个ID)中的GeneID,下载其序列,并保存到文件中
05 '''
06
07 __file__ = 'download_gene.py'
08 __date__ = '2008-10-30'
09 __version__ = '0.1'
10 __author__ = 'Wubin Qu <quwubin@gmail.com> @CZlab @BMI @CHINA'
11 __blog__ = 'http://quwubin.blogspot.com'
12 __license__ = 'GPL v3 License'
13
14 from Bio import Entrez
15
16 def read_id(file_name):
17 '''从文件中读取GeneID'''
18 id_array = []
19 fh = open(file_name, 'r')
20 lines = fh.readlines()
21 for line in lines:
22 id = line.strip()
23 id_array.append(id)
24
25 fh.close()
26
27 id_array = ','.join(id_array)
28 return id_array
29
30 def download_seq (id_array):
31 '''根据GeneID下载相应格式的序列'''
32
33 result_handle = Entrez.efetch(db="nucleotide", rettype="genbank", id=id_array)
34 result = result_handle.read()
35
36 return result
37
38 def write_to_file(file_out_name, content):
39 '''将序列写入文件中 '''
40 fh = open(file_out_name, 'w')
41 fh.write(content)
42 fh.close()
43
44 def main():
45 '''主控制程序'''
46 file_name = 'id_list.txt'
47 file_out_name = 'sequences.txt'
48 id_array = read_id(file_name)
49 result = download_seq(id_array)
50 write_to_file(file_out_name, result)
51
52 if __name__ == '__main__':
53 main()
02 # -*- coding:utf-8 -*-
03 '''
04 读取文件(每行一个ID)中的GeneID,下载其序列,并保存到文件中
05 '''
06
07 __file__ = 'download_gene.py'
08 __date__ = '2008-10-30'
09 __version__ = '0.1'
10 __author__ = 'Wubin Qu <quwubin@gmail.com> @CZlab @BMI @CHINA'
11 __blog__ = 'http://quwubin.blogspot.com'
12 __license__ = 'GPL v3 License'
13
14 from Bio import Entrez
15
16 def read_id(file_name):
17 '''从文件中读取GeneID'''
18 id_array = []
19 fh = open(file_name, 'r')
20 lines = fh.readlines()
21 for line in lines:
22 id = line.strip()
23 id_array.append(id)
24
25 fh.close()
26
27 id_array = ','.join(id_array)
28 return id_array
29
30 def download_seq (id_array):
31 '''根据GeneID下载相应格式的序列'''
32
33 result_handle = Entrez.efetch(db="nucleotide", rettype="genbank", id=id_array)
34 result = result_handle.read()
35
36 return result
37
38 def write_to_file(file_out_name, content):
39 '''将序列写入文件中 '''
40 fh = open(file_out_name, 'w')
41 fh.write(content)
42 fh.close()
43
44 def main():
45 '''主控制程序'''
46 file_name = 'id_list.txt'
47 file_out_name = 'sequences.txt'
48 id_array = read_id(file_name)
49 result = download_seq(id_array)
50 write_to_file(file_out_name, result)
51
52 if __name__ == '__main__':
53 main()
所有评论,共0条:( 我也来说两句)
代码
