def generate(): r = report.get(report_slug = report_slug) t = trait.get(report = r, trait_slug = trait_slug) intervals = list(report.select(mapping) \ .join(mapping) \ .where( (report.report_slug == report_slug) & (mapping.trait == t) ) \ .dicts() .execute()) yield "\t".join(["report", "trait", "CHROM_POS", "REF", "ALT", "gene_id", "locus", "feature_id", "transcript_biotype", "annotation", "putative_impact", "hgvs_p", "correlation"]) + "\n" for i in intervals: for cor in get_correlated_genes(r, t, i["chrom"], i["interval_start"], i["interval_end"]): for variant in cor["variant_set"]: line = map(str, [r.report_slug, t.trait_slug, variant["CHROM_POS"], variant["REF"], variant["ALT"], variant["gene_id"], cor["gene_name"], variant["feature_id"], cor["transcript_biotype"], variant["annotation"], variant["putative_impact"], variant["hgvs_p"], variant["correlation"]]) yield '\t'.join(line) + "\n"
def statistics(): title = "Site Statistics" bcs = OrderedDict([("About", url_for("about")), ("Statistics", None)]) # Number of reports n_reports = report.select().count() n_traits = trait.select().count() n_significant_mappings = mapping.select().count() n_distinct_strains = strain.select(strain.strain).distinct().count() n_distinct_isotypes = strain.select(strain.isotype).filter(strain.isotype != None).distinct().count() # Collection dates collection_dates = list(strain.select().filter( strain.isotype != None, strain.isolation_date != None).order_by(strain.isolation_date).execute()) return render_template('statistics.html', **locals())
def status_page(): # queue bcs = OrderedDict([("Status", None)]) title = "Status" queue = get_queue() ql = [json.loads(x["body"]) for x in queue.peek(max=100)["messages"]] qsize = queue.size() from googleapiclient import discovery from oauth2client.client import GoogleCredentials credentials = GoogleCredentials.get_application_default() compute = discovery.build("compute", "v1", credentials=credentials) # Get instance list instances = ( compute.instances().list(project="andersen-lab", zone="us-central1-a", filter="status eq RUNNING").execute() ) if "items" in instances: instances = [x["name"] for x in instances["items"]] else: instances = [] workers = [] for w in instances: query = ds.query(kind="Worker") query.add_filter("full_name", "=", w + ".c.andersen-lab.internal") worker_list = list(query.fetch()) if len(worker_list) > 0: workers.append(worker_list[0]) recently_complete = list( report.select(report, trait) .filter(trait.submission_complete != None) .join(trait) .order_by(trait.submission_complete.desc()) .limit(10) .dicts() .execute() ) return render_template("status.html", **locals())
def trait_view(report_slug, trait_slug="", rerun=None): report_data = list( report.select(report, trait, mapping.trait_id) .join(trait) .where( ((report.report_slug == report_slug) & (report.release == 0)) | ((report.report_hash == report_slug) & (report.release > 0)) ) .join(mapping, JOIN.LEFT_OUTER) .distinct() .dicts() .execute() ) if not report_data: return render_template("404.html"), 404 if report_data[0]["release"] == 0: report_url_slug = report_data[0]["report_slug"] else: report_url_slug = report_data[0]["report_hash"] if not trait_slug: return redirect(url_for("trait_view", report_slug=report_url_slug, trait_slug=report_data[0]["trait_slug"])) else: try: trait_data = [x for x in report_data if x["trait_slug"] == trait_slug][0] except: # Redirect user to first trait if it can't be found. return redirect(url_for("trait_view", report_slug=report_url_slug, trait_slug=report_data[0]["trait_slug"])) page_title = trait_data["report_name"] + " > " + trait_data["trait_name"] title = trait_data["report_name"] subtitle = trait_data["trait_name"] # Define report and trait slug report_slug = trait_data["report_slug"] # don't remove trait_slug = trait_data["trait_slug"] # don't remove r = report.get(report_slug=report_slug) t = trait.get(report=r, trait_slug=trait_slug) # phenotype data phenotype_data = list( trait_value.select(strain.strain, trait_value.value) .join(trait) .join(report) .switch(trait_value) .join(strain) .where(report.report_slug == r.report_slug) .where(trait.trait_slug == t.trait_slug) .dicts() .execute() ) if rerun == "rerun": t.status = "queue" t.save() launch_mapping(verify_request=False) # Return user to current trait return redirect(url_for("trait_view", report_slug=report_url_slug, trait_slug=trait_slug)) report_trait = "%s/%s" % (report_slug, trait_slug) base_url = "https://storage.googleapis.com/cendr/" + report_trait # Fetch significant mappings mapping_results = list( mapping.select(mapping, report, trait) .join(trait) .join(report) .filter((report.report_slug == report_slug), (trait.trait_slug == trait_slug)) .dicts() .execute() ) ####################### # Variant Correlation # ####################### var_corr = [] for m in mapping_results: var_corr.append(correlation.get_correlated_genes(r, t, m["chrom"], m["interval_start"], m["interval_end"])) tbl_color = {"LOW": "success", "MODERATE": "warning", "HIGH": "danger"} ####################### # Fetch geo locations # ####################### geo_gt = {} for m in mapping_results: try: result = GT.fetch_geo_gt(m["chrom"], m["pos"]) geo_gt[m["chrom"] + ":" + str(m["pos"])] = result except: pass geo_gt = json.dumps(geo_gt) status = trait_data["status"] # List available datasets report_files = list(storage.Client().get_bucket("cendr").list_blobs(prefix=report_trait + "/tables")) report_files = [os.path.split(x.name)[1] for x in report_files] # Fetch biotypes descriptions from cendr import biotypes return render_template("report.html", **locals())