def search(self,start,end): ncbi_dict = GenBank.NCBIDictionary() 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 gi_list = GenBank.search_for(self.accs[k],database='protein') for i in range(0,len(gi_list)): try: gb_record = ncbi_dict[gi_list[i]] sys.stdout.write('>'+self.accs[k]+'\n') sys.stdout.write( gb_record) except: sys.stderr.write( self.accs[k] + " fetching error \n")
body = '\n'.join(textwrap.wrap(rec.seq.data, width=80)) return head, body if __name__ == '__main__': mode = sys.argv[1] text = sys.argv[2] output_file = sys.argv[3] print 'Searching for %s <br>' % text # check if inputs are all numbers try: gi_list = text.split() tmp = map(int, gi_list) except ValueError: gi_list = GenBank.search_for(text, max_ids=10) fp = open(output_file, 'wt') record_parser = GenBank.FeatureParser() ncbi_dict = GenBank.NCBIDictionary(mode, 'genbank', parser = record_parser) for gid in gi_list: res = ncbi_dict[gid] head, body = make_fasta(res) fp.write(head+body+'\n') print head fp.close()
org = rec.annotations.get('organism', '') date = rec.annotations.get('date', '') head = '>gi:%s, id:%s, org:%s, date:%s\n' % (gi, rec.id, org, date) body = '\n'.join(textwrap.wrap(rec.seq.data, width=80)) return head, body if __name__ == '__main__': mode = sys.argv[1] text = sys.argv[2] output_file = sys.argv[3] print('Searching for %s <br>' % text) # check if inputs are all numbers try: gi_list = text.split() [int(_) for _ in gi_list] except ValueError: gi_list = GenBank.search_for(text, max_ids=10) fp = open(output_file, 'wt') record_parser = GenBank.FeatureParser() ncbi_dict = GenBank.NCBIDictionary(mode, 'genbank', parser=record_parser) for gid in gi_list: res = ncbi_dict[gid] head, body = make_fasta(res) fp.write(head + body + '\n') print(head) fp.close()