@@ -119,6 +119,7 @@ def from_field(
119
119
* ,
120
120
num_variants ,
121
121
num_samples ,
122
+ max_alleles ,
122
123
variants_chunk_size ,
123
124
samples_chunk_size ,
124
125
array_name = None ,
@@ -137,23 +138,38 @@ def from_field(
137
138
if array_name is None :
138
139
array_name = prefix + vcf_field .name
139
140
140
- # TODO make an option to add in the empty extra dimension
141
141
max_number = vcf_field .max_number
142
- if (max_number > 0 and vcf_field .vcf_number in ("R" , "A" , "G" )) or (
143
- max_number > 1 or vcf_field .full_name == "FORMAT/LAA"
144
- ):
145
- shape .append (max_number )
146
- chunks .append (max_number )
147
- # TODO we should really be checking this to see if the named dimensions
148
- # are actually correct.
149
- if vcf_field .vcf_number == "R" :
142
+ if vcf_field .vcf_number == "R" :
143
+ if max_number > max_alleles :
144
+ raise ValueError (
145
+ f"Max number of values { max_number } exceeds max alleles "
146
+ f"{ max_alleles } for { vcf_field .full_name } "
147
+ )
148
+ if max_alleles > 0 :
149
+ shape .append (max_alleles )
150
+ chunks .append (max_alleles )
150
151
dimensions .append ("alleles" )
151
- elif vcf_field .vcf_number == "A" :
152
+ elif vcf_field .vcf_number == "A" :
153
+ max_alt_alleles = max_alleles - 1
154
+ if max_number > max_alt_alleles :
155
+ raise ValueError (
156
+ f"Max number of values { max_number } exceeds max alt alleles "
157
+ f"{ max_alt_alleles } for { vcf_field .full_name } "
158
+ )
159
+ if max_alt_alleles > 0 :
160
+ shape .append (max_alt_alleles )
161
+ chunks .append (max_alt_alleles )
152
162
dimensions .append ("alt_alleles" )
153
- elif vcf_field .vcf_number == "G" :
154
- dimensions .append ("genotypes" )
155
- else :
156
- dimensions .append (f"{ vcf_field .category } _{ vcf_field .name } _dim" )
163
+ elif max_number > 0 and vcf_field .vcf_number == "G" :
164
+ # TODO: need max_genotypes
165
+ shape .append (max_number )
166
+ chunks .append (max_number )
167
+ dimensions .append ("genotypes" )
168
+ elif max_number > 1 or vcf_field .full_name == "FORMAT/LAA" :
169
+ # TODO make an option to add in the empty extra dimension
170
+ shape .append (max_number )
171
+ chunks .append (max_number )
172
+ dimensions .append (f"{ vcf_field .category } _{ vcf_field .name } _dim" )
157
173
return ZarrArraySpec (
158
174
source = vcf_field .full_name ,
159
175
name = array_name ,
0 commit comments