コード例 #1
0
ファイル: gene.py プロジェクト: AndersenLab/CeNDR
def gene(gene_name):
    title = gene_name
    tbl_color = {"LOW": 'success', "MODERATE": 'warning', "HIGH": 'danger'}
    bcs = OrderedDict([("Gene", None), (title, None)])

    result = list(wb_gene.filter((wb_gene.Name == gene_name) |
                                  (wb_gene.sequence_name == gene_name) |
                                  (wb_gene.locus == gene_name)).dicts().execute())

    if len(result) != 1:
        return render_template('404.html'), 404

    gene_record = result[0]

    # Retrieve variants
    variants = WI.select().filter(
               WI.CHROM == gene_record["CHROM"],
               WI.gene_id == gene_record["Name"]).dicts().execute()

    # Retrieve mappings
    mapping_set = mapping.select(mapping, trait, report) \
                       .join(trait) \
                       .join(report) \
                       .where((gene_record["CHROM"] == mapping.chrom) &
                        (report.release == 0) &
                        (gene_record["start"] >= mapping.interval_start) & 
                        (gene_record["end"] <= mapping.interval_end)) \
                       .dicts() \
                       .execute()



    return render_template('gene.html', **locals())
コード例 #2
0
ファイル: about_us.py プロジェクト: AndersenLab/CeNDR
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())
コード例 #3
0
ファイル: genetic_mapping.py プロジェクト: AndersenLab/CeNDR
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())
コード例 #4
0
ファイル: genetic_mapping.py プロジェクト: AndersenLab/CeNDR
def public_mapping():
    query = request.args.get("query")
    if query is not None:
        bcs = OrderedDict([("Public Mappings", url_for("public_mapping")), ("Search", None)])
        title = "Search: " + query
        subtitle = "results"
        q = "%" + query + "%"
        results = (
            trait.select(report, trait, mapping)
            .filter(trait.status == "complete", report.release == 0)
            .join(mapping)
            .join(report)
            .dicts()
            .filter(
                (trait.trait_slug % q) | (trait.trait_name % q) | (report.report_name % q) | (report.report_slug % q)
            )
            .order_by(mapping.log10p.desc())
        )
        search_results = list(results.dicts().execute())
        search = True
        return render_template("public_mapping.html", **locals())
    title = "Perform Mapping"
    results = (
        trait.select(
            report.release,
            report.report_name,
            report.report_slug,
            trait.trait_name,
            trait.trait_slug,
            trait.status,
            trait.submission_complete,
            trait.submission_date,
            mapping,
        )
        .filter(trait.status == "complete", report.release == 0)
        .join(mapping, JOIN.LEFT_OUTER)
        .switch(trait)
        .join(report)
        .distinct()
        .dicts()
        .order_by(trait.submission_complete.desc())
        .execute()
    )

    date_set = dict(
        Counter([time.mktime((x["submission_date"] + relativedelta(hours=+6)).timetuple()) for x in results])
    )
    wdata = Counter([(x["submission_date"] + relativedelta(hours=+6)).date().isoformat() for x in results])
    waffle_date_set = [{"date": x, "count": y} for x, y in wdata.items()]

    # added in here waffle_date_set should be filtered by month instead of time stamp. Then could be used for the waffle plot
    # submission date is a datetime object
    # waffle_date_set=[]
    # sum=0
    # current_month=results[0]["submission_date"].month
    # for x in results:
    #    if x["submission_date"].month==current_month:
    #        sum++
    #    else:
    #        waffle_date_set.append(("month": current_month, "total": sum)) #appending a tuple
    #        sum=1
    #        current_month=x["submission_date"].month
    recent_results = list(results)[0:20]
    bcs = OrderedDict([("Public", None)])
    title = "Public Mappings"
    pub_mappings = list(
        mapping.select(mapping, report, trait).join(trait).join(report).filter(report.release == 0).dicts().execute()
    )
    return render_template("public_mapping.html", **locals())