Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * SingleChildCountStatistic.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: SingleChildCountStatistic.java,v 1.2 2005/09/28 13:50:56 rambaut Exp $
34 *
35 * @author Alexei Drummond
36 */
37 public class SingleChildCountStatistic extends AbstractTreeSummaryStatistic {
38
39 private SingleChildCountStatistic() { }
40
41 public double[] getSummaryStatistic(Tree tree) {
42
43 int singleChildCount = 0;
44
45 int internalNodeCount = tree.getInternalNodeCount();
46 for (int i = 0; i < internalNodeCount; i++) {
47 NodeRef node = tree.getInternalNode(i);
48 if (tree.getChildCount(node) == 1) {
49 singleChildCount += 1;
50 }
51 }
52 return new double[] { (double)singleChildCount };
53 }
54
55 public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); }
56 public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); }
57 public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); }
58 public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); }
59 public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); }
60 public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); }
61 public Category getCategory() { return FACTORY.getCategory(); }
62
63 public static final Factory FACTORY = new Factory() {
64
65 public TreeSummaryStatistic createStatistic() {
66 return new SingleChildCountStatistic();
67 }
68
69 public String getSummaryStatisticName() {
70 return "Single child count";
71 }
72
73 public String getSummaryStatisticDescription() {
74
75 return "The number of internal nodes that have only a single child node.";
76 }
77
78 public String getSummaryStatisticReference() {
79 return "Drummond unpublished";
80 }
81
82 public boolean allowsPolytomies() { return true; }
83
84 public boolean allowsNonultrametricTrees() { return true; }
85
86 public boolean allowsUnrootedTrees() { return false; }
87
88 public Category getCategory() { return Category.TREE_SHAPE; }
89 };
90 }