scout/server/blueprints/cases/controllers.py
def case_report_content(store, institute_obj, case_obj):
    """Gather contents to be visualized in a case report

    Args:
        store(adapter.MongoAdapter)
        institute_obj(models.Institute)
        case_obj(models.Case)

    Returns:
        data(dict)

    """
    variant_types = {
        'causatives_detailed': 'causatives',
        'suspects_detailed': 'suspects',
        'classified_detailed': 'acmg_classification',
        'tagged_detailed': 'manual_rank',
        'dismissed_detailed': 'dismiss_variant',
        'commented_detailed': 'is_commented',
    }
    data = case_obj

    for individual in data['individuals']:
        try:
            sex = int(individual.get('sex', 0))
        except ValueError as err:
            sex = 0
        individual['sex_human'] = SEX_MAP[sex]
        individual['phenotype_human'] = PHENOTYPE_MAP.get(individual['phenotype'])

    # Add the case comments
    data['comments'] = store.events(institute_obj, case=case_obj, comments=True)

    data['manual_rank_options'] = MANUAL_RANK_OPTIONS
    data['dismissed_options'] = DISMISS_VARIANT_OPTIONS
    data['genetic_models'] = dict(GENETIC_MODELS)
    data['report_created_at'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    evaluated_variants = {}
    for vt in variant_types:
        evaluated_variants[vt] = []
    # We collect all causatives and suspected variants
    # These are handeled in separate since they are on case level
    for var_type in ['causatives', 'suspects']:
        #These include references to variants
        vt = '_'.join([var_type, 'detailed'])
        for var_id in case_obj.get(var_type,[]):
            variant_obj = store.variant(var_id)
            if not variant_obj:
                continue
            # If the variant exists we add it to the evaluated variants
            evaluated_variants[vt].append(variant_obj)

    ## get variants for this case that are either classified, commented, tagged or dismissed.
    for var_obj in store.evaluated_variants(case_id=case_obj['_id']):
        # Check which category it belongs to
        for vt in variant_types:
            keyword = variant_types[vt]
            # When found we add it to the categpry
            # Eac variant can belong to multiple categories
            if keyword in var_obj:
                evaluated_variants[vt].append(var_obj)

    for var_type in evaluated_variants:
        decorated_variants = []
        for var_obj in evaluated_variants[var_type]:
        # We decorate the variant with some extra information
            if var_obj['category'] == 'snv':
                decorated_info = variant_decorator(
                        store=store,
                        institute_obj=institute_obj,
                        case_obj=case_obj,
                        variant_id=None,
                        variant_obj=var_obj,
                        add_case=False,
                        add_other=False,
                        get_overlapping=False
                    )
            else:
                decorated_info = sv_variant(
                    store=store,
                    institute_id=institute_obj['_id'],
                    case_name=case_obj['display_name'],
                    variant_obj=var_obj,
                    add_case=False,
                    get_overlapping=False
                    )
            decorated_variants.append(decorated_info['variant'])
        # Add the decorated variants to the case
        data[var_type] = decorated_variants

    return data
def case_report_content(store, institute_obj, case_obj):
    variant_types = {
        'causatives_detailed': 'causatives',
        'suspects_detailed': 'suspects',
        'classified_detailed': 'acmg_classification',
        'tagged_detailed': 'manual_rank',
        'dismissed_detailed': 'dismiss_variant',
        'commented_detailed': 'is_commented',
    }
    data = case_obj

    for individual in data['individuals']:
        try:
            sex = int(individual.get('sex', 0))
        except ValueError as err:
            sex = 0
        individual['sex_human'] = SEX_MAP[sex]
        individual['phenotype_human'] = PHENOTYPE_MAP.get(individual['phenotype'])

    # Add the case comments
    data['comments'] = store.events(institute_obj, case=case_obj, comments=True)

    data['manual_rank_options'] = MANUAL_RANK_OPTIONS
    data['dismissed_options'] = DISMISS_VARIANT_OPTIONS
    data['genetic_models'] = dict(GENETIC_MODELS)
    data['report_created_at'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    evaluated_variants = {}
    for vt in variant_types:
        evaluated_variants[vt] = []
    # We collect all causatives and suspected variants
    # These are handeled in separate since they are on case level
    for var_type in ['causatives', 'suspects']:
        #These include references to variants
        vt = '_'.join([var_type, 'detailed'])
        for var_id in case_obj.get(var_type,[]):
            variant_obj = store.variant(var_id)
            if not variant_obj:
                continue
            # If the variant exists we add it to the evaluated variants
            evaluated_variants[vt].append(variant_obj)

    ## get variants for this case that are either classified, commented, tagged or dismissed.
    for var_obj in store.evaluated_variants(case_id=case_obj['_id']):
        # Check which category it belongs to
        for vt in variant_types:
            keyword = variant_types[vt]
            # When found we add it to the categpry
            # Eac variant can belong to multiple categories
            if keyword in var_obj:
                evaluated_variants[vt].append(var_obj)

    for var_type in evaluated_variants:
        decorated_variants = []
        for var_obj in evaluated_variants[var_type]:
        # We decorate the variant with some extra information
            if var_obj['category'] == 'snv':
                decorated_info = variant_decorator(
                        store=store,
                        institute_obj=institute_obj,
                        case_obj=case_obj,
                        variant_id=None,
                        variant_obj=var_obj,
                        add_case=False,
                        add_other=False,
                        get_overlapping=False
                    )
            else:
                decorated_info = sv_variant(
                    store=store,
                    institute_id=institute_obj['_id'],
                    case_name=case_obj['display_name'],
                    variant_obj=var_obj,
                    add_case=False,
                    get_overlapping=False
                    )
            decorated_variants.append(decorated_info['variant'])
        # Add the decorated variants to the case
        data[var_type] = decorated_variants

    return data
def case_report_content ( store , institute_obj , case_obj ) : variant_types = { 'causatives_detailed' : 'causatives' , 'suspects_detailed' : 'suspects' , 'classified_detailed' : 'acmg_classification' , 'tagged_detailed' : 'manual_rank' , 'dismissed_detailed' : 'dismiss_variant' , 'commented_detailed' : 'is_commented' , } data = case_obj for individual in data [ 'individuals' ] : try : sex = int ( individual . get ( 'sex' , 0 ) ) except ValueError as err : sex = 0 individual [ 'sex_human' ] = SEX_MAP [ sex ] individual [ 'phenotype_human' ] = PHENOTYPE_MAP . get ( individual [ 'phenotype' ] ) # Add the case comments data [ 'comments' ] = store . events ( institute_obj , case = case_obj , comments = True ) data [ 'manual_rank_options' ] = MANUAL_RANK_OPTIONS data [ 'dismissed_options' ] = DISMISS_VARIANT_OPTIONS data [ 'genetic_models' ] = dict ( GENETIC_MODELS ) data [ 'report_created_at' ] = datetime . datetime . now ( ) . strftime ( "%Y-%m-%d %H:%M" ) evaluated_variants = { } for vt in variant_types : evaluated_variants [ vt ] = [ ] # We collect all causatives and suspected variants # These are handeled in separate since they are on case level for var_type in [ 'causatives' , 'suspects' ] : #These include references to variants vt = '_' . join ( [ var_type , 'detailed' ] ) for var_id in case_obj . get ( var_type , [ ] ) : variant_obj = store . variant ( var_id ) if not variant_obj : continue # If the variant exists we add it to the evaluated variants evaluated_variants [ vt ] . append ( variant_obj ) ## get variants for this case that are either classified, commented, tagged or dismissed. for var_obj in store . evaluated_variants ( case_id = case_obj [ '_id' ] ) : # Check which category it belongs to for vt in variant_types : keyword = variant_types [ vt ] # When found we add it to the categpry # Eac variant can belong to multiple categories if keyword in var_obj : evaluated_variants [ vt ] . append ( var_obj ) for var_type in evaluated_variants : decorated_variants = [ ] for var_obj in evaluated_variants [ var_type ] : # We decorate the variant with some extra information if var_obj [ 'category' ] == 'snv' : decorated_info = variant_decorator ( store = store , institute_obj = institute_obj , case_obj = case_obj , variant_id = None , variant_obj = var_obj , add_case = False , add_other = False , get_overlapping = False ) else : decorated_info = sv_variant ( store = store , institute_id = institute_obj [ '_id' ] , case_name = case_obj [ 'display_name' ] , variant_obj = var_obj , add_case = False , get_overlapping = False ) decorated_variants . append ( decorated_info [ 'variant' ] ) # Add the decorated variants to the case data [ var_type ] = decorated_variants return data
Gather contents to be visualized in a case report

    Args:
        store(adapter.MongoAdapter)
        institute_obj(models.Institute)
        case_obj(models.Case)

    Returns:
        data(dict)
Gather contents to be visualized in a case report