Debian Codegraph @

src/dr/evomodel/tree/AncestralTrait.java

raw symbols SCIP
1 /*
2 * AncestralTrait.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.TreeTrait;
31 import dr.evolution.tree.TreeUtils;
32 import dr.evolution.util.TaxonList;
33 import dr.inference.loggers.LogColumn;
34 import dr.inference.loggers.Loggable;
35
36 import java.util.Set;
37
38 /**
39 * A statistic that logs the inferred trait at the 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 AncestralTrait implements Loggable {
46
47 public AncestralTrait(String name, TreeTrait ancestralTrait, Tree tree, TaxonList taxa) throws TreeUtils.MissingTaxonException {
48 this.name = name;
49 this.tree = tree;
50 this.ancestralTrait = ancestralTrait;
51 if (taxa != null) {
52 this.leafSet = TreeUtils.getLeavesForTaxa(tree, taxa);
53 }
54 }
55
56 public Tree getTree() {
57 return tree;
58 }
59
60 /**
61 * @return the ancestral state of the MRCA node.
62 */
63 public String getAncestralState() {
64
65 NodeRef node;
66 if (leafSet != null) {
67 node = TreeUtils.getCommonAncestorNode(tree, leafSet);
68 if (node == null) throw new RuntimeException("No node found that is MRCA of " + leafSet);
69 } else {
70 node = tree.getRoot();
71 }
72
73 return ancestralTrait.getTraitString(tree, node);
74 }
75
76 // **************************************************************
77 // Loggable IMPLEMENTATION
78 // **************************************************************
79
80 /**
81 * @return the log columns.
82 */
83 public LogColumn[] getColumns() {
84 LogColumn[] columns = new LogColumn[1];
85 columns[0] = new LogColumn.Abstract(name) {
86
87 protected String getFormattedValue() {
88 return getAncestralState();
89 }
90 };
91 return columns;
92 }
93
94 private final Tree tree;
95 private final TreeTrait ancestralTrait;
96 private final String name;
97 private Set<String> leafSet = null;
98
99 }