-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwobble bonding.py
36 lines (34 loc) · 1.04 KB
/
wobble bonding.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
#include wobble bonding
def pair(a, b):
if a == "A" and b == "U":
return True
elif a == "U" and b == "A":
return True
elif a == "G" and b == "C":
return True
elif a == "C" and b == "G":
return True
elif a == "G" and b == "U":
return True
elif a == "U" and b == "G":
return True
else:
return False
# Motzkin number on the basis of Catalan number
def catalan(dna, cata):
#bonding distance >= 4
if len(dna) <= 4:
return 1
if dna in cata:
return cata[dna]
n = len(dna)
c=0
for m in range(4, n):
if pair(dna[0], dna[m]):
c += (catalan(dna[1:m], cata) * catalan(dna[m+1:], cata))
c += catalan(dna[1:], cata)
cata[dna] = c
return cata[dna]
dna = 'CACCGUUUUCACACAAUUUGACUGUGAACCAGCGGAAAAUCCGACGGAGCUUGGAUUCAGUCCAGAACGAUAGAUCAUUUGAAGCUAUUUAUGUAUUCCCGUUUUUUGGUGGUACACCCAUUUUAGUUAAGUCCGACGUCCAUGUGUAAAGAUUCCUCGAGACUCAUGGCCGCCG'
cata = {}
print(catalan(dna, cata))