Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
133 lines (114 sloc) 3.15 KB
;; Model for measuring ancestral GC content
;; To see how the macros expand, use the -x option to xrate
;; Here's the grammar...
(grammar
(name Ancestral_GC_content)
(parametric)
;; Define a hybrid chain with a different chain on each branch.
;; What this block does is map each node name (e.g. "NODE") to its own substitution model ("CHAIN_NODE").
;; The way that branches are mapped to substitution models is via "#=GS NODE TAG VALUE" Stockholm tags.
;; This allows for arbitrary splits of the tree, to be defined in the Stockholm file.
;; However, the split we want is rather unwieldy to define in this way,
;; since we'd need to add a separate "#=GS..." line to the Stockholm file for every node of the tree.
;; We can get around this using a piece of syntactic sugar: xrate's implicit #=GS annotations.
;; Specifically, we use the special "?" TAG, whose VALUE xrate implicitly defines as the name of the node.
(hybrid-chain
(terminal (HYBRID)) ;; the name of the hybrid chain
(row ?) ;; the #=GS tag used to select substitution models (automagically equal to the node name)
(components
(&foreach-branch ;; loop over node names
NODE
((label NODE) (terminal ((&. CHAIN_ NODE)))) ;; if the #=GS tag has value NODE, set the chain to CHAIN_NODE
)
)
)
;; Main loop over branches
(&foreach-branch
NODE
;; Parameters
;; Branch-specific GC/AT content
(pgroup
(((&. pGC_ NODE) 0.5) ((&. pAT_ NODE) 0.5))
)
;; Branch-specific substitution rate
(rate
((&. RATE_ NODE) 1)
)
;; Branch-specific substitution rate matrix
(chain
(update-policy parametric)
(terminal ((&. CHAIN_ NODE)))
(&foreach-token
SRC
;; initial probability distribution
(initial (state (SRC)) (prob ((&. (&?
(&or
(&= SRC g)
(&= SRC c)
)
pGC_
pAT_
)
NODE) / 2)))
;; mutation rates
(&foreach-token
DEST
(&?
(&= SRC DEST)
()
(mutate
(from (SRC))
(to (DEST))
(rate (((&. RATE_ NODE) * (&. (&?
(&or
(&= DEST g)
(&= DEST c)
)
pGC_
pAT_
)
NODE))))
)
)
)
)
) ;; end chain
) ;; end loop over branches
;; transformation rules
;; START state
(transform
(from (START))
(to (EMIT)))
(transform
(from (START))
(to ()))
;; EMIT state
(transform
(from (EMIT))
(to (HYBRID EMIT*)))
(transform
(from (EMIT*))
(to (EMIT)))
(transform
(from (EMIT*))
(to ()))
) ;; end grammar Ancestral_GC_content
(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