2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.
25 import java.awt.event.*;
27 import javax.swing.event.*;
29 import jalview.analysis.AlignSeq;
30 import jalview.commands.*;
31 import jalview.datamodel.*;
32 import jalview.jbgui.*;
33 import jalview.util.MessageManager;
41 public class RedundancyPanel extends GSliderPanel implements Runnable
47 Stack historyList = new Stack(); // simpler than synching with alignFrame.
51 SequenceI[] originalSequences;
58 * Creates a new RedundancyPanel object.
65 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
69 redundantSeqs = new Vector();
71 slider.addChangeListener(new ChangeListener()
73 public void stateChanged(ChangeEvent evt)
75 valueField.setText(slider.getValue() + "");
80 applyButton.setText(MessageManager.getString("action.remove"));
81 allGroupsCheck.setVisible(false);
83 slider.setMaximum(100);
86 Thread worker = new Thread(this);
89 frame = new JInternalFrame();
90 frame.setContentPane(this);
91 Desktop.addInternalFrame(frame, MessageManager
92 .getString("label.redundancy_threshold_selection"), 400, 100,
94 frame.addInternalFrameListener(new InternalFrameAdapter()
96 public void internalFrameClosing(InternalFrameEvent evt)
98 ap.idPanel.idCanvas.setHighlighted(null);
105 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
106 * we dont want to remove redundancy, just calculate once so we can use the
107 * slider to dynamically hide redundant sequences
114 * @return DOCUMENT ME!
118 JProgressBar progress = new JProgressBar();
119 progress.setIndeterminate(true);
120 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
122 label.setText(MessageManager.getString("label.calculating"));
124 slider.setVisible(false);
125 applyButton.setEnabled(false);
126 valueField.setVisible(false);
130 String[] omitHidden = null;
132 SequenceGroup sg = ap.av.getSelectionGroup();
137 if ((sg != null) && (sg.getSize() >= 1))
139 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
140 start = sg.getStartRes();
141 end = sg.getEndRes();
145 originalSequences = ap.av.getAlignment().getSequencesArray();
147 end = ap.av.getAlignment().getWidth();
150 height = originalSequences.length;
151 if (ap.av.hasHiddenColumns())
153 omitHidden = ap.av.getViewAsString(sg != null);
155 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
156 omitHidden, start, end, false);
158 progress.setIndeterminate(false);
159 progress.setVisible(false);
162 label.setText("Enter the redundancy threshold");
163 slider.setVisible(true);
164 applyButton.setEnabled(true);
165 valueField.setVisible(true);
168 sliderValueChanged();
169 // System.out.println((System.currentTimeMillis()-start));
172 void sliderValueChanged()
174 if (redundancy == null)
179 float value = slider.getValue();
180 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
181 for (int i = 0; i < redundancy.length; i++)
183 if (value <= redundancy[i])
185 redundantSequences.add(originalSequences[i]);
188 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
197 public void applyButton_actionPerformed(ActionEvent e)
199 Vector del = new Vector();
201 undoButton.setEnabled(true);
203 float value = slider.getValue();
204 SequenceGroup sg = ap.av.getSelectionGroup();
206 for (int i = 0; i < redundancy.length; i++)
208 if (value <= redundancy[i])
210 del.addElement(originalSequences[i]);
214 // This has to be done before the restoreHistoryItem method of alignFrame
216 // actually restore these sequences.
219 SequenceI[] deleted = new SequenceI[del.size()];
222 for (int i = 0; i < del.size(); i++)
224 deleted[i] = (SequenceI) del.elementAt(i);
225 if (deleted[i].getLength() > width)
227 width = deleted[i].getLength();
231 EditCommand cut = new EditCommand("Remove Redundancy",
232 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
234 for (int i = 0; i < del.size(); i++)
236 ap.av.getAlignment().deleteSequence(deleted[i]);
239 sg.deleteSequence(deleted[i], false);
243 historyList.push(cut);
245 ap.alignFrame.addHistoryItem(cut);
247 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
248 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
260 public void undoButton_actionPerformed(ActionEvent e)
262 CommandI command = (CommandI) historyList.pop();
263 command.undoCommand(af.getViewAlignments());
265 if (ap.av.historyList.contains(command))
267 ap.av.historyList.remove(command);
268 af.updateEditMenuBar();
271 ap.paintAlignment(true);
273 if (historyList.size() == 0)
275 undoButton.setEnabled(false);
285 public void valueField_actionPerformed(ActionEvent e)
289 int i = Integer.parseInt(valueField.getText());
291 } catch (Exception ex)
293 valueField.setText(slider.getValue() + "");