@@ -69,11 +69,9 @@ def root_attrs(self):
69
69
return {}
70
70
71
71
@abc .abstractmethod
72
- def iter_alleles (self , start , stop , num_alleles ):
73
- pass
74
-
75
- @abc .abstractmethod
76
- def iter_genotypes (self , start , stop , num_alleles ):
72
+ def iter_alleles_and_genotypes (
73
+ self , start , stop , include_genotypes , shape , num_alleles
74
+ ):
77
75
pass
78
76
79
77
def iter_id (self , start , stop ):
@@ -718,12 +716,11 @@ def encode_partition(self, partition_index):
718
716
self .encode_filters_partition (partition_index )
719
717
if "variant_contig" in all_field_names :
720
718
self .encode_contig_partition (partition_index )
721
- self .encode_alleles_partition (partition_index )
719
+ self .encode_alleles_and_genotypes_partition (partition_index )
722
720
for array_spec in self .schema .fields :
723
721
if array_spec .source is not None :
724
722
self .encode_array_partition (array_spec , partition_index )
725
723
if self .has_genotypes ():
726
- self .encode_genotypes_partition (partition_index )
727
724
self .encode_genotype_mask_partition (partition_index )
728
725
if self .has_local_alleles ():
729
726
self .encode_local_alleles_partition (partition_index )
@@ -774,22 +771,33 @@ def encode_array_partition(self, array_spec, partition_index):
774
771
775
772
self .finalise_partition_array (partition_index , ba )
776
773
777
- def encode_genotypes_partition (self , partition_index ):
774
+ def encode_alleles_and_genotypes_partition (self , partition_index ):
778
775
partition = self .metadata .partitions [partition_index ]
779
- gt = self .init_partition_array (partition_index , "call_genotype" )
780
- gt_phased = self .init_partition_array (partition_index , "call_genotype_phased" )
776
+ alleles = self .init_partition_array (partition_index , "variant_allele" )
777
+ has_gt = self .has_genotypes ()
778
+ shape = None
779
+ if has_gt :
780
+ gt = self .init_partition_array (partition_index , "call_genotype" )
781
+ gt_phased = self .init_partition_array (
782
+ partition_index , "call_genotype_phased"
783
+ )
784
+ shape = gt .buff .shape [1 :]
781
785
782
- for genotype , phased in self .source .iter_genotypes (
783
- gt . buff . shape [ 1 :], partition .start , partition .stop
786
+ for alleles_value , genotype , phased in self .source .iter_alleles_and_genotypes (
787
+ partition .start , partition .stop , has_gt , shape , alleles . array . shape [ 1 ]
784
788
):
785
- j = gt .next_buffer_row ()
786
- gt .buff [j ] = genotype
789
+ j_alleles = alleles .next_buffer_row ()
790
+ alleles .buff [j_alleles ] = alleles_value
791
+ if has_gt :
792
+ j = gt .next_buffer_row ()
793
+ gt .buff [j ] = genotype
794
+ j_phased = gt_phased .next_buffer_row ()
795
+ gt_phased .buff [j_phased ] = phased
787
796
788
- j_phased = gt_phased .next_buffer_row ()
789
- gt_phased .buff [j_phased ] = phased
790
-
791
- self .finalise_partition_array (partition_index , gt )
792
- self .finalise_partition_array (partition_index , gt_phased )
797
+ self .finalise_partition_array (partition_index , alleles )
798
+ if has_gt :
799
+ self .finalise_partition_array (partition_index , gt )
800
+ self .finalise_partition_array (partition_index , gt_phased )
793
801
794
802
def encode_genotype_mask_partition (self , partition_index ):
795
803
partition = self .metadata .partitions [partition_index ]
@@ -851,18 +859,6 @@ def encode_local_allele_fields_partition(self, partition_index):
851
859
buff .buff [j ] = descriptor .convert (value , la )
852
860
self .finalise_partition_array (partition_index , buff )
853
861
854
- def encode_alleles_partition (self , partition_index ):
855
- alleles = self .init_partition_array (partition_index , "variant_allele" )
856
- partition = self .metadata .partitions [partition_index ]
857
-
858
- for value in self .source .iter_alleles (
859
- partition .start , partition .stop , alleles .array .shape [1 ]
860
- ):
861
- j = alleles .next_buffer_row ()
862
- alleles .buff [j ] = value
863
-
864
- self .finalise_partition_array (partition_index , alleles )
865
-
866
862
def encode_id_partition (self , partition_index ):
867
863
vid = self .init_partition_array (partition_index , "variant_id" )
868
864
vid_mask = self .init_partition_array (partition_index , "variant_id_mask" )
0 commit comments