Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * TMRCASummaryStatistic.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 import dr.evolution.tree.TreeUtils;
31 import dr.evolution.util.*;
32
33 import java.util.*;
34
35 /**
36 *
37 * @version $Id: TMRCASummaryStatistic.java,v 1.3 2006/05/09 10:24:27 rambaut Exp $
38 *
39 * @author Alexei Drummond
40 */
41 public class TMRCASummaryStatistic extends AbstractTreeSummaryStatistic {
42
43 private TMRCASummaryStatistic() {
44 this.taxonList = null;
45 }
46
47 public void setTaxonList(TaxonList taxonList) {
48 this.taxonList = taxonList;
49 }
50
51 public double[] getSummaryStatistic(Tree tree) {
52 if (taxonList == null) {
53 return new double[] { tree.getNodeHeight(tree.getRoot()) };
54 }
55 try {
56 Set<String> leafSet = TreeUtils.getLeavesForTaxa(tree, taxonList);
57 NodeRef node = TreeUtils.getCommonAncestorNode(tree, leafSet);
58 if (node == null) throw new RuntimeException("No node found that is MRCA of " + leafSet);
59 return new double[] { tree.getNodeHeight(node) };
60 } catch (TreeUtils.MissingTaxonException e) {
61 throw new RuntimeException("Missing taxon!");
62 }
63 }
64
65 public String getSummaryStatisticName() {
66 if (characterState != null) {
67 return "tMRCA(" + characterState + ")";
68 } else if (taxonList != null) {
69 return "tMRCA(" + taxonList.getId() + ")";
70 } else {
71 return "tMRCA";
72 }
73 }
74
75 public String getSummaryStatisticDescription() {
76 if (characterState != null) {
77 return "The time of the most recent common ancestor of the character state " + characterState;
78 } else if (taxonList != null) {
79 return "The time of the most recent common ancestor of the given taxon list";
80 }
81 return "The time of the most recent common ancestor of a set of taxa. In order to use this statistic, a taxon set must be defined (see the Taxon Set tab).";
82 }
83
84 public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); }
85 public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); }
86 public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); }
87 public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); }
88 public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); }
89
90 public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() {
91
92 public TreeSummaryStatistic createStatistic() {
93 return new TMRCASummaryStatistic();
94 }
95
96 public String getSummaryStatisticName() {
97 return "tMRCA";
98 }
99
100 public String getSummaryStatisticDescription() {
101 return "The time of the most recent common ancestor";
102 }
103
104 public String getSummaryStatisticReference() {
105 return "-";
106 }
107
108 public boolean allowsPolytomies() { return true; }
109
110 public boolean allowsNonultrametricTrees() { return true; }
111
112 public boolean allowsUnrootedTrees() { return false; }
113
114 public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.GENERAL; }
115
116 public boolean allowsWholeTree() { return true; }
117
118 public boolean allowsCharacter() { return false; }
119
120 public boolean allowsCharacterState() { return false; }
121
122 public boolean allowsTaxonList() { return true; }
123 };
124
125 private String characterState = null;
126 private TaxonList taxonList = null;
127 }
128