Debian Codegraph @

src/dr/app/treestat/statistics/CherryStatistic.java

raw symbols SCIP
1 /*
2 * CherryStatistic.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.treestat.statistics;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evolution.tree.Tree;
30
31 /**
32 *
33 * @version $Id: CherryStatistic.java,v 1.2 2005/09/28 13:50:56 rambaut Exp $
34 *
35 * @author Alexei Drummond
36 */
37 public class CherryStatistic extends AbstractTreeSummaryStatistic {
38
39 private CherryStatistic() { }
40
41 public double[] getSummaryStatistic(Tree tree) {
42
43 int cherryCount = 0;
44
45 int internalNodeCount = tree.getInternalNodeCount();
46 for (int i = 0; i < internalNodeCount; i++) {
47 NodeRef node = tree.getInternalNode(i);
48 boolean allChildrenExternal = true;
49 for (int j = 0; j < tree.getChildCount(node); j++) {
50 if (!tree.isExternal(tree.getChild(node, j))) {
51 allChildrenExternal = false;
52 }
53 }
54 if (allChildrenExternal) cherryCount += 1;
55 }
56 return new double[] { (double)cherryCount };
57 }
58
59 public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); }
60 public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); }
61 public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); }
62 public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); }
63 public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); }
64 public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); }
65 public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); }
66
67 public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() {
68
69 public TreeSummaryStatistic createStatistic() {
70 return new CherryStatistic();
71 }
72
73 public String getSummaryStatisticName() {
74 return "Cherry count";
75 }
76
77 public String getSummaryStatisticDescription() {
78
79 return "The number of internal nodes that have only tips as children.";
80 }
81
82 public String getSummaryStatisticReference() {
83 return "Steel and McKenzie (2001)";
84 }
85
86 public boolean allowsPolytomies() { return true; }
87
88 public boolean allowsNonultrametricTrees() { return true; }
89
90 public boolean allowsUnrootedTrees() { return false; }
91
92 public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.TREE_SHAPE; }
93 };
94 }