Skip to content

Commit

Permalink
Add lphy script
Browse files Browse the repository at this point in the history
  • Loading branch information
glstott committed May 15, 2024
1 parent df3a1da commit 5c00fa7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions nextflow/scripts/discrete_symmetric.lphy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
data {
// Specify options for reading the date information from file
options = {ageDirection="forward", ageRegex=".*_.*_(\d*\.\d+|\d+\.\d*)$"};
D = readNexus(file="data/simulated.nex", options=options);

// Retrieve number of sites in alignment and taxa names
L = D.nchar();
taxa = D.taxa();

// Extract Trait information and count # of traits
D_trait = extractTrait(taxa=taxa, sep="_", i=0);
K = D_trait.canonicalStateCount();

// Specify the data type for traits and number of pairwise combos
dim = K*(K-1)/2;
dataType = D_trait.dataType();
}
model {
// Model evolutionary history
Π ~ Dirichlet(conc=[2.0, 2.0, 2.0, 2.0]); // Nucleotide Frequency prior
κ ~ LogNormal(meanlog=1.0, sdlog=1.25); // Transition/transversion ratio prior
γ ~ LogNormal(meanlog=0.0, sdlog=2.0); // Shape parameter for discretized gamma
r ~ DiscretizeGamma(shape=γ, ncat=4,
replicates=L); // Site rates
Θ ~ LogNormal(meanlog=0.0, sdlog=1.0); // Effective population size prior
ψ ~ Coalescent(taxa=taxa, theta=Θ); // Coalescent time scaled phylogenetic tree prior
D ~ PhyloCTMC(Q=hky(kappa=κ, freq=Π), mu=0.004,
siteRates=r, tree=ψ); // MCMC for evolution of alignment

// Model the geographic history
// modeled via P(t) = e^(Dt)
π_trait ~ Dirichlet(conc=rep(element=3.0, times=K)); // Base frequencies, assuming symmetry
I ~ Bernoulli(minSuccesses=dim-2, p=0.5,
replicates=dim); // Determines which rates are 0.
// This, plus select, implements BSSVS.
R_trait ~ Dirichlet(conc=rep(element=1.0, times=dim)); // Off-diagonal entries of the rate matrix.
Q_trait = generalTimeReversible(rates=select(x=R_trait,
indicator=I), freq=π_trait); // intantaneous rate matrix
μ_trait ~ LogNormal(meanlog=0, sdlog=1.25); // migration events per unit time
D_trait ~ PhyloCTMC(L=1, Q=Q_trait, dataType=dataType,
mu=μ_trait, tree=ψ); // MCMC for discrete locations
}

0 comments on commit 5c00fa7

Please sign in to comment.