|
a |
|
b/tests/conftest.py |
|
|
1 |
""" |
|
|
2 |
""" |
|
|
3 |
import os |
|
|
4 |
from pytest import fixture |
|
|
5 |
from pathlib import Path |
|
|
6 |
import gdown |
|
|
7 |
from bpnet.cli.train import bpnet_train |
|
|
8 |
from bpnet.cli.contrib import bpnet_contrib |
|
|
9 |
import gin |
|
|
10 |
import keras.backend as K |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
@fixture(scope='session') |
|
|
14 |
def test_dir(): |
|
|
15 |
import inspect |
|
|
16 |
filename = inspect.getframeinfo(inspect.currentframe()).filename |
|
|
17 |
return Path(os.path.dirname(os.path.abspath(filename))) |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
@fixture(scope='session') |
|
|
21 |
def data_dir(test_dir): |
|
|
22 |
return test_dir / 'data' |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
@fixture(scope='session') |
|
|
26 |
def fasta_file(data_dir): |
|
|
27 |
return data_dir / 'dummy/dummy.fa' |
|
|
28 |
|
|
|
29 |
|
|
|
30 |
@fixture(scope='session') |
|
|
31 |
def regions(data_dir): |
|
|
32 |
return data_dir / 'dummy/peaks.bed' |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
@fixture(scope='session') |
|
|
36 |
def genome_file(data_dir): |
|
|
37 |
return data_dir / 'dummy/dummy.genome' |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
@fixture(scope='session') |
|
|
41 |
def dataspec_task1(data_dir): |
|
|
42 |
return data_dir / 'dataspec.task1.yml' |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
@fixture(scope='session') |
|
|
46 |
def dataspec_bias(data_dir): |
|
|
47 |
return data_dir / 'dataspec.w-bias.yml' |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
@fixture(scope='session') |
|
|
51 |
def dataspec_bed6(data_dir): |
|
|
52 |
return data_dir / 'dataspec.bed6.yml' |
|
|
53 |
|
|
|
54 |
|
|
|
55 |
@fixture(scope='session') |
|
|
56 |
def config_gin(data_dir): |
|
|
57 |
return data_dir / 'config.gin' |
|
|
58 |
|
|
|
59 |
|
|
|
60 |
@fixture(scope='session') |
|
|
61 |
def modisco_config_gin(data_dir): |
|
|
62 |
return data_dir / 'modisco-config.gin' |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
@fixture(scope="session") |
|
|
66 |
def trained_model(data_dir, dataspec_task1, config_gin): |
|
|
67 |
K.clear_session() |
|
|
68 |
gin.clear_config() |
|
|
69 |
bpnet_train(dataspec=dataspec_task1, |
|
|
70 |
output_dir=data_dir, |
|
|
71 |
run_id='trained_model', |
|
|
72 |
premade='bpnet9', |
|
|
73 |
config=str(config_gin), |
|
|
74 |
num_workers=1, |
|
|
75 |
overwrite=True |
|
|
76 |
) |
|
|
77 |
return data_dir / 'trained_model' |
|
|
78 |
|
|
|
79 |
|
|
|
80 |
@fixture(scope="session") |
|
|
81 |
def trained_model_w_bias(config_gin, data_dir, dataspec_bias): |
|
|
82 |
K.clear_session() |
|
|
83 |
gin.clear_config() |
|
|
84 |
bpnet_train(dataspec=str(dataspec_bias), |
|
|
85 |
output_dir=str(data_dir), |
|
|
86 |
run_id='trained_model_w_bias', |
|
|
87 |
premade='bpnet9', |
|
|
88 |
config=str(config_gin), |
|
|
89 |
num_workers=1, |
|
|
90 |
overwrite=True, |
|
|
91 |
) |
|
|
92 |
return data_dir / 'trained_model_w_bias' |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
@fixture(scope='session') |
|
|
96 |
def contrib_score_grad(trained_model): |
|
|
97 |
K.clear_session() |
|
|
98 |
fpath = trained_model / 'imp-score.grad.fixture.h5' |
|
|
99 |
bpnet_contrib(str(trained_model), |
|
|
100 |
str(fpath), |
|
|
101 |
method='grad', |
|
|
102 |
overwrite=True) |
|
|
103 |
return fpath |
|
|
104 |
|
|
|
105 |
|
|
|
106 |
@fixture(scope='session') |
|
|
107 |
def contrib_score_grad_null(trained_model): |
|
|
108 |
K.clear_session() |
|
|
109 |
fpath = trained_model / 'imp-score.grad.null.fixture.h5' |
|
|
110 |
bpnet_contrib(str(trained_model), |
|
|
111 |
str(fpath), |
|
|
112 |
method='grad', |
|
|
113 |
shuffle_seq=True, |
|
|
114 |
max_regions=16, |
|
|
115 |
overwrite=True) |
|
|
116 |
return fpath |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
@fixture(scope='session') |
|
|
120 |
def download_dir(): |
|
|
121 |
dir_path = '/tmp/bpnet' |
|
|
122 |
os.makedirs(dir_path, exist_ok=True) |
|
|
123 |
return Path(dir_path) |
|
|
124 |
|
|
|
125 |
|
|
|
126 |
@fixture(scope='session') |
|
|
127 |
def contrib_file(download_dir): |
|
|
128 |
"""Download the contributon file |
|
|
129 |
""" |
|
|
130 |
contrib_file = download_dir / 'contrib.deeplift.h5' |
|
|
131 |
url = 'https://drive.google.com/uc?id=1-70VlFvcOCwwt4SrEXoqkaXyBQPnlQGZ' |
|
|
132 |
md5 = '56e456f0d1aeffc9d3fcdfead0520c17' |
|
|
133 |
gdown.cached_download(url, str(contrib_file), md5=md5) |
|
|
134 |
return contrib_file |
|
|
135 |
|
|
|
136 |
|
|
|
137 |
@fixture(scope='session') |
|
|
138 |
def modisco_dir(download_dir): |
|
|
139 |
"""Download the contributon file |
|
|
140 |
""" |
|
|
141 |
_modisco_dir = download_dir / 'Oct4' |
|
|
142 |
_modisco_dir.mkdir(exist_ok=True) |
|
|
143 |
|
|
|
144 |
path = _modisco_dir / 'modisco-run.subset-contrib-file.npy' |
|
|
145 |
url = 'https://drive.google.com/uc?id=11uW8WaJ2EZuXQXUPq9g_TqrmWYTF-59V' |
|
|
146 |
md5 = '5b1425618cf87127f5a02cf54b2e361a' |
|
|
147 |
gdown.cached_download(url, str(path), md5=md5) |
|
|
148 |
|
|
|
149 |
path = _modisco_dir / 'modisco-run.kwargs.json' |
|
|
150 |
url = 'https://drive.google.com/uc?id=1zExhfQZ0-3irlpK6RrG1M-FBXvjHuQdm' |
|
|
151 |
md5 = '6bb33a8a0a2d0745ea9bf1ab2f5d241d' |
|
|
152 |
gdown.cached_download(url, str(path), md5=md5) |
|
|
153 |
|
|
|
154 |
path = _modisco_dir / 'modisco.h5' |
|
|
155 |
url = 'https://drive.google.com/uc?id=10owbBEB3PasIBSnMJ6KZQmJjbsyzhEgG' |
|
|
156 |
md5 = '8132fdbe7095748e8b229e81db45a6c9' |
|
|
157 |
gdown.cached_download(url, str(path), md5=md5) |
|
|
158 |
|
|
|
159 |
return _modisco_dir |
|
|
160 |
|
|
|
161 |
|
|
|
162 |
@fixture(scope='session') |
|
|
163 |
def mf(modisco_dir): |
|
|
164 |
"""ModiscoFile |
|
|
165 |
""" |
|
|
166 |
from bpnet.modisco.files import ModiscoFile |
|
|
167 |
mf = ModiscoFile(modisco_dir / 'modisco.h5') |
|
|
168 |
return mf |
|
|
169 |
|
|
|
170 |
|
|
|
171 |
@fixture(scope='session') |
|
|
172 |
def mfg(mf): |
|
|
173 |
"""ModiscoFile |
|
|
174 |
""" |
|
|
175 |
from bpnet.modisco.files import ModiscoFileGroup |
|
|
176 |
return ModiscoFileGroup({"Oct4": mf, "Sox2": mf}) |