diff --git a/examples/Human.H3.81-98-elc-StrictClock.xml b/examples/Human.H3.81-98-elc-StrictClock.xml new file mode 100644 index 0000000..112cab7 --- /dev/null +++ b/examples/Human.H3.81-98-elc-StrictClock.xml @@ -0,0 +1,454 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + beast.base.inference.distribution.Uniform + beast.base.inference.distribution.Exponential + beast.base.inference.distribution.LogNormalDistributionModel + beast.base.inference.distribution.Normal + beast.base.inference.distribution.Beta + beast.base.inference.distribution.Gamma + beast.base.inference.distribution.LaplaceDistribution + beast.base.inference.distribution.Prior + beast.base.inference.distribution.InverseGamma + beast.base.inference.distribution.OneOnX + + + + + + + + + + + + + + A_Belgium_2_1981=1981.0, + A_ChristHospital_231_1982=1982.0, + A_Philippines_2_1982=1982.0, + A_Baylor1B_1983=1983.0, + A_Oita_3_1983=1983.0, + A_Texas_12764_1983=1983.0, + A_Alaska_8_1984=1984.0, + A_Caen_1_1984=1984.0, + A_Texas_17988_1984=1984.0, + A_Colorado_2_1987=1987.0, + A_Guangdong_9_1987=1987.0, + A_Guizhou_1_1987=1987.0, + A_LosAngeles_1987=1987.0, + A_Qingdao_10_1987=1987.0, + A_Shanghai_11_1987=1987.0, + A_Sichuan_2_1987=1987.0, + A_Sydney_1_1987=1987.0, + A_Tokyo_1275_1987=1987.0, + A_Victoria_7_1987=1987.0, + A_Alaska_9_1992=1992.0, + A_Beijing_32_1992=1992.0, + A_California_271_1992=1992.0, + A_Finland_205_1992=1992.0, + A_Harbin_15_1992=1992.0, + A_Hawaii_3_1992=1992.0, + A_Indonesia_3946_1992=1992.0, + A_Perth_1_1992=1992.0, + A_Qingdao_53_1992=1992.0, + A_Sapporo_304_1992=1992.0, + A_SouthAustralia_36_1992=1992.0, + A_Tianjin_33_1992=1992.0, + A_Umea_1_1992=1992.0, + A_Victoria_29_1992=1992.0, + A_Wellington_66_1992=1992.0, + A_Aichi_69_1994=1994.0, + A_Akita_1_1994=1994.0, + A_Argentina_3779_1994=1994.0, + A_England_67_1994=1994.0, + A_France_1109_1994=1994.0, + A_HongKong_1_1994=1994.0, + A_Johannesburg_33_1994=1994.0, + A_Mexico_3255_1994=1994.0, + A_Pennsylvania_7_1994=1994.0, + A_Romania_160_1994=1994.0, + A_Santiago_7198_1994=1994.0, + A_Shangdong_5_1994=1994.0, + A_Singapore_7_1994=1994.0, + A_Thailand_75_1994=1994.0, + A_Vermont_3_1994=1994.0, + A_Athens_1_1998=1998.0, + A_Christchurch_45_1998=1998.0, + A_Cordoba_V185_1998=1998.0, + A_Greece_103_1998=1998.0, + A_JOHANNESBURG_3_1998=1998.0, + A_MALMO_1_1998=1998.0, + A_Nagasaki_76_1998=1998.0, + A_Neuquen_V541_1998=1998.0, + A_PERTH_24_1998=1998.0, + A_Pusan_68_1998=1998.0, + A_Seoul_37_1998=1998.0, + A_Switzerland_7729_1998=1998.0, + A_Tucuman_V425_1998=1998.0, + A_Ushuaia_R127_1998=1998.0, + A_Waikato_12_1998=1998.0, + A_Czechoslovakia_4_1986=1986.0, + A_Leningrad_360_1986=1986.0, + A_Memphis_6_1986=1986.0, + A_Wellington_4_1985=1985.0, + A_Tonga_23_1985=1985.0 + + + + + + + 0.5 + 2.0 + + 1.0 + 1.0 + + 0.3 + 0.25 + + + + + 1.0 + + + + + + + + + + + + + 1.0 + + + + + 1.0 + 1.25 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.0 + 0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/mf/beast/evolution/branchratemodel/FlexibleLocalClockModel.java b/src/mf/beast/evolution/branchratemodel/FlexibleLocalClockModel.java index 8ce2205..b7995bf 100644 --- a/src/mf/beast/evolution/branchratemodel/FlexibleLocalClockModel.java +++ b/src/mf/beast/evolution/branchratemodel/FlexibleLocalClockModel.java @@ -33,6 +33,63 @@ public class FlexibleLocalClockModel extends BranchRateModel.Base { private Map nodeClockMap = new HashMap(); + private Map nodeClockMapStored = new HashMap(); + + @Override + protected boolean requiresRecalculation() { + if (isStrictClockLineage(rootRateModel) && isStrictClockClade(cladeRateModels)) { + // update node indices for strict clock models only + updateNodeIndex(); + } + return true; + } + + @Override + protected void store() { + // store nodeClockMap + nodeClockMapStored = nodeClockMap; + super.store(); + } + + @Override + protected void restore() { + // restore nodeClockMap + nodeClockMap = nodeClockMapStored; + super.restore(); + } + + public void updateNodeIndex() { + cladeRateModels = cladeRateModelInputs.get(); + rootRateModel = rootRateModelInput.get(); + + nodeClockMap = new HashMap(); + nodeClockMap.put(tree.getRoot().getNr(), rootRateModel); + postorderTraverse(tree.getRoot()); + preorderTraverse(tree.getRoot()); + // node assignments + Set nodes = new HashSet(); + for (Integer nodeNr : nodeClockMap.keySet()) { + if (nodeClockMap.get(nodeNr).equals(rootRateModel) && nodeNr != tree.getRoot().getNr()) { + Node node = tree.getNode(nodeNr); + nodes.add(node); + } + } + rootRateModel.initializeNodeAssignment(nodes); + } + + private boolean isStrictClockLineage(LineageRateModel model) { + return model instanceof StrictLineageClockModel; + } + + private boolean isStrictClockClade(List cladeList) { + for (CladeRateModel model : cladeList) { + if (!(model instanceof StrictCladeModel)) { + return false; + } + } + return true; + } + @Override public void initAndValidate() { tree = treeInput.get();