Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * LineageProportionStatistic.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.coalescent.TreeIntervals;
29 import dr.evolution.tree.Tree;
30
31 /**
32 * Returns the total time in the genealogy in which exactly k lineages are present.
33 *
34 * @version $Id: IntervalKStatistic.java,v 1.2 2005/09/28 13:50:56 rambaut Exp $
35 *
36 * @author Alexei Drummond
37 */
38 public class LineageProportionStatistic extends AbstractTreeSummaryStatistic {
39
40 public LineageProportionStatistic() {
41 this.t = 1.0;
42 }
43
44 public void setDouble(double value) {
45 this.t = value;
46 }
47
48 public double[] getSummaryStatistic(Tree tree) {
49
50 TreeIntervals intervals = new TreeIntervals(tree);
51 int tipCount = tree.getExternalNodeCount();
52
53 double totalTime = 0.0;
54 for (int i = 0; i < intervals.getIntervalCount(); i++) {
55 totalTime += intervals.getInterval(i);
56 if (totalTime > t) {
57 return new double[] { ((double)intervals.getLineageCount(i)) / tipCount };
58 }
59 }
60 return new double[] { 1.0 / tipCount };
61 }
62
63 public String getSummaryStatisticName() {
64 return "LineageProportion(" + t + ")";
65 }
66
67 public String getSummaryStatisticDescription() {
68 return getSummaryStatisticName() + " is the proportion of lineages that exists in the genealogy at " +
69 "time " + t + ".";
70 }
71
72 public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); }
73 public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); }
74 public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); }
75 public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); }
76 public Category getCategory() { return FACTORY.getCategory(); }
77
78 public static final Factory FACTORY = new Factory() {
79
80 public TreeSummaryStatistic createStatistic() {
81 return new LineageProportionStatistic();
82 }
83
84 public String getSummaryStatisticName() {
85 return "LineageProportion(t)";
86 }
87
88 public String getSummaryStatisticDescription() {
89 return getSummaryStatisticName() + " is the proportion of lineages that exists in the genealogy at " +
90 "time t.";
91 }
92
93 public String getSummaryStatisticReference() {
94 return "-";
95 }
96
97 public String getValueName() { return "The time (t):"; }
98 public boolean allowsPolytomies() { return true; }
99
100 public boolean allowsNonultrametricTrees() { return true; }
101
102 public boolean allowsUnrootedTrees() { return false; }
103
104 public Category getCategory() { return Category.POPULATION_GENETIC; }
105
106 public boolean allowsWholeTree() { return true; }
107
108 public boolean allowsCharacter() { return false; }
109
110 public boolean allowsCharacterState() { return false; }
111
112 public boolean allowsTaxonList() { return false; }
113
114 public boolean allowsInteger() { return false; }
115
116 public boolean allowsDouble() { return true; }
117 };
118
119 double t = 1.0;
120 }