Debian Codegraph @

src/dr/evolution/tree/SplitSystem.java

raw symbols SCIP
1 /*
2 * SplitSystem.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.util.TaxonList;
29
30 import java.io.PrintWriter;
31 import java.io.StringWriter;
32
33 /**
34 * data structure for a set of splits
35 *
36 * @version $Id: SplitSystem.java,v 1.5 2005/05/24 20:25:57 rambaut Exp $
37 *
38 * @author Korbinian Strimmer
39 */
40 public class SplitSystem
41 {
42 //
43 // Public stuff
44 //
45
46 /**
47 * @param taxonList the list of taxa
48 * @param size number of splits
49 */
50 public SplitSystem(TaxonList taxonList, int size)
51 {
52 this.taxonList = taxonList;
53
54 labelCount = taxonList.getTaxonCount();
55 splitCount = size;
56
57 splits = new boolean[splitCount][labelCount];
58 }
59
60 /** get number of splits */
61 public int getSplitCount()
62 {
63 return splitCount;
64 }
65
66 /** get number of labels */
67 public int getLabelCount()
68 {
69 return labelCount;
70 }
71
72 /** get split vector */
73 public boolean[][] getSplitVector()
74 {
75 return splits;
76 }
77
78 /** get split */
79 public boolean[] getSplit(int i)
80 {
81 return splits[i];
82 }
83
84
85 /** get taxon list */
86 public TaxonList getTaxonList() { return taxonList; }
87
88 /**
89 + test whether a split is contained in this split system
90 * (assuming the same leaf order)
91 *
92 * @param split split
93 */
94 public boolean hasSplit(boolean[] split)
95 {
96 for (int i = 0; i < splitCount; i++)
97 {
98 if (SplitUtils.isSame(split, splits[i])) return true;
99 }
100
101 return false;
102 }
103
104
105 /** print split system */
106 public String toString()
107 {
108 StringWriter sw = new StringWriter();
109 PrintWriter pw = new PrintWriter(sw);
110
111 for (int i = 0; i < labelCount; i++)
112 {
113 pw.println(taxonList.getTaxon(i));
114 }
115 pw.println();
116
117
118 for (int i = 0; i < splitCount; i++)
119 {
120 for (int j = 0; j < labelCount; j++)
121 {
122 if (splits[i][j] == true)
123 pw.print('*');
124 else
125 pw.print('.');
126 }
127
128 pw.println();
129 }
130
131 return sw.toString();
132 }
133
134
135 //
136 // Private stuff
137 //
138
139 private int labelCount, splitCount;
140 private TaxonList taxonList;
141 private boolean[][] splits;
142 }