def test_ret():
    pps = PostProcModelStruct.from_config(
        from_yaml(postproc_yaml % ('', args_w_default)))
    model = dummy_container()
    model.postprocessing = pps
    avail_scoring_fns, avail_scoring_fn_def_args, avail_scoring_fn_names, default_scoring_fns = get_avail_scoring_methods(
        model)
示例#2
0
def test_use_rc():
    pps = PostProcModelStruct.from_config(from_yaml(yaml_in_simple_rc))
    assert pps.variant_effects is not None
    assert pps.variant_effects.seq_input == [
        "seq"
    ]  # should always be there and is always a list of strings
    assert pps.variant_effects.use_rc
def test_auto_default():
    pps = PostProcModelStruct.from_config(from_yaml(postproc_autodefault_yaml))
    model = dummy_container()
    model.postprocessing = pps
    avail_scoring_fns, avail_scoring_fn_def_args, avail_scoring_fn_names, default_scoring_fns = \
        get_avail_scoring_methods(model)
    output = [avail_scoring_fn_names]
    expected = [default_scoring_fns + ["logit_ref", "diff", "ref", "alt"]]
    assert_groupwise_identity(output, expected)
示例#4
0
def test_rename_custom():
    pps = PostProcModelStruct.from_config(from_yaml(rename_custom_yaml))
    model = dummy_container()
    model.postprocessing = pps
    avail_scoring_fns, avail_scoring_fn_def_args, avail_scoring_fn_names, default_scoring_fns =\
        get_avail_scoring_fns(model)
    output = [avail_scoring_fn_names]
    expected = [["custom_logit", "diff", "ref", "alt", "logit_ref", "logit", "deepsea_effect"]]
    assert_groupwise_identity(output, expected)
    assert default_scoring_fns == ["custom_logit"]
示例#5
0
def test_default_diff():
    pps = PostProcModelStruct.from_config(from_yaml(postproc_yaml_nofndef))
    model = dummy_container()
    model.postprocessing = pps
    avail_scoring_fns, avail_scoring_fn_def_args, avail_scoring_fn_names, default_scoring_fns =\
        get_avail_scoring_fns(model)
    #
    output = [avail_scoring_fn_names, avail_scoring_fns, avail_scoring_fn_def_args]
    expected = [["diff", "ref", "alt"], [ve.Diff, ve.Ref, ve.Alt], [builtin_default_kwargs] * 3]
    assert_groupwise_identity(output, expected)
    assert default_scoring_fns == ["diff"]
def test_custom_fns():
    template_avail_scoring_fns = [ve.Logit, ve.DeepSEA_effect, ve.LogitAlt]
    template_avail_scoring_fn_labels = ["logit", "deepsea_effect", "mydiff"]
    #
    exp_avail_scoring_fns = [
        template_avail_scoring_fns + [ve.Diff] + [ve.Ref, ve.Alt, ve.LogitRef],
        [ve.Diff] + template_avail_scoring_fns + [ve.Ref, ve.Alt, ve.LogitRef]
    ]
    exp_avail_scoring_fn_labels = [
        template_avail_scoring_fn_labels + ["diff"] +
        ["ref", "alt", "logit_ref"], ["diff"] +
        template_avail_scoring_fn_labels + ["ref", "alt", "logit_ref"]
    ]
    #
    for i, diff_str_here in enumerate(["", diff_str]):
        if diff_str_here == "":
            exp_avail_scoring_fn_def_args = [
                None, [builtin_default_kwargs] * 2 + [{
                    "rc_merging": "max"
                }] + [builtin_default_kwargs] * 4,
                [builtin_default_kwargs] * 2 + [{}] +
                [builtin_default_kwargs] * 5
            ]
        else:
            exp_avail_scoring_fn_def_args = [
                None, [builtin_default_kwargs] * 3 + [{
                    "rc_merging": "max"
                }] + [builtin_default_kwargs] * 4,
                [builtin_default_kwargs] * 3 + [{}] +
                [builtin_default_kwargs] * 5
            ]
        for i2, mydiff_args in enumerate(["", args_w_default, optional_args]):
            pps = PostProcModelStruct.from_config(
                from_yaml(postproc_yaml % (diff_str_here, mydiff_args)))
            model = dummy_container()
            model.postprocessing = pps
            if i2 == 0:
                # mydiff has one argument but none are defined.
                with pytest.raises(ValueError):
                    get_avail_scoring_methods(model)
            else:
                avail_scoring_fns, avail_scoring_fn_def_args, avail_scoring_fn_names, default_scoring_fns =\
                    get_avail_scoring_methods(model)
                output = [
                    avail_scoring_fn_names, avail_scoring_fns,
                    avail_scoring_fn_def_args
                ]
                expected = [
                    exp_avail_scoring_fn_labels[i], exp_avail_scoring_fns[i],
                    exp_avail_scoring_fn_def_args[i2]
                ]
                assert_groupwise_identity(output, expected)
                assert default_scoring_fns == ["deepsea_effect"]
示例#7
0
def test__get_scoring_fns():
    pps = PostProcModelStruct.from_config(from_yaml(postproc_cli_yaml))
    model = dummy_container()
    model.postprocessing = pps
    scorers = [{"logit": ve.Logit, "deepsea_effect": ve.DeepSEA_effect}, {"logit": ve.Logit}, {}]
    kwargs = {"rc_merging": 'max'}
    for sel_scoring_labels, scorer in zip([[], ["logit"], ["inexistent", "logit"], ["all"]], scorers):
        jk_list = [kwargs] * len(sel_scoring_labels)
        for sel_scoring_kwargs in [[], jk_list]:
            if "inexistent" in sel_scoring_labels:
                with pytest.warns(None):
                    dts = get_scoring_fns(model, sel_scoring_labels, sel_scoring_kwargs)
            else:
                dts = get_scoring_fns(model, sel_scoring_labels, sel_scoring_kwargs)
                for k in scorer:
                    assert isinstance(dts[k], scorer[k])
    with pytest.raises(Exception):
        get_scoring_fns(model, ["all"], [kwargs])
示例#8
0
def test_complex_example():
    pps = PostProcModelStruct.from_config(from_yaml(yaml_in))
    ppsv = pps.variant_effects
    assert ppsv.seq_input == [
        "seq"
    ]  # should always be there and is always a list of strings
    scoring_fns = [{
        "name": "diff",
        "type": VarEffectFuncType.diff,
        "default": False
    }, {
        "type": VarEffectFuncType.logit,
        "default": False
    }, {
        "default": True,
        "type": VarEffectFuncType.deepsea_effect
    }, {
        "name": "mydiff",
        "type": VarEffectFuncType.custom,
        "defined_as": "postproc.py::myfun",
        "default": False
    }]

    for in_obj, fn in zip(ppsv.scoring_functions, scoring_fns):
        for k in fn:
            if k == "type":
                assert in_obj.type is fn["type"]
            else:
                assert getattr(in_obj, k) == fn[k]

    expected_args = {
        "first_arg": {
            "doc": "blablabla1",
            "default": "1"
        },
        "second_arg": {
            "doc": "blablabla",
            "default": "10"
        }
    }
    custom_fn_args = ppsv.scoring_functions[-1].args
    for k in expected_args:
        for k2 in expected_args[k]:
            assert getattr(custom_fn_args[k], k2) == expected_args[k][k2]
def test_insufficient_info():
    assert PostProcModelStruct.from_config(from_yaml(yaml_in_no_args)).variant_effects is None
def test_dupl_name():
    pps = PostProcModelStruct.from_config(from_yaml(dupl_name_yaml))
    model = dummy_container()
    model.postprocessing = pps
    with pytest.raises(Exception):
        get_avail_scoring_methods(model)