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.bin.JalviewLite;
25 import jalview.commands.CommandI;
26 import jalview.commands.EditCommand;
27 import jalview.commands.EditCommand.Action;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.util.MessageManager;
33 import awt2swing.Frame;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.AdjustmentEvent;
36 import java.awt.event.AdjustmentListener;
37 import java.awt.event.WindowEvent;
38 import java.awt.event.WindowListener;
39 import java.util.ArrayList;
40 import java.util.List;
41 import java.util.Stack;
42 import java.util.Vector;
44 public class RedundancyPanel extends SliderPanel implements Runnable,
47 Stack historyList = new Stack(); // simpler than synching with alignFrame.
51 SequenceI[] originalSequences;
57 public RedundancyPanel(AlignmentPanel ap)
59 super(ap, 0, false, null);
61 redundantSeqs = new Vector();
63 undoButton.setVisible(true);
64 applyButton.setVisible(true);
65 allGroupsCheck.setVisible(false);
67 label.setText(MessageManager
68 .getString("label.enter_redundancy_threshold"));
69 valueField.setText("100");
71 slider.setVisibleAmount(1);
73 slider.setMaximum(100 + slider.getVisibleAmount());
76 slider.addAdjustmentListener(new AdjustmentListener()
78 public void adjustmentValueChanged(AdjustmentEvent evt)
80 valueField.setText(slider.getValue() + "");
87 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!
110 label.setText(MessageManager.getString("label.calculating"));
112 slider.setVisible(false);
113 applyButton.setEnabled(false);
114 valueField.setVisible(false);
118 String[] omitHidden = null;
120 SequenceGroup sg = ap.av.getSelectionGroup();
125 if ((sg != null) && (sg.getSize() >= 1))
127 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
128 start = sg.getStartRes();
129 end = sg.getEndRes();
133 originalSequences = ap.av.getAlignment().getSequencesArray();
135 end = ap.av.getAlignment().getWidth();
138 height = originalSequences.length;
140 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
141 omitHidden, start, end, false);
142 label.setText(MessageManager
143 .getString("label.enter_redundancy_threshold"));
144 slider.setVisible(true);
145 applyButton.setEnabled(true);
146 valueField.setVisible(true);
149 sliderValueChanged();
150 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
153 void sliderValueChanged()
155 if (redundancy == null)
160 float value = slider.getValue();
162 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
163 for (int i = 0; i < redundancy.length; i++)
165 if (value <= redundancy[i])
167 redundantSequences.add(originalSequences[i]);
171 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
172 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
176 public void applyButton_actionPerformed()
178 Vector del = new Vector();
180 undoButton.setEnabled(true);
182 float value = slider.getValue();
183 SequenceGroup sg = ap.av.getSelectionGroup();
185 for (int i = 0; i < redundancy.length; i++)
187 if (value <= redundancy[i])
189 del.addElement(originalSequences[i]);
193 // This has to be done before the restoreHistoryItem method of alignFrame
195 // actually restore these sequences.
198 SequenceI[] deleted = new SequenceI[del.size()];
201 for (int i = 0; i < del.size(); i++)
203 deleted[i] = (SequenceI) del.elementAt(i);
204 if (deleted[i].getLength() > width)
206 width = deleted[i].getLength();
210 EditCommand cut = new EditCommand(MessageManager.getString("action.remove_redundancy"),
211 Action.CUT, deleted, 0, width, ap.av.getAlignment());
212 AlignmentI alignment = ap.av.getAlignment();
213 for (int i = 0; i < del.size(); i++)
215 alignment.deleteSequence(deleted[i]);
218 sg.deleteSequence(deleted[i], false);
222 historyList.push(cut);
224 ap.alignFrame.addHistoryItem(cut);
226 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
227 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
232 public void undoButton_actionPerformed()
234 CommandI command = (CommandI) historyList.pop();
235 command.undoCommand(null);
237 if (ap.av.getHistoryList().contains(command))
239 ap.av.getHistoryList().remove(command);
240 ap.alignFrame.updateEditMenuBar();
241 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
244 ap.paintAlignment(true);
246 if (historyList.size() == 0)
248 undoButton.setEnabled(false);
252 public void valueField_actionPerformed(ActionEvent e)
256 int i = Integer.parseInt(valueField.getText());
258 } catch (Exception ex)
260 valueField.setText(slider.getValue() + "");
264 public void windowOpened(WindowEvent evt)
268 public void windowClosing(WindowEvent evt)
270 ap.idPanel.idCanvas.setHighlighted(null);
273 public void windowClosed(WindowEvent evt)
277 public void windowActivated(WindowEvent evt)
281 public void windowDeactivated(WindowEvent evt)
285 public void windowIconified(WindowEvent evt)
289 public void windowDeiconified(WindowEvent evt)