2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.commands.*;
26 import jalview.datamodel.*;
28 public class RedundancyPanel extends SliderPanel implements Runnable,
33 Stack historyList = new Stack(); // simpler than synching with alignFrame.
37 SequenceI[] originalSequences;
43 public RedundancyPanel(AlignmentPanel ap)
45 super(ap, 0, false, null);
47 redundantSeqs = new Vector();
49 undoButton.setVisible(true);
50 applyButton.setVisible(true);
51 allGroupsCheck.setVisible(false);
53 label.setText("Enter the redundancy threshold");
54 valueField.setText("100");
56 slider.setVisibleAmount(1);
58 slider.setMaximum(100 + slider.getVisibleAmount());
61 slider.addAdjustmentListener(new AdjustmentListener()
63 public void adjustmentValueChanged(AdjustmentEvent evt)
65 valueField.setText(slider.getValue() + "");
72 jalview.bin.JalviewLite.addFrame(frame,
73 "Redundancy threshold selection", 400, 100);
75 frame.addWindowListener(this);
77 Thread worker = new Thread(this);
82 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
83 * we dont want to remove redundancy, just calculate once so we can use the
84 * slider to dynamically hide redundant sequences
91 * @return DOCUMENT ME!
95 label.setText("Calculating....");
97 slider.setVisible(false);
98 applyButton.setEnabled(false);
99 valueField.setVisible(false);
103 String[] omitHidden = null;
105 SequenceGroup sg = ap.av.getSelectionGroup();
110 if ((sg != null) && (sg.getSize() >= 1))
112 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
113 start = sg.getStartRes();
114 end = sg.getEndRes();
118 originalSequences = ap.av.alignment.getSequencesArray();
120 end = ap.av.alignment.getWidth();
123 height = originalSequences.length;
125 redundancy = new float[height];
126 for (int i = 0; i < height; i++)
131 // if (ap.av.hasHiddenColumns)
133 // omitHidden = ap.av.getSelectionAsString();
136 // long start = System.currentTimeMillis();
140 for (int i = 0; i < height; i++)
142 for (int j = 0; j < i; j++)
149 if (omitHidden == null)
151 seqi = originalSequences[i].getSequenceAsString(start, end);
152 seqj = originalSequences[j].getSequenceAsString(start, end);
156 seqi = omitHidden[i];
157 seqj = omitHidden[j];
160 pid = jalview.util.Comparison.PID(seqi, seqj);
162 if (seqj.length() < seqi.length())
164 redundancy[j] = Math.max(pid, redundancy[j]);
168 redundancy[i] = Math.max(pid, redundancy[i]);
174 label.setText("Enter the redundancy threshold");
175 slider.setVisible(true);
176 applyButton.setEnabled(true);
177 valueField.setVisible(true);
180 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
183 void sliderValueChanged()
185 if (redundancy == null)
190 float value = slider.getValue();
192 for (int i = 0; i < redundancy.length; i++)
194 if (value > redundancy[i])
196 redundantSeqs.removeElement(originalSequences[i]);
198 else if (!redundantSeqs.contains(originalSequences[i]))
200 redundantSeqs.addElement(originalSequences[i]);
204 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
205 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
209 public void applyButton_actionPerformed()
211 Vector del = new Vector();
213 undoButton.setEnabled(true);
215 float value = slider.getValue();
216 SequenceGroup sg = ap.av.getSelectionGroup();
218 for (int i = 0; i < redundancy.length; i++)
220 if (value <= redundancy[i])
222 del.addElement(originalSequences[i]);
226 // This has to be done before the restoreHistoryItem method of alignFrame
228 // actually restore these sequences.
231 SequenceI[] deleted = new SequenceI[del.size()];
234 for (int i = 0; i < del.size(); i++)
236 deleted[i] = (SequenceI) del.elementAt(i);
237 if (deleted[i].getLength() > width)
239 width = deleted[i].getLength();
243 EditCommand cut = new EditCommand("Remove Redundancy",
244 EditCommand.CUT, deleted, 0, width, ap.av.alignment);
246 for (int i = 0; i < del.size(); i++)
248 ap.av.alignment.deleteSequence(deleted[i]);
249 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
252 sg.deleteSequence(deleted[i], false);
256 historyList.push(cut);
258 ap.alignFrame.addHistoryItem(cut);
260 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
266 public void undoButton_actionPerformed()
268 CommandI command = (CommandI) historyList.pop();
269 command.undoCommand(null);
271 if (ap.av.historyList.contains(command))
273 ap.av.historyList.removeElement(command);
274 ap.alignFrame.updateEditMenuBar();
277 ap.paintAlignment(true);
279 if (historyList.size() == 0)
281 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() + "");
297 public void windowOpened(WindowEvent evt)
301 public void windowClosing(WindowEvent evt)
303 ap.idPanel.idCanvas.setHighlighted(null);
306 public void windowClosed(WindowEvent evt)
310 public void windowActivated(WindowEvent evt)
314 public void windowDeactivated(WindowEvent evt)
318 public void windowIconified(WindowEvent evt)
322 public void windowDeiconified(WindowEvent evt)