diff --git a/src/dr/app/tools/newtreeannotator/CladeSystem.java b/src/dr/app/tools/newtreeannotator/CladeSystem.java index 6dbd433933..be6833f3a8 100644 --- a/src/dr/app/tools/newtreeannotator/CladeSystem.java +++ b/src/dr/app/tools/newtreeannotator/CladeSystem.java @@ -31,10 +31,10 @@ import dr.evolution.tree.Tree; import dr.evolution.util.Taxon; import dr.evolution.util.TaxonList; +import dr.stats.DiscreteStatistics; import java.util.HashMap; import java.util.Map; -import java.util.Set; /** * @author Andrew Rambaut @@ -258,6 +258,28 @@ public boolean expectAllClades() { return minCladeCredibility[0] / tree.getInternalNodeCount(); } + public double getMedianCladeCredibility(Tree tree) { + final double[] cladeCredibility = new double[tree.getInternalNodeCount()]; + final int[] i = { 0 }; + traverseTree(tree, new CladeAction() { + @Override + public void actOnClade(Clade clade, Tree tree, NodeRef node) { + if (clade.getTaxon() == null) { + cladeCredibility[i[0]] = clade.getCredibility(); + i[0] += 1; + } + } + + @Override + public boolean expectAllClades() { + return true; + } + }); + + + return DiscreteStatistics.median(cladeCredibility); + } + /** * Returns the number of clades in the tree with threshold credibility or higher * @param tree diff --git a/src/dr/app/tools/newtreeannotator/TreeAnnotator.java b/src/dr/app/tools/newtreeannotator/TreeAnnotator.java index f6b1335564..8f46c69cf0 100644 --- a/src/dr/app/tools/newtreeannotator/TreeAnnotator.java +++ b/src/dr/app/tools/newtreeannotator/TreeAnnotator.java @@ -492,6 +492,7 @@ private MutableTree getHIPSTRTree(CladeSystem cladeSystem) { private static void reportStatistics(CladeSystem cladeSystem, Tree tree) { progressStream.println("Lowest individual clade credibility: " + String.format("%.4f", cladeSystem.getMinimumCladeCredibility(tree))); progressStream.println("Mean individual clade credibility: " + String.format("%.4f", cladeSystem.getMeanCladeCredibility(tree))); + progressStream.println("Median individual clade credibility: " + String.format("%.4f", cladeSystem.getMedianCladeCredibility(tree))); progressStream.println("Number of clades with credibility 1.0: " + cladeSystem.getTopCladeCredibility(tree, 1.0)); progressStream.println("Number of clades with credibility > 0.99: " + cladeSystem.getTopCladeCredibility(tree, 0.99) + " (out of " + cladeSystem.getTopCladeCredibility(0.99) + " in all trees)");