Skip to content

Commit

Permalink
add GeneratorInfo for LPhy Doc #525
Browse files Browse the repository at this point in the history
  • Loading branch information
yxu927 committed Sep 25, 2024
1 parent daaa025 commit db050b2
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 28 deletions.
29 changes: 25 additions & 4 deletions phylonco-lphy/examples/SVS.lphy
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@ b_exp ~ LogNormal(meanlog=-0.98, sdlog=0.35);
N0_exp ~ LogNormal(meanlog=9.2, sdlog=0.2);
exponentialPopFunc = exponentialPopFunc(GrowthRate=b_exp, N0=N0_exp);

t50_gom ~ LogNormal(meanlog=4, sdlog=1.2);
t50_gom ~ LogNormal(meanlog=4, sdlog=0.2);
b_gom ~ LogNormal(meanlog=-0.98, sdlog=0.35);
NInf_gomp ~ LogNormal(meanlog=9.2, sdlog=0.12);
gompertzPopFunc = gompertzPopFunc_t50(NInfinity=NInf_gomp, t50=t50_gom, b=b_gom);

t50_log ~ LogNormal(meanlog=4, sdlog=1.2);
t50_log ~ LogNormal(meanlog=4, sdlog=0.2);
b_log ~ LogNormal(meanlog=-0.98, sdlog=0.35);
Ninf_log ~ LogNormal(meanlog=9.2, sdlog=0.12);
logisticPopFunc = logisticPopFunc(t50=t50_log, nCarryingCapacity=Ninf_log, b=b_log);

models = [constantPopFunc, exponentialPopFunc, logisticPopFunc, gompertzPopFunc];
tau_expansion ~ LogNormal(meanlog=4.0, sdlog=0.7);
r_expansion ~ LogNormal(meanlog=-3.0, sdlog=1.0);
NC_expansion ~ LogNormal(meanlog=8.0, sdlog=0.7);
N0_expansion ~ LogNormal(meanlog=5.15, sdlog=0.7);
expansionPopFunc = expansionPopFunc(tau=tau_expansion, N0=N0_expansion, r=r_expansion, NC=NC_expansion);

models = [constantPopFunc, exponentialPopFunc, logisticPopFunc, gompertzPopFunc, expansionPopFunc];
I ~ UniformDiscrete(lower=0, upper=length(models)-1);
SVSmodel = stochasticVariableSelection(indicator=I, models=models);
tree ~CoalescentPopFunc(n=40, popFunc=SVSmodel);
D ~ PhyloCTMC(L=2000, Q=jukesCantor(),mu=0.01, tree=tree);
κ ~ LogNormal(meanlog=1.0, sdlog=0.5);
π ~ Dirichlet(conc=[2.0,2.0,2.0,2.0]);
D ~ PhyloCTMC(L=2000, Q=hky(kappa=κ, freq=π), mu=0.00079, tree=tree);
height = tree.rootAge();
length = tree.treeLength();















//π ~ Dirichlet(conc=[30.0, 3.0, 3.0, 3.0, 3.0, 30.0, 3.0, 3.0, 3.0, 3.0, 30.0, 3.0, 3.0, 3.0, 3.0, 30.0]);
//rates ~ Dirichlet(conc=[1.0, 2.0, 1.0, 1.0, 2.0, 1.0]);
//Q = gt16(rates=rates, freq=π);
Expand Down
11 changes: 7 additions & 4 deletions phylonco-lphy/examples/expansionCoal.lphy
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
model {
tau ~ LogNormal(meanlog=1.0, sdlog=0.2);
r ~ LogNormal(meanlog=-0.95, sdlog=0.2);
NC ~ LogNormal(meanlog=6.0, sdlog=0.2);
N0 ~ LogNormal(meanlog=0.15, sdlog=0.2);
tau ~ LogNormal(meanlog=4.0, sdlog=0.7);
r ~ LogNormal(meanlog=-3.0, sdlog=0.5);
NC ~ LogNormal(meanlog=8.0, sdlog=0.7);
N0 ~ LogNormal(meanlog=5.15, sdlog=0.7);
expansionPopFunc = expansionPopFunc(tau=tau, N0=N0, r=r, NC=NC);
tree ~CoalescentPopFunc(n=40, popFunc=expansionPopFunc);
D ~ PhyloCTMC(L=1000, Q=jukesCantor(),mu=0.01, tree=tree);
height = tree.rootAge();
length = tree.treeLength();
}




tau ~ LogNormal(meanlog=1.0, sdlog=0.2);
r ~ LogNormal(meanlog=-0.95, sdlog=0.2);
NC ~ LogNormal(meanlog=6.0, sdlog=0.2);
Expand Down
3 changes: 2 additions & 1 deletion phylonco-lphy/examples/gomp_f0_jc69.lphy
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ model {
tree ~ CoalescentPopFunc(n=40, popFunc=gompertzPopFunc);
D ~ PhyloCTMC(L=L, Q=jukesCantor(), mu=0.01, tree=tree);
//height = tree.rootAge();
}
}

10 changes: 6 additions & 4 deletions phylonco-lphy/examples/gomp_t50_gt16.lphy
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ model {
rates ~ Dirichlet(conc=[1.0, 2.0, 1.0, 1.0, 2.0, 1.0]);
Q = gt16(rates=rates, freq=π);

t50 ~ LogNormal(meanlog=0.3, sdlog=0.1);
b ~ LogNormal(meanlog=2, sdlog=0.5);
NInfinity ~ LogNormal(meanlog=4.5, sdlog=0.5);
t50 ~ LogNormal(meanlog=4, sdlog=1.2);
b ~ LogNormal(meanlog=-0.98, sdlog=0.35);
NInfinity ~ LogNormal(meanlog=9.2, sdlog=0.12);

gompertzPopFunc = gompertzPopFunc_t50(NInfinity=NInfinity,t50=t50, b=b);
ψ ~ CoalescentPopFunc(n=40, popFunc=gompertzPopFunc);
Expand All @@ -18,4 +18,6 @@ delta ~ Beta(alpha=1.5, beta=4.5);
E ~ GT16ErrorModel(delta=delta, epsilon=epsilon, alignment=A);
D = unphase(alignment=E);
height = ψ.rootAge();
}
}


22 changes: 16 additions & 6 deletions phylonco-lphy/examples/gomp_t50_jc69.lphy
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ data {
L = 1000;
}
model {
t50 ~ LogNormal(meanlog=0.3, sdlog=0.1);
b ~ LogNormal(meanlog=2, sdlog=0.5);
NInfinity ~ LogNormal(meanlog=4.5, sdlog=0.5);
t50 =8.9;
b =0.226;
NInfinity =150.0;
gompertzPopFunc = gompertzPopFunc_t50(NInfinity=NInfinity,t50=t50, b=b);
//n0 = gompertzPopFunc.getN0();
//f0=n0/NInfinity;
tree ~ CoalescentPopFunc(n=40, popFunc=gompertzPopFunc);
D ~ PhyloCTMC(tree=tree, L=L, Q=jukesCantor(), mu=1e-2);
height = tree.rootAge();
}
length = tree.treeLength();
}


t50 ~ LogNormal(meanlog=4.0, sdlog=0.5);
b ~ LogNormal(meanlog=-0.98, sdlog=0.5);
NInfinity ~ LogNormal(meanlog=9.2, sdlog=1.7);


//n0 = gompertzPopFunc.getN0();
//f0=n0/NInfinity;

b ~ LogNormal(meanlog=0.4, sdlog=0.35);
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<Class<? extends Generator>> getExcludedGenerator() {
SampleBranch.class, SubstituteClade.class, SubsampledTree.class, LabelClade.class,
MRCA.class,
PopulationFunctionCoalescent.class,
SVSFunction.class,
SVSPopulationFunction.class,
GompertzPopulationFunction_f0.class,
GompertzPopulationFunction_t50.class,
ExponentialPopulationFunction.class,
Expand All @@ -90,7 +90,7 @@ public List<Class<? extends Generator>> getExcludedGenerator() {
@Override
public List<Class> getExcludedValueType() {
return Arrays.asList(TimeTreeNode.class,
SVSPopulationFunction.class);
SVSPopulation.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import beast.base.evolution.tree.TreeIntervals;
import lphy.base.evolution.coalescent.PopulationFunction;
import lphy.base.evolution.coalescent.PopulationFunctionCoalescent;
import lphy.base.evolution.coalescent.populationmodel.SVSPopulation;
import lphy.base.evolution.coalescent.populationmodel.SVSPopulationFunction;
import lphy.core.model.Value;
import lphybeast.BEASTContext;
Expand All @@ -29,7 +30,7 @@ public beast.base.evolution.tree.coalescent.Coalescent generatorToBEAST(Populati

beast.base.evolution.tree.coalescent.PopulationFunction populationFunction;

if (beastObj instanceof SVSPopulationFunction) {
if (beastObj instanceof SVSPopulation) {
populationFunction = convertSVSPopulationFunction((SVSPopulationFunction) beastObj, context);
} else if (beastObj instanceof beast.base.evolution.tree.coalescent.PopulationFunction) {
populationFunction = (beast.base.evolution.tree.coalescent.PopulationFunction) beastObj;
Expand Down Expand Up @@ -58,7 +59,7 @@ public beast.base.evolution.tree.coalescent.Coalescent generatorToBEAST(Populati
}

private beast.base.evolution.tree.coalescent.PopulationFunction convertSVSPopulationFunction(SVSPopulationFunction svsPopFunc, BEASTContext context) {
PopulationFunction model = svsPopFunc.getModel();
PopulationFunction model = (PopulationFunction) svsPopFunc.getModels();
Value<PopulationFunction> modelValue = new Value<>(model, null);

Object beastObj = context.getBEASTObject(modelValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import beast.base.inference.parameter.IntegerParameter;
import lphy.base.evolution.coalescent.PopulationFunction;
import lphy.base.evolution.coalescent.populationmodel.SVSFunction;
import lphy.base.evolution.coalescent.populationmodel.SVSPopulation;
import lphy.base.evolution.coalescent.populationmodel.SVSPopulationFunction;
import lphy.core.model.GraphicalModelNode;
import lphy.core.model.Value;
Expand All @@ -13,14 +13,14 @@

import java.util.ArrayList;

public class SVSPopulationFunctionToBEAST implements ValueToBEAST<SVSPopulationFunction, StochasticVariableSelection> {
public class SVSPopulationFunctionToBEAST implements ValueToBEAST<SVSPopulation, StochasticVariableSelection> {

@Override
public StochasticVariableSelection valueToBEAST(Value<SVSPopulationFunction> lphyPopFuncVal, BEASTContext context) {
public StochasticVariableSelection valueToBEAST(Value<SVSPopulation> lphyPopFuncVal, BEASTContext context) {

StochasticVariableSelection beastPopFunc = new StochasticVariableSelection();

SVSFunction gen = (SVSFunction) lphyPopFuncVal.getGenerator();
SVSPopulationFunction gen = (SVSPopulationFunction) lphyPopFuncVal.getGenerator();

IntegerParameter indicatorParam = context.getAsIntegerParameter(gen.getIndicator());

Expand Down Expand Up @@ -68,7 +68,7 @@ public StochasticVariableSelection valueToBEAST(Value<SVSPopulationFunction> lph

@Override
public Class getValueClass() {
return SVSPopulationFunction.class;
return SVSPopulation.class;
}

@Override
Expand Down

0 comments on commit db050b2

Please sign in to comment.