Ejemplo n.º 1
0
def test_calc_empty_variants(fake_phenotype_data):
    pheno_tool = PhenoTool(fake_phenotype_data, "i1.m1")
    variants = Counter({})

    res = pheno_tool.calc(variants)
    assert isinstance(res, PhenoResult)
    assert res.positive_count == 0
    assert res.positive_mean == 0
    assert res.positive_deviation == 0
    assert res.negative_count == len(pheno_tool.pheno_df)
    assert res.negative_mean
    assert res.negative_deviation
    assert res.pvalue == "NA"

    resM, resF = pheno_tool.calc(variants, sex_split=True).values()
    assert isinstance(resM, PhenoResult)
    assert isinstance(resF, PhenoResult)

    assert resM.positive_count == 0
    assert resM.positive_mean == 0
    assert resM.positive_deviation == 0
    assert resM.negative_count == res.negative_count - resF.negative_count
    assert resM.negative_mean
    assert resM.negative_deviation
    assert resM.pvalue == "NA"

    assert resF.positive_count == 0
    assert resF.positive_mean == 0
    assert resF.positive_deviation == 0
    assert resF.negative_count == res.negative_count - resM.negative_count
    assert resF.negative_mean
    assert resF.negative_deviation
    assert resF.pvalue == "NA"
Ejemplo n.º 2
0
def test_calc_split_by_sex(mocker, fake_phenotype_data):
    pheno_tool = PhenoTool(fake_phenotype_data, "i1.m1")
    variants = Counter({
        "f4.p1": 1,
        "f5.p1": 1,
        "f7.p1": 1,
        "f10.p1": 1,
        "f12.p1": 1,
        "f16.p1": 1,
        "f24.p1": 1,
        "f25.p1": 1,
        "f30.p1": 1,
        "f32.p1": 1,
    })
    merged_df = PhenoTool.join_pheno_df_with_variants(pheno_tool.pheno_df,
                                                      variants)

    mocker.spy(PhenoTool, "join_pheno_df_with_variants")
    mocker.spy(pheno_tool, "_calc_stats")

    pheno_tool.calc(variants, sex_split=True)

    assert pheno_tool._calc_stats.call_count == 2
    assert PhenoTool.join_pheno_df_with_variants.call_count == 1

    call_arg_df, call_arg_sex_split = pheno_tool._calc_stats.call_args_list[0][
        0]
    assert merged_df.equals(call_arg_df)
    assert call_arg_sex_split is Sex.M

    call_arg_df, call_arg_sex_split = pheno_tool._calc_stats.call_args_list[1][
        0]
    assert merged_df.equals(call_arg_df)
    assert call_arg_sex_split is Sex.F
Ejemplo n.º 3
0
def test_calc(mocker, fake_phenotype_data):
    pheno_tool = PhenoTool(fake_phenotype_data, "i1.m1")
    variants = Counter({
        "f4.p1": 1,
        "f5.p1": 1,
        "f7.p1": 1,
        "f10.p1": 1,
        "f12.p1": 1,
        "f16.p1": 1,
        "f24.p1": 1,
        "f25.p1": 1,
        "f30.p1": 1,
        "f32.p1": 1,
    })
    merged_df = PhenoTool.join_pheno_df_with_variants(pheno_tool.pheno_df,
                                                      variants)

    mocker.spy(PhenoTool, "join_pheno_df_with_variants")
    mocker.spy(pheno_tool, "_calc_stats")

    pheno_tool.calc(variants, sex_split=False)

    pheno_tool._calc_stats.assert_called_once()
    PhenoTool.join_pheno_df_with_variants.assert_called_once()

    call_arg_df, call_arg_sex_split = pheno_tool._calc_stats.call_args_list[0][
        0]
    assert merged_df.equals(call_arg_df)
    assert call_arg_sex_split is None
Ejemplo n.º 4
0
def test_calc_empty_pheno_df(fake_phenotype_data):
    pheno_tool = PhenoTool(fake_phenotype_data, "i1.m1", person_ids=[])
    variants = Counter({
        "f4.p1": 1,
        "f5.p1": 1,
        "f7.p1": 1,
        "f10.p1": 1,
        "f12.p1": 1,
        "f16.p1": 1,
        "f24.p1": 1,
        "f25.p1": 1,
        "f30.p1": 1,
        "f32.p1": 1,
    })

    res = pheno_tool.calc(variants)
    assert isinstance(res, PhenoResult)
    assert res.positive_count == 0
    assert res.positive_mean == 0
    assert res.positive_deviation == 0
    assert res.negative_count == 0
    assert res.negative_mean == 0
    assert res.negative_deviation == 0
    assert res.pvalue == "NA"

    resM, resF = pheno_tool.calc(variants, sex_split=True).values()
    assert isinstance(resM, PhenoResult)
    assert isinstance(resF, PhenoResult)

    assert resM.positive_count == 0
    assert resM.positive_mean == 0
    assert resM.positive_deviation == 0
    assert resM.negative_count == 0
    assert resM.negative_mean == 0
    assert resM.negative_deviation == 0
    assert resM.pvalue == "NA"

    assert resF.positive_count == 0
    assert resF.positive_mean == 0
    assert resF.positive_deviation == 0
    assert resF.negative_count == 0
    assert resF.negative_mean == 0
    assert resF.negative_deviation == 0
    assert resF.pvalue == "NA"