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 |
|
|
|
|
| 0% |
Uncovered Elements: 99 (99) |
Complexity: 33 |
Complexity Density: 0.53 |
|
33 |
|
public class ConsensusThread extends AlignCalcWorker |
34 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
35 |
0 |
public ConsensusThread(AlignViewportI alignViewport,... |
36 |
|
AlignmentViewPanel alignPanel) |
37 |
|
{ |
38 |
0 |
super(alignViewport, alignPanel); |
39 |
|
} |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 13 |
Complexity Density: 0.42 |
|
41 |
0 |
@Override... |
42 |
|
public void run() |
43 |
|
{ |
44 |
0 |
if (calcMan.isPending(this)) |
45 |
|
{ |
46 |
0 |
return; |
47 |
|
} |
48 |
0 |
calcMan.notifyStart(this); |
49 |
|
|
50 |
0 |
try |
51 |
|
{ |
52 |
0 |
AlignmentAnnotation consensus = getConsensusAnnotation(); |
53 |
0 |
AlignmentAnnotation gap = getGapAnnotation(); |
54 |
0 |
if ((consensus == null && gap == null) || calcMan.isPending(this)) |
55 |
|
{ |
56 |
0 |
calcMan.workerComplete(this); |
57 |
0 |
return; |
58 |
|
} |
59 |
0 |
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 |
0 |
if (alignViewport.isClosed()) |
76 |
|
{ |
77 |
0 |
abortAndDestroy(); |
78 |
0 |
return; |
79 |
|
} |
80 |
0 |
AlignmentI alignment = alignViewport.getAlignment(); |
81 |
|
|
82 |
0 |
int aWidth = -1; |
83 |
|
|
84 |
0 |
if (alignment == null || (aWidth = alignment.getWidth()) < 0) |
85 |
|
{ |
86 |
0 |
calcMan.workerComplete(this); |
87 |
0 |
return; |
88 |
|
} |
89 |
|
|
90 |
0 |
eraseConsensus(aWidth); |
91 |
0 |
computeConsensus(alignment); |
92 |
0 |
updateResultAnnotation(true); |
93 |
|
|
94 |
0 |
if (ap != null) |
95 |
|
{ |
96 |
0 |
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 |
0 |
calcMan.workerComplete(this); |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
118 |
0 |
protected void eraseConsensus(int aWidth)... |
119 |
|
{ |
120 |
0 |
AlignmentAnnotation consensus = getConsensusAnnotation(); |
121 |
0 |
if (consensus != null) |
122 |
|
{ |
123 |
0 |
consensus.annotations = new Annotation[aWidth]; |
124 |
|
} |
125 |
0 |
AlignmentAnnotation gap = getGapAnnotation(); |
126 |
0 |
if (gap != null) |
127 |
|
{ |
128 |
0 |
gap.annotations = new Annotation[aWidth]; |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
135 |
0 |
protected void computeConsensus(AlignmentI alignment)... |
136 |
|
{ |
137 |
|
|
138 |
0 |
SequenceI[] aseqs = getSequences(); |
139 |
0 |
int width = alignment.getWidth(); |
140 |
0 |
ProfilesI hconsensus = AAFrequency.calculate(aseqs, width, 0, width, |
141 |
|
true); |
142 |
|
|
143 |
0 |
alignViewport.setSequenceConsensusHash(hconsensus); |
144 |
0 |
setColourSchemeConsensus(hconsensus); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
@return |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
protected SequenceI[] getSequences()... |
151 |
|
{ |
152 |
0 |
return alignViewport.getAlignment().getSequencesArray(); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
@param |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
158 |
0 |
protected void setColourSchemeConsensus(ProfilesI hconsensus)... |
159 |
|
{ |
160 |
0 |
ResidueShaderI cs = alignViewport.getResidueShading(); |
161 |
0 |
if (cs != null) |
162 |
|
{ |
163 |
0 |
cs.setConsensus(hconsensus); |
164 |
|
} |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
protected AlignmentAnnotation getConsensusAnnotation()... |
173 |
|
{ |
174 |
0 |
return alignViewport.getAlignmentConsensusAnnotation(); |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
@return |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0 |
protected AlignmentAnnotation getGapAnnotation()... |
183 |
|
{ |
184 |
0 |
return alignViewport.getAlignmentGapAnnotation(); |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
0 |
@Override... |
192 |
|
public void updateAnnotation() |
193 |
|
{ |
194 |
0 |
updateResultAnnotation(false); |
195 |
|
} |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 6 |
Complexity Density: 0.86 |
|
197 |
0 |
public void updateResultAnnotation(boolean immediate)... |
198 |
|
{ |
199 |
0 |
AlignmentAnnotation consensus = getConsensusAnnotation(); |
200 |
0 |
ProfilesI hconsensus = (ProfilesI) getViewportConsensus(); |
201 |
0 |
if (immediate || !calcMan.isWorking(this) && consensus != null |
202 |
|
&& hconsensus != null) |
203 |
|
{ |
204 |
0 |
deriveConsensus(consensus, hconsensus); |
205 |
0 |
AlignmentAnnotation gap = getGapAnnotation(); |
206 |
0 |
if (gap != null) |
207 |
|
{ |
208 |
0 |
deriveGap(gap, hconsensus); |
209 |
|
} |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
@param |
218 |
|
|
219 |
|
@param |
220 |
|
|
221 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
222 |
0 |
protected void deriveConsensus(AlignmentAnnotation consensusAnnotation,... |
223 |
|
ProfilesI hconsensus) |
224 |
|
{ |
225 |
|
|
226 |
0 |
long nseq = getSequences().length; |
227 |
0 |
AAFrequency.completeConsensus(consensusAnnotation, hconsensus, |
228 |
|
hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, |
229 |
|
alignViewport.isIgnoreGapsConsensus(), |
230 |
|
alignViewport.isShowSequenceLogo(), nseq); |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
@param |
240 |
|
|
241 |
|
@param |
242 |
|
|
243 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
244 |
0 |
protected void deriveGap(AlignmentAnnotation gapAnnotation,... |
245 |
|
ProfilesI hconsensus) |
246 |
|
{ |
247 |
0 |
long nseq = getSequences().length; |
248 |
0 |
AAFrequency.completeGapAnnot(gapAnnotation, hconsensus, |
249 |
|
hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, |
250 |
|
nseq); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@return |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
0 |
protected Object getViewportConsensus()... |
259 |
|
{ |
260 |
|
|
261 |
0 |
return alignViewport.getSequenceConsensusHash(); |
262 |
|
} |
263 |
|
} |