@@ -813,6 +813,9 @@ def Garud_h(
813
813
if ds .dims ["ploidy" ] != 2 :
814
814
raise NotImplementedError ("Garud H only implemented for diploid genotypes" )
815
815
816
+ if not has_windows (ds ):
817
+ raise ValueError ("Dataset must be windowed for Garud_h" )
818
+
816
819
variables .validate (ds , {call_genotype : variables .call_genotype_spec })
817
820
818
821
gt = ds [call_genotype ]
@@ -822,51 +825,36 @@ def Garud_h(
822
825
hsc = np .stack ((sc , sc ), axis = 1 ).ravel () # TODO: assumes diploid
823
826
n_cohorts = sc .max () + 1 # 0-based indexing
824
827
825
- if has_windows (ds ):
826
- gh = window_statistic (
827
- gt ,
828
- lambda gt : _Garud_h_cohorts (gt , hsc , n_cohorts ),
829
- ds .window_start .values ,
830
- ds .window_stop .values ,
831
- dtype = np .float64 ,
832
- # first chunks dimension is windows, computed in window_statistic
833
- chunks = (- 1 , n_cohorts , N_GARUD_H_STATS ),
834
- )
835
- n_windows = ds .window_start .shape [0 ]
836
- assert_array_shape (gh , n_windows , n_cohorts , N_GARUD_H_STATS )
837
- new_ds = Dataset (
838
- {
839
- variables .stat_Garud_h1 : (
840
- ("windows" , "cohorts" ),
841
- gh [:, :, 0 ],
842
- ),
843
- variables .stat_Garud_h12 : (
844
- ("windows" , "cohorts" ),
845
- gh [:, :, 1 ],
846
- ),
847
- variables .stat_Garud_h123 : (
848
- ("windows" , "cohorts" ),
849
- gh [:, :, 2 ],
850
- ),
851
- variables .stat_Garud_h2_h1 : (
852
- ("windows" , "cohorts" ),
853
- gh [:, :, 3 ],
854
- ),
855
- }
856
- )
857
- else :
858
- # TODO: note this materializes all the data, so windowless should be discouraged/not supported
859
- gt = gt .values
860
-
861
- gh = _Garud_h_cohorts (gt , sample_cohort = hsc , n_cohorts = n_cohorts )
862
- assert_array_shape (gh , n_cohorts , N_GARUD_H_STATS )
828
+ gh = window_statistic (
829
+ gt ,
830
+ lambda gt : _Garud_h_cohorts (gt , hsc , n_cohorts ),
831
+ ds .window_start .values ,
832
+ ds .window_stop .values ,
833
+ dtype = np .float64 ,
834
+ # first chunks dimension is windows, computed in window_statistic
835
+ chunks = (- 1 , n_cohorts , N_GARUD_H_STATS ),
836
+ )
837
+ n_windows = ds .window_start .shape [0 ]
838
+ assert_array_shape (gh , n_windows , n_cohorts , N_GARUD_H_STATS )
839
+ new_ds = Dataset (
840
+ {
841
+ variables .stat_Garud_h1 : (
842
+ ("windows" , "cohorts" ),
843
+ gh [:, :, 0 ],
844
+ ),
845
+ variables .stat_Garud_h12 : (
846
+ ("windows" , "cohorts" ),
847
+ gh [:, :, 1 ],
848
+ ),
849
+ variables .stat_Garud_h123 : (
850
+ ("windows" , "cohorts" ),
851
+ gh [:, :, 2 ],
852
+ ),
853
+ variables .stat_Garud_h2_h1 : (
854
+ ("windows" , "cohorts" ),
855
+ gh [:, :, 3 ],
856
+ ),
857
+ }
858
+ )
863
859
864
- new_ds = Dataset (
865
- {
866
- variables .stat_Garud_h1 : gh [:, 0 ],
867
- variables .stat_Garud_h12 : gh [:, 1 ],
868
- variables .stat_Garud_h123 : gh [:, 2 ],
869
- variables .stat_Garud_h2_h1 : gh [:, 3 ],
870
- }
871
- )
872
860
return conditional_merge_datasets (ds , variables .validate (new_ds ), merge )
0 commit comments