Debian Codegraph @

src/dr/evomodel/tree/ExternalLengthStatistic.java

raw symbols SCIP
1 /*
2 * ExternalLengthStatistic.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.evomodel.tree;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evolution.tree.Tree;
30 import dr.evolution.tree.TreeUtils;
31 import dr.evolution.util.Taxon;
32 import dr.evolution.util.TaxonList;
33 import dr.inference.model.Statistic;
34
35 import java.util.ArrayList;
36 import java.util.List;
37
38 /**
39 * A statistic that tracks the time of MRCA of a set of taxa
40 *
41 * @author Alexei Drummond
42 * @author Andrew Rambaut
43 * @version $Id: TMRCAStatistic.java,v 1.21 2005/07/11 14:06:25 rambaut Exp $
44 */
45 public class ExternalLengthStatistic extends TreeStatistic {
46
47 public ExternalLengthStatistic(String name, Tree tree, TaxonList taxa) throws TreeUtils.MissingTaxonException {
48 super(name);
49 this.tree = tree;
50 int m = taxa.getTaxonCount();
51 int n = tree.getExternalNodeCount();
52
53 for (int i = 0; i < m; i++) {
54
55 Taxon taxon = taxa.getTaxon(i);
56 NodeRef node = null;
57 boolean found = false;
58 for (int j = 0; j < n; j++) {
59
60 node = tree.getExternalNode(j);
61 if (tree.getNodeTaxon(node).getId().equals(taxon.getId())) {
62
63 found = true;
64 break;
65 }
66 }
67
68 if (!found) {
69 throw new TreeUtils.MissingTaxonException(taxon);
70 }
71
72 leafSet.add(node);
73 }
74 }
75
76 public void setTree(Tree tree) {
77 this.tree = tree;
78 }
79
80 public Tree getTree() {
81 return tree;
82 }
83
84 public int getDimension() {
85 return leafSet.size();
86 }
87
88 /**
89 * @return the height of the MRCA node.
90 */
91 public double getStatisticValue(int dim) {
92 NodeRef node = leafSet.get(dim);
93 return tree.getBranchLength(node);
94 }
95
96 private Tree tree = null;
97 private List<NodeRef> leafSet = new ArrayList<NodeRef>();
98
99 }