Skip to content

Commit

Permalink
[query] relax requirements of variant_qc
Browse files Browse the repository at this point in the history
CHANGELOG: `hl.variant_qc` no longer requires a `locus` field.

Fixes hail-is#12844.
  • Loading branch information
Dan King committed Apr 6, 2023
1 parent 6545062 commit a273514
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions hail/python/hail/methods/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ def require_row_key_variant(dataset, method):
"\n '{}': {}".format(k, str(dataset[k].dtype)) for k in key)))


def require_alleles_field(dataset, method):
if 'alleles' not in dataset.row:
raise ValueError(
f"Method '{method}' requires a field 'alleles' (type 'array<str>')\n")
if dataset.alleles.dtype != tarray(tstr):
raise ValueError(
f"Method '{method}' requires a field 'alleles' (type 'array<str>')\n"
f" Found:\n"
f" 'alleles': {dataset.alleles.dtype}")


def require_row_key_variant_w_struct_locus(dataset, method):
if (list(dataset.row_key) != ['locus', 'alleles']
or not dataset['alleles'].dtype == tarray(tstr)
Expand Down
4 changes: 2 additions & 2 deletions hail/python/hail/methods/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hail.matrixtable import MatrixTable
from hail.table import Table
from hail.ir import TableToTableApply
from .misc import require_biallelic, require_row_key_variant, require_col_key_str, require_table_key_variant
from .misc import require_biallelic, require_row_key_variant, require_col_key_str, require_table_key_variant, require_alleles_field


@typecheck(mt=MatrixTable, name=str)
Expand Down Expand Up @@ -251,7 +251,7 @@ def variant_qc(mt, name='variant_qc') -> MatrixTable:
-------
:class:`.MatrixTable`
"""
require_row_key_variant(mt, 'variant_qc')
require_alleles_field(mt, 'variant_qc')

bound_exprs = {}
gq_dp_exprs = {}
Expand Down
10 changes: 10 additions & 0 deletions hail/python/test/hail/methods/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def test_variant_qc(self):
self.assertEqual(r[1].vqc.gq_stats.mean, 10)
self.assertEqual(r[1].vqc.gq_stats.stdev, 0)

def test_variant_qc_alleles_field(self):
mt = hl.balding_nichols_model(1, 1, 1)
mt = mt.key_rows_by().drop('alleles')
with pytest.raises(ValueError, match="Method 'variant_qc' requires a field 'alleles' \\(type 'array<str>'\\).*"):
hl.variant_qc(mt).variant_qc.collect()

mt = hl.balding_nichols_model(1, 1, 1)
mt = mt.key_rows_by().drop('locus')
hl.variant_qc(mt).variant_qc.collect()

def test_concordance(self):
dataset = get_dataset()
glob_conc, cols_conc, rows_conc = hl.concordance(dataset, dataset)
Expand Down

0 comments on commit a273514

Please sign in to comment.