Skip to content

Commit 6efe964

Browse files
authored
bugfix unsorted pedigree (#1029)
1 parent 2fcb8cc commit 6efe964

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

v03_pipeline/lib/misc/pedigree.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class Family:
8080
def __hash__(self):
8181
return hash(self.family_guid)
8282

83+
def __eq__(self, other):
84+
return self.family_guid == other.family_guid
85+
8386
@staticmethod
8487
def parse_direct_lineage(rows: list[hl.Struct]) -> dict[str, Sample]:
8588
samples = {}
@@ -162,7 +165,7 @@ def parse_pedigree_ht_to_families(
162165
) -> set[Family]:
163166
families = set()
164167
for family_guid, rows in itertools.groupby(
165-
pedigree_ht.collect(),
168+
sorted(pedigree_ht.collect(), key=lambda x: x.family_guid),
166169
lambda x: x.family_guid,
167170
):
168171
families.add(Family.parse(family_guid, list(rows)))

v03_pipeline/lib/misc/pedigree_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
TEST_PEDIGREE_1 = 'v03_pipeline/var/test/pedigrees/test_pedigree_1.tsv'
1010
TEST_PEDIGREE_2 = 'v03_pipeline/var/test/pedigrees/test_pedigree_2.tsv'
11+
TEST_PEDIGREE_9 = 'v03_pipeline/var/test/pedigrees/test_pedigree_9.tsv'
1112

1213

1314
class PedigreesTest(unittest.TestCase):
@@ -490,3 +491,20 @@ def test_subsetted_pedigree_with_removed_parent(self) -> None:
490491
family.samples['BBL_BC1-000345_01_D1'].mother,
491492
'BBL_BC1-000345_03_D1',
492493
)
494+
495+
def test_pedigree_ungrouped_families(self) -> None:
496+
pedigree_ht = import_pedigree(TEST_PEDIGREE_9)
497+
parsed_pedigree = parse_pedigree_ht_to_families(pedigree_ht)
498+
self.assertEqual(len(parsed_pedigree), 2)
499+
family = next(
500+
iter(
501+
[
502+
family
503+
for family in parsed_pedigree
504+
if family.family_guid == 'family_2_1'
505+
],
506+
),
507+
)
508+
self.assertTrue(
509+
family.samples.keys() == {'RGP_164_1', 'RGP_164_2', 'RGP_164_4'},
510+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Project_GUID Family_GUID Family_ID Individual_ID Paternal_ID Maternal_ID Sex
2+
R0115_test_project2 family_2_1 family_2 RGP_164_1 F
3+
R0115_test_project2 family_2_1 family_2 RGP_164_2 M
4+
R0115_test_project2 family_2_3 family_3 RGP_165_1 F
5+
R0115_test_project2 family_2_1 family_2 RGP_164_4 RGP_164_1 RGP_164_2 F

0 commit comments

Comments
 (0)