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()
77 public void adjustmentValueChanged(AdjustmentEvent evt)
79 valueField.setText(slider.getValue() + "");
86 jalview.bin.JalviewLite.addFrame(frame, MessageManager
87 .getString("label.redundancy_threshold_selection"), 400, 100);
89 frame.addWindowListener(this);
91 Thread worker = new Thread(this);
96 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
97 * we dont want to remove redundancy, just calculate once so we can use the
98 * slider to dynamically hide redundant sequences
105 * @return DOCUMENT ME!
109 label.setText(MessageManager.getString("label.calculating"));
111 slider.setVisible(false);
112 applyButton.setEnabled(false);
113 valueField.setVisible(false);
117 String[] omitHidden = null;
119 SequenceGroup sg = ap.av.getSelectionGroup();
124 if ((sg != null) && (sg.getSize() >= 1))
126 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
127 start = sg.getStartRes();
128 end = sg.getEndRes();
132 originalSequences = ap.av.getAlignment().getSequencesArray();
134 end = ap.av.getAlignment().getWidth();
137 height = originalSequences.length;
139 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
140 omitHidden, start, end, false);
141 label.setText(MessageManager
142 .getString("label.enter_redundancy_threshold"));
143 slider.setVisible(true);
144 applyButton.setEnabled(true);
145 valueField.setVisible(true);
148 sliderValueChanged();
149 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
152 void sliderValueChanged()
154 if (redundancy == null)
159 float value = slider.getValue();
161 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
162 for (int i = 0; i < redundancy.length; i++)
164 if (value <= redundancy[i])
166 redundantSequences.add(originalSequences[i]);
170 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
171 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
175 public void applyButton_actionPerformed()
177 Vector del = new Vector();
179 undoButton.setEnabled(true);
181 float value = slider.getValue();
182 SequenceGroup sg = ap.av.getSelectionGroup();
184 for (int i = 0; i < redundancy.length; i++)
186 if (value <= redundancy[i])
188 del.addElement(originalSequences[i]);
192 // This has to be done before the restoreHistoryItem method of alignFrame
194 // actually restore these sequences.
197 SequenceI[] deleted = new SequenceI[del.size()];
200 for (int i = 0; i < del.size(); i++)
202 deleted[i] = (SequenceI) del.elementAt(i);
203 if (deleted[i].getLength() > width)
205 width = deleted[i].getLength();
209 EditCommand cut = new EditCommand(MessageManager.getString("action.remove_redundancy"),
210 Action.CUT, deleted, 0, width, ap.av.getAlignment());
211 AlignmentI alignment = ap.av.getAlignment();
212 for (int i = 0; i < del.size(); i++)
214 alignment.deleteSequence(deleted[i]);
217 sg.deleteSequence(deleted[i], false);
221 historyList.push(cut);
223 ap.alignFrame.addHistoryItem(cut);
225 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
226 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
231 public void undoButton_actionPerformed()
233 CommandI command = (CommandI) historyList.pop();
234 command.undoCommand(null);
236 if (ap.av.getHistoryList().contains(command))
238 ap.av.getHistoryList().remove(command);
239 ap.alignFrame.updateEditMenuBar();
240 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
243 ap.paintAlignment(true);
245 if (historyList.size() == 0)
247 undoButton.setEnabled(false);
251 public void valueField_actionPerformed(ActionEvent e)
255 int i = Integer.parseInt(valueField.getText());
257 } catch (Exception ex)
259 valueField.setText(slider.getValue() + "");
263 public void windowOpened(WindowEvent evt)
267 public void windowClosing(WindowEvent evt)
269 ap.idPanel.idCanvas.setHighlighted(null);
272 public void windowClosed(WindowEvent evt)
276 public void windowActivated(WindowEvent evt)
280 public void windowDeactivated(WindowEvent evt)
284 public void windowIconified(WindowEvent evt)
288 public void windowDeiconified(WindowEvent evt)