def search(self,start,end): search_command = 'Search' search_database = 'Protein' return_format = 'GenPept' Protein_gi_line = re.compile(r'Protein\<\/a\>') CDS_gi_line = re.compile(r'CDS\<\/a\>') pattern_gi = re.compile(r'val=(\d*)') j=1 if start<1: start =1 if end >len(self.accs) or end == 0: end = len(self.accs) for k in range(start-1,end): sys.stderr.write("No " + repr(j) + ": " + self.accs[k] +'\n') j=j+1 try : result_handle = NCBI.query(search_command, search_database, term=self.accs[k], doptcmdl = return_format) tmp=result_handle.readline() sys.stdout.write(tmp) while tmp: sys.stdout.write(tmp) if Protein_gi_line.search(tmp): protein_gi=pattern_gi.search(tmp).group(1) sys.stderr.write( "fetching "+protein_gi + '\n') protein_handle=NCBI.query('Text',search_database, uid=protein_gi,dopt=return_format) proteinfile.write(protein_handle.read()) if CDS_gi_line.search(tmp): CDS_gi=pattern_gi.search(tmp).group(1) #sys.stderr.write( "fetching " + CDS_gi + '\n') #CDS_handle=NCBI.query('Text','nucleotide', uid=CDS_gi,dopt='GenBank') #CDSfile.write(CDS_handle.read()) tmp = result_handle.readline() except: print "Entrez query error"
See http://www.ncbi.nlm.nih.gov/entrez/query/static/linking.html for more help understanding the parameters passed. This also requires a web browser to run -- either netscape or lynx are supported in this example.""" # standard library import os # biopython from Bio.WWW import NCBI search_command = 'Search' search_database = 'Nucleotide' return_format = 'FASTA' search_term = 'Cypripedioideae' my_browser = 'lynx' result_handle = NCBI.query(search_command, search_database, term = search_term, doptcmdl = return_format) result_file_name = os.path.join(os.getcwd(), 'results.html') result_file = open(result_file_name, 'w') result_file.write(result_handle.read()) result_file.close() if my_browser == 'lynx': os.system('lynx -force_html ' + result_file_name) elif my_browser == 'netscape': os.system('netscape file:' + result_file_name)
more help understanding the parameters passed. This also requires a web browser to run -- either netscape or lynx are supported in this example.""" # standard library import os # biopython from Bio.WWW import NCBI search_command = 'Search' search_database = 'Nucleotide' return_format = 'FASTA' search_term = 'Cypripedioideae' my_browser = 'lynx' result_handle = NCBI.query(search_command, search_database, term=search_term, doptcmdl=return_format) result_file_name = os.path.join(os.getcwd(), 'results.html') result_file = open(result_file_name, 'w') result_file.write(result_handle.read()) result_file.close() if my_browser == 'lynx': os.system('lynx -force_html ' + result_file_name) elif my_browser == 'netscape': os.system('netscape file:' + result_file_name)