scout/parse/case.py
def add_peddy_information(config_data):
    """Add information from peddy outfiles to the individuals"""
    ped_info = {}
    ped_check = {}
    sex_check = {}
    relations = []

    if config_data.get('peddy_ped'):
        file_handle = open(config_data['peddy_ped'], 'r')
        for ind_info in parse_peddy_ped(file_handle):
            ped_info[ind_info['sample_id']] = ind_info

    if config_data.get('peddy_ped_check'):
        file_handle = open(config_data['peddy_ped_check'], 'r')
        for pair_info in parse_peddy_ped_check(file_handle):
            ped_check[(pair_info['sample_a'], pair_info['sample_b'])] = pair_info

    if config_data.get('peddy_sex_check'):
        file_handle = open(config_data['peddy_sex_check'], 'r')
        for ind_info in parse_peddy_sex_check(file_handle):
            sex_check[ind_info['sample_id']] = ind_info

    if not ped_info:
        return

    analysis_inds = {}
    for ind in config_data['samples']:
        ind_id = ind['sample_id']
        analysis_inds[ind_id] = ind

    for ind_id in analysis_inds:
        ind = analysis_inds[ind_id]
        # Check if peddy has inferred the ancestry
        if ind_id in ped_info:
            ind['predicted_ancestry'] = ped_info[ind_id].get('ancestry-prediction', 'UNKNOWN')
        # Check if peddy has inferred the sex
        if ind_id in sex_check:
            if sex_check[ind_id]['error']:
                ind['confirmed_sex'] = False
            else:
                ind['confirmed_sex'] = True

        # Check if peddy har confirmed parental relations
        for parent in ['mother', 'father']:
            # If we are looking at individual with parents
            if ind[parent] != '0':
                # Check if the child/parent pair is in peddy data
                for pair in ped_check:
                    if (ind_id in pair and ind[parent] in pair):
                        # If there is a parent error we mark that
                        if ped_check[pair]['parent_error']:
                            analysis_inds[ind[parent]]['confirmed_parent'] = False
                        else:
                            # Else if parent confirmation has not been done
                            if 'confirmed_parent' not in analysis_inds[ind[parent]]:
                                # Set confirmatio to True
                                analysis_inds[ind[parent]]['confirmed_parent'] = True
def add_peddy_information(config_data):
    """Add information from peddy outfiles to the individuals"""
    ped_info = {}
    ped_check = {}
    sex_check = {}
    relations = []

    if config_data.get('peddy_ped'):
        file_handle = open(config_data['peddy_ped'], 'r')
        for ind_info in parse_peddy_ped(file_handle):
            ped_info[ind_info['sample_id']] = ind_info

    if config_data.get('peddy_ped_check'):
        file_handle = open(config_data['peddy_ped_check'], 'r')
        for pair_info in parse_peddy_ped_check(file_handle):
            ped_check[(pair_info['sample_a'], pair_info['sample_b'])] = pair_info

    if config_data.get('peddy_sex_check'):
        file_handle = open(config_data['peddy_sex_check'], 'r')
        for ind_info in parse_peddy_sex_check(file_handle):
            sex_check[ind_info['sample_id']] = ind_info

    if not ped_info:
        return

    analysis_inds = {}
    for ind in config_data['samples']:
        ind_id = ind['sample_id']
        analysis_inds[ind_id] = ind

    for ind_id in analysis_inds:
        ind = analysis_inds[ind_id]
        # Check if peddy has inferred the ancestry
        if ind_id in ped_info:
            ind['predicted_ancestry'] = ped_info[ind_id].get('ancestry-prediction', 'UNKNOWN')
        # Check if peddy has inferred the sex
        if ind_id in sex_check:
            if sex_check[ind_id]['error']:
                ind['confirmed_sex'] = False
            else:
                ind['confirmed_sex'] = True

        # Check if peddy har confirmed parental relations
        for parent in ['mother', 'father']:
            # If we are looking at individual with parents
            if ind[parent] != '0':
                # Check if the child/parent pair is in peddy data
                for pair in ped_check:
                    if (ind_id in pair and ind[parent] in pair):
                        # If there is a parent error we mark that
                        if ped_check[pair]['parent_error']:
                            analysis_inds[ind[parent]]['confirmed_parent'] = False
                        else:
                            # Else if parent confirmation has not been done
                            if 'confirmed_parent' not in analysis_inds[ind[parent]]:
                                # Set confirmatio to True
                                analysis_inds[ind[parent]]['confirmed_parent'] = True
def add_peddy_information ( config_data ) : ped_info = { } ped_check = { } sex_check = { } relations = [ ] if config_data . get ( 'peddy_ped' ) : file_handle = open ( config_data [ 'peddy_ped' ] , 'r' ) for ind_info in parse_peddy_ped ( file_handle ) : ped_info [ ind_info [ 'sample_id' ] ] = ind_info if config_data . get ( 'peddy_ped_check' ) : file_handle = open ( config_data [ 'peddy_ped_check' ] , 'r' ) for pair_info in parse_peddy_ped_check ( file_handle ) : ped_check [ ( pair_info [ 'sample_a' ] , pair_info [ 'sample_b' ] ) ] = pair_info if config_data . get ( 'peddy_sex_check' ) : file_handle = open ( config_data [ 'peddy_sex_check' ] , 'r' ) for ind_info in parse_peddy_sex_check ( file_handle ) : sex_check [ ind_info [ 'sample_id' ] ] = ind_info if not ped_info : return analysis_inds = { } for ind in config_data [ 'samples' ] : ind_id = ind [ 'sample_id' ] analysis_inds [ ind_id ] = ind for ind_id in analysis_inds : ind = analysis_inds [ ind_id ] # Check if peddy has inferred the ancestry if ind_id in ped_info : ind [ 'predicted_ancestry' ] = ped_info [ ind_id ] . get ( 'ancestry-prediction' , 'UNKNOWN' ) # Check if peddy has inferred the sex if ind_id in sex_check : if sex_check [ ind_id ] [ 'error' ] : ind [ 'confirmed_sex' ] = False else : ind [ 'confirmed_sex' ] = True # Check if peddy har confirmed parental relations for parent in [ 'mother' , 'father' ] : # If we are looking at individual with parents if ind [ parent ] != '0' : # Check if the child/parent pair is in peddy data for pair in ped_check : if ( ind_id in pair and ind [ parent ] in pair ) : # If there is a parent error we mark that if ped_check [ pair ] [ 'parent_error' ] : analysis_inds [ ind [ parent ] ] [ 'confirmed_parent' ] = False else : # Else if parent confirmation has not been done if 'confirmed_parent' not in analysis_inds [ ind [ parent ] ] : # Set confirmatio to True analysis_inds [ ind [ parent ] ] [ 'confirmed_parent' ] = True
Add information from peddy outfiles to the individuals
Add information from peddy outfiles to the individuals