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 |
|
|
|
|
| 57.8% |
Uncovered Elements: 49 (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 |
60 |
public GroupSet()... |
48 |
|
{ |
49 |
|
|
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
52 |
2 |
public GroupSet(boolean abs2, float thresh2, List<BitSet> groups2,... |
53 |
|
String treeType2, String newick2) |
54 |
|
{ |
55 |
2 |
abs = abs2; |
56 |
2 |
thresh = thresh2; |
57 |
2 |
groups = groups2; |
58 |
2 |
treeType = treeType2; |
59 |
2 |
newick = newick2; |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
5 |
@Override... |
63 |
|
public boolean hasGroups() |
64 |
|
{ |
65 |
5 |
return groups != null; |
66 |
|
} |
67 |
|
|
68 |
|
String newick = null; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
6 |
@Override... |
71 |
|
public String getNewick() |
72 |
|
{ |
73 |
6 |
return newick; |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
5 |
@Override... |
77 |
|
public boolean hasTree() |
78 |
|
{ |
79 |
5 |
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 |
|
|
|
|
| 54.5% |
Uncovered Elements: 5 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
97 |
4003 |
@Override... |
98 |
|
public BitSet getGroupsFor(int column) |
99 |
|
{ |
100 |
4003 |
if (groups != null) |
101 |
|
{ |
102 |
4003 |
for (BitSet gp : groups) |
103 |
|
{ |
104 |
0 |
if (gp.get(column)) |
105 |
|
{ |
106 |
0 |
return gp; |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
4003 |
BitSet bs = new BitSet(); |
112 |
4003 |
bs.set(column); |
113 |
4003 |
return bs; |
114 |
|
} |
115 |
|
|
116 |
|
HashMap<BitSet, Color> colorMap = new HashMap<>(); |
117 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
118 |
4003 |
@Override... |
119 |
|
public Color getColourForGroup(BitSet bs) |
120 |
|
{ |
121 |
4003 |
if (bs == null) |
122 |
|
{ |
123 |
0 |
return Color.white; |
124 |
|
} |
125 |
4003 |
Color groupCol = colorMap.get(bs); |
126 |
4003 |
if (groupCol == null) |
127 |
|
{ |
128 |
4003 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
139 |
2 |
@Override... |
140 |
|
public void restoreGroups(List<BitSet> newgroups, String treeMethod, |
141 |
|
String tree, double thresh2) |
142 |
|
{ |
143 |
2 |
treeType = treeMethod; |
144 |
2 |
groups = newgroups; |
145 |
2 |
thresh = thresh2; |
146 |
2 |
newick = tree; |
147 |
|
|
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
3 |
@Override... |
151 |
|
public boolean hasCutHeight() |
152 |
|
{ |
153 |
3 |
return groups != null && thresh != 0; |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
3 |
@Override... |
157 |
|
public double getCutHeight() |
158 |
|
{ |
159 |
3 |
return thresh; |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
3 |
@Override... |
163 |
|
public String getTreeMethod() |
164 |
|
{ |
165 |
3 |
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 |
|
|
|
|
| 52% |
Uncovered Elements: 24 (50) |
Complexity: 10 |
Complexity Density: 0.29 |
|
173 |
2 |
public static GroupSet makeGroups(ContactMatrixI matrix, boolean auto,... |
174 |
|
float thresh, boolean abs) |
175 |
|
{ |
176 |
2 |
AverageDistanceEngine clusterer = new AverageDistanceEngine(null, null, |
177 |
|
matrix, true); |
178 |
2 |
double height = clusterer.findHeight(clusterer.getTopNode()); |
179 |
2 |
Console.debug("Column tree height: " + height); |
180 |
2 |
String newick = new jalview.io.NewickFile(clusterer.getTopNode(), false, |
181 |
|
true).print(); |
182 |
2 |
String treeType = "UPGMA"; |
183 |
2 |
Console.trace("Newick string\n" + newick); |
184 |
|
|
185 |
2 |
List<BinaryNode> nodegroups; |
186 |
2 |
float cut = -1f; |
187 |
2 |
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 |
2 |
if (abs ? (height > thresh) : (0 < thresh && thresh < 1)) |
210 |
|
{ |
211 |
2 |
cut = abs ? thresh : (float) (thresh * height); |
212 |
2 |
Console.debug("Threshold " + cut + " for height=" + height); |
213 |
2 |
nodegroups = clusterer.groupNodes(cut); |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
0 |
nodegroups = new ArrayList<BinaryNode>(); |
218 |
0 |
nodegroups.add(clusterer.getTopNode()); |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
2 |
List<BitSet> groups = new ArrayList<>(); |
223 |
2 |
for (BinaryNode root : nodegroups) |
224 |
|
{ |
225 |
5 |
BitSet gpset = new BitSet(); |
226 |
5 |
for (BinaryNode leaf : clusterer.findLeaves(root)) |
227 |
|
{ |
228 |
16 |
gpset.set((Integer) leaf.element()); |
229 |
|
} |
230 |
5 |
groups.add(gpset); |
231 |
|
} |
232 |
2 |
GroupSet grps = new GroupSet(abs, (cut == -1f) ? thresh : cut, groups, |
233 |
|
treeType, newick); |
234 |
2 |
return grps; |
235 |
|
} |
236 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
237 |
6 |
@Override... |
238 |
|
public List<BitSet> getGroups() |
239 |
|
{ |
240 |
6 |
return groups; |
241 |
|
} |
242 |
|
} |