2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.commands.*;
27 import jalview.datamodel.*;
28 import jalview.jbgui.*;
29 import jalview.util.*;
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.alignment);
135 start = sg.getStartRes();
136 end = sg.getEndRes();
140 originalSequences = ap.av.alignment.getSequencesArray();
142 end = ap.av.alignment.getWidth();
145 height = originalSequences.length;
147 redundancy = new float[height];
148 for (int i = 0; i < height; i++)
153 if (ap.av.hasHiddenColumns)
155 omitHidden = ap.av.getViewAsString(sg != null);
158 // long start = System.currentTimeMillis();
162 for (int i = 0; i < height; i++)
165 for (int j = 0; j < i; j++)
172 if (omitHidden == null)
174 seqi = originalSequences[i].getSequenceAsString(start, end);
175 seqj = originalSequences[j].getSequenceAsString(start, end);
179 seqi = omitHidden[i];
180 seqj = omitHidden[j];
183 pid = Comparison.PID(seqi, seqj);
185 if (seqj.length() < seqi.length())
187 redundancy[j] = Math.max(pid, redundancy[j]);
191 redundancy[i] = Math.max(pid, redundancy[i]);
197 progress.setIndeterminate(false);
198 progress.setVisible(false);
201 label.setText("Enter the redundancy threshold");
202 slider.setVisible(true);
203 applyButton.setEnabled(true);
204 valueField.setVisible(true);
207 // System.out.println((System.currentTimeMillis()-start));
210 void sliderValueChanged()
212 if (redundancy == null)
217 float value = slider.getValue();
219 for (int i = 0; i < redundancy.length; i++)
221 if (value > redundancy[i])
223 redundantSeqs.remove(originalSequences[i]);
225 else if (!redundantSeqs.contains(originalSequences[i]))
227 redundantSeqs.add(originalSequences[i]);
232 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
241 public void applyButton_actionPerformed(ActionEvent e)
243 Vector del = new Vector();
245 undoButton.setEnabled(true);
247 float value = slider.getValue();
248 SequenceGroup sg = ap.av.getSelectionGroup();
250 for (int i = 0; i < redundancy.length; i++)
252 if (value <= redundancy[i])
254 del.addElement(originalSequences[i]);
258 // This has to be done before the restoreHistoryItem method of alignFrame
260 // actually restore these sequences.
263 SequenceI[] deleted = new SequenceI[del.size()];
266 for (int i = 0; i < del.size(); i++)
268 deleted[i] = (SequenceI) del.elementAt(i);
269 if (deleted[i].getLength() > width)
271 width = deleted[i].getLength();
275 EditCommand cut = new EditCommand("Remove Redundancy",
276 EditCommand.CUT, deleted, 0, width, ap.av.alignment);
278 for (int i = 0; i < del.size(); i++)
280 ap.av.alignment.deleteSequence(deleted[i]);
281 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
284 sg.deleteSequence(deleted[i], false);
288 historyList.push(cut);
290 ap.alignFrame.addHistoryItem(cut);
292 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
304 public void undoButton_actionPerformed(ActionEvent e)
306 CommandI command = (CommandI) historyList.pop();
307 command.undoCommand(af.getViewAlignments());
309 if (ap.av.historyList.contains(command))
311 ap.av.historyList.remove(command);
312 af.updateEditMenuBar();
315 ap.paintAlignment(true);
317 if (historyList.size() == 0)
319 undoButton.setEnabled(false);
329 public void valueField_actionPerformed(ActionEvent e)
333 int i = Integer.parseInt(valueField.getText());
335 } catch (Exception ex)
337 valueField.setText(slider.getValue() + "");