Esempio n. 1
0
def test_parse_case_two_cases_ped():
    # GIVEN ped lines from multiple families
    case_lines = [
        "#Family ID\tIndividual ID\tPaternal ID\tMaternal ID\tSex\tPhenotype",
        "636808\tADM1059A1\t0\t0\t1\t1",
        "636808\tADM1059A2\tADM1059A1\tADM1059A3\t1\t2",
        "636808\tADM1059A3\t0\t0\t2\t1",
        "636809\tADM1059A3\t0\t0\t2\t1",
    ]
    # WHEN parsing case info
    with pytest.raises(PedigreeError):
        # THEN it should raise since there are multiple families
        parse_ped(case_lines)
Esempio n. 2
0
def test_parse_case_two_cases_ped():
    # GIVEN ped lines from multiple families
    case_lines = [
        "#Family ID\tIndividual ID\tPaternal ID\tMaternal ID\tSex\tPhenotype",
        "636808\tADM1059A1\t0\t0\t1\t1",
        "636808\tADM1059A2\tADM1059A1\tADM1059A3\t1\t2",
        "636808\tADM1059A3\t0\t0\t2\t1",
        "636809\tADM1059A3\t0\t0\t2\t1",
    ]
    # WHEN parsing case info
    with pytest.raises(PedigreeError):
        # THEN it should raise since there are multiple families
        parse_ped(case_lines)
Esempio n. 3
0
def test_parse_ped_file(ped_file):
    # GIVEN a pedigree with three samples
    with open(ped_file, 'r') as case_lines:
        # WHEN parsing out relevant sample info
        family_id, samples = parse_ped(case_lines)
    # THEN it should return correct family id
    assert family_id == '643594'
    # THEN it should return correct number of individuals
    assert len(samples) == 3
Esempio n. 4
0
def test_parse_ped_file(ped_file):
    # GIVEN a pedigree with three samples
    with open(ped_file, 'r') as case_lines:
        # WHEN parsing out relevant sample info
        family_id, samples = parse_ped(case_lines)
    # THEN it should return correct family id
    assert family_id == '643594'
    # THEN it should return correct number of individuals
    assert len(samples) == 3
    # THEN assert the sex has been converted
    for sample in samples:
        assert sample['sex'] in REV_SEX_MAP
Esempio n. 5
0
def test_parse_ped_file(ped_file):
    # GIVEN a pedigree with three samples
    with open(ped_file, 'r') as case_lines:
        # WHEN parsing out relevant sample info
        family_id, samples = parse_ped(case_lines)
    # THEN it should return correct family id
    assert family_id == '643594'
    # THEN it should return correct number of individuals
    assert len(samples) == 3
    # THEN assert the sex has been converted
    for sample in samples:
        assert sample['sex'] in REV_SEX_MAP
Esempio n. 6
0
def test_parse_ped():
    # GIVEN a pedigree with three samples
    case_lines = [
        "#Family ID\tIndividual ID\tPaternal ID\tMaternal ID\tSex\tPhenotype",
        "636808\tADM1059A1\t0\t0\t1\t1",
        "636808\tADM1059A2\tADM1059A1\tADM1059A3\t1\t2",
        "636808\tADM1059A3\t0\t0\t2\t1",
    ]

    # WHEN parsing out relevant sample info
    family_id, samples = parse_ped(case_lines)
    # THEN it should return correct family id
    assert family_id == '636808'
    # THEN it should return correct number of individuals
    assert len(samples) == 3
Esempio n. 7
0
def test_parse_ped():
    # GIVEN a pedigree with three samples
    case_lines = [
        "#Family ID\tIndividual ID\tPaternal ID\tMaternal ID\tSex\tPhenotype",
        "636808\tADM1059A1\t0\t0\t1\t1",
        "636808\tADM1059A2\tADM1059A1\tADM1059A3\t1\t2",
        "636808\tADM1059A3\t0\t0\t2\t1",
    ]

    # WHEN parsing out relevant sample info
    family_id, samples = parse_ped(case_lines)
    # THEN it should return correct family id
    assert family_id == '636808'
    # THEN it should return correct number of individuals
    assert len(samples) == 3
Esempio n. 8
0
def case(context, vcf, vcf_sv, owner, ped, update, config, no_variants):
    """Load a case into the database"""
    if config is None and ped is None:
        click.echo("You have to provide either config or ped file")
        context.abort()

    config_data = yaml.load(config) if config else {}

    if not config_data:
        config_data['analysis_date'] = datetime.datetime.now()

    if ped:
        with open(ped, 'r') as f:
            family_id, samples = parse_ped(f)
            config_data['family'] = family_id

    if 'gene_panels' in config_data:
        log.debug("handle whitespace in gene panel names")
        config_data['gene_panels'] = [
            panel.strip() for panel in config_data['gene_panels']
        ]
        config_data['default_gene_panels'] = [
            panel.strip() for panel in config_data['default_gene_panels']
        ]

    log.info("Use family %s" % config_data['family'])
    # check if the analysis is from a newer analysis
    adapter = context.obj['adapter']

    if 'owner' not in config_data:
        if not owner:
            click.echo("You have to specify the owner of the case")
            context.abort()
        else:
            config_data['owner'] = owner

    existing_case = adapter.case(institute_id=config_data['owner'],
                                 display_name=config_data['family'])

    if existing_case:
        new_analysisdate = config_data.get('analysis_date')
        if new_analysisdate and new_analysisdate > existing_case[
                'analysis_date']:
            log.info("updated analysis - updating existing case")
            # update by default!
            update = True
        else:
            log.warning("Case already exists in database")
            context.abort()
    else:
        log.info("Case does not exist in database")

    config_data['vcf_snv'] = vcf if vcf else config_data.get('vcf_snv')
    config_data['vcf_sv'] = vcf_sv if vcf_sv else config_data.get('vcf_sv')
    config_data['owner'] = config_data.get('owner')
    config_data['rank_score_threshold'] = config_data.get(
        'rank_score_threshold', 5)

    if not (config_data.get('vcf_snv') or config_data.get('vcf_sv')):
        log.warn("Please provide a vcf file (use '--vcf')")
        context.abort()

    if not config_data.get('owner'):
        log.warn("Please provide an owner for the case (use '--owner')")
        context.abort()

    try:
        load_scout(adapter, config_data, ped=ped, update=update)
    except (IntegrityError, ValueError, ConfigError, KeyError) as error:
        log.exception(error)
        context.abort()