Debian Codegraph @

src/dr/evolution/tree/ColouredTree.java

raw symbols SCIP
1 /*
2 * ColouredTree.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.evolution.tree;
27
28 import dr.evolution.datatype.DataType;
29
30 import java.util.List;
31
32 /**
33 * @author Alexei Drummond
34 *
35 * @version $Id: ColouredTree.java,v 1.7 2005/04/28 09:29:07 alexei Exp $
36 */
37 public interface ColouredTree extends Tree {
38
39 /**
40 * @param node
41 * @return the colour of the given node.
42 */
43 int getColour(NodeRef node);
44
45 /**
46 * This method will return the colour on the ancestral branch if the given time
47 * is older than the parent of the given node.
48 * @param node
49 * @return the colour of the branch above the given node at the given (absolute) time.
50 */
51 int getColour(NodeRef node, double time);
52
53
54 /**
55 * @return the dataType that describes the colours.
56 */
57 DataType getColourDataType();
58
59 /**
60 * @param node
61 * @return an list of colour change objects representing the colour changes on the branch above this node
62 */
63 List getColourChanges(NodeRef node);
64
65 public class Utils {
66
67 /**
68 * @param tree the tree to count the changes on
69 * @return the total number of changes on the given tree
70 */
71 public static int getChangeCount(ColouredTree tree) {
72
73 int changeCount = 0;
74 int nodeCount = tree.getNodeCount();
75 for (int i = 0; i < nodeCount; i++) {
76 NodeRef node = tree.getNode(i);
77 if (!tree.isRoot(node)) {
78 changeCount += tree.getColourChanges(tree.getNode(i)).size();
79 }
80 }
81 return changeCount;
82 }
83 }
84 }