2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.analysis.AlignSeq;
27 import jalview.commands.*;
28 import jalview.datamodel.*;
29 import jalview.util.MessageManager;
31 public class RedundancyPanel extends SliderPanel implements Runnable,
34 Stack historyList = new Stack(); // simpler than synching with alignFrame.
38 SequenceI[] originalSequences;
44 public RedundancyPanel(AlignmentPanel ap)
46 super(ap, 0, false, null);
48 redundantSeqs = new Vector();
50 undoButton.setVisible(true);
51 applyButton.setVisible(true);
52 allGroupsCheck.setVisible(false);
54 label.setText(MessageManager.getString("label.enter_redundancy_threshold"));
55 valueField.setText("100");
57 slider.setVisibleAmount(1);
59 slider.setMaximum(100 + slider.getVisibleAmount());
62 slider.addAdjustmentListener(new AdjustmentListener()
64 public void adjustmentValueChanged(AdjustmentEvent evt)
66 valueField.setText(slider.getValue() + "");
73 jalview.bin.JalviewLite.addFrame(frame,
74 MessageManager.getString("label.redundancy_threshold_selection"), 400, 100);
76 frame.addWindowListener(this);
78 Thread worker = new Thread(this);
83 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
84 * we dont want to remove redundancy, just calculate once so we can use the
85 * slider to dynamically hide redundant sequences
92 * @return DOCUMENT ME!
96 label.setText(MessageManager.getString("label.calculating"));
98 slider.setVisible(false);
99 applyButton.setEnabled(false);
100 valueField.setVisible(false);
104 String[] omitHidden = null;
106 SequenceGroup sg = ap.av.getSelectionGroup();
111 if ((sg != null) && (sg.getSize() >= 1))
113 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
114 start = sg.getStartRes();
115 end = sg.getEndRes();
119 originalSequences = ap.av.getAlignment().getSequencesArray();
121 end = ap.av.getAlignment().getWidth();
124 height = originalSequences.length;
126 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
127 omitHidden, start, end, false);
128 label.setText(MessageManager.getString("label.enter_redundancy_threshold"));
129 slider.setVisible(true);
130 applyButton.setEnabled(true);
131 valueField.setVisible(true);
134 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
137 void sliderValueChanged()
139 if (redundancy == null)
144 float value = slider.getValue();
146 for (int i = 0; i < redundancy.length; i++)
148 if (value > redundancy[i])
150 redundantSeqs.removeElement(originalSequences[i]);
152 else if (!redundantSeqs.contains(originalSequences[i]))
154 redundantSeqs.addElement(originalSequences[i]);
158 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
159 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
163 public void applyButton_actionPerformed()
165 Vector del = new Vector();
167 undoButton.setEnabled(true);
169 float value = slider.getValue();
170 SequenceGroup sg = ap.av.getSelectionGroup();
172 for (int i = 0; i < redundancy.length; i++)
174 if (value <= redundancy[i])
176 del.addElement(originalSequences[i]);
180 // This has to be done before the restoreHistoryItem method of alignFrame
182 // actually restore these sequences.
185 SequenceI[] deleted = new SequenceI[del.size()];
188 for (int i = 0; i < del.size(); i++)
190 deleted[i] = (SequenceI) del.elementAt(i);
191 if (deleted[i].getLength() > width)
193 width = deleted[i].getLength();
197 EditCommand cut = new EditCommand("Remove Redundancy",
198 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
199 AlignmentI alignment = ap.av.getAlignment();
200 for (int i = 0; i < del.size(); i++)
202 alignment.deleteSequence(deleted[i]);
205 sg.deleteSequence(deleted[i], false);
209 historyList.push(cut);
211 ap.alignFrame.addHistoryItem(cut);
213 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
214 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
220 public void undoButton_actionPerformed()
222 CommandI command = (CommandI) historyList.pop();
223 command.undoCommand(null);
225 if (ap.av.historyList.contains(command))
227 ap.av.historyList.removeElement(command);
228 ap.alignFrame.updateEditMenuBar();
231 ap.paintAlignment(true);
233 if (historyList.size() == 0)
235 undoButton.setEnabled(false);
239 public void valueField_actionPerformed(ActionEvent e)
243 int i = Integer.parseInt(valueField.getText());
245 } catch (Exception ex)
247 valueField.setText(slider.getValue() + "");
251 public void windowOpened(WindowEvent evt)
255 public void windowClosing(WindowEvent evt)
257 ap.idPanel.idCanvas.setHighlighted(null);
260 public void windowClosed(WindowEvent evt)
264 public void windowActivated(WindowEvent evt)
268 public void windowDeactivated(WindowEvent evt)
272 public void windowIconified(WindowEvent evt)
276 public void windowDeiconified(WindowEvent evt)