|
a |
|
b/tests/cli/test_contrib.py |
|
|
1 |
"""Test bpnet contrib |
|
|
2 |
""" |
|
|
3 |
import pytest |
|
|
4 |
from bpnet.cli.contrib import bpnet_contrib, ContribFile |
|
|
5 |
import keras.backend as K |
|
|
6 |
|
|
|
7 |
|
|
|
8 |
@pytest.mark.parametrize("method", ['deeplift', 'grad']) |
|
|
9 |
def test_contrib_bias_model(tmp_path, method, trained_model_w_bias): |
|
|
10 |
"""Test whether we can compute differnet contribution scores |
|
|
11 |
""" |
|
|
12 |
K.clear_session() |
|
|
13 |
fpath = tmp_path / 'imp-score.h5' |
|
|
14 |
bpnet_contrib(str(trained_model_w_bias), |
|
|
15 |
str(fpath), |
|
|
16 |
method=method) |
|
|
17 |
|
|
|
18 |
cf = ContribFile(fpath) |
|
|
19 |
assert cf.get_contrib()['Task1'].shape[-1] == 4 |
|
|
20 |
|
|
|
21 |
|
|
|
22 |
@pytest.mark.parametrize("method", ['deeplift', 'grad']) |
|
|
23 |
def test_contrib_default_model(tmp_path, method, trained_model): |
|
|
24 |
"""Test whether we can compute differnet contribution scores |
|
|
25 |
""" |
|
|
26 |
K.clear_session() |
|
|
27 |
fpath = tmp_path / 'imp-score.h5' |
|
|
28 |
bpnet_contrib(str(trained_model), |
|
|
29 |
str(fpath), |
|
|
30 |
method=method) |
|
|
31 |
|
|
|
32 |
cf = ContribFile(fpath) |
|
|
33 |
assert cf.get_contrib()['Task1'].shape[-1] == 4 |
|
|
34 |
|
|
|
35 |
|
|
|
36 |
@pytest.mark.parametrize("method", ['grad']) |
|
|
37 |
def test_contrib_regions(tmp_path, method, trained_model, regions): |
|
|
38 |
"""Test different scenarios regarding subsetting |
|
|
39 |
""" |
|
|
40 |
K.clear_session() |
|
|
41 |
bpnet_contrib(str(trained_model), |
|
|
42 |
str(tmp_path / 'imp-score.h5'), |
|
|
43 |
method=method, |
|
|
44 |
regions=str(regions)) |
|
|
45 |
|
|
|
46 |
|
|
|
47 |
@pytest.mark.parametrize("method", ['grad']) |
|
|
48 |
def test_contrib_dataspec(tmp_path, method, trained_model, dataspec_bias, regions): |
|
|
49 |
"""Test different scenarios regarding subsetting |
|
|
50 |
""" |
|
|
51 |
K.clear_session() |
|
|
52 |
bpnet_contrib(str(trained_model), |
|
|
53 |
str(tmp_path / 'imp-score.h5'), |
|
|
54 |
method=method, |
|
|
55 |
dataspec=str(dataspec_bias), |
|
|
56 |
regions=str(regions)) |
|
|
57 |
|
|
|
58 |
|
|
|
59 |
@pytest.mark.parametrize("method", ['grad']) |
|
|
60 |
def test_contrib_fasta_file(tmp_path, method, trained_model, fasta_file, regions): |
|
|
61 |
"""Test different scenarios regarding subsetting |
|
|
62 |
""" |
|
|
63 |
K.clear_session() |
|
|
64 |
bpnet_contrib(str(trained_model), |
|
|
65 |
str(tmp_path / 'imp-score.h5'), |
|
|
66 |
method=method, |
|
|
67 |
fasta_file=str(fasta_file), |
|
|
68 |
regions=str(regions)) |
|
|
69 |
|
|
|
70 |
|
|
|
71 |
@pytest.mark.parametrize("method", ['grad']) |
|
|
72 |
def test_contrib_dataspec_fasta_file(tmp_path, method, trained_model, dataspec_bias, fasta_file): |
|
|
73 |
"""Test different scenarios regarding subsetting |
|
|
74 |
""" |
|
|
75 |
K.clear_session() |
|
|
76 |
with pytest.raises(ValueError): |
|
|
77 |
bpnet_contrib(str(trained_model), |
|
|
78 |
str(tmp_path / 'imp-score.h5'), |
|
|
79 |
method=method, |
|
|
80 |
fasta_file=str(fasta_file), |
|
|
81 |
dataspec=str(dataspec_bias)) |