def process_seq2sites(handler): """Process data submitted in seq2sites form""" # get posted parameters content = handler.request.get('content') wNN = handler.request.get('wNN') == 'yes' # submission validation and error reporting problems = [] valid = True # get the submitted data content = content.encode('utf8') # make sure something was submitted if len(content) == 0: valid = False handler.redirect("/seq2sites/") # determine format format = None if content.startswith('>'): format = 'fasta' else: format = 'single_seq' # pull names and sequence out of submitted content names = [] seqs = [] if format == 'fasta': try: fnames = [] fseqs = [] for entry in fasta(content, 's'): fnames.append(entry['name']) fseqs.append(RE_NON_IUPAC.sub('', entry['sequence'].upper())) names = fnames seqs = fseqs except: valid = False problems.append('There was an error in the FASTA format') else: names = [''] seqs = [RE_NON_IUPAC.sub('', content.upper())] # enforce limits for multisequence submissions if format == 'fasta': max_length = 0 for seq in seqs: if len(seq) > max_length: max_length = len(seq) if max_length <= LONG_SEQ_CUTOFF: if len(seqs) > MAX_SEQS_SHORT: valid = False problems.append('too many sequences submitted') elif len(seqs) > MAX_SEQS_LONG: valid = False problems.append('too many sequences submitted') if not valid: return (False, {'problems': problems}) result_lines = [] sites_by_line = [] for seq in seqs: try: sites = seq2sites(seq) sites_by_line.append(sites) result_lines.append(sites2str(sites)) except Exception, e: result_lines.append('There was an error: %s' % e)
for seq in seqs: try: sites = seq2sites(seq) sites_by_line.append(sites) result_lines.append(sites2str(sites)) except Exception, e: result_lines.append('There was an error: %s' % e) if wNN: names = ['']*len(sites_by_line) result_lines = [] for sites in sites_by_line: curr_hvs1 = list(x for x in sites if int(x.position) in range(16023, 16570) and not x.is_deletion()) result_lines.append(sites2str(curr_hvs1)) # un-comment the following when it is possible to POST # a multipart/form-data form from google app engine #form_fields = {'samples': '\n'.join(hvs1_lines)} #form_data = urllib.urlencode(form_fields) #url = "http://nnhgtool.nationalgeographic.com/cgi-bin/classify/classify.ksh" #result = urlfetch.fetch(url=url, # payload=form_data, # method=urlfetch.POST, # headers={'Content-Type': 'multipart/form-data'}) #logging.info('urlfetch content: %s' % result.content) results = list(Result(x,y) for x,y in zip(names,result_lines)) template_values = {'results': results} if wNN: template_values['show_note'] = 'wNN'