diff --git a/examples/birth-death/calibratedYule.lphy b/examples/birth-death/calibratedYule.lphy new file mode 100644 index 00000000..81e85839 --- /dev/null +++ b/examples/birth-death/calibratedYule.lphy @@ -0,0 +1,6 @@ +λ ~ LogNormal(meanlog=3.0, sdlog=1.0); +clade1TaxaNames = ["1","2","3"]; +clade2TaxaNames = ["1","2","3"]; +clade1MRCAAge ~ Uniform(lower=5, upper=8); +clade2MRCAAge ~ Uniform(lower=5, upper=8); +ψ ~ CalibratedYule(lambda=λ, n=16, cladeTaxa=[clade1TaxaNames,clade2TaxaNames], cladeMRCAAge=[clade1MRCAAge,clade2MRCAAge]); \ No newline at end of file diff --git a/lphy-base/src/main/java/lphy/base/evolution/birthdeath/CalibratedYule.java b/lphy-base/src/main/java/lphy/base/evolution/birthdeath/CalibratedYule.java index d99b664c..1f5e9ae5 100644 --- a/lphy-base/src/main/java/lphy/base/evolution/birthdeath/CalibratedYule.java +++ b/lphy-base/src/main/java/lphy/base/evolution/birthdeath/CalibratedYule.java @@ -72,7 +72,7 @@ private int getTaxaLength(Value taxa) { } @GeneratorInfo(name = "CalibratedYule", - category = GeneratorCategory.BD_TREE, + category = GeneratorCategory.BD_TREE, examples = {"calibratedYule.lphy"}, description = "The CalibratedYule method accepts one or more clade taxa and generates a tip-labelled time tree. If a root age is provided, the method conditions the tree generation on this root age.") @Override public RandomVariable sample() { @@ -141,7 +141,6 @@ public RandomVariable sample() { // get a certain lambda for Yule coalescent double lambda = (double) getBirthRate().value(); - System.out.println("done initialising"); // coalescent double t = 0.0; @@ -174,7 +173,6 @@ public RandomVariable sample() { } else coalesceNodes(activeNodes, t); } - System.out.println("done coalescent"); // set root to construct the tree if (tree != null) { tree.setRoot(activeNodes.get(0), true); @@ -191,8 +189,7 @@ public RandomVariable sample() { } } - System.out.println("calibrated yule tree is " + tree); - return new RandomVariable<>(null, tree, this); + return new RandomVariable<>("calibratedYuleTree", tree, this); } /** @@ -350,20 +347,17 @@ private static TimeTreeNode randomNode(List nodeList) { public Map getParams() { Map map = super.getParams(); map.put(BirthDeathConstants.lambdaParamName, birthRate); - map.put(BirthDeathConstants.rootAgeParamName, rootAge); map.put(cladeMRCAAgeName, cladeMRCAAge); map.put(cladeTaxaName, cladeTaxaValue); - map.put(otherTaxaName,otherTaxa); + if (rootAge != null) map.put(BirthDeathConstants.rootAgeParamName, rootAge); + if (otherTaxa != null) map.put(otherTaxaName,otherTaxa); return map; } public void setParam(String paramName, Value value){ if (paramName.equals(BirthDeathConstants.lambdaParamName)) birthRate = value; else if (paramName.equals(BirthDeathConstants.rootAgeParamName)) rootAge = value; - else if (paramName.equals(cladeTaxaName)) { - cladeTaxaValue = value; - constructCladeTaxa(); - } + else if (paramName.equals(cladeTaxaName)) cladeTaxaValue = value; else if (paramName.equals(cladeMRCAAgeName)) cladeMRCAAge = value; else if (paramName.equals(otherTaxaName)) otherTaxa = value; else super.setParam(paramName, value); diff --git a/lphy-base/src/main/java/lphy/base/spi/LPhyBaseImpl.java b/lphy-base/src/main/java/lphy/base/spi/LPhyBaseImpl.java index 8fb67602..85176863 100644 --- a/lphy-base/src/main/java/lphy/base/spi/LPhyBaseImpl.java +++ b/lphy-base/src/main/java/lphy/base/spi/LPhyBaseImpl.java @@ -59,7 +59,7 @@ public List> declareDistributions() { Uniform.class, UniformDiscrete.class, Weibull.class, WeightedDirichlet.class, Multinomial.class, // tree distribution - Yule.class, BirthDeathTree.class, FullBirthDeathTree.class, BirthDeathTreeDT.class, + Yule.class, CalibratedYule.class, BirthDeathTree.class, FullBirthDeathTree.class, BirthDeathTreeDT.class, BirthDeathSamplingTree.class, BirthDeathSamplingTreeDT.class, BirthDeathSerialSamplingTree.class, RhoSampleTree.class, FossilBirthDeathTree.class, SimBDReverse.class, SimFBDAge.class, SimFossilsPoisson.class,