| 1 |
module Model where |
| 2 |
|
| 3 |
import Bio.Alignment |
| 4 |
import Bio.Alphabet |
| 5 |
import IModel |
| 6 |
import MCMC |
| 7 |
import Probability |
| 8 |
import SModel |
| 9 |
import SModel.Parsimony |
| 10 |
import System.Environment |
| 11 |
import Tree |
| 12 |
import Tree.Newick |
| 13 |
|
| 14 |
gtr_m7_model codons = do |
| 15 |
let nucs = getNucleotides codons |
| 16 |
|
| 17 |
-- GTR model parameters |
| 18 |
sym <- sample $ symmetricDirichletOn (letter_pair_names nucs) 1 |
| 19 |
pi <- sample $ symmetricDirichletOn (getLetters nucs) 1 |
| 20 |
|
| 21 |
let posSelModel w = gtr' sym pi nucs +> x3 codons +> dNdS w |
| 22 |
|
| 23 |
-- M7 model parameters |
| 24 |
mu <- sample $ uniform 0 1 |
| 25 |
gamma <- sample $ beta 1 10 |
| 26 |
let m7Model = posSelModel +> m7 mu gamma 4 |
| 27 |
|
| 28 |
let loggers = |
| 29 |
[ "gtr:sym" %=% sym |
| 30 |
, "gtr:pi" %=% pi |
| 31 |
, "m7:mu" %=% mu |
| 32 |
, "m7:gamma" %=% gamma |
| 33 |
] |
| 34 |
|
| 35 |
return (m7Model, loggers) |
| 36 |
|
| 37 |
model sequenceData = do |
| 38 |
let taxa = getTaxa sequenceData |
| 39 |
|
| 40 |
tree <- sample $ uniformLabelledTree taxa (gamma 0.5 (1 / fromIntegral (length taxa))) |
| 41 |
let tlength = treeLength tree |
| 42 |
|
| 43 |
sigma <- sample $ logLaplace (-3) 1 |
| 44 |
indelRates <- fmap (** sigma) <$> sample (iidMap (getUEdgesSet tree) (logNormal 0 1)) |
| 45 |
let indelTree = addBranchRates indelRates tree |
| 46 |
|
| 47 |
scale <- sample $ gamma 0.5 2 |
| 48 |
addMove 2 (scaleGroupsSlice [scale] (branchLengths tree)) |
| 49 |
addMove 1 (scaleGroupsMH [scale] (branchLengths tree)) |
| 50 |
|
| 51 |
(m7_model, log_m7_model) <- gtr_m7_model (mkCodons dna (geneticCode "standard")) |
| 52 |
|
| 53 |
rate <- sample $ logLaplace (-4) 0.707 |
| 54 |
meanLength <- sample $ shifted_exponential 10 1 |
| 55 |
let imodel = IModel.rs07 rate meanLength tree |
| 56 |
|
| 57 |
let sequenceLengths = getSequenceLengths sequenceData |
| 58 |
(alignment, propertiesA) <- sampleWithProps (phyloAlignment indelTree imodel scale sequenceLengths) |
| 59 |
properties <- observe sequenceData (phyloCTMC tree alignment m7_model scale) |
| 60 |
|
| 61 |
let alignment_length = alignmentLength alignment |
| 62 |
let num_indels = totalNumIndels alignment |
| 63 |
let total_length_indels = totalLengthIndels alignment |
| 64 |
let prior_A = ln (probability propertiesA) |
| 65 |
let anc_alignment = toFasta (prop_anc_seqs properties) |
| 66 |
let substs = parsimony tree (unitCostMatrix (mkCodons dna standard_code)) (sequenceData, alignment) |
| 67 |
|
| 68 |
let loggers = |
| 69 |
["indelRates:sigma" %=% sigma |
| 70 |
, "S1" %>% log_m7_model |
| 71 |
, "rs07:rate" %=% rate |
| 72 |
, "rs07:mean_length" %=% meanLength |
| 73 |
, "scale" %=% scale |
| 74 |
, "scale*|T|" %=% (scale * tlength) |
| 75 |
, "|A|" %=% alignment_length |
| 76 |
, "#indels" %=% num_indels |
| 77 |
, "|indels|" %=% total_length_indels |
| 78 |
, "#substs" %=% substs |
| 79 |
, "prior_A" %=% prior_A |
| 80 |
] |
| 81 |
|
| 82 |
return loggers |
| 83 |
|
| 84 |
main logDir = do |
| 85 |
[filename] <- getArgs |
| 86 |
|
| 87 |
sequenceData <- mkUnalignedCharacterData (mkCodons dna standard_code) <$> loadSequences filename |
| 88 |
|
| 89 |
return $ model sequenceData |