Skip to content

Commit d4ead0f

Browse files
authored
feat: increase relatedness tolerance for parent/child relationships (#1067)
* feat: improve parent/child s&r * Update pedigree.py
1 parent 22a744a commit d4ead0f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

v03_pipeline/lib/misc/family_loading_failures.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from collections import defaultdict
22

33
import hail as hl
4-
import numpy as np
54

65
from v03_pipeline.lib.logger import get_logger
76
from v03_pipeline.lib.misc.pedigree import Family, Relation, Sample
87
from v03_pipeline.lib.model import Sex
98

10-
RELATEDNESS_TOLERANCE = 0.2
11-
129
logger = get_logger(__name__)
1310

1411

@@ -26,11 +23,7 @@ def passes_relatedness_check(
2623
(min(sample_id, other_id), max(sample_id, other_id)),
2724
)
2825
if not coefficients or not any(
29-
np.allclose(
30-
coefficients,
31-
relation.coefficients,
32-
atol=RELATEDNESS_TOLERANCE,
33-
)
26+
relation.coefficients_equal(coefficients)
3427
for relation in (
3528
[expected_relation, additional_allowed_relation]
3629
if additional_allowed_relation

v03_pipeline/lib/misc/pedigree.py

+17
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
from enum import Enum
44

55
import hail as hl
6+
import numpy as np
67

78
from v03_pipeline.lib.model import Sex
89

10+
DEFAULT_RELATEDNESS_TOLERANCE = 0.2
11+
PARENT_CHILD_RELATEDNESS_TOLERANCE = 0.4
12+
913

1014
class Relation(Enum):
1115
PARENT_CHILD = 'parent_child'
@@ -24,6 +28,19 @@ def coefficients(self):
2428
Relation.AUNT_NEPHEW: [0.5, 0.5, 0, 0.25],
2529
}[self]
2630

31+
def coefficients_equal(self, coefficients: list[float]) -> bool:
32+
if self == Relation.PARENT_CHILD:
33+
return (coefficients[0] == self.coefficients[0]) and np.allclose(
34+
coefficients[1:],
35+
self.coefficients[1:],
36+
atol=DEFAULT_RELATEDNESS_TOLERANCE,
37+
)
38+
return np.allclose(
39+
coefficients,
40+
self.coefficients,
41+
atol=DEFAULT_RELATEDNESS_TOLERANCE,
42+
)
43+
2744

2845
@dataclass
2946
class Sample:

0 commit comments

Comments
 (0)