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.
23 import java.awt.event.*;
25 import javax.swing.event.*;
27 import jalview.analysis.AlignSeq;
28 import jalview.commands.*;
29 import jalview.datamodel.*;
30 import jalview.jbgui.*;
31 import jalview.util.MessageManager;
39 public class RedundancyPanel extends GSliderPanel implements Runnable
45 Stack historyList = new Stack(); // simpler than synching with alignFrame.
49 SequenceI[] originalSequences;
56 * Creates a new RedundancyPanel object.
63 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
67 redundantSeqs = new Vector();
69 slider.addChangeListener(new ChangeListener()
71 public void stateChanged(ChangeEvent evt)
73 valueField.setText(slider.getValue() + "");
78 applyButton.setText(MessageManager.getString("action.remove"));
79 allGroupsCheck.setVisible(false);
81 slider.setMaximum(100);
84 Thread worker = new Thread(this);
87 frame = new JInternalFrame();
88 frame.setContentPane(this);
89 Desktop.addInternalFrame(frame, MessageManager.getString("label.redundancy_threshold_selection"), 400,
91 frame.addInternalFrameListener(new InternalFrameAdapter()
93 public void internalFrameClosing(InternalFrameEvent evt)
95 ap.idPanel.idCanvas.setHighlighted(null);
102 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
103 * we dont want to remove redundancy, just calculate once so we can use the
104 * slider to dynamically hide redundant sequences
111 * @return DOCUMENT ME!
115 JProgressBar progress = new JProgressBar();
116 progress.setIndeterminate(true);
117 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
119 label.setText(MessageManager.getString("label.calculating"));
121 slider.setVisible(false);
122 applyButton.setEnabled(false);
123 valueField.setVisible(false);
127 String[] omitHidden = null;
129 SequenceGroup sg = ap.av.getSelectionGroup();
134 if ((sg != null) && (sg.getSize() >= 1))
136 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
137 start = sg.getStartRes();
138 end = sg.getEndRes();
142 originalSequences = ap.av.getAlignment().getSequencesArray();
144 end = ap.av.getAlignment().getWidth();
147 height = originalSequences.length;
148 if (ap.av.hasHiddenColumns())
150 omitHidden = ap.av.getViewAsString(sg != null);
152 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
153 omitHidden, start, end, false);
155 progress.setIndeterminate(false);
156 progress.setVisible(false);
159 label.setText("Enter the redundancy threshold");
160 slider.setVisible(true);
161 applyButton.setEnabled(true);
162 valueField.setVisible(true);
165 // System.out.println((System.currentTimeMillis()-start));
168 void sliderValueChanged()
170 if (redundancy == null)
175 float value = slider.getValue();
177 for (int i = 0; i < redundancy.length; i++)
179 if (value > redundancy[i])
181 redundantSeqs.remove(originalSequences[i]);
183 else if (!redundantSeqs.contains(originalSequences[i]))
185 redundantSeqs.add(originalSequences[i]);
190 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
199 public void applyButton_actionPerformed(ActionEvent e)
201 Vector del = new Vector();
203 undoButton.setEnabled(true);
205 float value = slider.getValue();
206 SequenceGroup sg = ap.av.getSelectionGroup();
208 for (int i = 0; i < redundancy.length; i++)
210 if (value <= redundancy[i])
212 del.addElement(originalSequences[i]);
216 // This has to be done before the restoreHistoryItem method of alignFrame
218 // actually restore these sequences.
221 SequenceI[] deleted = new SequenceI[del.size()];
224 for (int i = 0; i < del.size(); i++)
226 deleted[i] = (SequenceI) del.elementAt(i);
227 if (deleted[i].getLength() > width)
229 width = deleted[i].getLength();
233 EditCommand cut = new EditCommand("Remove Redundancy",
234 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
236 for (int i = 0; i < del.size(); i++)
238 ap.av.getAlignment().deleteSequence(deleted[i]);
241 sg.deleteSequence(deleted[i], false);
245 historyList.push(cut);
247 ap.alignFrame.addHistoryItem(cut);
249 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
250 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
262 public void undoButton_actionPerformed(ActionEvent e)
264 CommandI command = (CommandI) historyList.pop();
265 command.undoCommand(af.getViewAlignments());
267 if (ap.av.historyList.contains(command))
269 ap.av.historyList.remove(command);
270 af.updateEditMenuBar();
273 ap.paintAlignment(true);
275 if (historyList.size() == 0)
277 undoButton.setEnabled(false);
287 public void valueField_actionPerformed(ActionEvent e)
291 int i = Integer.parseInt(valueField.getText());
293 } catch (Exception ex)
295 valueField.setText(slider.getValue() + "");