Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * IntervalKStatistic.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 IntervalKStatistic extends AbstractTreeSummaryStatistic {
39
40 public IntervalKStatistic() {
41 this.k = 2;
42 }
43
44 public void setInteger(int value) {
45 this.k = value;
46 }
47
48 public double[] getSummaryStatistic(Tree tree) {
49
50 TreeIntervals intervals = new TreeIntervals(tree);
51
52 double totalTime = 0.0;
53 int intervalCount = intervals.getIntervalCount();
54 for (int i = 0; i < intervalCount; i++) {
55 if (intervals.getLineageCount(i) == k) {
56 totalTime += intervals.getInterval(i);
57 }
58 }
59 return new double[] { totalTime };
60 }
61
62 public String getSummaryStatisticName() {
63 return "TotalTime(" + k + ")";
64 }
65
66 public String getSummaryStatisticDescription() {
67 return getSummaryStatisticName() + " is the total amount of time in the genealogy that " +
68 "exactly " + k + " lineages exist.";
69 }
70
71 public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); }
72 public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); }
73 public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); }
74 public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); }
75 public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); }
76
77 public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() {
78
79 public TreeSummaryStatistic createStatistic() {
80 return new IntervalKStatistic();
81 }
82
83 public String getSummaryStatisticName() {
84 return "TotalTime(k)";
85 }
86
87 public String getSummaryStatisticDescription() {
88 return getSummaryStatisticName() + " is the total amount of time in the genealogy that " +
89 "exactly k lineages exist.";
90 }
91
92 public String getSummaryStatisticReference() {
93 return "-";
94 }
95
96 public String getValueName() { return "The number of lineaeges (k):"; }
97
98 public boolean allowsPolytomies() { return true; }
99
100 public boolean allowsNonultrametricTrees() { return true; }
101
102 public boolean allowsUnrootedTrees() { return false; }
103
104 public TreeSummaryStatistic.Category getCategory() { return TreeSummaryStatistic.Category.POPULATION_GENETIC; }
105
106 public boolean allowsWholeTree() { return true; }
107 public boolean allowsCharacter() { return false; }
108 public boolean allowsCharacterState() { return false; }
109 public boolean allowsTaxonList() { return false; }
110 public boolean allowsInteger() { return true; }
111 public boolean allowsDouble() { return false; }
112 };
113
114 int k = 1;
115 }