forked from kyclark/biofx_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution4_kmers_functional.py
executable file
·48 lines (33 loc) · 1.18 KB
/
solution4_kmers_functional.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
""" Find subsequences """
import argparse
from itertools import starmap
from typing import NamedTuple, Iterator
class Args(NamedTuple):
""" Command-line arguments """
seq: str
subseq: str
# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """
parser = argparse.ArgumentParser(
description='Find subsequences',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('seq', metavar='seq', help='Sequence')
parser.add_argument('subseq', metavar='subseq', help='Sub-sequence')
args = parser.parse_args()
return Args(args.seq, args.subseq)
# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """
args = get_args()
seq, subseq = args.seq, args.subseq
k = len(subseq)
kmers = enumerate(seq[i:i + k] for i in range(len(seq) - k + 1))
found: Iterator[int] = filter(
None, starmap(lambda i, kmer: i + 1
if kmer == subseq else None, kmers))
print(*found)
# --------------------------------------------------
if __name__ == '__main__':
main()