Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (111 sloc) 3.67 KB
;; This phylo-HMM has &COLUMNS states.
;; Each state has its own Markov chain for generating an alignment column.
;; Each chain is parameterized by one rate parameter and a probability distribution over &TOKENS.
;; Each column's substitution model thus follows the idea of (Felsenstein, 1981)
;; and the overall construct is something like (Bruno, 1996).
(name Site_specific_frequencies)
(update-rates 1)
(update-rules 1)
;; Transition from START state to first column
;; This must come before any other transitions,
;; so that START is the first nonterminal.
(from (START))
(to (&?
(&= &COLUMNS 0)
() ;; if zero columns, alignment is empty: just goto end state
(NONTERM1))) ;; otherwise, goto NONTERM1
;; Main loop over columns
(&warn Generating column COLUMN ...)
;; First, define the parameters for COLUMN, and their priors.
;; Rate parameter for COLUMN
((&. Rate COLUMN) 1) ;; seed the rate at one
;; Pseudocounts for the rate parameter (effectively specifying a gamma prior)
((&. Rate COLUMN)
1 ;; shape parameter
1 ;; scale parameter
;; Frequency parameters for COLUMN
((&. Freq COLUMN TOK)
(&/ 1 &TOKENS)))) ;; seed with flat frequency distribution
;; Pseudocounts for the frequency parameters (effectively specifying a Dirichlet prior)
((&. Freq COLUMN TOK)
1)) ;; pseudocount of 1 for each frequency parameter (Laplace)
;; Now define the Markov chain substitution matrix for COLUMN,
;; specifying the functional mapping from the rate matrix to the parameters.
(update-policy parametric)
(terminal ((&. TERM COLUMN)))
;; initial probability of being in state SRC is Freq[COLUMN][SRC]
(state (SRC))
(prob ((&. Freq COLUMN SRC))))
;; mutation rate from SRC to DEST is Rate[COLUMN] * Freq[COLUMN][DEST]
() ;; if SRC=DEST, just insert empty brackets (which will be ignored) into the chain expression
(mutate ;; SRC != DEST
(from (SRC))
(to (DEST))
(rate ((&. Rate COLUMN) * (&. Freq COLUMN DEST)))
) ;; end of chain
;; Emission of COLUMN
;; The mapping from phyloHMM state to Markov chain.
(from ((&. NONTERM COLUMN)))
;; The following "minlen" and "maxlen" clauses help the DP run more efficiently,
;; by avoiding computation of the emission likelihoods except at the one subsequence where it matters.
;; The "len" in this co-ordinate scheme refers to the length of the Inside subsequence,
;; which is (1 + &COLUMNS - COLUMN).
(minlen (&+ 1 (&- &COLUMNS COLUMN)))
(maxlen (&+ 1 (&- &COLUMNS COLUMN)))
;; Transition to next COLUMN
;; The connectivity of the phyloHMM.
(from ((&. NONTERM COLUMN *)))
(to (&?
(&< COLUMN &COLUMNS) ;; still more columns to go?
((&. NONTERM (&+ COLUMN 1))) ;; yes, so goto next column
() ;; no, so goto end state
) ;; end main loop over columns
;; alphabet
(name Protein)
(token (a r n d c q e g h i l k m f p s t w y v))
(extend (to x) (from a) (from r) (from n) (from d) (from c) (from q) (from e) (from g) (from h) (from i) (from l) (from k) (from m) (from f) (from p) (from s) (from t) (from w) (from y) (from v))
(extend (to b) (from n) (from d))
(extend (to z) (from q) (from e))
(wildcard *)
) ;; end alphabet Protein