[BioPython] More results at NCBI Search

João Rodrigues anaryin at gmail.com
Fri Sep 21 16:33:55 EDT 2007


Sure I can :) Must warn though, that I have 2 weeks of "python-ing" so the
code *could* be clearer! Oh, and some of it is in Portuguese because it's
for personal use..


# NCBI Retriever

import os
import sys

# What should I look for?

query = raw_input('Qual a expressao que deseja procurar?\n..: ')

# Where should I look for?

print 'Em qual das bases de dados deseja procurar?'

databases = {1: 'PubMed', 2: 'Nucleotide', 3:
'Protein',4:'Genome',5:'Structure'}

choice = raw_input('[1] PubMed\n[2] Nucleotide\n[3] Protein\n[4] Genome\n[5]
Structure\n..: ')

if int(choice) not in databases.keys():
    print 'Escolha Inválida'
    sys.exit()

search_database = databases[int(choice)]

# Quit playing around, let s search!

from Bio.WWW import NCBI

search_command = 'Search'

results = NCBI.query(search_command , search_database, term = query,
doptcmdl = 'FASTA')

# Where should I save the results?

import time
actual_date = str(time.localtime()[0])+str(time.localtime()[1])+str(
time.localtime()[2])
results_file_name = os.path.join(os.getcwd(),
str(query)+'_'+str(actual_date)+".txt")

results_file = open(results_file_name, 'w')

results_file.write(results.read())
results_file.close()



More information about the BioPython mailing list