Skip to content

Commit bca9c0f

Browse files
committed
fix test
1 parent e6bab92 commit bca9c0f

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

v03_pipeline/lib/misc/family_loading_failures.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ def passes_relatedness_check(
3131
return True, None
3232

3333

34-
def passes_all_relatedness_checks( # noqa: C901
34+
def all_relatedness_checks( # noqa: C901
3535
relatedness_check_lookup: dict[tuple[str, str], list],
3636
sample: Sample,
37-
) -> tuple[bool, str | None]:
37+
) -> list[str]:
38+
failure_reasons = []
3839
for parent_id in [sample.mother, sample.father]:
3940
success, reason = passes_relatedness_check(
4041
relatedness_check_lookup,
@@ -43,7 +44,7 @@ def passes_all_relatedness_checks( # noqa: C901
4344
Relation.PARENT,
4445
)
4546
if not success:
46-
return False, reason
47+
failure_reasons.append(reason)
4748

4849
for grandparent_id in [
4950
sample.maternal_grandmother,
@@ -58,7 +59,7 @@ def passes_all_relatedness_checks( # noqa: C901
5859
Relation.GRANDPARENT,
5960
)
6061
if not success:
61-
return False, reason
62+
failure_reasons.append(reason)
6263

6364
for sibling_id in sample.siblings:
6465
success, reason = passes_relatedness_check(
@@ -68,7 +69,7 @@ def passes_all_relatedness_checks( # noqa: C901
6869
Relation.SIBLING,
6970
)
7071
if not success:
71-
return False, reason
72+
failure_reasons.append(reason)
7273

7374
for half_sibling_id in sample.half_siblings:
7475
# NB: A "half sibling" parsed from the pedigree may actually be a sibling, so we allow those
@@ -86,7 +87,7 @@ def passes_all_relatedness_checks( # noqa: C901
8687
Relation.HALF_SIBLING,
8788
)
8889
if not success1 and not success2:
89-
return False, reason
90+
failure_reasons.append(reason)
9091

9192
for aunt_nephew_id in sample.aunt_nephews:
9293
success, reason = passes_relatedness_check(
@@ -96,8 +97,8 @@ def passes_all_relatedness_checks( # noqa: C901
9697
Relation.AUNT_NEPHEW,
9798
)
9899
if not success:
99-
return False, reason
100-
return True, None
100+
failure_reasons.append(reason)
101+
return failure_reasons
101102

102103

103104
def build_relatedness_check_lookup(
@@ -156,12 +157,12 @@ def get_families_failed_relatedness_check(
156157
failed_families = defaultdict(list)
157158
for family in families:
158159
for sample in family.samples.values():
159-
success, reason = passes_all_relatedness_checks(
160+
failure_reasons = all_relatedness_checks(
160161
relatedness_check_lookup,
161162
sample,
162163
)
163-
if not success:
164-
failed_families[family].append(reason)
164+
if failure_reasons:
165+
failed_families[family].extend(failure_reasons)
165166
return dict(failed_families)
166167

167168

v03_pipeline/lib/misc/family_loading_failures_test.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
build_relatedness_check_lookup,
77
build_sex_check_lookup,
88
get_families_failed_sex_check,
9-
passes_all_relatedness_checks,
9+
all_relatedness_checks,
1010
)
1111
from v03_pipeline.lib.misc.io import import_pedigree
1212
from v03_pipeline.lib.misc.pedigree import Sample, parse_pedigree_ht_to_families
@@ -81,7 +81,7 @@ def test_build_sex_check_lookup(self):
8181
},
8282
)
8383

84-
def test_passes_all_relatedness_checks(self):
84+
def test_all_relatedness_checks(self):
8585
relatedness_check_lookup = {
8686
# Parent
8787
('sample_1', 'sample_2'): [
@@ -102,8 +102,8 @@ def test_passes_all_relatedness_checks(self):
102102
paternal_grandfather='sample_3',
103103
half_siblings=['sample_4'],
104104
)
105-
success, _ = passes_all_relatedness_checks(relatedness_check_lookup, sample)
106-
self.assertTrue(success)
105+
failure_reasons = all_relatedness_checks(relatedness_check_lookup, sample)
106+
self.assertListEqual(failure_reasons, [])
107107

108108
# Defined grandparent missing in relatedness table
109109
sample = Sample(
@@ -113,14 +113,13 @@ def test_passes_all_relatedness_checks(self):
113113
paternal_grandfather='sample_3',
114114
paternal_grandmother='sample_5',
115115
)
116-
success, reason = passes_all_relatedness_checks(
116+
failure_reasons = all_relatedness_checks(
117117
relatedness_check_lookup,
118118
sample,
119119
)
120-
self.assertFalse(success)
121-
self.assertEqual(
122-
reason,
123-
'Sample sample_1 has expected relation "grandparent" to sample_5 but has coefficients []',
120+
self.assertListEqual(
121+
failure_reasons,
122+
['Sample sample_1 has expected relation "grandparent" to sample_5 but has coefficients []'],
124123
)
125124

126125
# Sibling is actually a half sibling.
@@ -135,17 +134,15 @@ def test_passes_all_relatedness_checks(self):
135134
paternal_grandfather='sample_3',
136135
siblings=['sample_4'],
137136
)
138-
success, reason = passes_all_relatedness_checks(
137+
failure_reasons = all_relatedness_checks(
139138
relatedness_check_lookup,
140139
sample,
141140
)
142-
self.assertFalse(success)
143-
self.assertEqual(
144-
reason,
145-
'Sample sample_1 has expected relation "sibling" to sample_4 but has coefficients [0.5, 0.5, 0, 0.25]',
141+
self.assertListEqual(
142+
failure_reasons,
143+
['Sample sample_1 has expected relation "sibling" to sample_4 but has coefficients [0.5, 0.5, 0, 0.25]'],
146144
)
147145

148-
# Sibling is actually a half sibling.
149146
relatedness_check_lookup = {
150147
**relatedness_check_lookup,
151148
('sample_1', 'sample_2'): [
@@ -162,14 +159,17 @@ def test_passes_all_relatedness_checks(self):
162159
paternal_grandfather='sample_3',
163160
siblings=['sample_4'],
164161
)
165-
success, reason = passes_all_relatedness_checks(
162+
failure_reasons = all_relatedness_checks(
166163
relatedness_check_lookup,
167164
sample,
168165
)
169-
self.assertFalse(success)
170-
self.assertEqual(
171-
reason,
172-
'Sample sample_1 has expected relation "parent" to sample_2 but has coefficients [0.5, 0.5, 0.5, 0.5]',
166+
print('ben', failure_reasons)
167+
self.assertListEqual(
168+
failure_reasons,
169+
[
170+
'Sample sample_1 has expected relation "parent" to sample_2 but has coefficients [0.5, 0.5, 0.5, 0.5]',
171+
'Sample sample_1 has expected relation "sibling" to sample_4 but has coefficients [0.5, 0.5, 0, 0.25]'
172+
],
173173
)
174174

175175
def test_get_families_failed_sex_check(self):

0 commit comments

Comments
 (0)