2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.analysis.AlignSeq;
26 import jalview.commands.*;
27 import jalview.datamodel.*;
28 import jalview.util.MessageManager;
30 public class RedundancyPanel extends SliderPanel implements Runnable,
33 Stack historyList = new Stack(); // simpler than synching with alignFrame.
37 SequenceI[] originalSequences;
43 public RedundancyPanel(AlignmentPanel ap)
45 super(ap, 0, false, null);
47 redundantSeqs = new Vector();
49 undoButton.setVisible(true);
50 applyButton.setVisible(true);
51 allGroupsCheck.setVisible(false);
53 label.setText(MessageManager.getString("label.enter_redundancy_threshold"));
54 valueField.setText("100");
56 slider.setVisibleAmount(1);
58 slider.setMaximum(100 + slider.getVisibleAmount());
61 slider.addAdjustmentListener(new AdjustmentListener()
63 public void adjustmentValueChanged(AdjustmentEvent evt)
65 valueField.setText(slider.getValue() + "");
72 jalview.bin.JalviewLite.addFrame(frame,
73 MessageManager.getString("label.redundancy_threshold_selection"), 400, 100);
75 frame.addWindowListener(this);
77 Thread worker = new Thread(this);
82 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
83 * we dont want to remove redundancy, just calculate once so we can use the
84 * slider to dynamically hide redundant sequences
91 * @return DOCUMENT ME!
95 label.setText(MessageManager.getString("label.calculating"));
97 slider.setVisible(false);
98 applyButton.setEnabled(false);
99 valueField.setVisible(false);
103 String[] omitHidden = null;
105 SequenceGroup sg = ap.av.getSelectionGroup();
110 if ((sg != null) && (sg.getSize() >= 1))
112 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
113 start = sg.getStartRes();
114 end = sg.getEndRes();
118 originalSequences = ap.av.getAlignment().getSequencesArray();
120 end = ap.av.getAlignment().getWidth();
123 height = originalSequences.length;
125 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
126 omitHidden, start, end, false);
127 label.setText(MessageManager.getString("label.enter_redundancy_threshold"));
128 slider.setVisible(true);
129 applyButton.setEnabled(true);
130 valueField.setVisible(true);
133 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
136 void sliderValueChanged()
138 if (redundancy == null)
143 float value = slider.getValue();
145 for (int i = 0; i < redundancy.length; i++)
147 if (value > redundancy[i])
149 redundantSeqs.removeElement(originalSequences[i]);
151 else if (!redundantSeqs.contains(originalSequences[i]))
153 redundantSeqs.addElement(originalSequences[i]);
157 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
158 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
162 public void applyButton_actionPerformed()
164 Vector del = new Vector();
166 undoButton.setEnabled(true);
168 float value = slider.getValue();
169 SequenceGroup sg = ap.av.getSelectionGroup();
171 for (int i = 0; i < redundancy.length; i++)
173 if (value <= redundancy[i])
175 del.addElement(originalSequences[i]);
179 // This has to be done before the restoreHistoryItem method of alignFrame
181 // actually restore these sequences.
184 SequenceI[] deleted = new SequenceI[del.size()];
187 for (int i = 0; i < del.size(); i++)
189 deleted[i] = (SequenceI) del.elementAt(i);
190 if (deleted[i].getLength() > width)
192 width = deleted[i].getLength();
196 EditCommand cut = new EditCommand("Remove Redundancy",
197 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
198 AlignmentI alignment = ap.av.getAlignment();
199 for (int i = 0; i < del.size(); i++)
201 alignment.deleteSequence(deleted[i]);
204 sg.deleteSequence(deleted[i], false);
208 historyList.push(cut);
210 ap.alignFrame.addHistoryItem(cut);
212 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
213 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
219 public void undoButton_actionPerformed()
221 CommandI command = (CommandI) historyList.pop();
222 command.undoCommand(null);
224 if (ap.av.historyList.contains(command))
226 ap.av.historyList.removeElement(command);
227 ap.alignFrame.updateEditMenuBar();
230 ap.paintAlignment(true);
232 if (historyList.size() == 0)
234 undoButton.setEnabled(false);
238 public void valueField_actionPerformed(ActionEvent e)
242 int i = Integer.parseInt(valueField.getText());
244 } catch (Exception ex)
246 valueField.setText(slider.getValue() + "");
250 public void windowOpened(WindowEvent evt)
254 public void windowClosing(WindowEvent evt)
256 ap.idPanel.idCanvas.setHighlighted(null);
259 public void windowClosed(WindowEvent evt)
263 public void windowActivated(WindowEvent evt)
267 public void windowDeactivated(WindowEvent evt)
271 public void windowIconified(WindowEvent evt)
275 public void windowDeiconified(WindowEvent evt)