-
Notifications
You must be signed in to change notification settings - Fork 0
/
investigate-chain-moran.py
57 lines (50 loc) · 1.53 KB
/
investigate-chain-moran.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
51
52
53
54
55
56
57
"""
Look in detail at finite-N A--B--C mutation continuous time Moran process.
This is the simplest parent-dependent mutational process that I can imagine.
"""
import argparse
import math
import numpy as np
import scipy.linalg
import scipy.stats
import wrightcore
import multinomstate
import MatrixUtil
def main(args):
alpha = args.alpha
N = args.N
k = 3
print 'alpha:', alpha
print 'N:', N
print 'k:', k
print
M = np.array(list(multinomstate.gen_states(N, k)), dtype=int)
T = multinomstate.get_inverse_map(M)
R_mut = wrightcore.create_mutation_abc(M, T)
R_drift = wrightcore.create_moran_drift_rate_k3(M, T)
Q = alpha * R_mut + R_drift
# pick out the correct eigenvector
W, V = scipy.linalg.eig(Q.T)
w, v = min(zip(np.abs(W), V.T))
print 'rate matrix:'
print Q
print
print 'transpose of rate matrix:'
print Q.T
print
print 'eigendecomposition of transpose of rate matrix as integers:'
print scipy.linalg.eig(Q.T)
print
print 'transpose of rate matrix in mathematica notation:'
print MatrixUtil.m_to_mathematica_string(Q.T.astype(int))
print
print 'abs eigenvector corresponding to smallest abs eigenvalue:'
print np.abs(v)
print
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--alpha', default=2.0, type=float,
help='concentration parameter of beta distribution')
parser.add_argument('--N', default=5, type=int,
help='population size'),
main(parser.parse_args())