def impute(request): '''Impute one or more SNPs. dbsnp will be one or more dbSNP identifiers (only rsIDs), separated by commas. ''' dbsnps = helpers.check_dbsnp_array(request.REQUEST.get('dbsnps', None)) user_dbsnps = helpers.check_dbsnp_array( request.REQUEST.get('user_dbsnps', None)) population = helpers.check_population( request.REQUEST.get('population', None)) if None in (dbsnps, population, user_dbsnps): return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() phases = {} for index, dbsnp in enumerate(dbsnps): query_snp_in_hapmap = helpers.get_individuals(cursor, dbsnp, population) anchor_snp_in_hapmap = helpers.get_individuals(cursor, user_dbsnps[index], population) phase = helpers.get_best_phases(query_snp_in_hapmap, anchor_snp_in_hapmap) phase['user_snp'] = user_dbsnps[index] phases[dbsnp] = phase return http.HttpResponse(simplejson.dumps(phases), mimetype="application/json")
def get_damaging_info(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) output = {} if dbsnps is None: return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() for dbsnp in dbsnps: query = ''' SELECT chrom FROM %s WHERE rsid=%s ''' % (dbsnp_table, dbsnp) cursor.execute(query) chrom = cursor.fetchone() if chrom is not None and chrom['chrom'] is not None: query = ''' SELECT * FROM public_coding.dbNSFP1_3_chr%s WHERE unisnp_ids LIKE "%%rs%s%%" ''' % (chrom['chrom'], dbsnp) cursor.execute(query) data = cursor.fetchone() if data is not None: output[dbsnp] = data return http.HttpResponse(simplejson.dumps(output), mimetype="application/json")
def get_snps_on_map(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('dbsnps', None)) cursor = connections['default'].dict_cursor() output = {} for dbsnp in dbsnps: query = 'select alfred_uid from interpretome_ancestry.alfred_variant_info where rs_number ="rs%s"' % dbsnp output[dbsnp] = cursor.execute(query) return http.HttpResponse(simplejson.dumps(output), mimetype = "application/json")
def get_snps_on_map(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('dbsnps', None)) cursor = connections['default'].dict_cursor() output = {} for dbsnp in dbsnps: query = 'select alfred_uid from interpretome_ancestry.alfred_variant_info where rs_number ="rs%s"' % dbsnp output[dbsnp] = cursor.execute(query) return http.HttpResponse(simplejson.dumps(output), mimetype="application/json")
def linked(request): dbsnps = helpers.check_dbsnp_array(request.REQUEST.get('dbsnps', None)) population = helpers.check_population( request.REQUEST.get('population', None)) ld_cutoff = helpers.check_float(request.REQUEST.get('ld_cutoff', None)) if None in (dbsnps, population, ld_cutoff): return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() results = {} for dbsnp in dbsnps: query = ''' SELECT * FROM var_hapmap.hapmap_phased_%s WHERE dbSNP = %s; ''' % (population, dbsnp) cursor.execute(query) hapmap_result = cursor.fetchone() query = ''' SELECT dbSNP1, dbSNP2, R_square FROM var_ld_data.ld_%s WHERE dbSNP1 = %d OR dbSNP2 = %d AND R_square >= %s ORDER BY R_square DESC; ''' % (population, dbsnp, dbsnp, ld_cutoff) cursor.execute(query) raw_result = cursor.fetchall() if hapmap_result is None or raw_result is None: results[dbsnp] = [] continue result = [] for entry in raw_result: if entry['dbSNP1'] == dbsnp: other_dbsnp = entry['dbSNP2'] else: other_dbsnp = entry['dbSNP1'] query = ''' SELECT * FROM var_hapmap.hapmap_phased_%s WHERE dbSNP = %s; ''' % (population, other_dbsnp) cursor.execute(query) if cursor.fetchone() is not None: result.append(entry) results[dbsnp] = result return http.HttpResponse(simplejson.dumps(results), mimetype='application/json')
def linked(request): dbsnps = helpers.check_dbsnp_array(request.REQUEST.get('dbsnps', None)) population = helpers.check_population(request.REQUEST.get('population', None)) ld_cutoff = helpers.check_float(request.REQUEST.get('ld_cutoff', None)) if None in (dbsnps, population, ld_cutoff): return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() results = {} for dbsnp in dbsnps: query = ''' SELECT * FROM var_hapmap.hapmap_phased_%s WHERE dbSNP = %s; ''' % (population, dbsnp) cursor.execute(query) hapmap_result = cursor.fetchone() query = ''' SELECT dbSNP1, dbSNP2, R_square FROM var_ld_data.ld_%s WHERE dbSNP1 = %d OR dbSNP2 = %d AND R_square >= %s ORDER BY R_square DESC; ''' % (population, dbsnp, dbsnp, ld_cutoff) cursor.execute(query) raw_result = cursor.fetchall() if hapmap_result is None or raw_result is None: results[dbsnp] = [] continue result = [] for entry in raw_result: if entry['dbSNP1'] == dbsnp: other_dbsnp = entry['dbSNP2'] else: other_dbsnp = entry['dbSNP1'] query = ''' SELECT * FROM var_hapmap.hapmap_phased_%s WHERE dbSNP = %s; ''' % (population, other_dbsnp) cursor.execute(query) if cursor.fetchone() is not None: result.append(entry) results[dbsnp] = result return http.HttpResponse(simplejson.dumps(results), mimetype = 'application/json')
def impute(request): '''Impute one or more SNPs. dbsnp will be one or more dbSNP identifiers (only rsIDs), separated by commas. ''' dbsnps = helpers.check_dbsnp_array(request.REQUEST.get('dbsnps', None)) user_dbsnps = helpers.check_dbsnp_array(request.REQUEST.get('user_dbsnps', None)) population = helpers.check_population(request.REQUEST.get('population', None)) if None in (dbsnps, population, user_dbsnps): return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() phases = {} for index, dbsnp in enumerate(dbsnps): query_snp_in_hapmap = helpers.get_individuals(cursor, dbsnp, population) anchor_snp_in_hapmap = helpers.get_individuals(cursor, user_dbsnps[index], population) phase = helpers.get_best_phases(query_snp_in_hapmap, anchor_snp_in_hapmap) phase['user_snp'] = user_dbsnps[index] phases[dbsnp] = phase return http.HttpResponse(simplejson.dumps(phases), mimetype = "application/json")
def get_chrom_pos(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) if dbsnps is None: return http.HttpResponseBadRequest() info = {} for dbsnp in dbsnps: query = ''' SELECT chrom, chromstart, chromend FROM %s WHERE rsid=%s ''' % (dbsnp_table, dbsnp) cursor = connections['default'].dict_cursor() cursor.execute(query) data = cursor.fetchone() info[dbsnp] = data return http.HttpResponse(simplejson.dumps(info), mimetype = "application/json")
def get_allele_frequencies(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) population = helpers.check_population(request.GET.get('population', None)) if None in (population, dbsnps): return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() frequencies = {} for dbsnp in dbsnps: query = ''' SELECT refallele, refallele_freq, otherallele, otherallele_freq FROM var_hapmap.allele_freqs_%s WHERE rsid=%s ''' % (population, dbsnp) cursor.execute(query) data = cursor.fetchone() frequencies[dbsnp] = data return http.HttpResponse(simplejson.dumps(frequencies), mimetype = "application/json")
def get_chrom_pos(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) if dbsnps is None: return http.HttpResponseBadRequest() info = {} for dbsnp in dbsnps: query = ''' SELECT chrom, chromstart, chromend FROM %s WHERE rsid=%s ''' % (dbsnp_table, dbsnp) cursor = connections['default'].dict_cursor() cursor.execute(query) data = cursor.fetchone() info[dbsnp] = data return http.HttpResponse(simplejson.dumps(info), mimetype="application/json")
def get_reference_alleles(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) references = {} if dbsnps is None: return http.HttpResponseBadRequest() for dbsnp in dbsnps: query = ''' SELECT strand, refncbi FROM %s WHERE rsid=%s ''' % (dbsnp_table, dbsnp) cursor = connections['default'].dict_cursor() cursor.execute(query) data = cursor.fetchone() if data is not None: references[dbsnp] = data['refncbi'] return http.HttpResponse(simplejson.dumps(references), mimetype = "application/json")
def get_allele_frequencies(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) population = helpers.check_population(request.GET.get('population', None)) if None in (population, dbsnps): return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() frequencies = {} for dbsnp in dbsnps: query = ''' SELECT refallele, refallele_freq, otherallele, otherallele_freq FROM var_hapmap.allele_freqs_%s WHERE rsid=%s ''' % (population, dbsnp) cursor.execute(query) data = cursor.fetchone() frequencies[dbsnp] = data return http.HttpResponse(simplejson.dumps(frequencies), mimetype="application/json")
def get_reference_alleles(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) references = {} if dbsnps is None: return http.HttpResponseBadRequest() for dbsnp in dbsnps: query = ''' SELECT strand, refncbi FROM %s WHERE rsid=%s ''' % (dbsnp_table, dbsnp) cursor = connections['default'].dict_cursor() cursor.execute(query) data = cursor.fetchone() if data is not None: references[dbsnp] = data['refncbi'] return http.HttpResponse(simplejson.dumps(references), mimetype="application/json")
def get_damaging_info(request): dbsnps = helpers.check_dbsnp_array(request.GET.get('snps', None)) output = {} if dbsnps is None: return http.HttpResponseBadRequest() cursor = connections['default'].dict_cursor() for dbsnp in dbsnps: query = ''' SELECT chrom FROM %s WHERE rsid=%s ''' % (dbsnp_table, dbsnp) cursor.execute(query) chrom = cursor.fetchone() if chrom is not None and chrom['chrom'] is not None: query = ''' SELECT * FROM public_coding.dbNSFP1_3_chr%s WHERE unisnp_ids LIKE "%%rs%s%%" ''' % (chrom['chrom'], dbsnp) cursor.execute(query) data = cursor.fetchone() if data is not None: output[dbsnp] = data return http.HttpResponse(simplejson.dumps(output), mimetype = "application/json")