From 5fadc781ebbede7369e66fbbf37c5d83c5226e12 Mon Sep 17 00:00:00 2001 From: Chris Seymour Date: Mon, 12 Sep 2022 11:19:18 +0000 Subject: [PATCH] set a max trim percent threshold --- bonito/reader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bonito/reader.py b/bonito/reader.py index 086f4107..49c7d56a 100644 --- a/bonito/reader.py +++ b/bonito/reader.py @@ -108,9 +108,9 @@ def read_chunks(read, chunksize=4000, overlap=400): yield ReadChunk(read, block.numpy(), i+1, blocks.shape[0]) -def trim(signal, window_size=40, threshold=2.4, min_trim=10, min_elements=3, max_samples=8000): - seen_peak = False +def trim(signal, window_size=40, threshold=2.4, min_trim=10, min_elements=3, max_samples=8000, max_trim=0.3): + seen_peak = False num_windows = min(max_samples, len(signal)) // window_size for pos in range(num_windows): @@ -121,7 +121,7 @@ def trim(signal, window_size=40, threshold=2.4, min_trim=10, min_elements=3, max seen_peak = True if window[-1] > threshold: continue - if end >= min(max_samples, len(signal)): + if end >= min(max_samples, len(signal)) or end / len(signal) > max_trim: return min_trim return end