Skip to content

Commit

Permalink
[query] Don't error on VCF export when haploid call is unphased (#14375)
Browse files Browse the repository at this point in the history
resolves #14330
  • Loading branch information
chrisvittal committed Jul 10, 2024
1 parent 90ab54a commit d13028f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions hail/python/test/hail/methods/test_impex.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ def test_export_vcf_invalid_format_types(self):
"""
assert msg in str(exp.value)

def test_export_vcf_haploid(self):
ds = hl.import_vcf(resource("sample.vcf"))
ds = ds.select_entries(GT=hl.call(0))
with TemporaryFilename(suffix='.vcf') as export_path:
hl.export_vcf(ds, export_path)

def import_gvcfs_sample_vcf(self, path):
parts_type = hl.tarray(hl.tinterval(hl.tstruct(locus=hl.tlocus('GRCh37'))))
parts = [
Expand Down
5 changes: 4 additions & 1 deletion hail/src/main/scala/is/hail/expr/ir/MatrixWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,10 @@ case class VCFPartitionWriter(
case v: SCallValue =>
val ploidy = v.ploidy(cb)
cb.if_(ploidy.ceq(0), cb._fatal("VCF spec does not support 0-ploid calls."))
cb.if_(ploidy.ceq(1), cb._fatal("VCF spec does not support phased haploid calls."))
cb.if_(
ploidy.ceq(1) && v.isPhased(cb),
cb._fatal("VCF spec does not support phased haploid calls."),
)
val c = v.canonicalCall(cb)
_writeB(cb, Code.invokeScalaObject1[Int, Array[Byte]](Call.getClass, "toUTF8", c))
}
Expand Down

0 comments on commit d13028f

Please sign in to comment.