from flask_restful import Resource from cendr.models import tajimaD from flask import jsonify from cendr import api, cache class tajima_d(Resource): @cache.memoize(50) def get(self, chrom, start, end): data = list(tajimaD.select(tajimaD.BIN_START, tajimaD.TajimaD) .filter((tajimaD.CHROM == chrom) & (tajimaD.BIN_START >= start - 50000) & (tajimaD.BIN_END <= end + 50000), ).tuples().execute()) data = [(int(x[0]) + 50000, float(x[1])) for x in data] response = {"x": [x[0] for x in data], "y": [x[1] for x in data]} return jsonify(response) api.add_resource( tajima_d, '/api/variant/tajima/<string:chrom>/<int:start>/<int:end>')
(mapping_correlation.POS == WI.POS)) \ .where(mapping_correlation.report == r, mapping_correlation.trait == t, mapping_correlation.CHROM == chrom, mapping_correlation.POS >= start, mapping_correlation.POS <= end) \ .order_by(-fn.MAX(fn.ABS(mapping_correlation.correlation))) \ .dicts().execute()) av_set = {} for i in av: if i["gene_id"] not in av_set: av_set[i["gene_id"]] = [] av_set[i["gene_id"]].append(i) for gene in max_corr: if gene["gene_id"] in av_set: gene["variant_set"] = av_set[gene["gene_id"]] else: gene["variant_set"] = [] return max_corr class get_mapping_correlation(Resource): def get(self, report, trait): interval = get_correlated_genes(report, trait) return jsonify(interval) api.add_resource(get_mapping_correlation, '/api/correlation/<string:report>/<string:trait>')
from flask_restful import Resource from cendr.models import wb_gene from cendr import api, cache from collections import OrderedDict from flask import jsonify class get_gene(Resource): def get(self, gene): result = list(wb_gene.filter((wb_gene.Name == gene) | (wb_gene.sequence_name == gene) | (wb_gene.locus == gene)) .dicts() .execute()) ordered = OrderedDict() if len(result) == 1: order = [x.name for x in wb_gene._meta.sorted_fields if x.name != "id"] for k in order: ordered[k] = result[0][k] return jsonify(result) api.add_resource(get_gene, '/api/gene/<string:gene>')
for x in strain._meta.sorted_fields if x.name != "id"] class strain_api(Resource): @cache.memoize(50) def get(self): """ Return information for all strains. """ strain_data = list(strain.select( *PEEWEE_FIELDS_LIST).tuples().execute()) response = [OrderedDict(zip(FIELDS, x)) for x in strain_data] return jsonify(response) api.add_resource(strain_api, '/api/strain') class strain_ind_api(Resource): @cache.memoize(50) def get(self, strain_name): """ Return information for an individual strain. """ strain_data = list(strain.select( *PEEWEE_FIELDS_LIST).filter(strain.strain == strain_name) .tuples() .execute()) response = OrderedDict(zip(FIELDS, strain_data[0])) print response, "RESPONSE" return jsonify(response)
.select(wb_orthologs.gene_symbol, wb_orthologs.ce_gene_name, wb_orthologs.species) .distinct() .dicts().execute()) for x in hgene_results: x.update({"source": "homologene"}) for x in wbgene_results: x.update({"source": "wormbase"}) homologs = hgene_results + wbgene_results # For genes that can't be looked up, fetch coordinates. for x in homologs: if x["ce_gene_name"].find(".") > 0: try: gene = wb_gene.get( wb_gene.sequence_name == x["ce_gene_name"]) x.update( {"CHROM": gene.CHROM, "start": gene.start, "end": gene.end}) except: del x result = hgene_results + wbgene_results return jsonify(result) api.add_resource(search_homologs, '/api/homolog/<string:term>')
.dicts() .execute()) for i in result: i["GT"] = decode_gt(i["GT"]) return result class api_get_gt(Resource): def get(self, chrom, pos): """ Retrieve a single genotype. """ gt = get_gt(chrom, pos) return jsonify(gt) api.add_resource(api_get_gt, '/api/variant/gt/<string:chrom>/<int:pos>') class strain_gt_locations(Resource): def get(self, chrom, pos): """ Retreive genotypes with location information """ result = fetch_geo_gt(chrom, pos) return jsonify(result) api.add_resource(strain_gt_locations, '/api/variant/gtloc/<string:chrom>/<int:pos>')
result = OrderedDict((("chrom", chrom), ("start", start), ("end", end), ("total", len(gene_list)), ("biotype_summary", biotype_summary))) if include_list: result["gene_list"] = gene_list return result class api_gene_list(Resource): def get(self, chrom, start, end): result = get_gene_interval_summary(chrom, start, end, True) return jsonify(result) api.add_resource( api_gene_list, '/api/genelist/<string:chrom>/<int:start>/<int:end>') # Variants @cache.memoize(timeout=500) def get_variant_count(chrom, start, end, filter=True): """ Return the number of variants within an interval """ if filter: var_filter = (WI.FILTER == "") else: var_filter = (1 == 1) return WI.select(WI.variant) \ .filter((WI.CHROM == chrom) & (WI.POS >= start) &