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