from Portal.hvp.models.search.Variant import Variant from Portal.hvp.models.search.HG_Build import HG_Build from Portal.search.hgvs_parser.Validator import Validator from Portal.search.hgvs_parser.Parser import Parser # mutalyzer soap url URL = 'https://mutalyzer.nl/services/?wsdl' # get genomic build number hg_build = HG_Build.objects.all()[0].BuildNumber # get all variants variant_list = Variant.objects.all() # extract all the variants cDNA, refseq, refseqver and output to txt file v = Validator() file = open('input.txt', 'w') for variant in variant_list: if v.validate(variant.cDNA): file.write(variant.Gene.RefSeqName + '.' + variant.Gene.RefSeqVer + ':' + variant.cDNA + '\n') file.close() # encode file to base64 binary encoded = open('input.txt', 'rb').read().encode("base64") print 'Connecting to web services...' c = Client(URL, cache=None) o = c.service
def variant_patient_view(request, geneID, variantID, instanceID, path_filter, path_filter_ratio): template = 'variant_patient' if not request.user.is_authenticated(): return render_to_response('home/timeout.html') if request.user.get_profile().AccessStatus.ID != 2: return render_to_response('home/permission.html', {'user': request.user}) gene = get_object_or_404(Gene, pk = geneID) instance = get_object_or_404(VariantInstance, pk = instanceID) searched_variant = '' searched_variant_safe = '' variant_query_string = '' params = [instance.Patient_id] page_error = False search_tooshort = False invalid_variant = False # apply path filters dict_path = Dict_path_filter(path_filter) # apply path filter path_id = Path_ID(path_filter) # apply path filters ratio (the total number of instance per path) dict_path_ratio = Dict_path_filter(path_filter_ratio) # apply path filter ratio path_ratio_id = Path_ID(path_filter_ratio) # query options to filter by community consensus path path_query_string = '' if path_id != '': if path_id == 'NULL': path_query_string = ' and v.Pathogenicity_id is NULL ' else: path_query_string = ' and v.Pathogenicity_id = %s ' params.append(path_id) # search results if 'search' in request.POST: search_type = 'variantType' #request.POST['search_type'] if request.POST['searched_variant'] != '': searched_variant = request.POST['searched_variant'] seached_variant_safe = searched_variant # url friendly searched_variant = urllib.unquote(searched_variant) # raw form validator = Validator() if validator.validate(searched_variant) == False: page_error = True invalid_variant = True # if there are no errors then proceed with the query if not page_error: parser = Parser() variant = parser.parse('', searched_variant) # query options filter by community consensus path path_query_string = '' variant_query_string = VariantQueryString(variant, params) # query options filter by path count count_query_string = '' order_query_string = ' order by Instances desc ' if path_ratio_id != '': count_query_string = """, (select count(hvp_variantinstance.Pathogenicity_id) as path from hvp_variantinstance where hvp_variantinstance.Variant_ID = v.ID and hvp_variantinstance.pathogenicity_id = """ + str(path_ratio_id) + ') as Path_Count ' order_query_string = ' order by Path_Count desc ' query = """select v.*, hvp_variantinstance.Patient_id, (select Count(hvp_variantinstance.Variant_id) as i from hvp_variantinstance left join hvp_variant on hvp_variantinstance.Variant_ID = hvp_variant.ID where hvp_variant.ID = v.ID) as instances """ + count_query_string + """ from hvp_variant v left join hvp_variantinstance on v.ID = hvp_variantinstance.Variant_id where hvp_variantinstance.Patient_id = %s """ + path_query_string + variant_query_string + ' group by ID ' + order_query_string qs = Variant.objects.raw(query, params) variant_list = list(qs) # sum of total results used to display on screen results = len(variant_list) # sets the paginator with the list of objects and number objects per page paginator = Paginator(variant_list, 10) # gets the current page page = request.GET.get('page') try: variants = paginator.page(page) except PageNotAnInteger: variants = paginator.page(1) except EmptyPage: variants = paginator.page(paginator.num_pages) return render_to_response('search/variant.html', { 'user': request.user, 'template': template, 'dict_path': dict_path, 'path_filter': path_filter, 'geneID': geneID, 'variantID': variantID, 'gene': gene, 'variants': variants, 'instance': instance, 'results': results, 'page_error': page_error, 'search_tooshort': search_tooshort, 'invalid_variant': invalid_variant, 'searched_variant': searched_variant, 'searched_variant_safe': searched_variant_safe, 'dict_path_ratio': dict_path_ratio, 'path_filter_ratio': path_filter_ratio, })
def variant_results_view(request, geneID, searched_variant, search_type, path_filter, path_filter_ratio): template = 'variant_result' if not request.user.is_authenticated(): return render_to_response('home/timeout.html') if request.user.get_profile().AccessStatus.ID != 2: return render_to_response('home/permission.html', {'user': request.user}) # searching/filtering for a specific variant search if 'search' in request.POST: if request.POST['searched_variant'] != '': #search_type = request.POST['search_type'] search_type = "variantType" searched_variant = request.POST['searched_variant'] return HttpResponseRedirect('/search/gene/' + geneID + '/searchvariant/' + urllib.quote(searched_variant) + '/' + search_type + '/results/' + path_filter + '/' + path_filter_ratio + '/') else: # go back to the default variant page that lists all variants return HttpResponseRedirect('/search/gene/' + geneID + '/searchvariant/path_all/path_all/') gene = get_object_or_404(Gene, pk = geneID) geneName = gene.GeneName page_error = False search_tooShort = False invalid_variant = False # apply path filters dict_path = Dict_path_filter(path_filter) # apply path filter path_id = Path_ID(path_filter) # apply path filters ratio (the total number of instance per path) dict_path_ratio = Dict_path_filter(path_filter_ratio) # apply path filter ratio path_ratio_id = Path_ID(path_filter_ratio) # keep url safe version for path filter links searched_variant_safe = searched_variant # converting url string back to a proper variant nomenclature searched_variant = urllib.unquote(searched_variant) # search_type = searchType paginate_results = 5 # check if the search query string is less than 2 characters, if so return error message to user if len(searched_variant) < 2: page_error = True search_tooShort = True # check if the entered variant is valid validator = Validator() if validator.validate(searched_variant) == False: page_error = True invalid_variant = True # if there are no errors then proceed with the query variant_list = [] variants = None results = None if not page_error: # Break down the searched_variant using variant_parser to use in search with solr # NB: I noticed that any values that have been broken down in the parser that # has a '+' or '-' will be converted to a long int. parser = Parser() variant = parser.parse('', searched_variant) # query options filter by community consensus path path_query_string = '' params = [geneName] variant_query_string = VariantQueryString(variant, params) if path_id != '': if path_id == 'NULL': path_query_string = ' and v.Pathogenicity_id is NULL ' else: path_query_string = ' and v.Pathogenicity_id = %s ' params.append(path_id) # query options filter by path count count_query_string = '' order_query_string = ' order by Instances desc ' if path_ratio_id != '': count_query_string = """, (select count(hvp_variantinstance.Pathogenicity_id) as path from hvp_variantinstance where hvp_variantinstance.Variant_ID = v.ID and hvp_variantinstance.pathogenicity_id = """ + str(path_ratio_id) + ') as Path_Count ' order_query_string = ' order by Path_Count desc ' query = 'select v.*, Count(hvp_variantinstance.Variant_id) as Instances' + count_query_string + """ from hvp_variant v left join hvp_variantinstance on v.ID = hvp_variantinstance.Variant_id left join hvp_gene on v.Gene_id = hvp_gene.ID where hvp_gene.GeneName = %s """ + path_query_string + variant_query_string + ' group by ID ' + order_query_string qs = Variant.objects.raw(query, params) variant_list = list(qs) # sum of total results used to display on screen results = variant_list.count #len(variant_list) # sets the paginator with the list of objects and number of objects per page paginator = Paginator(variant_list, 10) # gets the current page page = request.GET.get('page') try: variants = paginator.page(page) except PageNotAnInteger: variants = paginator.page(1) except EmptyPage: variants = paginator.page(paginator.num_pages) return render_to_response('search/variant.html', { 'user': request.user, 'template': template, 'searched_variant': searched_variant, 'searched_variant_safe': searched_variant_safe, 'page_error': page_error, 'invalid_variant': invalid_variant, 'paginate_results': paginate_results, 'geneName' : geneName, 'geneID' : geneID, 'search_type': search_type, 'variants': variants, 'results': results, 'search_tooShort': search_tooShort, 'path_filter': path_filter, 'dict_path': dict_path, 'dict_path_ratio': dict_path_ratio, 'path_filter_ratio': path_filter_ratio, }, context_instance=RequestContext(request))