Skip to content

Commit

Permalink
allow for situation where current variant is non-support, so partner …
Browse files Browse the repository at this point in the history
…can be support-only
  • Loading branch information
MattWellie committed Feb 12, 2025
1 parent e52e637 commit 19c8fd5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/talos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def sample_category_check(self, sample_id: str, allow_support: bool = True) -> b
if not allow_support:
categories_applied -= self.support_categories

return bool(len(categories_applied) > 0)
return len(categories_applied) > 0

def check_ab_ratio(self, *args, **kwargs) -> set[str]: # noqa: ARG002, ANN002, ANN003
"""
Expand Down
83 changes: 31 additions & 52 deletions src/talos/moi_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def check_for_second_hit(
comp_hets: CompHetDict,
sample: str,
require_non_support: bool = False,
min_alt_depth: int = 5,
) -> list[VARIANT_MODELS]:
"""
checks for a second hit partner in this gene
Expand Down Expand Up @@ -102,8 +103,14 @@ def check_for_second_hit(
return []

partners = comp_hets[sample].get(first_variant, [])

# thin out the possible partners by alt depth
partners = [partner for partner in partners if not partner.check_minimum_alt_depth(sample, min_alt_depth)]

if require_non_support:
return [partner for partner in partners if partner.sample_category_check(sample, allow_support=False)]
return [
partner for partner in partners if partner.sample_category_check(sample, allow_support=require_non_support)
]
return partners


Expand Down Expand Up @@ -372,10 +379,8 @@ def run(
# force a minimum depth on the proband call
# and a minimum number of alt reads supporting
if (
not (
self.pedigree.by_id[sample_id].affected == '2'
and principal.sample_category_check(sample_id, allow_support=False)
)
self.pedigree.by_id[sample_id].affected != '2'
or not principal.sample_category_check(sample_id, allow_support=False)
or principal.check_read_depth(
sample_id,
self.minimum_depth,
Expand Down Expand Up @@ -444,6 +449,9 @@ def run(
list[ReportVariant]: data object if RecessiveAutosomal fits
"""

if principal.coordinates.pos == 71652747:
print('waiting')

if comp_het is None:
comp_het = {}

Expand All @@ -458,15 +466,12 @@ def run(

# if hets are present, try and find support
for sample_id in principal.het_samples:
print(sample_id)
# skip primary analysis for unaffected members
# this sample must be categorised - check Cat 4 contents
if (
(
not (
self.pedigree.by_id[sample_id].affected == '2'
and principal.sample_category_check(sample_id, allow_support=True)
)
)
self.pedigree.by_id[sample_id].affected != '2'
or (not principal.sample_category_check(sample_id, allow_support=True))
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand All @@ -477,6 +482,7 @@ def run(
comp_hets=comp_het,
sample=sample_id,
require_non_support=principal.sample_category_check(sample_id, allow_support=False),
min_alt_depth=self.minimum_alt_depth,
):
if partner_variant.check_read_depth(
sample_id,
Expand Down Expand Up @@ -554,12 +560,8 @@ def run(
# require this sample to be categorised - check Sample contents
# minimum depth of call
if (
(
not (
self.pedigree.by_id[sample_id].affected == '2'
and principal.sample_category_check(sample_id, allow_support=False)
)
)
self.pedigree.by_id[sample_id].affected != '2'
or not (principal.sample_category_check(sample_id, allow_support=False))
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand Down Expand Up @@ -656,12 +658,8 @@ def run(
# we require this specific sample to be categorised (non-support)
# force minimum depth
if (
(
not (
principal.sample_category_check(sample_id, allow_support=False)
and self.pedigree.by_id[sample_id].affected == '2'
)
)
self.pedigree.by_id[sample_id].affected != '2'
or not (principal.sample_category_check(sample_id, allow_support=False))
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand Down Expand Up @@ -757,12 +755,8 @@ def run(
# we require this specific sample to be categorised
# force minimum depth
if (
(
not (
principal.sample_category_check(sample_id, allow_support=False)
and self.pedigree.by_id[sample_id].affected == '2'
)
)
self.pedigree.by_id[sample_id].affected != '2'
or not (principal.sample_category_check(sample_id, allow_support=False))
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand Down Expand Up @@ -843,10 +837,7 @@ def run(
classifications = []

# remove from analysis if too many homs are present in population databases
if too_common_in_population(
principal.info,
self.freq_tests[principal.__class__.__name__],
):
if too_common_in_population(principal.info, self.freq_tests[principal.__class__.__name__]):
return classifications

# combine het and hom here, we don't trust the variant callers
Expand All @@ -859,12 +850,8 @@ def run(
for sample_id in males:
# specific affected sample category check, never consider support on X for males
if (
(
not (
self.pedigree.by_id[sample_id].affected == '2'
and principal.sample_category_check(sample_id, allow_support=False)
)
)
self.pedigree.by_id[sample_id].affected != '2'
or not (principal.sample_category_check(sample_id, allow_support=False))
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand Down Expand Up @@ -940,12 +927,8 @@ def run(
for sample_id in samples_to_check:
# specific affected sample category check
if (
(
not (
self.pedigree.by_id[sample_id].affected == '2'
and principal.sample_category_check(sample_id, allow_support=False)
)
)
self.pedigree.by_id[sample_id].affected != '2'
or not principal.sample_category_check(sample_id, allow_support=False)
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand Down Expand Up @@ -1027,12 +1010,8 @@ def run(
# don't run primary analysis for unaffected
# we require this specific sample to be categorised - check Cat 4 contents
if (
(
not (
self.pedigree.by_id[sample_id].affected == '2'
and principal.sample_category_check(sample_id, allow_support=True)
)
)
self.pedigree.by_id[sample_id].affected != '2'
or not principal.sample_category_check(sample_id, allow_support=True)
or principal.check_read_depth(sample_id, self.minimum_depth, principal.info.get('categoryboolean1'))
or principal.check_minimum_alt_depth(sample_id, self.minimum_alt_depth)
):
Expand All @@ -1045,7 +1024,7 @@ def run(
require_non_support=principal.sample_category_check(sample_id, allow_support=False),
):
# allow for de novo check - also screen out high-AF partners
if (not partner.sample_category_check(sample_id, allow_support=True)) or too_common_in_population(
if too_common_in_population(
partner.info,
self.freq_tests[partner.__class__.__name__],
):
Expand Down

0 comments on commit 19c8fd5

Please sign in to comment.