Esempio n. 1
0
def process_vcf(job):
    '''
        wait for the annotation job to finish by continually checking the job status
    '''
    status = runner.job_status(RUNNER_DB, job)
    if status is None:
        return flask.render_template('main.html', errors=['Job not found'], form=flask.request.form)
    elif status['status'] == 'F': # finished
        return flask.redirect(flask.url_for("vcf_result", job=job))
    else: # still in progress
        return flask.render_template('process_vcf.html', job=job, status=status)
Esempio n. 2
0
def gene_result(job, gene):
    '''
        find AF details for a requested gene in a job
    '''
    status = runner.job_status(RUNNER_DB, job)  # ensure it's a real job
    if status is None:  # no output
        return flask.render_template('main.html',
                                     errors=['Job not found'],
                                     form=flask.request.form)

    skip = 2
    # determine counts for genes
    settings = json.loads(status['settings'])

    result = {'x': [], 'y': [], 'pass': [], 'text': []}
    for line in open(
            os.path.join(app.config['UPLOAD_FOLDER'], '{}.out'.format(job)),
            'r'):
        if skip > 0:  # skip header
            if skip == 2:
                cases = float(line.strip())
            skip -= 1
            continue

        fields = line.strip('\n').split('\t')
        if fields[helpers.OUTPUT_FIELDS['gene']] == gene:
            ac = float(fields[helpers.OUTPUT_FIELDS['allele_count']])
            an = float(fields[helpers.OUTPUT_FIELDS['allele_number']])
            exac_ac = float(fields[helpers.OUTPUT_FIELDS['exac_all_pop_ac']])
            exac_an = float(fields[helpers.OUTPUT_FIELDS['exac_all_pop_an']])
            if an != 0:
                result['y'].append(ac / an)
                if exac_an != 0:
                    result['x'].append(exac_ac / exac_an)
                else:
                    result['x'].append(0)
                result['pass'].append(
                    helpers.get_vcf_match(fields, settings) > 0)
                result['text'].append('AC={} {}'.format(
                    fields[helpers.OUTPUT_FIELDS['allele_count']],
                    fields[helpers.OUTPUT_FIELDS['impact_type']]))

    return flask.jsonify(result)
Esempio n. 3
0
def job_status(job):
    status = runner.job_status(RUNNER_DB, job)
    if status is None:
        return flask.render_template('main.html', form=flask.request.form)
    else: # still in progress
        return flask.jsonify(status)
Esempio n. 4
0
def vcf_result(job):
    '''
        redirected to this after annotation has finished
    '''
    status = runner.job_status(RUNNER_DB, job) # ensure it's a real job
    if status is None: # no output
        return flask.render_template('main.html', errors=['Job not found'], form=flask.request.form)

    # determine counts for genes
    settings = json.loads(status['settings'])
    result = []
    warnings = []
    current = [None, 0]
    skip = 2
    for line in open(os.path.join(app.config['UPLOAD_FOLDER'], '{}.out'.format(job)), 'r'):
        if skip > 0: # skip header
            if skip == 2:
                settings['cases'] = int(line.strip())
            skip -=1
            continue
        fields = line.strip('\n').split('\t')
        if current[0] == fields[0]: # same gene
            current[1] += helpers.get_vcf_match(fields, settings)
        else: # new gene
            if current[0] is not None and current[1] > 0: # an actual gene
                matches = helpers.get_exac_detail(query_db=query_db, gene=current[0], settings=settings)
                if matches[1] is not None:
                    statistics = calculate.calculate_burden_statistics(case_burden=current[1], total_cases=settings['cases'], population_burden=matches[0], total_population=EXAC_POPULATION)
                    result.append({'gene': current[0], 'burden': current[1], 'matches': matches[0], 'protein_length': matches[1], \
                        'z_test': statistics[0], 'binomial_test': statistics[1], 'relative_risk': statistics[2], 'rr_conf_interval': statistics[3]})
                else:
                    # gene is no good
                    warnings.append( 'Gene "{}" or variants not found in the selected database'.format(current[0]))
            # start counting new gene
            current = [fields[0], helpers.get_vcf_match(fields, settings)]
    if current[1] > 0:
        matches = helpers.get_exac_detail(query_db=query_db, gene=current[0], settings=settings)
        if matches[1] is not None:
            statistics = calculate.calculate_burden_statistics(case_burden=current[1], total_cases=settings['cases'], population_burden=matches[0], total_population=EXAC_POPULATION)
            result.append({'gene': current[0], 'burden': current[1], 'matches': matches[0], 'protein_length': matches[1], \
                'z_test': statistics[0], 'binomial_test': statistics[1], 'relative_risk': statistics[2], 'rr_conf_interval': statistics[3]})
        else:
            # gene is no good
            warnings.append( 'Gene "{}" or variants not found in the selected database'.format(current[0]))

    return flask.render_template('results.html',
        result=result,
        filter_type=settings['filter_type'],
        filter_value=settings['filter_value'],
        filter_af_pop=','.join(settings['filter_af_pop']),
        filter_af_value=settings['filter_af_value'],
        cases=settings['cases'],
        include_impacts=', '.join(settings['include_impacts']),
        gene_list = ','.join(["'{}'".format(item['gene'].replace("'", "\\'")) for item in result if item['protein_length'] is not None]),
        protein_lengths = ','.join([ str(item['protein_length']) for item in result if item['protein_length'] is not None]),
        binomial_pvalues = ','.join([ '{0:0.3e}'.format(item['binomial_test']) for item in result if item['protein_length'] is not None]),
        relative_risk = ','.join([ '{0:0.3e}'.format(item['relative_risk']) for item in result if item['protein_length'] is not None]),
        rr_conf_interval = ','.join([ str(item['rr_conf_interval']) for item in result if item['protein_length'] is not None]),
        warnings = warnings,
        is_vcf = True,
        job = job
    )