Skip to content

Commit

Permalink
Ensure name_filter actually filters peaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Aug 1, 2023
1 parent 54c7ddb commit 0b71268
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions libgunshotmatch/consolidate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,32 @@ def print_skip_reason(self, peak: ConsolidatedPeak, reason: str) -> None:
if self.verbose:
print(f"Skipping peak at {peak.rt / 60:0.3f} mins:", reason)

def should_filter_peak(self, peak: ConsolidatedPeak) -> bool:
"""
Returns :py:obj:`True` if the peak should be excluded based on the current filter options.
:param peak:
"""

hit = peak.hits[0]

if len(hit) < self.min_appearances:
self.print_skip_reason(peak, f"top hit {hit.name!r} only appears {len(hit)} times")
return True

for nf in self.name_filter:
if fnmatch.fnmatch(hit.name.lower(), nf):
self.print_skip_reason(peak, f"name {hit.name!r} matches {nf!r}")
return True

# mean_match_factor = mean(hit.mf_list)
mean_match_factor = hit.match_factor
if mean_match_factor < self.min_match_factor:
self.print_skip_reason(peak, f"MF {mean_match_factor} <600")
return True

return False

def filter(self, consolidated_peaks: List[ConsolidatedPeak]) -> List[ConsolidatedPeak]: # noqa: A003 # pylint: disable=redefined-builtin
"""
Filter a list of consolidated peaks.
Expand All @@ -724,23 +750,7 @@ def filter(self, consolidated_peaks: List[ConsolidatedPeak]) -> List[Consolidate
filtered_consolidated_peaks = []

for cp in consolidated_peaks:
hit = cp.hits[0]

if len(hit) < self.min_appearances:
self.print_skip_reason(cp, f"top hit {hit.name!r} only appears {len(hit)} times")
continue

for nf in self.name_filter:
if fnmatch.fnmatch(hit.name.lower(), nf):
self.print_skip_reason(cp, f"name {hit.name!r} matches {nf!r}")
continue

# mean_match_factor = mean(hit.mf_list)
mean_match_factor = hit.match_factor
if mean_match_factor < self.min_match_factor:
self.print_skip_reason(cp, f"MF {mean_match_factor} <600")
continue

filtered_consolidated_peaks.append(cp)
if not self.should_filter_peak(cp):
filtered_consolidated_peaks.append(cp)

return filtered_consolidated_peaks

0 comments on commit 0b71268

Please sign in to comment.