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.analysis.Conservation; |
25 |
|
import jalview.analysis.scoremodels.ScoreModels; |
26 |
|
import jalview.api.AlignViewportI; |
27 |
|
import jalview.api.AlignmentViewPanel; |
28 |
|
import jalview.bin.Console; |
29 |
|
import jalview.datamodel.AlignedCodonFrame; |
30 |
|
import jalview.datamodel.AlignmentAnnotation; |
31 |
|
import jalview.datamodel.AlignmentI; |
32 |
|
import jalview.datamodel.Annotation; |
33 |
|
import jalview.datamodel.SequenceI; |
34 |
|
import jalview.util.MappingUtils; |
35 |
|
|
36 |
|
import java.util.ArrayList; |
37 |
|
import java.util.ConcurrentModificationException; |
38 |
|
import java.util.Hashtable; |
39 |
|
import java.util.List; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@author |
46 |
|
|
47 |
|
|
|
|
| 0% |
Uncovered Elements: 81 (81) |
Complexity: 30 |
Complexity Density: 0.54 |
|
48 |
|
public class AlignmentComparisonThread extends AlignCalcWorker |
49 |
|
{ |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
0 |
public AlignmentComparisonThread(AlignViewportI alignViewport,... |
52 |
|
AlignmentViewPanel alignPanel) |
53 |
|
{ |
54 |
0 |
super(alignViewport, alignPanel); |
55 |
0 |
comparisonAnnot = alignViewport.getComparisonAnnotation(); |
56 |
|
} |
57 |
|
|
58 |
|
Annotation[] correspondence = new Annotation[1]; |
59 |
|
AlignmentAnnotation comparisonAnnot=null; |
60 |
|
int alWidth; |
61 |
|
private int maxCor=1; |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 17 |
Complexity Density: 0.52 |
|
63 |
0 |
@Override... |
64 |
|
public void run() |
65 |
|
{ |
66 |
0 |
try |
67 |
|
{ |
68 |
0 |
calcMan.notifyStart(this); |
69 |
|
|
70 |
0 |
while ((calcMan != null) && (!calcMan.notifyWorking(this))) |
71 |
|
{ |
72 |
0 |
try |
73 |
|
{ |
74 |
0 |
if (ap != null) |
75 |
|
{ |
76 |
|
|
77 |
|
} |
78 |
0 |
Thread.sleep(200); |
79 |
|
} catch (Exception ex) |
80 |
|
{ |
81 |
0 |
ex.printStackTrace(); |
82 |
|
} |
83 |
|
} |
84 |
0 |
if ((alignViewport == null) || (calcMan == null) |
85 |
|
|| (alignViewport.isClosed())) |
86 |
|
{ |
87 |
0 |
abortAndDestroy(); |
88 |
0 |
return; |
89 |
|
} |
90 |
0 |
List<AlignmentAnnotation> ourAnnot = new ArrayList<>(); |
91 |
|
|
92 |
0 |
AlignmentI alignment = alignViewport.getAlignment(); |
93 |
0 |
AlignViewportI codingComplement = alignViewport.getCodingComplement(); |
94 |
0 |
if (alignment == null || (alWidth = alignment.getWidth()) < 0 |
95 |
|
|| (codingComplement == null)) |
96 |
|
{ |
97 |
0 |
calcMan.workerComplete(this); |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
0 |
return; |
102 |
|
} |
103 |
|
|
104 |
0 |
comparisonAnnot.annotations=correspondence; |
105 |
0 |
ourAnnot.add(comparisonAnnot); |
106 |
0 |
ourAnnots = ourAnnot; |
107 |
|
|
108 |
0 |
try |
109 |
|
{ |
110 |
0 |
computeColumnCorrespondence(alignViewport, codingComplement); |
111 |
|
} catch (Throwable x) |
112 |
|
{ |
113 |
0 |
Console.error("Unexpected error computing similarity of alignments",x); |
114 |
|
|
115 |
0 |
calcMan.workerComplete(this); |
116 |
0 |
return; |
117 |
|
} |
118 |
0 |
updateResultAnnotation(true); |
119 |
|
} catch (OutOfMemoryError error) |
120 |
|
{ |
121 |
0 |
ap.raiseOOMWarning("calculating conservation", error); |
122 |
0 |
calcMan.disableWorker(this); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
} |
127 |
0 |
calcMan.workerComplete(this); |
128 |
|
|
129 |
0 |
if ((alignViewport == null) || (calcMan == null) |
130 |
|
|| (alignViewport.isClosed())) |
131 |
|
{ |
132 |
0 |
abortAndDestroy(); |
133 |
0 |
return; |
134 |
|
} |
135 |
0 |
if (ap != null) |
136 |
|
{ |
137 |
0 |
ap.paintAlignment(true, true); |
138 |
|
} |
139 |
|
|
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 7 |
Complexity Density: 0.47 |
|
142 |
0 |
private void computeColumnCorrespondence(AlignViewportI alignViewport,... |
143 |
|
AlignViewportI codingComplement) |
144 |
|
{ |
145 |
0 |
List<SequenceI> us = alignViewport.getAlignment().getSequences(); |
146 |
0 |
List<AlignedCodonFrame> ourMappings = alignViewport.getAlignment() |
147 |
|
.getCodonFrames(); |
148 |
0 |
List<SequenceI> them = codingComplement.getAlignment().getSequences(); |
149 |
0 |
List<AlignedCodonFrame> theirMappings = codingComplement.getAlignment() |
150 |
|
.getCodonFrames(); |
151 |
0 |
if (us == null || them == null || us.isEmpty() || them.isEmpty()) |
152 |
|
{ |
153 |
0 |
return; |
154 |
|
} |
155 |
|
|
156 |
0 |
int colEnd = alignViewport.getAlignment().getWidth(); |
157 |
0 |
Annotation[] colCorrsp = new Annotation[colEnd]; |
158 |
0 |
maxCor=0; |
159 |
0 |
for (int col = 0; col < colEnd; col++) |
160 |
|
{ |
161 |
0 |
int[] theirWidth = MappingUtils.findMappedColumns(col, ourMappings, |
162 |
|
us, them, alignViewport.getGapCharacter()); |
163 |
0 |
int wid =theirWidth != null ? Math.abs(theirWidth[1] - theirWidth[0]) |
164 |
|
: 0; |
165 |
0 |
colCorrsp[col] = new Annotation( |
166 |
|
wid); |
167 |
0 |
maxCor = Math.max(maxCor, wid); |
168 |
|
} |
169 |
0 |
correspondence=colCorrsp; |
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
172 |
0 |
private void updateResultAnnotation(boolean b)... |
173 |
|
{ |
174 |
0 |
if (b || !calcMan.isWorking(this) && correspondence!=null) |
175 |
|
{ |
176 |
0 |
comparisonAnnot.annotations = correspondence; |
177 |
0 |
comparisonAnnot.graphMax=(float)maxCor; |
178 |
0 |
comparisonAnnot.validateRangeAndDisplay(); |
179 |
0 |
ap.paintAlignment(false, false); |
180 |
|
} |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
183 |
0 |
@Override... |
184 |
|
public void updateAnnotation() |
185 |
|
{ |
186 |
0 |
updateResultAnnotation(false); |
187 |
|
|
188 |
|
} |
189 |
|
|
190 |
|
} |