1
1
import itertools
2
2
3
- import allel
4
3
import dask .array as da
5
4
import msprime # type: ignore
6
5
import numpy as np
7
6
import pytest
8
7
import tskit # type: ignore
9
8
import xarray as xr
10
- from allel import hudson_fst
11
9
from hypothesis import given , settings
12
10
from hypothesis import strategies as st
13
11
@@ -136,6 +134,8 @@ def test_diversity(sample_size, chunks, cohort_allele_count):
136
134
137
135
@pytest .mark .parametrize ("sample_size" , [10 ])
138
136
def test_diversity__windowed (sample_size ):
137
+ allel = pytest .importorskip ("allel" )
138
+
139
139
ts = simulate_ts (sample_size , length = 200 )
140
140
ds = ts_to_dataset (ts )
141
141
ds , subsets = add_cohorts (ds , ts , cohort_key_names = ["cohorts" ])
@@ -223,6 +223,8 @@ def test_divergence__windowed(sample_size, n_cohorts, chunks):
223
223
@pytest .mark .parametrize ("chunks" , [(- 1 , - 1 ), (50 , - 1 )])
224
224
@pytest .mark .xfail () # combine with test_divergence__windowed when this is passing
225
225
def test_divergence__windowed_scikit_allel_comparison (sample_size , n_cohorts , chunks ):
226
+ allel = pytest .importorskip ("allel" )
227
+
226
228
ts = simulate_ts (sample_size , length = 200 )
227
229
ds = ts_to_dataset (ts , chunks )
228
230
ds , subsets = add_cohorts (ds , ts , n_cohorts )
@@ -272,6 +274,8 @@ def test_divergence__missing_calls():
272
274
273
275
@pytest .mark .parametrize ("sample_size" , [2 , 3 , 10 , 100 ])
274
276
def test_Fst__Hudson (sample_size ):
277
+ allel = pytest .importorskip ("allel" )
278
+
275
279
# scikit-allel can only calculate Fst for pairs of cohorts (populations)
276
280
n_cohorts = 2
277
281
ts = simulate_ts (sample_size )
@@ -285,7 +289,7 @@ def test_Fst__Hudson(sample_size):
285
289
# scikit-allel
286
290
ac1 = ds .cohort_allele_count .values [:, 0 , :]
287
291
ac2 = ds .cohort_allele_count .values [:, 1 , :]
288
- num , den = hudson_fst (ac1 , ac2 )
292
+ num , den = allel . hudson_fst (ac1 , ac2 )
289
293
ska_fst = np .sum (num ) / np .sum (den )
290
294
291
295
np .testing .assert_allclose (fst , ska_fst )
@@ -326,6 +330,8 @@ def test_Fst__unknown_estimator():
326
330
)
327
331
@pytest .mark .parametrize ("chunks" , [(- 1 , - 1 ), (50 , - 1 )])
328
332
def test_Fst__windowed (sample_size , n_cohorts , chunks ):
333
+ allel = pytest .importorskip ("allel" )
334
+
329
335
ts = simulate_ts (sample_size , length = 200 )
330
336
ds = ts_to_dataset (ts , chunks )
331
337
ds , subsets = add_cohorts (ds , ts , n_cohorts )
@@ -395,6 +401,8 @@ def test_Tajimas_D_per_site(sample_size):
395
401
[(10 , 3 ), (20 , 4 )],
396
402
)
397
403
def test_pbs (sample_size , n_cohorts ):
404
+ allel = pytest .importorskip ("allel" )
405
+
398
406
ts = simulate_ts (sample_size )
399
407
ds = ts_to_dataset (ts )
400
408
ds , subsets = add_cohorts (
@@ -432,6 +440,8 @@ def test_pbs(sample_size, n_cohorts):
432
440
)
433
441
@pytest .mark .parametrize ("chunks" , [(- 1 , - 1 ), (50 , - 1 )])
434
442
def test_pbs__windowed (sample_size , n_cohorts , cohorts , cohort_indexes , chunks ):
443
+ allel = pytest .importorskip ("allel" )
444
+
435
445
ts = simulate_ts (sample_size , length = 200 )
436
446
ds = ts_to_dataset (ts , chunks )
437
447
ds , subsets = add_cohorts (
@@ -475,6 +485,8 @@ def test_pbs__windowed(sample_size, n_cohorts, cohorts, cohort_indexes, chunks):
475
485
def test_Garud_h (
476
486
n_variants , n_samples , n_contigs , n_cohorts , cohorts , cohort_indexes , chunks
477
487
):
488
+ allel = pytest .importorskip ("allel" )
489
+
478
490
ds = simulate_genotype_call_dataset (
479
491
n_variant = n_variants , n_sample = n_samples , n_contig = n_contigs
480
492
)
@@ -674,6 +686,8 @@ def test_observed_heterozygosity__windowed(chunks, cohorts, expectation):
674
686
def test_observed_heterozygosity__scikit_allel_comparison (
675
687
n_variant , n_sample , missing_pct , window_size , seed
676
688
):
689
+ allel = pytest .importorskip ("allel" )
690
+
677
691
ds = simulate_genotype_call_dataset (
678
692
n_variant = n_variant ,
679
693
n_sample = n_sample ,
0 commit comments