@@ -577,7 +577,15 @@ def test_observed_heterozygosity(chunks):
577
577
578
578
579
579
@pytest .mark .parametrize ("chunks" , [((4 ,), (6 ,), (4 ,)), ((2 , 2 ), (3 , 3 ), (2 , 2 ))])
580
- def test_observed_heterozygosity__windowed (chunks ):
580
+ @pytest .mark .parametrize (
581
+ "cohorts,expectation" ,
582
+ [
583
+ ([0 , 0 , 1 , 1 , 2 , 2 ], [[1 / 4 , 2 / 3 , 2 / 3 ], [1 / 2 , 5 / 3 , np .nan ]]),
584
+ ([2 , 2 , 1 , 1 , 0 , 0 ], [[2 / 3 , 2 / 3 , 1 / 4 ], [np .nan , 5 / 3 , 1 / 2 ]]),
585
+ ([- 1 , - 1 , 1 , 1 , 0 , 0 ], [[2 / 3 , 2 / 3 ], [np .nan , 5 / 3 ]]),
586
+ ],
587
+ )
588
+ def test_observed_heterozygosity__windowed (chunks , cohorts , expectation ):
581
589
ds = simulate_genotype_call_dataset (
582
590
n_variant = 4 ,
583
591
n_sample = 6 ,
@@ -625,18 +633,13 @@ def test_observed_heterozygosity__windowed(chunks):
625
633
ds .call_genotype_mask .values = ds .call_genotype < 0
626
634
ds ["sample_cohort" ] = (
627
635
["samples" ],
628
- da .asarray ([ 0 , 0 , 1 , 1 , 2 , 2 ] ).rechunk (chunks [1 ]),
636
+ da .asarray (cohorts ).rechunk (chunks [1 ]),
629
637
)
630
638
ds = window (ds , size = 2 )
631
639
ho = observed_heterozygosity (ds )["stat_observed_heterozygosity" ]
632
640
np .testing .assert_almost_equal (
633
641
ho ,
634
- np .array (
635
- [
636
- [1 / 4 , 2 / 3 , 2 / 3 ],
637
- [1 / 2 , 5 / 3 , np .nan ],
638
- ]
639
- ),
642
+ np .array (expectation ),
640
643
)
641
644
642
645
0 commit comments