Skip to content

Commit 9df1ce8

Browse files
authored
fix pedigree parsing for missing parents -- need to preserve missing … (#921)
* fix pedigree parsing for missing parents -- need to preserve missing parents to ensure siblings are not misidentified * ruff
1 parent 90a97d1 commit 9df1ce8

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

v03_pipeline/lib/misc/pedigree.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __hash__(self):
8181
return hash(self.family_guid)
8282

8383
@staticmethod
84-
def parse_direct_lineage(rows: list[hl.Struct]) -> dict[str, Sample]: # noqa: C901
84+
def parse_direct_lineage(rows: list[hl.Struct]) -> dict[str, Sample]:
8585
samples = {}
8686
for row in rows:
8787
samples[row.s] = Sample(
@@ -94,22 +94,15 @@ def parse_direct_lineage(rows: list[hl.Struct]) -> dict[str, Sample]: # noqa: C
9494
for row in rows:
9595
# Maternal GrandParents
9696
maternal_s = samples[row.s].mother
97-
if maternal_s and maternal_s not in samples:
98-
# A sample id may be referenced for a proband that has been
99-
# removed from the pedigree as an individual. We handle this by
100-
# nulling out the parent here.
101-
samples[row.s].mother = None
102-
elif maternal_s:
97+
if maternal_s and maternal_s in samples:
10398
if samples[maternal_s].mother:
10499
samples[row.s].maternal_grandmother = samples[maternal_s].mother
105100
if samples[maternal_s].father:
106101
samples[row.s].maternal_grandfather = samples[maternal_s].father
107102

108103
# Paternal GrandParents
109104
paternal_s = samples[row.s].father
110-
if paternal_s and paternal_s not in samples:
111-
samples[row.s].father = None
112-
elif paternal_s:
105+
if paternal_s and paternal_s in samples:
113106
if samples[paternal_s].mother:
114107
samples[row.s].paternal_grandmother = samples[paternal_s].mother
115108
if samples[paternal_s].father:

v03_pipeline/lib/misc/pedigree_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,13 @@ def test_subsetted_pedigree_with_removed_parent(self) -> None:
479479
),
480480
)
481481
self.assertEqual(len(family.samples), 2)
482-
self.assertIsNone(family.samples['BBL_BC1-000345_01_D1'].father)
482+
self.assertFalse(
483+
'BBL_BC1-000345_02_D1' in family.samples,
484+
)
485+
self.assertEqual(
486+
family.samples['BBL_BC1-000345_01_D1'].father,
487+
'BBL_BC1-000345_02_D1',
488+
)
483489
self.assertEqual(
484490
family.samples['BBL_BC1-000345_01_D1'].mother,
485491
'BBL_BC1-000345_03_D1',

0 commit comments

Comments
 (0)