Example #1
0
def transcript_page(transcript_id):
    db = get_db()
    try:
        transcript = lookups.get_transcript(db, transcript_id)

        cache_key = 't-transcript-{}'.format(transcript_id)
        t = cache.get(cache_key)
        print 'Rendering %stranscript: %s' % ('' if t is None else 'cached ', transcript_id)
        if t is None:

            gene = lookups.get_gene(db, transcript['gene_id'])
            gene['transcripts'] = lookups.get_transcripts_in_gene(db, transcript['gene_id'])
            variants_in_transcript = lookups.get_variants_in_transcript(db, transcript_id)

            coverage_stats = lookups.get_coverage_for_transcript(db, transcript['xstart'] - EXON_PADDING, transcript['xstop'] + EXON_PADDING)

            add_transcript_coordinate_to_variants(db, variants_in_transcript, transcript_id)

            t = render_template(
                'transcript.html',
                transcript=transcript,
                transcript_json=json.dumps(transcript),
                variants_in_transcript=variants_in_transcript,
                variants_in_transcript_json=json.dumps(variants_in_transcript),
                coverage_stats=coverage_stats,
                coverage_stats_json=json.dumps(coverage_stats),
                gene=gene,
                gene_json=json.dumps(gene),
                csq_order=csq_order,
            )
            cache.set(cache_key, t)
        return t
    except Exception, e:
        print 'Failed on transcript:', transcript_id, ';Error=', traceback.format_exc()
        abort(404)
Example #2
0
def get_transcript_data(db, transcript_id, transcript, request_type, cache_key):
    try:
        gene = lookups.get_gene(db, transcript['gene_id'])
        gene['transcripts'] = lookups.get_transcripts_in_gene(db, transcript['gene_id'])
        variant_data = lookups.get_variants_in_gene_or_transcript(db, transcript_id=transcript_id)
        variants_in_transcript = variant_data['all_variants']
        coverage_stats_exomes = lookups.get_coverage_for_transcript(db, 'exome_coverage', transcript['xstart'] - EXON_PADDING, transcript['xstop'] + EXON_PADDING)
        # change base_coverage to e.g. genome_base_coverage when the data gets here
        coverage_stats_genomes = lookups.get_coverage_for_transcript(db, 'genome_coverage', transcript['xstart'] - EXON_PADDING, transcript['xstop'] + EXON_PADDING)
        coverage_stats = {
            'exomes': coverage_stats_exomes,
            'genomes': coverage_stats_genomes
        }
        add_transcript_coordinate_to_variants(db, variants_in_transcript, transcript_id)
        if request_type == 'template':
            result = render_template(
                'transcript.html',
                transcript=transcript,
                variants_in_transcript=variants_in_transcript,
                coverage_stats=coverage_stats,
                gene=gene,
            )
        if request_type == 'json':
            result = jsonify(
                transcript=transcript,
                variants_in_transcript=variants_in_transcript,
                coverage_stats=coverage_stats,
                gene=gene,
            )
        cache.set(cache_key, result, timeout=1000*60)
        return result
    except Exception, e:
        print 'Failed on transcript:', transcript_id, ';Error=', traceback.format_exc()
        abort(404)
Example #3
0
def text_page():
    db = get_db()
    query = request.args.get("text")
    datatype, identifier = lookups.get_awesomebar_result(db, query)
    if datatype in ["gene", "transcript"]:
        gene = lookups.get_gene(db, identifier)
        link = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=chr%(chrom)s%%3A%(start)s-%(stop)s" % gene
        output = """Searched for %s. Found %s.
%s; Canonical: %s.
%s""" % (
            query,
            identifier,
            gene["full_gene_name"],
            gene["canonical_transcript"],
            link,
        )
        output += (
            ""
            if "omim_accession" not in gene
            else """
In OMIM: %(omim_description)s
http://omim.org/entry/%(omim_accession)s"""
            % gene
        )
        return output
    elif datatype == "error" or datatype == "not_found":
        return "Gene/transcript %s not found" % query
    else:
        return "Search types other than gene transcript not yet supported"
Example #4
0
def get_gene_page_content(gene_id):
    db = get_db()
    try:
        gene = lookups.get_gene(db, gene_id)
        if gene is None:
            abort(404)
        cache_key = 't-gene-{}'.format(gene_id)
        t = cache.get(cache_key)
        if t is None:
            variants_in_gene = lookups.get_variants_in_gene(db, gene_id)
            transcripts_in_gene = lookups.get_transcripts_in_gene(db, gene_id)

            # Get some canonical transcript and corresponding info
            transcript_id = gene['canonical_transcript']
            transcript = lookups.get_transcript(db, transcript_id)
            variants_in_transcript = lookups.get_variants_in_transcript(db, transcript_id)
            coverage_stats = lookups.get_coverage_for_transcript(db, transcript['xstart'] - EXON_PADDING, transcript['xstop'] + EXON_PADDING)
            add_transcript_coordinate_to_variants(db, variants_in_transcript, transcript_id)

            t = render_template(
                'gene.html',
                gene=gene,
                transcript=transcript,
                variants_in_gene=variants_in_gene,
                variants_in_transcript=variants_in_transcript,
                transcripts_in_gene=transcripts_in_gene,
                coverage_stats=coverage_stats
            )
            cache.set(cache_key, t, timeout=1000*60)
        print 'Rendering gene: %s' % gene_id
        return t
    except Exception, e:
        print 'Failed on gene:', gene_id, ';Error=', e
        abort(404)
Example #5
0
def gene_api(gene_id):
    db = get_db()
    gene = lookups.get_gene(db, gene_id)
    if gene is None:
        abort(404)
    cache_key = 'json-gene-{}'.format(gene_id)
    json = cache.get(cache_key)
    if json is None:
        json = get_gene_data(db, gene_id, gene, 'json', cache_key)
    print 'Sending json for gene: %s' % gene_id
    return json
Example #6
0
def gene_page(gene_id):
    db = get_db()
    try:
        gene = lookups.get_gene(db, gene_id)
        if not gene: return not_found_page('The requested gene {!s} could not be found.'.format(gene_id))
        _log('   ({})'.format(gene.get('gene_name')))
        intervalset = IntervalSet.from_gene(db, gene_id)
        genes = TranscriptSet.from_gene(db, gene_id).genes
        return render_template(
            'gene.html',
            intervalset=intervalset, genes=genes, csq=Consequence.as_obj,
            gene=gene,
        )
    except:_err(); abort(500)
Example #7
0
def gene_page(gene_id):
    if gene_id in GENES_TO_CACHE:
        return open(os.path.join(GENE_CACHE_DIR, '{}.html'.format(gene_id))).read()
        print 'accessing from gene page'
    else:
        db = get_db()
        gene = lookups.get_gene(db, gene_id)
        if gene is None:
            abort(404)
        cache_key = 'template-gene-{}'.format(gene_id)
        template = cache.get(cache_key)
        if template is None:
            template = get_gene_data(db, gene_id, gene, 'template', cache_key)
        print 'Rendering gene: %s' % gene_id
        return template
Example #8
0
def transcript_page(transcript_id):
    db = get_db()
    try:
        _log()
        transcript = lookups.get_transcript(db, transcript_id)
        if not transcript: return not_found_page('The requested transcript {!s} could not be found.'.format(transcript_id))
        gene = lookups.get_gene(db, transcript['gene_id'])
        intervalset = IntervalSet.from_transcript(db, transcript_id)
        genes = TranscriptSet.from_transcript(db, transcript_id).genes
        return render_template(
            'transcript.html',
            intervalset=intervalset, genes=genes, csq=Consequence.as_obj,
            gene=gene,
            transcript=transcript,
        )
    except:_err(); abort(500)
def get_gene_page_content(gene_id):
    dbname = session['db_selected']
    db = get_db()
    try:
        gene = lookups.get_gene(db, gene_id)
        if gene is None:
            abort(404)
        cache_key = 't-gene-{}'.format(gene_id)
        t = cache.get(cache_key)
        print 'Rendering %sgene: %s' % ('' if t is None else 'cached ',
                                        gene_id)
        if t is None:
            variants_in_gene = lookups.get_variants_in_gene(db, gene_id)
            transcripts_in_gene = lookups.get_transcripts_in_gene(db, gene_id)

            # Get some canonical transcript and corresponding info
            transcript_id = gene['canonical_transcript']
            transcript = lookups.get_transcript(db, transcript_id)
            variants_in_transcript = lookups.get_variants_in_transcript(
                db, transcript_id)
            coverage_stats = lookups.get_coverage_for_transcript(
                db, transcript['xstart'] - EXON_PADDING,
                transcript['xstop'] + EXON_PADDING)
            add_transcript_coordinate_to_variants(db, variants_in_transcript,
                                                  transcript_id)
            constraint_info = lookups.get_constraint_for_transcript(
                db, transcript_id)

            t = render_template(
                'gene.html',
                gene=gene,
                transcript=transcript,
                variants_in_gene=variants_in_gene,
                variants_in_transcript=variants_in_transcript,
                transcripts_in_gene=transcripts_in_gene,
                coverage_stats=coverage_stats,
                constraint=constraint_info,
                csq_order=csq_order,
                dbname=dbname,
            )
            cache.set(cache_key, t)
        return t
    except Exception, e:
        print 'Failed on gene:', gene_id, ';Error=', traceback.format_exc()
        abort(404)
Example #10
0
def text_page():
    db = get_db()
    query = request.args.get('text')
    datatype, identifier = lookups.get_awesomebar_result(db, query)
    if datatype in ['gene', 'transcript']:
        gene = lookups.get_gene(db, identifier)
        link = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=chr%(chrom)s%%3A%(start)s-%(stop)s" % gene
        output = '''Searched for %s. Found %s.
%s; Canonical: %s.
%s''' % (query, identifier, gene['full_gene_name'], gene['canonical_transcript'], link)
        output += '' if 'omim_accession' not in gene else '''
In OMIM: %(omim_description)s
http://omim.org/entry/%(omim_accession)s''' % gene
        return output
    elif datatype == 'error' or datatype == 'not_found':
        return "Gene/transcript %s not found" % query
    else:
        return "Search types other than gene transcript not yet supported"
Example #11
0
def text_page():
    db = get_db()
    query = request.args.get('text')
    datatype, identifier = lookups.get_awesomebar_result(db, query)
    if datatype in ['gene', 'transcript']:
        gene = lookups.get_gene(db, identifier)
        link = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=chr%(chrom)s%%3A%(start)s-%(stop)s" % gene
        output = '''Searched for %s. Found %s.
%s; Canonical: %s.
%s''' % (query, identifier, gene['full_gene_name'], gene['canonical_transcript'], link)
        output += '' if 'omim_accession' not in gene else '''
In OMIM: %(omim_description)s
http://omim.org/entry/%(omim_accession)s''' % gene
        return output
    elif datatype == 'error' or datatype == 'not_found':
        return "Gene/transcript %s not found" % query
    else:
        return "Search types other than gene transcript not yet supported"
Example #12
0
def transcript_page(transcript_id):
    db = get_db()
    try:
        transcript = lookups.get_transcript(db, transcript_id)

        cache_key = 't-transcript-{}'.format(transcript_id)
        t = cache.get(cache_key)
        if t is None:

            gene = lookups.get_gene(db, transcript['gene_id'])
            gene['transcripts'] = lookups.get_transcripts_in_gene(
                db, transcript['gene_id'])
            variants_in_transcript = lookups.get_variants_in_transcript(
                db, transcript_id)
            cnvs_in_transcript = lookups.get_exons_cnvs(db, transcript_id)
            cnvs_per_gene = lookups.get_cnvs(db, transcript['gene_id'])
            coverage_stats = lookups.get_coverage_for_transcript(
                db, transcript['xstart'] - EXON_PADDING,
                transcript['xstop'] + EXON_PADDING)

            add_transcript_coordinate_to_variants(db, variants_in_transcript,
                                                  transcript_id)

            t = render_template(
                'transcript.html',
                transcript=transcript,
                transcript_json=json.dumps(transcript),
                variants_in_transcript=variants_in_transcript,
                variants_in_transcript_json=json.dumps(variants_in_transcript),
                coverage_stats=coverage_stats,
                coverage_stats_json=json.dumps(coverage_stats),
                gene=gene,
                gene_json=json.dumps(gene),
                cnvs=cnvs_in_transcript,
                cnvs_json=json.dumps(cnvs_in_transcript),
                cnvgenes=cnvs_per_gene,
                cnvgenes_json=json.dumps(cnvs_per_gene))
            cache.set(cache_key, t, timeout=1000 * 60)
        print 'Rendering transcript: %s' % transcript_id
        return t
    except Exception, e:
        print 'Failed on transcript:', transcript_id, ';Error=', traceback.format_exc(
        )
        abort(404)
def transcript_page(transcript_id):
    dbname = session['db_selected']
    db = get_db()
    try:
        transcript = lookups.get_transcript(db, transcript_id)

        cache_key = 't-transcript-{}'.format(transcript_id)
        t = cache.get(cache_key)
        print 'Rendering %stranscript: %s' % ('' if t is None else 'cached ',
                                              transcript_id)
        if t is None:

            gene = lookups.get_gene(db, transcript['gene_id'])
            gene['transcripts'] = lookups.get_transcripts_in_gene(
                db, transcript['gene_id'])
            variants_in_transcript = lookups.get_variants_in_transcript(
                db, transcript_id)

            coverage_stats = lookups.get_coverage_for_transcript(
                db, transcript['xstart'] - EXON_PADDING,
                transcript['xstop'] + EXON_PADDING)

            add_transcript_coordinate_to_variants(db, variants_in_transcript,
                                                  transcript_id)

            t = render_template(
                'transcript.html',
                transcript=transcript,
                transcript_json=json.dumps(transcript),
                variants_in_transcript=variants_in_transcript,
                variants_in_transcript_json=json.dumps(variants_in_transcript),
                coverage_stats=coverage_stats,
                coverage_stats_json=json.dumps(coverage_stats),
                gene=gene,
                gene_json=json.dumps(gene),
                csq_order=csq_order,
                dbname=dbname,
            )
            cache.set(cache_key, t)
        return t
    except Exception, e:
        print 'Failed on transcript:', transcript_id, ';Error=', traceback.format_exc(
        )
        abort(404)
Example #14
0
def get_gene_page_content(gene_id):
    db = get_db()
    try:
        gene = lookups.get_gene(db, gene_id)
        if gene is None:
            abort(404)
        cache_key = 't-gene-{}'.format(gene_id)
        t = cache.get(cache_key)
        if t is None:
            variants_in_gene = lookups.get_variants_in_gene(db, gene_id)
            transcripts_in_gene = lookups.get_transcripts_in_gene(db, gene_id)

            # Get some canonical transcript and corresponding info
            transcript_id = gene['canonical_transcript']
            transcript = lookups.get_transcript(db, transcript_id)
            variants_in_transcript = lookups.get_variants_in_transcript(
                db, transcript_id)
            cnvs_in_transcript = lookups.get_exons_cnvs(db, transcript_id)
            cnvs_per_gene = lookups.get_cnvs(db, gene_id)
            coverage_stats = lookups.get_coverage_for_transcript(
                db, transcript['xstart'] - EXON_PADDING,
                transcript['xstop'] + EXON_PADDING)
            add_transcript_coordinate_to_variants(db, variants_in_transcript,
                                                  transcript_id)
            constraint_info = lookups.get_constraint_for_transcript(
                db, transcript_id)

            t = render_template('gene.html',
                                gene=gene,
                                transcript=transcript,
                                variants_in_gene=variants_in_gene,
                                variants_in_transcript=variants_in_transcript,
                                transcripts_in_gene=transcripts_in_gene,
                                coverage_stats=coverage_stats,
                                cnvs=cnvs_in_transcript,
                                cnvgenes=cnvs_per_gene,
                                constraint=constraint_info)
            cache.set(cache_key, t, timeout=1000 * 60)
        print 'Rendering gene: %s' % gene_id
        return t
    except Exception, e:
        print 'Failed on gene:', gene_id, ';Error=', traceback.format_exc()
        abort(404)
Example #15
0
def get_gene_page_content(gene_id):
    db = get_db()
    try:
        gene = lookups.get_gene(db, gene_id)
        if gene is None:
            abort(404)
        cache_key = "t-gene-{}".format(gene_id)
        t = cache.get(cache_key)
        print "Rendering %sgene: %s" % ("" if t is None else "cached ", gene_id)
        if t is None:
            variants_in_gene = lookups.get_variants_in_gene(db, gene_id)
            transcripts_in_gene = lookups.get_transcripts_in_gene(db, gene_id)

            # Get some canonical transcript and corresponding info
            transcript_id = gene["canonical_transcript"]
            transcript = lookups.get_transcript(db, transcript_id)
            variants_in_transcript = lookups.get_variants_in_transcript(db, transcript_id)
            coverage_stats = lookups.get_coverage_for_transcript(
                db, transcript["xstart"] - EXON_PADDING, transcript["xstop"] + EXON_PADDING
            )
            add_transcript_coordinate_to_variants(db, variants_in_transcript, transcript_id)
            constraint_info = lookups.get_constraint_for_transcript(db, transcript_id)

            t = render_template(
                "gene.html",
                gene=gene,
                transcript=transcript,
                variants_in_gene=variants_in_gene,
                variants_in_transcript=variants_in_transcript,
                transcripts_in_gene=transcripts_in_gene,
                coverage_stats=coverage_stats,
                constraint=constraint_info,
                csq_order=csq_order,
            )
            cache.set(cache_key, t)
        return t
    except Exception, e:
        print "Failed on gene:", gene_id, ";Error=", traceback.format_exc()
        abort(404)
Example #16
0
def transcript_page(transcript_id):
    db = get_db()
    try:
        transcript = lookups.get_transcript(db, transcript_id)

        cache_key = "t-transcript-{}".format(transcript_id)
        t = cache.get(cache_key)
        print "Rendering %stranscript: %s" % ("" if t is None else "cached ", transcript_id)
        if t is None:

            gene = lookups.get_gene(db, transcript["gene_id"])
            gene["transcripts"] = lookups.get_transcripts_in_gene(db, transcript["gene_id"])
            variants_in_transcript = lookups.get_variants_in_transcript(db, transcript_id)

            coverage_stats = lookups.get_coverage_for_transcript(
                db, transcript["xstart"] - EXON_PADDING, transcript["xstop"] + EXON_PADDING
            )

            add_transcript_coordinate_to_variants(db, variants_in_transcript, transcript_id)

            t = render_template(
                "transcript.html",
                transcript=transcript,
                transcript_json=json.dumps(transcript),
                variants_in_transcript=variants_in_transcript,
                variants_in_transcript_json=json.dumps(variants_in_transcript),
                coverage_stats=coverage_stats,
                coverage_stats_json=json.dumps(coverage_stats),
                gene=gene,
                gene_json=json.dumps(gene),
                csq_order=csq_order,
            )
            cache.set(cache_key, t)
        return t
    except Exception, e:
        print "Failed on transcript:", transcript_id, ";Error=", traceback.format_exc()
        abort(404)
def get_gene_page_content(gene_id):
    db = get_db()
    try:
        print "gene_id", gene_id
        gene = lookups.get_gene(db, gene_id)
        print "gene", gene
        if gene is None:
            abort(404)
        gene_name = gene['gene_name']
        print gene_name
        variants_in_gene = lookups.get_variants_in_gene(db, gene_name)
        transcripts_in_gene = lookups.get_transcripts_in_gene(db, gene_id)
        transcript_id = gene['canonical_transcript']
        transcript = lookups.get_transcript(db, transcript_id)
        variants_in_transcript = lookups.get_variants_in_transcript(
            db, transcript_id)
        add_transcript_coordinate_to_variants(db, variants_in_transcript,
                                              transcript_id)

        #print gene
        #print variants_in_gene
        #print transcript
        #print transcripts_in_gene
        #print "variants_in_transcript\n",variants_in_transcript

        t = render_template('gene.html',
                            gene=gene,
                            transcript=transcript,
                            variants_in_gene=variants_in_gene,
                            variants_in_transcript=variants_in_transcript,
                            transcripts_in_gene=transcripts_in_gene)
        print 'Rendering gene: %s' % gene_id
        return t
    except Exception, e:
        print 'Failed on gene:', gene_id, ';Error=', traceback.format_exc()
        abort(404)