From 8a7da91f59725dc947a35cc36be18d607c7284df Mon Sep 17 00:00:00 2001 From: Spill-Tea Date: Mon, 29 Sep 2025 00:23:58 -0700 Subject: [PATCH 1/2] feat(oligos): Minor ~10% speed improvement of nrepeats_py function. --- src/designer_dna/oligos.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/designer_dna/oligos.py b/src/designer_dna/oligos.py index f97cb98..acda2b2 100644 --- a/src/designer_dna/oligos.py +++ b/src/designer_dna/oligos.py @@ -283,19 +283,19 @@ def nrepeats_py(sequence: str, n: int) -> int: nrepeats_py("ACAACAACA", 3) == 2 # True """ - previous: list[str] = [sequence[i : n + i] for i in range(n)] - current: list[int] = [0] * n max_val: int = 0 - for j in range(n, len(sequence), n): - for k in range(n): + for k in range(n): + previous: str = sequence[k : n + k] + current: int = 0 + for j in range(n, len(sequence), n): phase: str = sequence[j + k : j + k + n] - if phase == previous[k]: - current[k] += 1 - if current[k] > max_val: - max_val = current[k] + if phase == previous: + current += 1 + if current > max_val: + max_val = current else: - current[k] = 0 - previous[k] = phase + current = 0 + previous = phase return max_val From cbb8b1b2561c12f24b51ef50c557c9054702901f Mon Sep 17 00:00:00 2001 From: Spill-Tea Date: Mon, 29 Sep 2025 00:36:46 -0700 Subject: [PATCH 2/2] feat(oligos): Minor minor speed up clean up of nrepeats py function. --- src/designer_dna/oligos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/designer_dna/oligos.py b/src/designer_dna/oligos.py index acda2b2..2e5b07b 100644 --- a/src/designer_dna/oligos.py +++ b/src/designer_dna/oligos.py @@ -284,11 +284,12 @@ def nrepeats_py(sequence: str, n: int) -> int: """ max_val: int = 0 + length: int = len(sequence) for k in range(n): previous: str = sequence[k : n + k] current: int = 0 - for j in range(n, len(sequence), n): + for j in range(n, length, n): phase: str = sequence[j + k : j + k + n] if phase == previous: current += 1