Skip to content

Commit

Permalink
refact(mi): move common overlap checking code to function
Browse files Browse the repository at this point in the history
lint(mi): remove debug log
  • Loading branch information
davidlougheed committed Jul 11, 2024
1 parent 21014f3 commit 4e25a17
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
8 changes: 8 additions & 0 deletions strkit/mi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def get_loci_overlapping(self, contig: str, start: int, end: int) -> list[tuple[
def should_exclude_locus(self, contig: str, start: int, end: int) -> bool:
return any(True for _ in overlapping_loci_dict_of_list(contig, start, end, self._exclude_dict))

def should_skip_locus(self, contig: str, start: int, end: int) -> bool:
# Check to make sure call is present in TRF BED file, if it is specified
# Check to make sure the locus is not excluded via overlap with exclude BED
return (
(self._loci_file and self._loci_dict and not self.get_loci_overlapping(contig, start, end))
or self.should_exclude_locus(contig, start, end)
)

@abstractmethod
def _get_sample_contigs(self, include_sex_chromosomes: bool = False) -> tuple[set, set, set]:
return set(), set(), set()
Expand Down
5 changes: 1 addition & 4 deletions strkit/mi/expansionhunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def calculate_contig(self, contig: str) -> MIContigResult:

k = (contig, cv.start, cv.stop)

# Check to make sure call is present in TRF BED file, if it is specified
# Check to make sure the locus is not excluded via overlap with exclude BED
if ((self._loci_file and self._loci_dict and not self.get_loci_overlapping(*k))
or self.should_exclude_locus(*k)):
if self.should_skip_locus(*k):
continue

cr.seen_locus(*k)
Expand Down
5 changes: 1 addition & 4 deletions strkit/mi/gangstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ def calculate_contig(self, contig: str) -> MIContigResult:
# Check to make sure call is present in TRF BED file, if it is specified
k1 = (contig, cv.start, cv.stop)
k2 = (contig, cv.start + 1, cv.stop + 1)
if (self._loci_file and self._loci_dict and not self.get_loci_overlapping(*k1)
and not self.get_loci_overlapping(*k2)):
continue

if self.should_exclude_locus(*k1) or self.should_exclude_locus(*k2):
if self.should_skip_locus(*k1) or self.should_skip_locus(*k2):
continue

cr.seen_locus(*k1)
Expand Down
5 changes: 1 addition & 4 deletions strkit/mi/repeathmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ def calculate_contig(self, contig: str) -> MIContigResult:
k = (contig, locus_start, locus_end)

# Check to make sure call is present in TRF BED file, if it is specified
if self._loci_file and self._loci_dict and not self.get_loci_overlapping(*k):
continue

if self.should_exclude_locus(*k):
if self.should_skip_locus(*k):
continue

cr.seen_locus(*k)
Expand Down
12 changes: 3 additions & 9 deletions strkit/mi/strkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def calculate_contig(self, contig: str) -> MIContigResult:
start = int(locus_data[1])
end = int(locus_data[2])

# Check to make sure call is present in TRF BED file, if it is specified
if self._loci_file and self._loci_dict and not self.get_loci_overlapping(contig, start, end):
if self.should_skip_locus(contig, start, end):
continue

# Check to make sure call is present in all trio individuals
Expand Down Expand Up @@ -203,10 +202,7 @@ def calculate_contig(self, contig: str) -> MIContigResult:
k = (contig, int(locus_start), int(locus_end))

# Check to make sure call is present in TRF BED file, if it is specified
if self._loci_file and self._loci_dict and not self.get_loci_overlapping(*k):
continue

if self.should_exclude_locus(*k):
if self.should_skip_locus(*k):
continue

cr.seen_locus(*k)
Expand Down Expand Up @@ -282,14 +278,12 @@ def calculate_contig(self, contig: str) -> MIContigResult:
# TODO: Handle sex chromosomes

# Check to make sure call is present in TRF BED file, if it is specified
if ((self._loci_file and self._loci_dict and not self.get_loci_overlapping(*k))
or self.should_exclude_locus(*k)):
if self.should_skip_locus(*k):
continue

cr.seen_locus(*k)

if mv is None or fv is None:
print("!!", k, list(mvf.fetch(*k)))
# Variant isn't found in at least one of the parents, so we can't do anything with it.
# TODO: We need to actually check calls, and check with sample ID, not just assume
continue
Expand Down
7 changes: 1 addition & 6 deletions strkit/mi/tandem_genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ def calculate_contig(self, contig: str) -> MIContigResult:

k = (contig, int(lookup[1]), int(lookup[2]))

# Check to make sure call is present in TRF BED file, if it is specified
if self._loci_file and self._loci_dict and not self.get_loci_overlapping(*k):
continue

# noinspection PyTypeChecker
if self.should_exclude_locus(*k):
if self.should_skip_locus(*k):
continue

cr.seen_locus(*k)
Expand Down

0 comments on commit 4e25a17

Please sign in to comment.