Skip to content

Commit

Permalink
chore(mi): LongTR: report skip reason
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Nov 12, 2024
1 parent 6943a1b commit cfc80b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions strkit/mi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,30 @@ def get_loci_overlapping(
self, contig: str, start: int, end: int, first_only: bool
) -> list[tuple[int, int, list[str]]]:
return overlapping_loci_dict_of_dict(
contig, start, end, self._loci_dict, first_only, dict_cache_key=self._loci_dict_cache_key
contig, start, end, self._loci_dict, first_only, dict_cache_key=self._loci_dict_cache_key
)

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, True))

def should_skip_locus(self, contig: str, start: int, end: int, cached_overlapping: Optional[list] = None) -> bool:
def should_skip_locus(
self, contig: str, start: int, end: int, cached_overlapping: Optional[list] = None
) -> str | None:
# Returns either a reason string (if yes) or None (=== no)

# 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 (cached_overlapping or self.get_loci_overlapping(contig, start, end, True))
)
or self.should_exclude_locus(contig, start, end)
)

if not self._loci_file or not self._loci_dict:
return None

if not (cached_overlapping or self.get_loci_overlapping(contig, start, end, True)):
return "no overlapping loci"

if self.should_exclude_locus(contig, start, end):
return "should_exclude_locus returned True"

return None

@abstractmethod
def _get_sample_contigs(self) -> tuple[set, set, set]:
Expand Down
4 changes: 2 additions & 2 deletions strkit/mi/longtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def calculate_contig(self, contig: str) -> MIContigResult:

overlapping = self.get_loci_overlapping(k[0], k[1], k[2], True)

if self.should_skip_locus(k[0], k[1], k[2], cached_overlapping=overlapping):
self._logger.debug(f"Skipping locus {k}: no overlap with BED")
if r := self.should_skip_locus(k[0], k[1], k[2], cached_overlapping=overlapping):
self._logger.debug(f"Skipping locus {k}: {r}")
continue

cr.seen_locus(*k)
Expand Down

0 comments on commit cfc80b6

Please sign in to comment.