Skip to content

Commit 05a0fcc

Browse files
committed
Merged the _contig versions into the main versions
1 parent d8e7e97 commit 05a0fcc

File tree

4 files changed

+10
-227
lines changed

4 files changed

+10
-227
lines changed

malariagen_data/anoph/h12.py

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def plot_h12_calibration(
226226
else:
227227
return fig
228228

229-
def _h12_gwss_contig(
229+
def _h12_gwss(
230230
self,
231231
contig,
232232
analysis,
@@ -279,39 +279,6 @@ def _h12_gwss_contig(
279279

280280
return results
281281

282-
def _h12_gwss(
283-
self,
284-
contig,
285-
analysis,
286-
window_size,
287-
sample_sets,
288-
sample_query,
289-
sample_query_options,
290-
cohort_size,
291-
min_cohort_size,
292-
max_cohort_size,
293-
random_seed,
294-
chunks,
295-
inline_array,
296-
):
297-
results_tmp = self._h12_gwss_contig(
298-
contig=contig,
299-
analysis=analysis,
300-
window_size=window_size,
301-
sample_query=sample_query,
302-
sample_sets=sample_sets,
303-
sample_query_options=sample_query_options,
304-
cohort_size=cohort_size,
305-
min_cohort_size=min_cohort_size,
306-
max_cohort_size=max_cohort_size,
307-
random_seed=random_seed,
308-
chunks=chunks,
309-
inline_array=inline_array,
310-
)
311-
results = dict(x=results_tmp["x"], h12=results_tmp["h12"])
312-
313-
return results
314-
315282
@check_types
316283
@doc(
317284
summary="Run h12 genome-wide selection scan.",
@@ -321,7 +288,7 @@ def _h12_gwss(
321288
contigs="An array with the contig for each window. The median is chosen for windows overlapping a change of contig.",
322289
),
323290
)
324-
def h12_gwss_contig(
291+
def h12_gwss(
325292
self,
326293
contig: base_params.contig,
327294
window_size: h12_params.window_size,
@@ -364,9 +331,7 @@ def h12_gwss_contig(
364331
results = self.results_cache_get(name=name, params=params)
365332

366333
except CacheMiss:
367-
results = self._h12_gwss_contig(
368-
chunks=chunks, inline_array=inline_array, **params
369-
)
334+
results = self._h12_gwss(chunks=chunks, inline_array=inline_array, **params)
370335
self.results_cache_set(name=name, params=params, results=results)
371336

372337
x = results["x"]
@@ -375,65 +340,6 @@ def h12_gwss_contig(
375340

376341
return x, h12, contigs
377342

378-
@check_types
379-
@doc(
380-
summary="Run h12 genome-wide selection scan.",
381-
returns=dict(
382-
x="An array containing the window centre point genomic positions.",
383-
h12="An array with h12 statistic values for each window.",
384-
),
385-
)
386-
def h12_gwss(
387-
self,
388-
contig: base_params.contig,
389-
window_size: h12_params.window_size,
390-
analysis: hap_params.analysis = base_params.DEFAULT,
391-
sample_query: Optional[base_params.sample_query] = None,
392-
sample_query_options: Optional[base_params.sample_query_options] = None,
393-
sample_sets: Optional[base_params.sample_sets] = None,
394-
cohort_size: Optional[base_params.cohort_size] = h12_params.cohort_size_default,
395-
min_cohort_size: Optional[
396-
base_params.min_cohort_size
397-
] = h12_params.min_cohort_size_default,
398-
max_cohort_size: Optional[
399-
base_params.max_cohort_size
400-
] = h12_params.max_cohort_size_default,
401-
random_seed: base_params.random_seed = 42,
402-
chunks: base_params.chunks = base_params.native_chunks,
403-
inline_array: base_params.inline_array = base_params.inline_array_default,
404-
) -> Tuple[np.ndarray, np.ndarray]:
405-
# Change this name if you ever change the behaviour of this function, to
406-
# invalidate any previously cached data.
407-
name = "h12_gwss_v1"
408-
409-
params = dict(
410-
contig=contig,
411-
analysis=self._prep_phasing_analysis_param(analysis=analysis),
412-
window_size=window_size,
413-
sample_sets=self._prep_sample_sets_param(sample_sets=sample_sets),
414-
# N.B., do not be tempted to convert this sample query into integer
415-
# indices using _prep_sample_selection_params, because the indices
416-
# are different in the haplotype data.
417-
sample_query=sample_query,
418-
sample_query_options=sample_query_options,
419-
cohort_size=cohort_size,
420-
min_cohort_size=min_cohort_size,
421-
max_cohort_size=max_cohort_size,
422-
random_seed=random_seed,
423-
)
424-
425-
try:
426-
results = self.results_cache_get(name=name, params=params)
427-
428-
except CacheMiss:
429-
results = self._h12_gwss(chunks=chunks, inline_array=inline_array, **params)
430-
self.results_cache_set(name=name, params=params, results=results)
431-
432-
x = results["x"]
433-
h12 = results["h12"]
434-
435-
return x, h12
436-
437343
@check_types
438344
@doc(
439345
summary="Plot h12 GWSS data.",
@@ -466,7 +372,7 @@ def plot_h12_gwss_track(
466372
inline_array: base_params.inline_array = base_params.inline_array_default,
467373
) -> gplt_params.figure:
468374
# Compute H12.
469-
x, h12, contigs = self.h12_gwss_contig(
375+
x, h12, contigs = self.h12_gwss(
470376
contig=contig,
471377
analysis=analysis,
472378
window_size=window_size,

malariagen_data/anoph/h1x.py

Lines changed: 4 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(
2424
# to the superclass constructor.
2525
super().__init__(**kwargs)
2626

27-
def _h1x_gwss_contig(
27+
def _h1x_gwss(
2828
self,
2929
contig,
3030
analysis,
@@ -93,40 +93,6 @@ def _h1x_gwss_contig(
9393

9494
return results
9595

96-
def _h1x_gwss(
97-
self,
98-
contig,
99-
analysis,
100-
window_size,
101-
sample_sets,
102-
cohort1_query,
103-
cohort2_query,
104-
cohort_size,
105-
min_cohort_size,
106-
max_cohort_size,
107-
random_seed,
108-
chunks,
109-
inline_array,
110-
):
111-
results_tmp = self._h1x_gwss_contig(
112-
contig=contig,
113-
analysis=analysis,
114-
window_size=window_size,
115-
cohort1_query=cohort1_query,
116-
cohort2_query=cohort2_query,
117-
sample_sets=sample_sets,
118-
cohort_size=cohort_size,
119-
min_cohort_size=min_cohort_size,
120-
max_cohort_size=max_cohort_size,
121-
random_seed=random_seed,
122-
chunks=chunks,
123-
inline_array=inline_array,
124-
)
125-
126-
results = dict(x=results_tmp["x"], h1x=results_tmp["h1x"])
127-
128-
return results
129-
13096
@check_types
13197
@doc(
13298
summary="""
@@ -139,7 +105,7 @@ def _h1x_gwss(
139105
contigs="An array with the contig for each window. The median is chosen for windows overlapping a change of contig.",
140106
),
141107
)
142-
def h1x_gwss_contig(
108+
def h1x_gwss(
143109
self,
144110
contig: base_params.contig,
145111
window_size: h12_params.window_size,
@@ -182,9 +148,7 @@ def h1x_gwss_contig(
182148
results = self.results_cache_get(name=name, params=params)
183149

184150
except CacheMiss:
185-
results = self._h1x_gwss_contig(
186-
chunks=chunks, inline_array=inline_array, **params
187-
)
151+
results = self._h1x_gwss(chunks=chunks, inline_array=inline_array, **params)
188152
self.results_cache_set(name=name, params=params, results=results)
189153

190154
x = results["x"]
@@ -193,68 +157,6 @@ def h1x_gwss_contig(
193157

194158
return x, h1x, contigs
195159

196-
@check_types
197-
@doc(
198-
summary="""
199-
Run a H1X genome-wide scan to detect genome regions with
200-
shared selective sweeps between two cohorts.
201-
""",
202-
returns=dict(
203-
x="An array containing the window centre point genomic positions.",
204-
h1x="An array with H1X statistic values for each window.",
205-
),
206-
)
207-
def h1x_gwss(
208-
self,
209-
contig: base_params.contig,
210-
window_size: h12_params.window_size,
211-
cohort1_query: base_params.sample_query,
212-
cohort2_query: base_params.sample_query,
213-
analysis: hap_params.analysis = base_params.DEFAULT,
214-
sample_sets: Optional[base_params.sample_sets] = None,
215-
cohort_size: Optional[base_params.cohort_size] = h12_params.cohort_size_default,
216-
min_cohort_size: Optional[
217-
base_params.min_cohort_size
218-
] = h12_params.min_cohort_size_default,
219-
max_cohort_size: Optional[
220-
base_params.max_cohort_size
221-
] = h12_params.max_cohort_size_default,
222-
random_seed: base_params.random_seed = 42,
223-
chunks: base_params.chunks = base_params.native_chunks,
224-
inline_array: base_params.inline_array = base_params.inline_array_default,
225-
) -> Tuple[np.ndarray, np.ndarray]:
226-
# Change this name if you ever change the behaviour of this function, to
227-
# invalidate any previously cached data.
228-
name = "h1x_gwss_v1"
229-
230-
params = dict(
231-
contig=contig,
232-
analysis=self._prep_phasing_analysis_param(analysis=analysis),
233-
window_size=window_size,
234-
# N.B., do not be tempted to convert these sample queries into integer
235-
# indices using _prep_sample_selection_params, because the indices
236-
# are different in the haplotype data.
237-
cohort1_query=cohort1_query,
238-
cohort2_query=cohort2_query,
239-
sample_sets=self._prep_sample_sets_param(sample_sets=sample_sets),
240-
cohort_size=cohort_size,
241-
min_cohort_size=min_cohort_size,
242-
max_cohort_size=max_cohort_size,
243-
random_seed=random_seed,
244-
)
245-
246-
try:
247-
results = self.results_cache_get(name=name, params=params)
248-
249-
except CacheMiss:
250-
results = self._h1x_gwss(chunks=chunks, inline_array=inline_array, **params)
251-
self.results_cache_set(name=name, params=params, results=results)
252-
253-
x = results["x"]
254-
h1x = results["h1x"]
255-
256-
return x, h1x
257-
258160
@check_types
259161
@doc(
260162
summary="""
@@ -290,7 +192,7 @@ def plot_h1x_gwss_track(
290192
inline_array: base_params.inline_array = base_params.inline_array_default,
291193
) -> gplt_params.figure:
292194
# Compute H1X.
293-
x, h1x, contigs = self.h1x_gwss_contig(
195+
x, h1x, contigs = self.h1x_gwss(
294196
contig=contig,
295197
analysis=analysis,
296198
window_size=window_size,

tests/anoph/test_h12.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,8 @@ def test_h12_calibration(fixture, api: AnophelesH12Analysis):
129129

130130
def check_h12_gwss(*, api, h12_params):
131131
# Run main gwss function under test.
132-
x, h12 = api.h12_gwss(**h12_params)
133132

134-
# Check results.
135-
assert isinstance(x, np.ndarray)
136-
assert isinstance(h12, np.ndarray)
137-
assert x.ndim == 1
138-
assert h12.ndim == 1
139-
assert x.shape == h12.shape
140-
assert x.dtype.kind == "f"
141-
assert h12.dtype.kind == "f"
142-
assert np.all(h12 >= 0)
143-
assert np.all(h12 <= 1)
144-
145-
x, h12, contigs = api.h12_gwss_contig(**h12_params)
133+
x, h12, contigs = api.h12_gwss(**h12_params)
146134

147135
# Check results.
148136
assert isinstance(x, np.ndarray)

tests/anoph/test_h1x.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,7 @@ def test_haplotype_joint_frequencies():
110110

111111
def check_h1x_gwss(*, api, h1x_params):
112112
# Run main gwss function under test.
113-
x, h1x = api.h1x_gwss(**h1x_params)
114-
115-
# Check results.
116-
assert isinstance(x, np.ndarray)
117-
assert isinstance(h1x, np.ndarray)
118-
assert x.ndim == 1
119-
assert h1x.ndim == 1
120-
assert x.shape == h1x.shape
121-
assert x.dtype.kind == "f"
122-
assert h1x.dtype.kind == "f"
123-
assert np.all(h1x >= 0)
124-
assert np.all(h1x <= 1)
125-
126-
x, h1x, contigs = api.h1x_gwss_contig(**h1x_params)
113+
x, h1x, contigs = api.h1x_gwss(**h1x_params)
127114

128115
# Check results.
129116
assert isinstance(x, np.ndarray)

0 commit comments

Comments
 (0)