Skip to content

Commit a1d8313

Browse files
committed
Undid my regression that used regex, lol
Signed-off-by: Drew Wock <dwock@esri.com>
1 parent be73d34 commit a1d8313

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

rounds/3_dna/solution.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from concurrent.futures import ThreadPoolExecutor
1010

1111
def find_match(args):
12-
regex,record = args
12+
pattern_str,record = args
1313
# Step 3: a record looks like ``"<id>\n<seq line 1>\n<seq line 2>\n..."``.
1414
# The id is the first line; the remaining lines are joined back into a
1515
# single contiguous sequence string.
@@ -18,7 +18,14 @@ def find_match(args):
1818
sequence = "".join(lines[1:]).replace(" ", "")
1919

2020
positions: list[int] = []
21-
positions = [m.start() for m in regex.finditer(sequence)]
21+
start = 0
22+
while True:
23+
pos = sequence.find(pattern_str, start)
24+
if pos == -1:
25+
break
26+
positions.append(pos)
27+
start = pos + 1
28+
2229
if positions:
2330
return (record_id, positions)
2431
else:
@@ -38,15 +45,14 @@ def find_matches(fasta_path: str, pattern: bytes) -> list[tuple[str, list[int]]]
3845

3946
matches: list[tuple[str, list[int]]] = []
4047
pattern_str = pattern.decode('ascii')
41-
regex = re.compile(pattern_str)
4248

4349
with ThreadPoolExecutor() as ex:
4450
futures = []
4551
for record in text.split(">"):
4652
if not record.strip():
4753
continue
4854

49-
t = ex.submit(find_match, args=(regex,record))
55+
t = ex.submit(find_match, args=(pattern_str,record))
5056
futures.append(t)
5157

5258
for t in futures:

0 commit comments

Comments
 (0)