/
rescaled_branch_phylohmm.eg
161 lines (134 loc) · 3.35 KB
/
rescaled_branch_phylohmm.eg
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;; Clone of DLESS-style phylo-HMM, to illustrate xrate macro functionality
;; To see how the macros expand, type the following:
;; echo | xrate -g dart/grammars/rescaled_branch_phylohmm.eg -t expanded.eg
;; more expanded.eg
;; Here's the grammar...
(grammar
(name DLESS_Doppelganger)
(parametric)
;; Probability parameters
(pgroup
;; Initial distribution over states
((&foreach-token TOK ((&. p TOK) (&/ 1 &TOKENS))))
;; Probability of staying in the same branch-scale class, or leaving
((stayProb .9) (leaveProb .1))
)
;; Rate parameters
(rate
(regular_rate 1)
(rescaled_rate 0.1)
)
;; define regular_chain and rescaled_chain
(&foreach
TYPE
(regular rescaled)
;; Markov chain for residue substitution
(chain
(update-policy parametric)
(terminal ((&. TYPE _chain)))
;; initial probability distribution
(&foreach-token
TOK
(initial (state (TOK)) (prob (&. p TOK)))
)
;; mutation rates
(&foreach-token
SRC
(&foreach-token
DEST
(&?
(&= SRC DEST)
()
(mutate (from (SRC)) (to (DEST)) (rate (((&. TYPE _ rate) * (&. p DEST)))))
)
)
)
) ;; end chain
)
;; Main loop over branches
(&foreach-branch
NODE
;; Define a hybrid chain for each branch
(hybrid-chain
(terminal ((&. hybrid_ NODE)))
(row (&. = NODE))
(components
((label 0) (terminal (regular_chain)))
((label 1) (terminal (rescaled_chain)))
)
)
;; transformation rules for state S{NODE}
(transform
(from (START))
(to ((&. SCALE_ NODE)))
(prob (&+ 1 (&/ 1 &BRANCHES))))
(transform
(from (REGULAR*))
(to ((&. SCALE_ NODE)))
(prob leaveProb * (&/ 1 (&+ 1 &BRANCHES))))
(transform
(from ((&. SCALE_ NODE)))
(to ((&. hybrid_ NODE) (&. SCALE_ NODE *)))
(annotate
(row (&. NODE _rescaled))
(column (&. hybrid_ NODE))
(label 1)))
(transform
(from ((&. SCALE_ NODE *)))
(to ()) (prob 1))
(transform
(from ((&. SCALE_ NODE *)))
(to (REGULAR))
(prob leaveProb * (&/ 1 (&+ 1 &BRANCHES))))
;; transitions
(&foreach-branch
DEST_NODE
(transform
(from ((&. SCALE_ NODE *)))
(to ((&. SCALE_ DEST_NODE)))
(prob (&?
(&= NODE DEST_NODE)
(stayProb)
(leaveProb * (&/ 1 (&+ 1 &BRANCHES)))
)
))
)
) ;; end main loop over branches
;; Other transitions involving START and REGULAR
(transform
(from (START))
(to (REGULAR))
(prob (&/ 1 (&+ 1 &BRANCHES))))
;; Add a START->END transition, so empty alignments don't have zero likelihood
(transform
(from (START))
(to ()))
;; REGULAR state: no rescaled branches
(transform
(from (REGULAR))
(to (regular_chain REGULAR*))
)
(transform
(from (REGULAR*))
(to (REGULAR))
(prob stayProb))
) ;; end grammar DLESS_Doppelganger
(alphabet
(name RNA)
(token (a c g u))
(complement (u g c a))
(extend (to n) (from a) (from c) (from g) (from u))
(extend (to x) (from a) (from c) (from g) (from u))
(extend (to t) (from u))
(extend (to r) (from a) (from g))
(extend (to y) (from c) (from u))
(extend (to m) (from a) (from c))
(extend (to k) (from g) (from u))
(extend (to s) (from c) (from g))
(extend (to w) (from a) (from u))
(extend (to h) (from a) (from c) (from u))
(extend (to b) (from c) (from g) (from u))
(extend (to v) (from a) (from c) (from g))
(extend (to d) (from a) (from g) (from u))
(wildcard *)
) ;; end alphabet RNA