From a0c45b71b8c85ffee663fb249668b21518aa644f Mon Sep 17 00:00:00 2001 From: jordandouglas Date: Fri, 28 Apr 2023 11:29:37 +1200 Subject: [PATCH] allow for cognate singletons --- .../StochasticDolloTreeLikelihoodFast.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/indeldollo/StochasticDolloTreeLikelihoodFast.java b/src/indeldollo/StochasticDolloTreeLikelihoodFast.java index 08fa04f..80b8722 100644 --- a/src/indeldollo/StochasticDolloTreeLikelihoodFast.java +++ b/src/indeldollo/StochasticDolloTreeLikelihoodFast.java @@ -184,12 +184,20 @@ public double calculateLogP() { // Mean birth rate (weighted by branch lengths) double totalWeightedRate = 0.0; double totalTreeLength = 0.0; - for (Node node : root.getAllChildNodesAndSelf()) { - double rate = branchRateModel.getRateForBranch(node); - double length = node == root ? (birthTime - node.getHeight()) : node.getLength(); + if (root.isLeaf()) { + double rate = branchRateModel.getRateForBranch(root); + double length = birthTime - root.getHeight(); totalWeightedRate += rate * length; totalTreeLength += length; + }else { + for (Node node : root.getAllChildNodesAndSelf()) { + double rate = branchRateModel.getRateForBranch(node); + double length = node == root ? (birthTime - node.getHeight()) : node.getLength(); + totalWeightedRate += rate * length; + totalTreeLength += length; + } } + double meanBranchRate = totalWeightedRate/totalTreeLength; double meanBirthRate = lambda * mutationRate * meanBranchRate;