def home(request): # return variables context = {} errors = [] # form submission items input_type = request.GET.get('input', '') inputid = request.GET.get('inputid', '') dnaseq = request.GET.get('dnaseq', '') snplocation = request.GET.get('snplocation', '') snpsubstitution = request.GET.get('snpsubstitution', '') # search error checking if request.GET: if not input_type: errors.append('Please select an input type') elif input_type == 'dna': dna_string = "" for line in dnaseq: dna_string += line.rstrip() # remove new line character from multiline DNA seq input dnaseq = dna_string valid_dna = re.match('^[ATCGatcg]*$', dnaseq, re.M) if not dnaseq: errors.append('Please enter a DNA sequence') elif not valid_dna: errors.append('Please enter a valid DNA sequence') elif len(dnaseq) > 10000: errors.append('Maximum DNA sequence input of 10,000 nucleotides') else: blast_ens_id, blast_snp_coordinate, blast_sub, blast_ancestral_snp, blast_snp_type, blast_snp_splice_site, blast_sift_prediction, blast_sift_score, blast_polyphen_prediction, blast_polyphen_score, blast_subjct_base, blast_query_base, blast_seq_before_snp, blast_seq_after_snp = seq_search(dnaseq) context = dna_search(request, blast_ens_id, blast_snp_coordinate, blast_sub, blast_ancestral_snp, blast_snp_type, blast_snp_splice_site, blast_sift_prediction, blast_sift_score, blast_polyphen_prediction, blast_polyphen_score, blast_subjct_base, blast_query_base, blast_seq_before_snp, blast_seq_after_snp) connection.close() return render(request, 'snippy/dna_results.html', context) elif not inputid and not dnaseq and not snplocation and not snpsubstitution: errors.append('Please enter a search term') elif input_type == 'rsid': if not inputid: errors.append('Please enter an rsID') elif not Variation.objects.filter(name=inputid).exists(): errors.append('Please enter a valid rsID') # rsID search elif inputid: context = rs_search(request) connection.close() return render(request, 'snippy/rs_results.html', context) elif input_type == 'ensemblid': if not inputid: errors.append('Please enter an Ensembl gene ID') elif not Gene.objects.filter(stable_id=inputid).exists(): errors.append('Please enter a valid Ensembl gene ID') # ensembl ID search elif inputid: if not snplocation: errors.append('Please enter a SNP location') elif snplocation.isdigit() is False: if ':' and '.' not in snplocation: errors.append('Please enter a SNP location in the format 24193 or 13:g.32339667') elif SeqRegion.objects.filter(name=snplocation.split(':')[0]).exists() and snplocation.split('.')[1].isdigit(): context = ensembl_search(request) connection.close() return render(request, 'snippy/ensembl_results.html', context) elif snplocation.isdigit() == True: context = ensembl_search(request) connection.close() return render(request, 'snippy/ensembl_results.html', context) # return errors else: connection.close() return render(request, 'snippy/home.html', {'errors': errors}) # return home as standard connection.close() return render(request, 'snippy/home.html', {'errors': errors})
def test_seq_search(): alist = range(10) random.shuffle(alist) assert search.seq_search(alist, 5) assert not search.seq_search(alist, 11)