Skip to content

Commit 159e5a7

Browse files
authored
Merge pull request #503 from broadinstitute/jg/assign_population_pcs_pc_cols_name_fix
Fix `assign_population_pcs` error when parameter `pc_cols` is a Hail ArrayExpression
2 parents c96646b + 7949d11 commit 159e5a7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gnomad/sample_qc/ancestry.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ def assign_population_pcs(
192192
pc_expr = pop_pca_scores[pc_expr]
193193
pcs_to_pull = [pc_expr[i - 1] for i in pc_cols]
194194
else:
195+
pc_col_len = list(
196+
filter(
197+
None,
198+
pop_pca_scores.aggregate(hl.agg.collect_as_set(hl.len(pc_cols))),
199+
)
200+
)
201+
if len(pc_col_len) > 1:
202+
raise ValueError(
203+
"More than one length was found among the 'pc_cols' "
204+
"ArrayExpression values. The length must be consistent!"
205+
)
195206
pcs_to_pull = pc_cols
207+
pc_cols = list(range(1, pc_col_len[0] + 1))
196208
if not fit:
197209
pop_pca_scores = pop_pca_scores.select(known_col, pca_scores=pcs_to_pull)
198210
else:

0 commit comments

Comments
 (0)