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 jalview.analysis.AAFrequency; |
24 |
|
import jalview.api.AlignViewportI; |
25 |
|
import jalview.api.AlignmentViewPanel; |
26 |
|
import jalview.datamodel.AlignmentAnnotation; |
27 |
|
import jalview.datamodel.AlignmentI; |
28 |
|
import jalview.datamodel.Annotation; |
29 |
|
import jalview.datamodel.ProfilesI; |
30 |
|
import jalview.datamodel.SequenceI; |
31 |
|
import jalview.renderer.ResidueShaderI; |
32 |
|
|
|
|
| 78.4% |
Uncovered Elements: 21 (97) |
Complexity: 32 |
Complexity Density: 0.52 |
|
33 |
|
public class ConsensusThread extends AlignCalcWorker |
34 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
35 |
190 |
public ConsensusThread(AlignViewportI alignViewport,... |
36 |
|
AlignmentViewPanel alignPanel) |
37 |
|
{ |
38 |
190 |
super(alignViewport, alignPanel); |
39 |
|
} |
40 |
|
|
|
|
| 56.5% |
Uncovered Elements: 20 (46) |
Complexity: 13 |
Complexity Density: 0.41 |
|
41 |
463 |
@Override... |
42 |
|
public void run() |
43 |
|
{ |
44 |
463 |
if (calcMan.isPending(this)) |
45 |
|
{ |
46 |
0 |
return; |
47 |
|
} |
48 |
463 |
calcMan.notifyStart(this); |
49 |
463 |
long started = System.currentTimeMillis(); |
50 |
463 |
try |
51 |
|
{ |
52 |
463 |
AlignmentAnnotation consensus = getConsensusAnnotation(); |
53 |
463 |
AlignmentAnnotation gap = getGapAnnotation(); |
54 |
463 |
if ((consensus == null && gap == null) || calcMan.isPending(this)) |
55 |
|
{ |
56 |
3 |
calcMan.workerComplete(this); |
57 |
3 |
return; |
58 |
|
} |
59 |
460 |
while (!calcMan.notifyWorking(this)) |
60 |
|
{ |
61 |
|
|
62 |
|
|
63 |
0 |
try |
64 |
|
{ |
65 |
0 |
if (ap != null) |
66 |
|
{ |
67 |
0 |
ap.paintAlignment(false, false); |
68 |
|
} |
69 |
0 |
Thread.sleep(200); |
70 |
|
} catch (Exception ex) |
71 |
|
{ |
72 |
0 |
ex.printStackTrace(); |
73 |
|
} |
74 |
|
} |
75 |
460 |
if (alignViewport.isClosed()) |
76 |
|
{ |
77 |
0 |
abortAndDestroy(); |
78 |
0 |
return; |
79 |
|
} |
80 |
460 |
AlignmentI alignment = alignViewport.getAlignment(); |
81 |
|
|
82 |
460 |
int aWidth = -1; |
83 |
|
|
84 |
? |
if (alignment == null || (aWidth = alignment.getWidth()) < 0) |
85 |
|
{ |
86 |
0 |
calcMan.workerComplete(this); |
87 |
0 |
return; |
88 |
|
} |
89 |
|
|
90 |
460 |
eraseConsensus(aWidth); |
91 |
460 |
computeConsensus(alignment); |
92 |
460 |
updateResultAnnotation(true); |
93 |
|
|
94 |
460 |
if (ap != null) |
95 |
|
{ |
96 |
460 |
ap.paintAlignment(true, true); |
97 |
|
} |
98 |
|
} catch (OutOfMemoryError error) |
99 |
|
{ |
100 |
0 |
calcMan.disableWorker(this); |
101 |
0 |
ap.raiseOOMWarning("calculating consensus", error); |
102 |
|
} finally |
103 |
|
{ |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
463 |
calcMan.workerComplete(this); |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
118 |
460 |
protected void eraseConsensus(int aWidth)... |
119 |
|
{ |
120 |
460 |
AlignmentAnnotation consensus = getConsensusAnnotation(); |
121 |
460 |
consensus.annotations = new Annotation[aWidth]; |
122 |
460 |
AlignmentAnnotation gap = getGapAnnotation(); |
123 |
460 |
if (gap != null) |
124 |
|
{ |
125 |
458 |
gap.annotations = new Annotation[aWidth]; |
126 |
|
} |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
132 |
459 |
protected void computeConsensus(AlignmentI alignment)... |
133 |
|
{ |
134 |
|
|
135 |
459 |
SequenceI[] aseqs = getSequences(); |
136 |
459 |
int width = alignment.getWidth(); |
137 |
459 |
ProfilesI hconsensus = AAFrequency.calculate(aseqs, width, 0, width, |
138 |
|
true); |
139 |
|
|
140 |
459 |
alignViewport.setSequenceConsensusHash(hconsensus); |
141 |
459 |
setColourSchemeConsensus(hconsensus); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
1425 |
protected SequenceI[] getSequences()... |
148 |
|
{ |
149 |
1425 |
return alignViewport.getAlignment().getSequencesArray(); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
155 |
459 |
protected void setColourSchemeConsensus(ProfilesI hconsensus)... |
156 |
|
{ |
157 |
459 |
ResidueShaderI cs = alignViewport.getResidueShading(); |
158 |
459 |
if (cs != null) |
159 |
|
{ |
160 |
459 |
cs.setConsensus(hconsensus); |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
@return |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
1405 |
protected AlignmentAnnotation getConsensusAnnotation()... |
170 |
|
{ |
171 |
1405 |
return alignViewport.getAlignmentConsensusAnnotation(); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@return |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
1406 |
protected AlignmentAnnotation getGapAnnotation()... |
180 |
|
{ |
181 |
1406 |
return alignViewport.getAlignmentGapAnnotation(); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
25 |
@Override... |
189 |
|
public void updateAnnotation() |
190 |
|
{ |
191 |
25 |
updateResultAnnotation(false); |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 6 |
Complexity Density: 0.86 |
|
194 |
484 |
public void updateResultAnnotation(boolean immediate)... |
195 |
|
{ |
196 |
484 |
AlignmentAnnotation consensus = getConsensusAnnotation(); |
197 |
484 |
ProfilesI hconsensus = (ProfilesI) getViewportConsensus(); |
198 |
484 |
if (immediate || !calcMan.isWorking(this) && consensus != null |
199 |
|
&& hconsensus != null) |
200 |
|
{ |
201 |
483 |
deriveConsensus(consensus, hconsensus); |
202 |
483 |
AlignmentAnnotation gap = getGapAnnotation(); |
203 |
483 |
if (gap != null) |
204 |
|
{ |
205 |
481 |
deriveGap(gap, hconsensus); |
206 |
|
} |
207 |
|
} |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
@param |
215 |
|
|
216 |
|
@param |
217 |
|
|
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
219 |
483 |
protected void deriveConsensus(AlignmentAnnotation consensusAnnotation,... |
220 |
|
ProfilesI hconsensus) |
221 |
|
{ |
222 |
|
|
223 |
483 |
long nseq = getSequences().length; |
224 |
483 |
AAFrequency.completeConsensus(consensusAnnotation, hconsensus, |
225 |
|
hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, |
226 |
|
alignViewport.isIgnoreGapsConsensus(), |
227 |
|
alignViewport.isShowSequenceLogo(), nseq); |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@param |
234 |
|
|
235 |
|
@param |
236 |
|
|
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
238 |
481 |
protected void deriveGap(AlignmentAnnotation gapAnnotation,... |
239 |
|
ProfilesI hconsensus) |
240 |
|
{ |
241 |
481 |
long nseq = getSequences().length; |
242 |
481 |
AAFrequency.completeGapAnnot(gapAnnotation, hconsensus, |
243 |
|
hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, |
244 |
|
nseq); |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
@return |
251 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
252 |
484 |
protected Object getViewportConsensus()... |
253 |
|
{ |
254 |
|
|
255 |
484 |
return alignViewport.getSequenceConsensusHash(); |
256 |
|
} |
257 |
|
} |