diff --git a/strkit/mi/base.py b/strkit/mi/base.py index 7b927cb..3805bf4 100644 --- a/strkit/mi/base.py +++ b/strkit/mi/base.py @@ -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]: diff --git a/strkit/mi/longtr.py b/strkit/mi/longtr.py index d17adb8..9cd55cc 100644 --- a/strkit/mi/longtr.py +++ b/strkit/mi/longtr.py @@ -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)