1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.appletgui; |
22 |
|
|
23 |
|
import jalview.analysis.AlignSeq; |
24 |
|
import jalview.commands.CommandI; |
25 |
|
import jalview.commands.EditCommand; |
26 |
|
import jalview.commands.EditCommand.Action; |
27 |
|
import jalview.datamodel.AlignmentI; |
28 |
|
import jalview.datamodel.SequenceGroup; |
29 |
|
import jalview.datamodel.SequenceI; |
30 |
|
import jalview.util.MessageManager; |
31 |
|
|
32 |
|
import java.awt.Frame; |
33 |
|
import java.awt.event.ActionEvent; |
34 |
|
import java.awt.event.AdjustmentEvent; |
35 |
|
import java.awt.event.AdjustmentListener; |
36 |
|
import java.awt.event.WindowEvent; |
37 |
|
import java.awt.event.WindowListener; |
38 |
|
import java.util.ArrayList; |
39 |
|
import java.util.List; |
40 |
|
import java.util.Stack; |
41 |
|
import java.util.Vector; |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 132 (132) |
Complexity: 29 |
Complexity Density: 0.32 |
|
43 |
|
public class RedundancyPanel extends SliderPanel |
44 |
|
implements Runnable, WindowListener |
45 |
|
{ |
46 |
|
Stack historyList = new Stack(); |
47 |
|
|
48 |
|
float[] redundancy; |
49 |
|
|
50 |
|
SequenceI[] originalSequences; |
51 |
|
|
52 |
|
Frame frame; |
53 |
|
|
54 |
|
Vector redundantSeqs; |
55 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
|
56 |
0 |
public RedundancyPanel(AlignmentPanel ap)... |
57 |
|
{ |
58 |
0 |
super(ap, 0, false, null); |
59 |
|
|
60 |
0 |
redundantSeqs = new Vector(); |
61 |
0 |
this.ap = ap; |
62 |
0 |
undoButton.setVisible(true); |
63 |
0 |
applyButton.setVisible(true); |
64 |
0 |
allGroupsCheck.setVisible(false); |
65 |
|
|
66 |
0 |
label.setText( |
67 |
|
MessageManager.getString("label.enter_redundancy_threshold")); |
68 |
0 |
valueField.setText("100"); |
69 |
|
|
70 |
0 |
slider.setVisibleAmount(1); |
71 |
0 |
slider.setMinimum(0); |
72 |
0 |
slider.setMaximum(100 + slider.getVisibleAmount()); |
73 |
0 |
slider.setValue(100); |
74 |
|
|
75 |
0 |
slider.addAdjustmentListener(new AdjustmentListener() |
76 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
77 |
0 |
@Override... |
78 |
|
public void adjustmentValueChanged(AdjustmentEvent evt) |
79 |
|
{ |
80 |
0 |
valueField.setText(String.valueOf(slider.getValue())); |
81 |
0 |
sliderValueChanged(); |
82 |
|
} |
83 |
|
}); |
84 |
|
|
85 |
0 |
frame = new Frame(); |
86 |
0 |
frame.add(this); |
87 |
0 |
jalview.bin.JalviewLite.addFrame(frame, MessageManager |
88 |
|
.getString("label.redundancy_threshold_selection"), 400, 100); |
89 |
|
|
90 |
0 |
frame.addWindowListener(this); |
91 |
|
|
92 |
0 |
Thread worker = new Thread(this); |
93 |
0 |
worker.start(); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
|
106 |
|
@return |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 3 |
Complexity Density: 0.12 |
|
108 |
0 |
@Override... |
109 |
|
public void run() |
110 |
|
{ |
111 |
0 |
label.setText(MessageManager.getString("label.calculating")); |
112 |
|
|
113 |
0 |
slider.setVisible(false); |
114 |
0 |
applyButton.setEnabled(false); |
115 |
0 |
valueField.setVisible(false); |
116 |
|
|
117 |
0 |
validate(); |
118 |
|
|
119 |
0 |
String[] omitHidden = null; |
120 |
|
|
121 |
0 |
SequenceGroup sg = ap.av.getSelectionGroup(); |
122 |
0 |
int height; |
123 |
|
|
124 |
0 |
int start, end; |
125 |
|
|
126 |
0 |
if ((sg != null) && (sg.getSize() >= 1)) |
127 |
|
{ |
128 |
0 |
originalSequences = sg.getSequencesInOrder(ap.av.getAlignment()); |
129 |
0 |
start = sg.getStartRes(); |
130 |
0 |
end = sg.getEndRes(); |
131 |
|
} |
132 |
|
else |
133 |
|
{ |
134 |
0 |
originalSequences = ap.av.getAlignment().getSequencesArray(); |
135 |
0 |
start = 0; |
136 |
0 |
end = ap.av.getAlignment().getWidth(); |
137 |
|
} |
138 |
|
|
139 |
0 |
height = originalSequences.length; |
140 |
|
|
141 |
0 |
redundancy = AlignSeq.computeRedundancyMatrix(originalSequences, |
142 |
|
omitHidden, start, end, false); |
143 |
0 |
label.setText( |
144 |
|
MessageManager.getString("label.enter_redundancy_threshold")); |
145 |
0 |
slider.setVisible(true); |
146 |
0 |
applyButton.setEnabled(true); |
147 |
0 |
valueField.setVisible(true); |
148 |
|
|
149 |
0 |
validate(); |
150 |
0 |
sliderValueChanged(); |
151 |
|
|
152 |
|
|
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
155 |
0 |
void sliderValueChanged()... |
156 |
|
{ |
157 |
0 |
if (redundancy == null) |
158 |
|
{ |
159 |
0 |
return; |
160 |
|
} |
161 |
|
|
162 |
0 |
float value = slider.getValue(); |
163 |
|
|
164 |
0 |
List<SequenceI> redundantSequences = new ArrayList<>(); |
165 |
0 |
for (int i = 0; i < redundancy.length; i++) |
166 |
|
{ |
167 |
0 |
if (value <= redundancy[i]) |
168 |
|
{ |
169 |
0 |
redundantSequences.add(originalSequences[i]); |
170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
0 |
ap.idPanel.idCanvas.setHighlighted(redundantSequences); |
174 |
0 |
PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true); |
175 |
|
|
176 |
|
} |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 8 |
Complexity Density: 0.33 |
|
178 |
0 |
@Override... |
179 |
|
public void applyButton_actionPerformed() |
180 |
|
{ |
181 |
0 |
Vector del = new Vector(); |
182 |
|
|
183 |
0 |
undoButton.setEnabled(true); |
184 |
|
|
185 |
0 |
float value = slider.getValue(); |
186 |
0 |
SequenceGroup sg = ap.av.getSelectionGroup(); |
187 |
|
|
188 |
0 |
for (int i = 0; i < redundancy.length; i++) |
189 |
|
{ |
190 |
0 |
if (value <= redundancy[i]) |
191 |
|
{ |
192 |
0 |
del.addElement(originalSequences[i]); |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
0 |
if (del.size() > 0) |
200 |
|
{ |
201 |
0 |
SequenceI[] deleted = new SequenceI[del.size()]; |
202 |
|
|
203 |
0 |
int width = 0; |
204 |
0 |
for (int i = 0; i < del.size(); i++) |
205 |
|
{ |
206 |
0 |
deleted[i] = (SequenceI) del.elementAt(i); |
207 |
0 |
if (deleted[i].getLength() > width) |
208 |
|
{ |
209 |
0 |
width = deleted[i].getLength(); |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
0 |
EditCommand cut = new EditCommand( |
214 |
|
MessageManager.getString("action.remove_redundancy"), |
215 |
|
Action.CUT, deleted, 0, width, ap.av.getAlignment()); |
216 |
0 |
AlignmentI alignment = ap.av.getAlignment(); |
217 |
0 |
for (int i = 0; i < del.size(); i++) |
218 |
|
{ |
219 |
0 |
alignment.deleteSequence(deleted[i]); |
220 |
0 |
if (sg != null) |
221 |
|
{ |
222 |
0 |
sg.deleteSequence(deleted[i], false); |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
0 |
historyList.push(cut); |
227 |
|
|
228 |
0 |
ap.alignFrame.addHistoryItem(cut); |
229 |
|
|
230 |
0 |
PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true); |
231 |
0 |
ap.av.firePropertyChange("alignment", null, |
232 |
|
ap.av.getAlignment().getSequences()); |
233 |
|
} |
234 |
|
|
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
237 |
0 |
@Override... |
238 |
|
public void undoButton_actionPerformed() |
239 |
|
{ |
240 |
0 |
CommandI command = (CommandI) historyList.pop(); |
241 |
0 |
command.undoCommand(null); |
242 |
|
|
243 |
0 |
if (ap.av.getHistoryList().contains(command)) |
244 |
|
{ |
245 |
0 |
ap.av.getHistoryList().remove(command); |
246 |
0 |
ap.alignFrame.updateEditMenuBar(); |
247 |
0 |
ap.av.firePropertyChange("alignment", null, |
248 |
|
ap.av.getAlignment().getSequences()); |
249 |
|
} |
250 |
|
|
251 |
0 |
ap.paintAlignment(true, true); |
252 |
|
|
253 |
0 |
if (historyList.size() == 0) |
254 |
|
{ |
255 |
0 |
undoButton.setEnabled(false); |
256 |
|
} |
257 |
|
} |
258 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
259 |
0 |
public void valueField_actionPerformed(ActionEvent e)... |
260 |
|
{ |
261 |
0 |
try |
262 |
|
{ |
263 |
0 |
int i = Integer.parseInt(valueField.getText()); |
264 |
0 |
slider.setValue(i); |
265 |
|
} catch (Exception ex) |
266 |
|
{ |
267 |
0 |
valueField.setText(slider.getValue() + ""); |
268 |
|
} |
269 |
|
} |
270 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
271 |
0 |
@Override... |
272 |
|
public void windowOpened(WindowEvent evt) |
273 |
|
{ |
274 |
|
} |
275 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
276 |
0 |
@Override... |
277 |
|
public void windowClosing(WindowEvent evt) |
278 |
|
{ |
279 |
0 |
ap.idPanel.idCanvas.setHighlighted(null); |
280 |
|
} |
281 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
282 |
0 |
@Override... |
283 |
|
public void windowClosed(WindowEvent evt) |
284 |
|
{ |
285 |
|
} |
286 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
287 |
0 |
@Override... |
288 |
|
public void windowActivated(WindowEvent evt) |
289 |
|
{ |
290 |
|
} |
291 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
292 |
0 |
@Override... |
293 |
|
public void windowDeactivated(WindowEvent evt) |
294 |
|
{ |
295 |
|
} |
296 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
297 |
0 |
@Override... |
298 |
|
public void windowIconified(WindowEvent evt) |
299 |
|
{ |
300 |
|
} |
301 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
302 |
0 |
@Override... |
303 |
|
public void windowDeiconified(WindowEvent evt) |
304 |
|
{ |
305 |
|
} |
306 |
|
} |