Skip to content

Commit

Permalink
[bugfix] Fix trio matrix (hail-is#5525)
Browse files Browse the repository at this point in the history
* [bugfix] Fix trio matrix

It was totally broken in the default case.

* Fix
  • Loading branch information
tpoterba authored and akotlar committed Mar 6, 2019
1 parent 45df77b commit 52f3c12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hail/python/hail/methods/family_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def trio_matrix(dataset, pedigree, complete_trios=False) -> MatrixTable:
samples = mt[k].collect()

pedigree = pedigree.filter_to(samples)
trios = pedigree.complete_trios() if complete_trios else pedigree.trios()
trios = pedigree.complete_trios() if complete_trios else pedigree.trios
n_trios = len(trios)

sample_idx = {}
Expand All @@ -76,8 +76,8 @@ def trio_matrix(dataset, pedigree, complete_trios=False) -> MatrixTable:

trios = [hl.Struct(
id=sample_idx[t.s],
pat_id=sample_idx[t.pat_id],
mat_id=sample_idx[t.mat_id],
pat_id=None if t.pat_id is None else sample_idx[t.pat_id],
mat_id=None if t.mat_id is None else sample_idx[t.mat_id],
is_female=t.is_female,
fam_id=t.fam_id) for t in trios]
trios_type = hl.dtype('array<struct{id:int,pat_id:int,mat_id:int,is_female:bool,fam_id:str}>')
Expand Down
6 changes: 6 additions & 0 deletions hail/python/test/hail/methods/test_family_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def test_trio_matrix_null_keys(self):
tt = hl.trio_matrix(mt, ped, complete_trios=True)
self.assertEqual(tt.count_cols(), 0)

def test_trio_matrix_incomplete_trios(self):
ped = hl.Pedigree.read(resource('triomatrix.fam'))
mt = hl.import_vcf(resource('triomatrix.vcf'))
hl.trio_matrix(mt, ped, complete_trios=False)


def test_mendel_errors(self):
mt = hl.import_vcf(resource('mendel.vcf'))
ped = hl.Pedigree.read(resource('mendel.fam'))
Expand Down

0 comments on commit 52f3c12

Please sign in to comment.