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/>.
22 import java.awt.event.*;
24 import javax.swing.event.*;
26 import jalview.analysis.AlignSeq;
27 import jalview.commands.*;
28 import jalview.datamodel.*;
29 import jalview.jbgui.*;
37 public class RedundancyPanel extends GSliderPanel implements Runnable
43 Stack historyList = new Stack(); // simpler than synching with alignFrame.
47 SequenceI[] originalSequences;
54 * Creates a new RedundancyPanel object.
61 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
65 redundantSeqs = new Vector();
67 slider.addChangeListener(new ChangeListener()
69 public void stateChanged(ChangeEvent evt)
71 valueField.setText(slider.getValue() + "");
76 applyButton.setText("Remove");
77 allGroupsCheck.setVisible(false);
79 slider.setMaximum(100);
82 Thread worker = new Thread(this);
85 frame = new JInternalFrame();
86 frame.setContentPane(this);
87 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400,
89 frame.addInternalFrameListener(new InternalFrameAdapter()
91 public void internalFrameClosing(InternalFrameEvent evt)
93 ap.idPanel.idCanvas.setHighlighted(null);
100 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
101 * we dont want to remove redundancy, just calculate once so we can use the
102 * slider to dynamically hide redundant sequences
109 * @return DOCUMENT ME!
113 JProgressBar progress = new JProgressBar();
114 progress.setIndeterminate(true);
115 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
117 label.setText("Calculating....");
119 slider.setVisible(false);
120 applyButton.setEnabled(false);
121 valueField.setVisible(false);
125 String[] omitHidden = null;
127 SequenceGroup sg = ap.av.getSelectionGroup();
132 if ((sg != null) && (sg.getSize() >= 1))
134 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
135 start = sg.getStartRes();
136 end = sg.getEndRes();
140 originalSequences = ap.av.getAlignment().getSequencesArray();
142 end = ap.av.getAlignment().getWidth();
145 height = originalSequences.length;
146 if (ap.av.hasHiddenColumns())
148 omitHidden = ap.av.getViewAsString(sg != null);
150 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
151 omitHidden, start, end, false);
153 progress.setIndeterminate(false);
154 progress.setVisible(false);
157 label.setText("Enter the redundancy threshold");
158 slider.setVisible(true);
159 applyButton.setEnabled(true);
160 valueField.setVisible(true);
163 // System.out.println((System.currentTimeMillis()-start));
166 void sliderValueChanged()
168 if (redundancy == null)
173 float value = slider.getValue();
175 for (int i = 0; i < redundancy.length; i++)
177 if (value > redundancy[i])
179 redundantSeqs.remove(originalSequences[i]);
181 else if (!redundantSeqs.contains(originalSequences[i]))
183 redundantSeqs.add(originalSequences[i]);
188 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
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() + "");