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.getString("label.redundancy_threshold_selection"), 400,
93 frame.addInternalFrameListener(new InternalFrameAdapter()
95 public void internalFrameClosing(InternalFrameEvent evt)
97 ap.idPanel.idCanvas.setHighlighted(null);
104 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
105 * we dont want to remove redundancy, just calculate once so we can use the
106 * slider to dynamically hide redundant sequences
113 * @return DOCUMENT ME!
117 JProgressBar progress = new JProgressBar();
118 progress.setIndeterminate(true);
119 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
121 label.setText(MessageManager.getString("label.calculating"));
123 slider.setVisible(false);
124 applyButton.setEnabled(false);
125 valueField.setVisible(false);
129 String[] omitHidden = null;
131 SequenceGroup sg = ap.av.getSelectionGroup();
136 if ((sg != null) && (sg.getSize() >= 1))
138 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
139 start = sg.getStartRes();
140 end = sg.getEndRes();
144 originalSequences = ap.av.getAlignment().getSequencesArray();
146 end = ap.av.getAlignment().getWidth();
149 height = originalSequences.length;
150 if (ap.av.hasHiddenColumns())
152 omitHidden = ap.av.getViewAsString(sg != null);
154 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
155 omitHidden, start, end, false);
157 progress.setIndeterminate(false);
158 progress.setVisible(false);
161 label.setText("Enter the redundancy threshold");
162 slider.setVisible(true);
163 applyButton.setEnabled(true);
164 valueField.setVisible(true);
167 sliderValueChanged();
168 // System.out.println((System.currentTimeMillis()-start));
171 void sliderValueChanged()
173 if (redundancy == null)
178 float value = slider.getValue();
179 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
180 for (int i = 0; i < redundancy.length; i++)
182 if (value <= redundancy[i])
184 redundantSequences.add(originalSequences[i]);
187 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
196 public void applyButton_actionPerformed(ActionEvent e)
198 Vector del = new Vector();
200 undoButton.setEnabled(true);
202 float value = slider.getValue();
203 SequenceGroup sg = ap.av.getSelectionGroup();
205 for (int i = 0; i < redundancy.length; i++)
207 if (value <= redundancy[i])
209 del.addElement(originalSequences[i]);
213 // This has to be done before the restoreHistoryItem method of alignFrame
215 // actually restore these sequences.
218 SequenceI[] deleted = new SequenceI[del.size()];
221 for (int i = 0; i < del.size(); i++)
223 deleted[i] = (SequenceI) del.elementAt(i);
224 if (deleted[i].getLength() > width)
226 width = deleted[i].getLength();
230 EditCommand cut = new EditCommand("Remove Redundancy",
231 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
233 for (int i = 0; i < del.size(); i++)
235 ap.av.getAlignment().deleteSequence(deleted[i]);
238 sg.deleteSequence(deleted[i], false);
242 historyList.push(cut);
244 ap.alignFrame.addHistoryItem(cut);
246 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
247 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
259 public void undoButton_actionPerformed(ActionEvent e)
261 CommandI command = (CommandI) historyList.pop();
262 command.undoCommand(af.getViewAlignments());
264 if (ap.av.historyList.contains(command))
266 ap.av.historyList.remove(command);
267 af.updateEditMenuBar();
270 ap.paintAlignment(true);
272 if (historyList.size() == 0)
274 undoButton.setEnabled(false);
284 public void valueField_actionPerformed(ActionEvent e)
288 int i = Integer.parseInt(valueField.getText());
290 } catch (Exception ex)
292 valueField.setText(slider.getValue() + "");