def sprot_search(accs, outf=sys.stdout): all_results = '' i=0 for acc in accs: outf.write('>'+acc+'\n') sys.stderr.write( acc + "\tNo. " + repr(i) +'\n') try: results=ExPASy.get_sprot_raw(acc) outf.write(results.read()) except IOError: sys.stderr.write( "I/O error: No results \n") i=i+1
def __getitem__(self, id): """__getitem__(self, id) -> object Return a SwissProt entry. id is either the id or accession for the entry. Raises a KeyError if there's an error. """ # First, check to see if enough time has passed since my # last query. self.limiter.wait() try: handle = ExPASy.get_sprot_raw(id) except IOError: raise KeyError, id if self.parser is not None: return self.parser.parse(handle) return handle.read()
"""Example of connecting with exPASy and parsing SwissProt records.""" # standard library import string # biopython from Bio.WWW import ExPASy from Bio.SwissProt import SProt from Bio import File # 'O23729', 'O23730', 'O23731', Chalcone synthases from Orchid ids = ['O23729', 'O23730', 'O23731'] all_results = '' for id in ids: results = ExPASy.get_sprot_raw(id) all_results = all_results + results.read() s_parser = SProt.RecordParser() s_iterator = SProt.Iterator(File.StringHandle(all_results), s_parser) while 1: cur_record = s_iterator.next() if cur_record is None: break print "description:", cur_record.description for ref in cur_record.references: print "authors:", ref.authors print "title:", ref.title