scout/server/blueprints/variants/controllers.py
def variant_case(store, case_obj, variant_obj):
    """Pre-process case for the variant view.

    Adds information about files from case obj to variant

    Args:
        store(scout.adapter.MongoAdapter)
        case_obj(scout.models.Case)
        variant_obj(scout.models.Variant)
    """
    case_obj['bam_files'] = []
    case_obj['mt_bams'] = []
    case_obj['bai_files'] = []
    case_obj['mt_bais'] = []
    case_obj['sample_names'] = []
    for individual in case_obj['individuals']:
        bam_path = individual.get('bam_file')
        mt_bam = individual.get('mt_bam')
        case_obj['sample_names'].append(individual.get('display_name'))
        if bam_path and os.path.exists(bam_path):
            case_obj['bam_files'].append(individual['bam_file'])
            case_obj['bai_files'].append(find_bai_file(individual['bam_file']))
        if mt_bam and os.path.exists(mt_bam):
            case_obj['mt_bams'].append(individual['mt_bam'])
            case_obj['mt_bais'].append(find_bai_file(individual['mt_bam']))

        else:
            LOG.debug("%s: no bam file found", individual['individual_id'])

    try:
        genes = variant_obj.get('genes', [])
        if len(genes) == 1:
            hgnc_gene_obj = store.hgnc_gene(variant_obj['genes'][0]['hgnc_id'])
            if hgnc_gene_obj:
                vcf_path = store.get_region_vcf(case_obj, gene_obj=hgnc_gene_obj)
                case_obj['region_vcf_file'] = vcf_path
            else:
                case_obj['region_vcf_file'] = None
        elif len(genes) > 1:
            chrom = variant_obj['genes'][0]['common']['chromosome']
            start = min(gene['common']['start'] for gene in variant_obj['genes'])
            end = max(gene['common']['end'] for gene in variant_obj['genes'])
            # Create a reduced VCF with variants in the region
            vcf_path = store.get_region_vcf(case_obj, chrom=chrom, start=start, end=end)
            case_obj['region_vcf_file'] = vcf_path
    except (SyntaxError, Exception):
        LOG.warning("skip VCF region for alignment view")
def variant_case(store, case_obj, variant_obj):
    case_obj['bam_files'] = []
    case_obj['mt_bams'] = []
    case_obj['bai_files'] = []
    case_obj['mt_bais'] = []
    case_obj['sample_names'] = []
    for individual in case_obj['individuals']:
        bam_path = individual.get('bam_file')
        mt_bam = individual.get('mt_bam')
        case_obj['sample_names'].append(individual.get('display_name'))
        if bam_path and os.path.exists(bam_path):
            case_obj['bam_files'].append(individual['bam_file'])
            case_obj['bai_files'].append(find_bai_file(individual['bam_file']))
        if mt_bam and os.path.exists(mt_bam):
            case_obj['mt_bams'].append(individual['mt_bam'])
            case_obj['mt_bais'].append(find_bai_file(individual['mt_bam']))

        else:
            LOG.debug("%s: no bam file found", individual['individual_id'])

    try:
        genes = variant_obj.get('genes', [])
        if len(genes) == 1:
            hgnc_gene_obj = store.hgnc_gene(variant_obj['genes'][0]['hgnc_id'])
            if hgnc_gene_obj:
                vcf_path = store.get_region_vcf(case_obj, gene_obj=hgnc_gene_obj)
                case_obj['region_vcf_file'] = vcf_path
            else:
                case_obj['region_vcf_file'] = None
        elif len(genes) > 1:
            chrom = variant_obj['genes'][0]['common']['chromosome']
            start = min(gene['common']['start'] for gene in variant_obj['genes'])
            end = max(gene['common']['end'] for gene in variant_obj['genes'])
            # Create a reduced VCF with variants in the region
            vcf_path = store.get_region_vcf(case_obj, chrom=chrom, start=start, end=end)
            case_obj['region_vcf_file'] = vcf_path
    except (SyntaxError, Exception):
        LOG.warning("skip VCF region for alignment view")
def variant_case ( store , case_obj , variant_obj ) : case_obj [ 'bam_files' ] = [ ] case_obj [ 'mt_bams' ] = [ ] case_obj [ 'bai_files' ] = [ ] case_obj [ 'mt_bais' ] = [ ] case_obj [ 'sample_names' ] = [ ] for individual in case_obj [ 'individuals' ] : bam_path = individual . get ( 'bam_file' ) mt_bam = individual . get ( 'mt_bam' ) case_obj [ 'sample_names' ] . append ( individual . get ( 'display_name' ) ) if bam_path and os . path . exists ( bam_path ) : case_obj [ 'bam_files' ] . append ( individual [ 'bam_file' ] ) case_obj [ 'bai_files' ] . append ( find_bai_file ( individual [ 'bam_file' ] ) ) if mt_bam and os . path . exists ( mt_bam ) : case_obj [ 'mt_bams' ] . append ( individual [ 'mt_bam' ] ) case_obj [ 'mt_bais' ] . append ( find_bai_file ( individual [ 'mt_bam' ] ) ) else : LOG . debug ( "%s: no bam file found" , individual [ 'individual_id' ] ) try : genes = variant_obj . get ( 'genes' , [ ] ) if len ( genes ) == 1 : hgnc_gene_obj = store . hgnc_gene ( variant_obj [ 'genes' ] [ 0 ] [ 'hgnc_id' ] ) if hgnc_gene_obj : vcf_path = store . get_region_vcf ( case_obj , gene_obj = hgnc_gene_obj ) case_obj [ 'region_vcf_file' ] = vcf_path else : case_obj [ 'region_vcf_file' ] = None elif len ( genes ) > 1 : chrom = variant_obj [ 'genes' ] [ 0 ] [ 'common' ] [ 'chromosome' ] start = min ( gene [ 'common' ] [ 'start' ] for gene in variant_obj [ 'genes' ] ) end = max ( gene [ 'common' ] [ 'end' ] for gene in variant_obj [ 'genes' ] ) # Create a reduced VCF with variants in the region vcf_path = store . get_region_vcf ( case_obj , chrom = chrom , start = start , end = end ) case_obj [ 'region_vcf_file' ] = vcf_path except ( SyntaxError , Exception ) : LOG . warning ( "skip VCF region for alignment view" )
Pre-process case for the variant view.

    Adds information about files from case obj to variant

    Args:
        store(scout.adapter.MongoAdapter)
        case_obj(scout.models.Case)
        variant_obj(scout.models.Variant)
Pre - process case for the variant view .