1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import java.awt.Color; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.BitSet; |
27 |
|
import java.util.HashMap; |
28 |
|
import java.util.List; |
29 |
|
|
30 |
|
import jalview.analysis.AverageDistanceEngine; |
31 |
|
import jalview.bin.Console; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 116 (116) |
Complexity: 31 |
Complexity Density: 0.42 |
|
33 |
|
public class GroupSet implements GroupSetI |
34 |
|
{ |
35 |
|
List<BitSet> groups = Arrays.asList(); |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
37 |
0 |
public GroupSet(GroupSet grps)... |
38 |
|
{ |
39 |
0 |
abs = grps.abs; |
40 |
0 |
colorMap = new HashMap<BitSet, Color>(grps.colorMap); |
41 |
0 |
groups = new ArrayList<BitSet>(grps.groups); |
42 |
0 |
newick = grps.newick; |
43 |
0 |
thresh = grps.thresh; |
44 |
0 |
treeType = grps.treeType; |
45 |
|
} |
46 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
47 |
0 |
public GroupSet()... |
48 |
|
{ |
49 |
|
|
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
52 |
0 |
public GroupSet(boolean abs2, float thresh2, List<BitSet> groups2,... |
53 |
|
String treeType2, String newick2) |
54 |
|
{ |
55 |
0 |
abs = abs2; |
56 |
0 |
thresh = thresh2; |
57 |
0 |
groups = groups2; |
58 |
0 |
treeType = treeType2; |
59 |
0 |
newick = newick2; |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
@Override... |
63 |
|
public boolean hasGroups() |
64 |
|
{ |
65 |
0 |
return groups != null; |
66 |
|
} |
67 |
|
|
68 |
|
String newick = null; |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@Override... |
71 |
|
public String getNewick() |
72 |
|
{ |
73 |
0 |
return newick; |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
@Override... |
77 |
|
public boolean hasTree() |
78 |
|
{ |
79 |
0 |
return newick != null && newick.length() > 0; |
80 |
|
} |
81 |
|
|
82 |
|
boolean abs = false; |
83 |
|
|
84 |
|
double thresh = 0; |
85 |
|
|
86 |
|
String treeType = null; |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
88 |
0 |
@Override... |
89 |
|
public void updateGroups(List<BitSet> colGroups) |
90 |
|
{ |
91 |
0 |
if (colGroups != null) |
92 |
|
{ |
93 |
0 |
groups = colGroups; |
94 |
|
} |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
97 |
0 |
@Override... |
98 |
|
public BitSet getGroupsFor(int column) |
99 |
|
{ |
100 |
0 |
if (groups != null) |
101 |
|
{ |
102 |
0 |
for (BitSet gp : groups) |
103 |
|
{ |
104 |
0 |
if (gp.get(column)) |
105 |
|
{ |
106 |
0 |
return gp; |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
0 |
BitSet bs = new BitSet(); |
112 |
0 |
bs.set(column); |
113 |
0 |
return bs; |
114 |
|
} |
115 |
|
|
116 |
|
HashMap<BitSet, Color> colorMap = new HashMap<>(); |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
118 |
0 |
@Override... |
119 |
|
public Color getColourForGroup(BitSet bs) |
120 |
|
{ |
121 |
0 |
if (bs == null) |
122 |
|
{ |
123 |
0 |
return Color.white; |
124 |
|
} |
125 |
0 |
Color groupCol = colorMap.get(bs); |
126 |
0 |
if (groupCol == null) |
127 |
|
{ |
128 |
0 |
return Color.white; |
129 |
|
} |
130 |
0 |
return groupCol; |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
0 |
@Override... |
134 |
|
public void setColorForGroup(BitSet bs, Color color) |
135 |
|
{ |
136 |
0 |
colorMap.put(bs, color); |
137 |
|
} |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
139 |
0 |
@Override... |
140 |
|
public void restoreGroups(List<BitSet> newgroups, String treeMethod, |
141 |
|
String tree, double thresh2) |
142 |
|
{ |
143 |
0 |
treeType = treeMethod; |
144 |
0 |
groups = newgroups; |
145 |
0 |
thresh = thresh2; |
146 |
0 |
newick = tree; |
147 |
|
|
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
@Override... |
151 |
|
public boolean hasCutHeight() |
152 |
|
{ |
153 |
0 |
return groups != null && thresh != 0; |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0 |
@Override... |
157 |
|
public double getCutHeight() |
158 |
|
{ |
159 |
0 |
return thresh; |
160 |
|
} |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0 |
@Override... |
163 |
|
public String getTreeMethod() |
164 |
|
{ |
165 |
0 |
return treeType; |
166 |
|
} |
167 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
168 |
0 |
public static GroupSet makeGroups(ContactMatrixI matrix, boolean autoCut)... |
169 |
|
{ |
170 |
0 |
return makeGroups(matrix, autoCut, 0, autoCut); |
171 |
|
} |
172 |
|
|
|
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 10 |
Complexity Density: 0.29 |
|
173 |
0 |
public static GroupSet makeGroups(ContactMatrixI matrix, boolean auto,... |
174 |
|
float thresh, boolean abs) |
175 |
|
{ |
176 |
0 |
AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null, |
177 |
|
matrix, true); |
178 |
0 |
double height = clusterer.findHeight(clusterer.getTopNode()); |
179 |
0 |
Console.debug("Column tree height: " + height); |
180 |
0 |
String newick = new jalview.io.NewickFile(clusterer.getTopNode(), false, |
181 |
|
true).print(); |
182 |
0 |
String treeType = "UPGMA"; |
183 |
0 |
Console.trace("Newick string\n" + newick); |
184 |
|
|
185 |
0 |
List<BinaryNode> nodegroups; |
186 |
0 |
float cut = -1f; |
187 |
0 |
if (auto) |
188 |
|
{ |
189 |
0 |
double rootw = 0; |
190 |
0 |
int p = 2; |
191 |
0 |
BinaryNode bn = clusterer.getTopNode(); |
192 |
0 |
while (p-- > 0 & bn.left() != null) |
193 |
|
{ |
194 |
0 |
if (bn.left() != null) |
195 |
|
{ |
196 |
0 |
bn = bn.left(); |
197 |
|
} |
198 |
0 |
if (bn.left() != null) |
199 |
|
{ |
200 |
0 |
rootw = bn.height; |
201 |
|
} |
202 |
|
} |
203 |
0 |
thresh = Math.max((float) (rootw / height) - 0.01f, 0); |
204 |
0 |
cut = thresh; |
205 |
0 |
nodegroups = clusterer.groupNodes(thresh); |
206 |
|
} |
207 |
|
else |
208 |
|
{ |
209 |
0 |
if (abs ? (height > thresh) : (0 < thresh && thresh < 1)) |
210 |
|
{ |
211 |
0 |
cut = abs ? thresh : (float) (thresh * height); |
212 |
0 |
Console.debug("Threshold " + cut + " for height=" + height); |
213 |
0 |
nodegroups = clusterer.groupNodes(cut); |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
0 |
nodegroups = new ArrayList<BinaryNode>(); |
218 |
0 |
nodegroups.add(clusterer.getTopNode()); |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
0 |
List<BitSet> groups = new ArrayList<>(); |
223 |
0 |
for (BinaryNode root : nodegroups) |
224 |
|
{ |
225 |
0 |
BitSet gpset = new BitSet(); |
226 |
0 |
for (BinaryNode leaf : clusterer.findLeaves(root)) |
227 |
|
{ |
228 |
0 |
gpset.set((Integer) leaf.element()); |
229 |
|
} |
230 |
0 |
groups.add(gpset); |
231 |
|
} |
232 |
0 |
GroupSet grps = new GroupSet(abs, (cut == -1f) ? thresh : cut, groups, |
233 |
|
treeType, newick); |
234 |
0 |
return grps; |
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
237 |
0 |
@Override... |
238 |
|
public List<BitSet> getGroups() |
239 |
|
{ |
240 |
0 |
return groups; |
241 |
|
} |
242 |
|
} |