forked from kyclark/biofx_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution1_zip_enumerate.py
executable file
·50 lines (35 loc) · 1.29 KB
/
solution1_zip_enumerate.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
49
50
#!/usr/bin/env python3
""" Locating Restriction Sites """
import argparse
from typing import NamedTuple, TextIO
from Bio import SeqIO, Seq
from common import find_kmers, fst, snd
class Args(NamedTuple):
""" Command-line arguments """
file: TextIO
# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """
parser = argparse.ArgumentParser(
description='Locating Restriction Sites',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('file',
help='Input FASTA file',
metavar='FILE',
type=argparse.FileType('rt'))
args = parser.parse_args()
return Args(args.file)
# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """
args = get_args()
for rec in SeqIO.parse(args.file, 'fasta'):
for k in range(4, 13):
kmers = find_kmers(str(rec.seq), k)
revc = list(map(Seq.reverse_complement, kmers))
for pos, pair in enumerate(zip(kmers, revc)):
if fst(pair) == snd(pair):
print(pos + 1, k)
# --------------------------------------------------
if __name__ == '__main__':
main()