1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.workers; |
22 |
|
|
23 |
|
import java.util.Collections; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import jalview.analysis.AAFrequency; |
29 |
|
import jalview.analysis.AlignmentUtils; |
30 |
|
import jalview.api.AlignViewportI; |
31 |
|
import jalview.api.AlignmentViewPanel; |
32 |
|
import jalview.datamodel.AlignmentAnnotation; |
33 |
|
import jalview.datamodel.AlignmentI; |
34 |
|
import jalview.datamodel.Annotation; |
35 |
|
import jalview.datamodel.ProfilesI; |
36 |
|
import jalview.datamodel.SequenceI; |
37 |
|
import jalview.renderer.ResidueShaderI; |
38 |
|
import jalview.util.Constants; |
39 |
|
import jalview.util.MessageManager; |
40 |
|
|
|
|
| 77.9% |
Uncovered Elements: 30 (136) |
Complexity: 40 |
Complexity Density: 0.46 |
|
41 |
|
public class SecondaryStructureConsensusThread extends AlignCalcWorker |
42 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
211 |
public SecondaryStructureConsensusThread(AlignViewportI alignViewport,... |
44 |
|
AlignmentViewPanel alignPanel) |
45 |
|
{ |
46 |
211 |
super(alignViewport, alignPanel); |
47 |
|
} |
48 |
|
|
|
|
| 56.5% |
Uncovered Elements: 20 (46) |
Complexity: 13 |
Complexity Density: 0.41 |
|
49 |
379 |
@Override... |
50 |
|
public void run() |
51 |
|
{ |
52 |
379 |
if (calcMan.isPending(this)) |
53 |
|
{ |
54 |
0 |
return; |
55 |
|
} |
56 |
379 |
calcMan.notifyStart(this); |
57 |
|
|
58 |
379 |
try |
59 |
|
{ |
60 |
379 |
List<AlignmentAnnotation> ssConsensus = getSSConsensusAnnotation(); |
61 |
379 |
AlignmentAnnotation gap = getGapAnnotation(); |
62 |
379 |
if ((ssConsensus == null && gap == null) || calcMan.isPending(this)) |
63 |
|
{ |
64 |
3 |
calcMan.workerComplete(this); |
65 |
3 |
return; |
66 |
|
} |
67 |
376 |
while (!calcMan.notifyWorking(this)) |
68 |
|
{ |
69 |
0 |
try |
70 |
|
{ |
71 |
0 |
if (ap != null) |
72 |
|
{ |
73 |
0 |
ap.paintAlignment(false, false); |
74 |
|
} |
75 |
0 |
Thread.sleep(200); |
76 |
|
} catch (Exception ex) |
77 |
|
{ |
78 |
0 |
ex.printStackTrace(); |
79 |
|
} |
80 |
|
} |
81 |
376 |
if (alignViewport.isClosed()) |
82 |
|
{ |
83 |
0 |
abortAndDestroy(); |
84 |
0 |
return; |
85 |
|
} |
86 |
376 |
AlignmentI alignment = alignViewport.getAlignment(); |
87 |
|
|
88 |
376 |
int aWidth = -1; |
89 |
|
|
90 |
? |
if (alignment == null || (aWidth = alignment.getWidth()) < 0) |
91 |
|
{ |
92 |
0 |
calcMan.workerComplete(this); |
93 |
0 |
return; |
94 |
|
} |
95 |
|
|
96 |
376 |
setSecondaryStructureSources(); |
97 |
376 |
eraseSSConsensus(aWidth); |
98 |
376 |
computeSSConsensus(alignment); |
99 |
376 |
updateResultAnnotation(true); |
100 |
|
|
101 |
376 |
if (ap != null) |
102 |
|
{ |
103 |
376 |
ap.paintAlignment(true, true); |
104 |
|
} |
105 |
|
} catch (OutOfMemoryError error) |
106 |
|
{ |
107 |
0 |
calcMan.disableWorker(this); |
108 |
0 |
ap.raiseOOMWarning("calculating consensus", error); |
109 |
|
} finally |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
379 |
calcMan.workerComplete(this); |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
@param |
123 |
|
|
124 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
125 |
376 |
protected void eraseSSConsensus(int aWidth)... |
126 |
|
{ |
127 |
376 |
List<AlignmentAnnotation> ssConsensuses = getSSConsensusAnnotation(); |
128 |
376 |
for (AlignmentAnnotation ssConsensus : ssConsensuses) |
129 |
|
{ |
130 |
336 |
if (ssConsensus != null) |
131 |
|
{ |
132 |
336 |
ssConsensus.annotations = new Annotation[aWidth]; |
133 |
|
} |
134 |
|
} |
135 |
376 |
AlignmentAnnotation gap = getGapAnnotation(); |
136 |
376 |
if (gap != null) |
137 |
|
{ |
138 |
374 |
gap.annotations = new Annotation[aWidth]; |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
145 |
376 |
protected void computeSSConsensus(AlignmentI alignment)... |
146 |
|
{ |
147 |
|
|
148 |
376 |
SequenceI[] aseqs = getSequences(); |
149 |
376 |
int width = alignment.getWidth(); |
150 |
376 |
Map<String, ProfilesI> hSSConsensusProfileMap = new HashMap<String, ProfilesI>(); |
151 |
376 |
List<String> ssSources = getSecondaryStructureSources(); |
152 |
376 |
for (String ssSource : ssSources) |
153 |
|
{ |
154 |
390 |
ProfilesI hSSConsensus = AAFrequency.calculateSS(aseqs, width, 0, |
155 |
|
width, true, ssSource); |
156 |
390 |
hSSConsensusProfileMap.put(ssSource, hSSConsensus); |
157 |
|
} |
158 |
|
|
159 |
376 |
alignViewport.setSequenceSSConsensusHash(hSSConsensusProfileMap); |
160 |
376 |
setColourSchemeConsensus(hSSConsensusProfileMap); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
@return |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
1046 |
protected SequenceI[] getSequences()... |
167 |
|
{ |
168 |
1046 |
return alignViewport.getAlignment().getSequencesArray(); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
174 |
376 |
protected void setColourSchemeConsensus(... |
175 |
|
Map<String, ProfilesI> ssConsensusProfileMap) |
176 |
|
{ |
177 |
376 |
ResidueShaderI cs = alignViewport.getResidueShading(); |
178 |
376 |
if (cs != null) |
179 |
|
{ |
180 |
376 |
cs.setSSConsensusProfileMap(ssConsensusProfileMap); |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
@return |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
1131 |
protected List<AlignmentAnnotation> getSSConsensusAnnotation()... |
190 |
|
{ |
191 |
1131 |
return alignViewport |
192 |
|
.getAlignmentSecondaryStructureConsensusAnnotation(); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
@return |
199 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
200 |
376 |
protected void setSecondaryStructureSources()... |
201 |
|
{ |
202 |
376 |
List<String> sources = null; |
203 |
376 |
AlignmentAnnotation[] aa = alignViewport.getAlignment() |
204 |
|
.getAlignmentAnnotation(); |
205 |
376 |
if (aa != null) |
206 |
|
{ |
207 |
376 |
sources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(aa); |
208 |
376 |
if (sources != null) |
209 |
|
{ |
210 |
376 |
sources.add(0, Constants.SS_ALL_PROVIDERS); |
211 |
376 |
alignViewport.setSecondaryStructureSources(sources); |
212 |
|
} |
213 |
|
} |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
376 |
protected List<String> getSecondaryStructureSources()... |
217 |
|
{ |
218 |
376 |
return alignViewport.getSecondaryStructureSources(); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@return |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
1091 |
protected AlignmentAnnotation getGapAnnotation()... |
227 |
|
{ |
228 |
1091 |
return alignViewport.getAlignmentGapAnnotation(); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0 |
@Override... |
236 |
|
public void updateAnnotation() |
237 |
|
{ |
238 |
0 |
updateResultAnnotation(false); |
239 |
|
} |
240 |
|
|
|
|
| 85.7% |
Uncovered Elements: 4 (28) |
Complexity: 9 |
Complexity Density: 0.5 |
|
241 |
376 |
public void updateResultAnnotation(boolean immediate)... |
242 |
|
{ |
243 |
376 |
List<AlignmentAnnotation> ssConsensuses = getSSConsensusAnnotation(); |
244 |
376 |
Map<String, ProfilesI> ssConsensusProfileMap = getViewportSSConsensus(); |
245 |
376 |
for (AlignmentAnnotation ssConsensus : ssConsensuses) |
246 |
|
{ |
247 |
336 |
ProfilesI ssConsensusProfile = null; |
248 |
336 |
for (String source : ssConsensusProfileMap.keySet()) |
249 |
|
{ |
250 |
350 |
if (ssConsensus.description.startsWith(source)) |
251 |
|
{ |
252 |
336 |
ssConsensusProfile = ssConsensusProfileMap.get(source); |
253 |
336 |
break; |
254 |
|
} |
255 |
|
} |
256 |
336 |
if (ssConsensusProfile == null) |
257 |
|
{ |
258 |
0 |
continue; |
259 |
|
} |
260 |
336 |
if (immediate || !calcMan.isWorking(this) && ssConsensus != null |
261 |
|
&& ssConsensusProfile != null) |
262 |
|
{ |
263 |
336 |
if (ssConsensusProfile.get(0) != null) |
264 |
336 |
ssConsensus.setNoOfSequencesIncluded( |
265 |
|
ssConsensusProfile.get(0).getSeqWithSSCount()); |
266 |
336 |
deriveSSConsensus(ssConsensus, ssConsensusProfile); |
267 |
336 |
ssConsensus.hasData=ssConsensusProfile.getCount()>0; |
268 |
|
|
269 |
336 |
AlignmentAnnotation gap = getGapAnnotation(); |
270 |
336 |
if (gap != null) |
271 |
|
{ |
272 |
334 |
deriveGap(gap, ssConsensusProfile); |
273 |
|
} |
274 |
|
} |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
@param |
283 |
|
|
284 |
|
@param |
285 |
|
|
286 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
287 |
336 |
protected void deriveSSConsensus(AlignmentAnnotation ssConsensus,... |
288 |
|
ProfilesI hSSConsensus) |
289 |
|
{ |
290 |
|
|
291 |
336 |
long nseq = getSequences().length; |
292 |
336 |
AAFrequency.completeSSConsensus(ssConsensus, hSSConsensus, |
293 |
|
hSSConsensus.getStartColumn(), hSSConsensus.getEndColumn() + 1, |
294 |
|
alignViewport.isIgnoreGapsConsensus(), |
295 |
|
alignViewport.isShowSequenceLogo(), nseq); |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
@param |
302 |
|
|
303 |
|
@param |
304 |
|
|
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
306 |
334 |
protected void deriveGap(AlignmentAnnotation gapAnnotation,... |
307 |
|
ProfilesI hconsensus) |
308 |
|
{ |
309 |
334 |
long nseq = getSequences().length; |
310 |
334 |
AAFrequency.completeGapAnnot(gapAnnotation, hconsensus, |
311 |
|
hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, |
312 |
|
nseq); |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
@return |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
320 |
376 |
protected Map<String, ProfilesI> getViewportSSConsensus()... |
321 |
|
{ |
322 |
|
|
323 |
376 |
return alignViewport.getSequenceSSConsensusHash(); |
324 |
|
} |
325 |
|
} |