-
Notifications
You must be signed in to change notification settings - Fork 0
/
motz.py
executable file
·49 lines (35 loc) · 985 Bytes
/
motz.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
#! /usr/bin/python3
import sys
import argparse
import signal
import numpy as np
import tools
_dtable = dict()
def motz(s, mod):
if s in _dtable:
return _dtable[s]
if len(s) < 2:
return 1
def match(i, j):
return int({s[i], s[j]} in [{'A', 'U'}, {'C', 'G'}])
res = motz(s[1:], mod)
for i in range(1, len(s)):
if match(0, i):
res = (res + motz(s[1:i], mod) * motz(s[i+1:], mod)) % mod
_dtable[s] = res
return res
def main(args):
inputs = tools.io.read_fasta(sys.stdin)
rna = ''.join(next(inputs)[1])
mod = 1000000
print(motz(rna, mod))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='description',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
args = parser.parse_args()
try:
main(args)
except BrokenPipeError:
sys.exit(128 + signal.SIGPIPE)
except KeyboardInterrupt:
sys.exit(128 + signal.SIGINT)