Debian Codegraph @

src/dr/evomodel/tree/MonophylyStatistic.java

raw symbols SCIP
1 /*
2 * MonophylyStatistic.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.Tree;
29 import dr.evolution.tree.TreeUtils;
30 import dr.evolution.util.TaxonList;
31 import dr.inference.model.BooleanStatistic;
32
33 import java.util.Collections;
34 import java.util.Set;
35
36 /**
37 * Performs monophyly test given a taxonList
38 *
39 * @author Roald Forsberg
40 * @author Alexei Drummond
41 * @author Andrew Rambaut
42 * @version $Id: MonophylyStatistic.java,v 1.16 2005/07/11 14:06:25 rambaut Exp $
43 */
44 public class MonophylyStatistic extends TreeStatistic implements BooleanStatistic {
45
46 public MonophylyStatistic(String name, Tree tree, TaxonList taxa, TaxonList ignore) throws TreeUtils.MissingTaxonException {
47
48 this(name, tree, taxa, ignore, false);
49
50 }
51
52 public MonophylyStatistic(String name, Tree tree, TaxonList taxa, TaxonList ignore, boolean inverse) throws TreeUtils.MissingTaxonException {
53
54 super(name);
55 this.tree = tree;
56 this.leafSet = TreeUtils.getLeavesForTaxa(tree, taxa);
57 if (ignore != null) {
58 this.ignoreLeafSet = TreeUtils.getLeavesForTaxa(tree, ignore);
59 } else {
60 this.ignoreLeafSet = Collections.emptySet();
61 }
62 this.inverse = inverse;
63
64 }
65
66 public void setTree(Tree tree) {
67 this.tree = tree;
68 }
69
70 public Tree getTree() {
71 return tree;
72 }
73
74 public int getDimension() {
75 return 1;
76 }
77
78 /**
79 * @return boolean result of test.
80 */
81 public double getStatisticValue(int dim) {
82 return getBoolean(dim) ? 1.0 : 0.0;
83 }
84
85 /**
86 * @return boolean result of test.
87 */
88 public boolean getBoolean(int dim) {
89 boolean monophyletic = TreeUtils.isMonophyletic(this.tree, this.leafSet, this.ignoreLeafSet);
90 if (inverse){
91 return !monophyletic;
92 } else {
93 return monophyletic;
94 }
95 }
96
97 private Tree tree = null;
98 private Set<String> leafSet = null;
99 private Set<String> ignoreLeafSet = null;
100 private boolean inverse = false;
101
102 }