Skip to content

Commit

Permalink
lazy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kyclark committed Feb 13, 2021
1 parent 6a6cb60 commit 7e4a4cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions 11_mprt/solution1_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def main():

for file in files:
prot_id, _ = os.path.splitext(os.path.basename(file))
if recs := list(SeqIO.parse(file, 'fasta')):
if matches := list(regex.finditer(str(recs[0].seq))):
recs = SeqIO.parse(file, 'fasta')
if rec := next(recs):
if matches := list(regex.finditer(str(rec.seq))):
print(prot_id)
print(*[match.start() + 1 for match in matches])

Expand Down
5 changes: 3 additions & 2 deletions 11_mprt/solution2_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def main() -> None:

for file in files:
prot_id, _ = os.path.splitext(os.path.basename(file))
if recs := list(SeqIO.parse(file, 'fasta')):
if matches := find_motif(str(recs[0].seq)):
recs = SeqIO.parse(file, 'fasta')
if rec := next(recs):
if matches := find_motif(str(rec.seq)):
pos = map(lambda p: p + 1, matches)
print('\n'.join([prot_id, ' '.join(map(str, pos))]))

Expand Down

0 comments on commit 7e4a4cc

Please sign in to comment.