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.*;
30 import jalview.util.*;
38 public class RedundancyPanel extends GSliderPanel implements Runnable
44 Stack historyList = new Stack(); // simpler than synching with alignFrame.
48 SequenceI[] originalSequences;
55 * Creates a new RedundancyPanel object.
62 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
66 redundantSeqs = new Vector();
68 slider.addChangeListener(new ChangeListener()
70 public void stateChanged(ChangeEvent evt)
72 valueField.setText(slider.getValue() + "");
77 applyButton.setText("Remove");
78 allGroupsCheck.setVisible(false);
80 slider.setMaximum(100);
83 Thread worker = new Thread(this);
86 frame = new JInternalFrame();
87 frame.setContentPane(this);
88 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400,
90 frame.addInternalFrameListener(new InternalFrameAdapter()
92 public void internalFrameClosing(InternalFrameEvent evt)
94 ap.idPanel.idCanvas.setHighlighted(null);
101 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
102 * we dont want to remove redundancy, just calculate once so we can use the
103 * slider to dynamically hide redundant sequences
110 * @return DOCUMENT ME!
114 JProgressBar progress = new JProgressBar();
115 progress.setIndeterminate(true);
116 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
118 label.setText("Calculating....");
120 slider.setVisible(false);
121 applyButton.setEnabled(false);
122 valueField.setVisible(false);
126 String[] omitHidden = null;
128 SequenceGroup sg = ap.av.getSelectionGroup();
133 if ((sg != null) && (sg.getSize() >= 1))
135 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
136 start = sg.getStartRes();
137 end = sg.getEndRes();
141 originalSequences = ap.av.getAlignment().getSequencesArray();
143 end = ap.av.getAlignment().getWidth();
146 height = originalSequences.length;
147 if (ap.av.hasHiddenColumns())
149 omitHidden = ap.av.getViewAsString(sg != null);
151 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
152 omitHidden, start, end, false);
154 progress.setIndeterminate(false);
155 progress.setVisible(false);
158 label.setText("Enter the redundancy threshold");
159 slider.setVisible(true);
160 applyButton.setEnabled(true);
161 valueField.setVisible(true);
164 // System.out.println((System.currentTimeMillis()-start));
167 void sliderValueChanged()
169 if (redundancy == null)
174 float value = slider.getValue();
176 for (int i = 0; i < redundancy.length; i++)
178 if (value > redundancy[i])
180 redundantSeqs.remove(originalSequences[i]);
182 else if (!redundantSeqs.contains(originalSequences[i]))
184 redundantSeqs.add(originalSequences[i]);
189 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
198 public void applyButton_actionPerformed(ActionEvent e)
200 Vector del = new Vector();
202 undoButton.setEnabled(true);
204 float value = slider.getValue();
205 SequenceGroup sg = ap.av.getSelectionGroup();
207 for (int i = 0; i < redundancy.length; i++)
209 if (value <= redundancy[i])
211 del.addElement(originalSequences[i]);
215 // This has to be done before the restoreHistoryItem method of alignFrame
217 // actually restore these sequences.
220 SequenceI[] deleted = new SequenceI[del.size()];
223 for (int i = 0; i < del.size(); i++)
225 deleted[i] = (SequenceI) del.elementAt(i);
226 if (deleted[i].getLength() > width)
228 width = deleted[i].getLength();
232 EditCommand cut = new EditCommand("Remove Redundancy",
233 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
235 for (int i = 0; i < del.size(); i++)
237 ap.av.getAlignment().deleteSequence(deleted[i]);
240 sg.deleteSequence(deleted[i], false);
244 historyList.push(cut);
246 ap.alignFrame.addHistoryItem(cut);
248 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
249 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
261 public void undoButton_actionPerformed(ActionEvent e)
263 CommandI command = (CommandI) historyList.pop();
264 command.undoCommand(af.getViewAlignments());
266 if (ap.av.historyList.contains(command))
268 ap.av.historyList.remove(command);
269 af.updateEditMenuBar();
272 ap.paintAlignment(true);
274 if (historyList.size() == 0)
276 undoButton.setEnabled(false);
286 public void valueField_actionPerformed(ActionEvent e)
290 int i = Integer.parseInt(valueField.getText());
292 } catch (Exception ex)
294 valueField.setText(slider.getValue() + "");