-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfret_sup35_simulation.py
More file actions
64 lines (57 loc) · 1.8 KB
/
fret_sup35_simulation.py
File metadata and controls
64 lines (57 loc) · 1.8 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
import itertools
import math
#The binomial coefficient nCk...
def binom(n, k):
if k > n or k < 0:
return 0
a = math.factorial(n)
b = math.factorial(k)
c = math.factorial(n - k)
return a / (b * c)
def a(n,y):
if n <= y:
return 0
x = math.sqrt(2)
result = - ((4 + 3 * x) / (x + 2) * 1.0) * pow((1.0/(-1.0-x)),n-y) - \
((4 - 3 * x) / (2 - x) * 1.0) * pow((1.0 / (x - 1)), n - y)
return result
def b(n):
x = math.sqrt(2)
result = - (1.0 / (2 * x + 2)) * pow((1.0 / (-1 - x)), n) - \
(1.0 / (2 - 2 * x)) * pow((1.0 / (x - 1)), n)
return result
def product(lst):
val = 1.0
for item in lst:
val *= item
return val
#This is the A(n,k) function I defined in my writeup...
def A(n, k):
result = 0.0
for q in range(0, n - k + 1):
innerSum = 0.0
for i in range(1, k + 1):
all_lists = itertools.product(range(1, n - q + 1), repeat=i)
lists_of_psi = [lst for lst in all_lists if sum(lst) == k]
all_lists = itertools.product(range(2, n - q + 1), repeat=i)
lists_of_sum_n=[lst for lst in all_lists if sum(lst)==n - q]
for lst in lists_of_sum_n:
for lst2 in lists_of_psi:
fin = zip(lst,lst2)
a_lst = [a(x,y) for x,y in fin]
innerSum += product(a_lst)
result += b(q) * innerSum
return result
#The expected number of fluorescing locations in a length n
#amyloid, according to formula I derived, is:
def expected_value(length):
result = 0.0
for i in range(0, length):
result += i * A(length, i)
result /= pow(3.0, length)
return result
if __name__ == '__main__':
for i in range(1, 1000):
r = expected_value(i) / i
print(f"{i}: {r}")