Skip to content

Commit

Permalink
Merge branch 'max-trim-percent' into 'master'
Browse files Browse the repository at this point in the history
set a max trim percent threshold

See merge request machine-learning/bonito!103
  • Loading branch information
iiSeymour committed Sep 12, 2022
2 parents f00c6b3 + 5fadc78 commit f0bf3b7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bonito/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit f0bf3b7

Please sign in to comment.