2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
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;
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;
43 public class RedundancyPanel extends SliderPanel implements Runnable,
46 Stack historyList = new Stack(); // simpler than synching with alignFrame.
50 SequenceI[] originalSequences;
56 public RedundancyPanel(AlignmentPanel ap)
58 super(ap, 0, false, null);
60 redundantSeqs = new Vector();
62 undoButton.setVisible(true);
63 applyButton.setVisible(true);
64 allGroupsCheck.setVisible(false);
66 label.setText(MessageManager
67 .getString("label.enter_redundancy_threshold"));
68 valueField.setText("100");
70 slider.setVisibleAmount(1);
72 slider.setMaximum(100 + slider.getVisibleAmount());
75 slider.addAdjustmentListener(new AdjustmentListener()
78 public void adjustmentValueChanged(AdjustmentEvent evt)
80 valueField.setText(String.valueOf(slider.getValue()));
87 jalview.bin.JalviewLite.addFrame(frame, MessageManager
88 .getString("label.redundancy_threshold_selection"), 400, 100);
90 frame.addWindowListener(this);
92 Thread worker = new Thread(this);
97 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
98 * we dont want to remove redundancy, just calculate once so we can use the
99 * slider to dynamically hide redundant sequences
106 * @return DOCUMENT ME!
111 label.setText(MessageManager.getString("label.calculating"));
113 slider.setVisible(false);
114 applyButton.setEnabled(false);
115 valueField.setVisible(false);
119 String[] omitHidden = null;
121 SequenceGroup sg = ap.av.getSelectionGroup();
126 if ((sg != null) && (sg.getSize() >= 1))
128 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
129 start = sg.getStartRes();
130 end = sg.getEndRes();
134 originalSequences = ap.av.getAlignment().getSequencesArray();
136 end = ap.av.getAlignment().getWidth();
139 height = originalSequences.length;
141 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
142 omitHidden, start, end, false);
143 label.setText(MessageManager
144 .getString("label.enter_redundancy_threshold"));
145 slider.setVisible(true);
146 applyButton.setEnabled(true);
147 valueField.setVisible(true);
150 sliderValueChanged();
151 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
154 void sliderValueChanged()
156 if (redundancy == null)
161 float value = slider.getValue();
163 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
164 for (int i = 0; i < redundancy.length; i++)
166 if (value <= redundancy[i])
168 redundantSequences.add(originalSequences[i]);
172 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
173 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
178 public void applyButton_actionPerformed()
180 Vector del = new Vector();
182 undoButton.setEnabled(true);
184 float value = slider.getValue();
185 SequenceGroup sg = ap.av.getSelectionGroup();
187 for (int i = 0; i < redundancy.length; i++)
189 if (value <= redundancy[i])
191 del.addElement(originalSequences[i]);
195 // This has to be done before the restoreHistoryItem method of alignFrame
197 // actually restore these sequences.
200 SequenceI[] deleted = new SequenceI[del.size()];
203 for (int i = 0; i < del.size(); i++)
205 deleted[i] = (SequenceI) del.elementAt(i);
206 if (deleted[i].getLength() > width)
208 width = deleted[i].getLength();
212 EditCommand cut = new EditCommand(
213 MessageManager.getString("action.remove_redundancy"),
214 Action.CUT, deleted, 0, width, ap.av.getAlignment());
215 AlignmentI alignment = ap.av.getAlignment();
216 for (int i = 0; i < del.size(); i++)
218 alignment.deleteSequence(deleted[i]);
221 sg.deleteSequence(deleted[i], false);
225 historyList.push(cut);
227 ap.alignFrame.addHistoryItem(cut);
229 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
230 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
237 public void undoButton_actionPerformed()
239 CommandI command = (CommandI) historyList.pop();
240 command.undoCommand(null);
242 if (ap.av.getHistoryList().contains(command))
244 ap.av.getHistoryList().remove(command);
245 ap.alignFrame.updateEditMenuBar();
246 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
250 ap.paintAlignment(true);
252 if (historyList.size() == 0)
254 undoButton.setEnabled(false);
258 public void valueField_actionPerformed(ActionEvent e)
262 int i = Integer.parseInt(valueField.getText());
264 } catch (Exception ex)
266 valueField.setText(slider.getValue() + "");
271 public void windowOpened(WindowEvent evt)
276 public void windowClosing(WindowEvent evt)
278 ap.idPanel.idCanvas.setHighlighted(null);
282 public void windowClosed(WindowEvent evt)
287 public void windowActivated(WindowEvent evt)
292 public void windowDeactivated(WindowEvent evt)
297 public void windowIconified(WindowEvent evt)
302 public void windowDeiconified(WindowEvent evt)