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,
31 Stack historyList = new Stack(); // simpler than synching with alignFrame.
35 SequenceI[] originalSequences;
41 public RedundancyPanel(AlignmentPanel ap)
43 super(ap, 0, false, null);
45 redundantSeqs = new Vector();
47 undoButton.setVisible(true);
48 applyButton.setVisible(true);
49 allGroupsCheck.setVisible(false);
51 label.setText("Enter the redundancy threshold");
52 valueField.setText("100");
54 slider.setVisibleAmount(1);
56 slider.setMaximum(100 + slider.getVisibleAmount());
59 slider.addAdjustmentListener(new AdjustmentListener()
61 public void adjustmentValueChanged(AdjustmentEvent evt)
63 valueField.setText(slider.getValue() + "");
70 jalview.bin.JalviewLite.addFrame(frame,
71 "Redundancy threshold selection", 400, 100);
73 frame.addWindowListener(this);
75 Thread worker = new Thread(this);
80 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
81 * we dont want to remove redundancy, just calculate once so we can use the
82 * slider to dynamically hide redundant sequences
89 * @return DOCUMENT ME!
93 label.setText("Calculating....");
95 slider.setVisible(false);
96 applyButton.setEnabled(false);
97 valueField.setVisible(false);
101 String[] omitHidden = null;
103 SequenceGroup sg = ap.av.getSelectionGroup();
108 if ((sg != null) && (sg.getSize() >= 1))
110 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
111 start = sg.getStartRes();
112 end = sg.getEndRes();
116 originalSequences = ap.av.getAlignment().getSequencesArray();
118 end = ap.av.getAlignment().getWidth();
121 height = originalSequences.length;
123 redundancy = new float[height];
124 for (int i = 0; i < height; i++)
129 // if (ap.av.hasHiddenColumns)
131 // omitHidden = ap.av.getSelectionAsString();
134 // long start = System.currentTimeMillis();
138 for (int i = 0; i < height; i++)
140 for (int j = 0; j < i; j++)
147 if (omitHidden == null)
149 seqi = originalSequences[i].getSequenceAsString(start, end);
150 seqj = originalSequences[j].getSequenceAsString(start, end);
154 seqi = omitHidden[i];
155 seqj = omitHidden[j];
158 pid = jalview.util.Comparison.PID(seqi, seqj);
160 if (seqj.length() < seqi.length())
162 redundancy[j] = Math.max(pid, redundancy[j]);
166 redundancy[i] = Math.max(pid, redundancy[i]);
172 label.setText("Enter the redundancy threshold");
173 slider.setVisible(true);
174 applyButton.setEnabled(true);
175 valueField.setVisible(true);
178 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
181 void sliderValueChanged()
183 if (redundancy == null)
188 float value = slider.getValue();
190 for (int i = 0; i < redundancy.length; i++)
192 if (value > redundancy[i])
194 redundantSeqs.removeElement(originalSequences[i]);
196 else if (!redundantSeqs.contains(originalSequences[i]))
198 redundantSeqs.addElement(originalSequences[i]);
202 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
203 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
207 public void applyButton_actionPerformed()
209 Vector del = new Vector();
211 undoButton.setEnabled(true);
213 float value = slider.getValue();
214 SequenceGroup sg = ap.av.getSelectionGroup();
216 for (int i = 0; i < redundancy.length; i++)
218 if (value <= redundancy[i])
220 del.addElement(originalSequences[i]);
224 // This has to be done before the restoreHistoryItem method of alignFrame
226 // actually restore these sequences.
229 SequenceI[] deleted = new SequenceI[del.size()];
232 for (int i = 0; i < del.size(); i++)
234 deleted[i] = (SequenceI) del.elementAt(i);
235 if (deleted[i].getLength() > width)
237 width = deleted[i].getLength();
241 EditCommand cut = new EditCommand("Remove Redundancy",
242 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
243 AlignmentI alignment=ap.av.getAlignment();
244 for (int i = 0; i < del.size(); i++)
246 alignment.deleteSequence(deleted[i]);
247 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
250 sg.deleteSequence(deleted[i], false);
254 historyList.push(cut);
256 ap.alignFrame.addHistoryItem(cut);
258 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
264 public void undoButton_actionPerformed()
266 CommandI command = (CommandI) historyList.pop();
267 command.undoCommand(null);
269 if (ap.av.historyList.contains(command))
271 ap.av.historyList.removeElement(command);
272 ap.alignFrame.updateEditMenuBar();
275 ap.paintAlignment(true);
277 if (historyList.size() == 0)
279 undoButton.setEnabled(false);
283 public void valueField_actionPerformed(ActionEvent e)
287 int i = Integer.parseInt(valueField.getText());
289 } catch (Exception ex)
291 valueField.setText(slider.getValue() + "");
295 public void windowOpened(WindowEvent evt)
299 public void windowClosing(WindowEvent evt)
301 ap.idPanel.idCanvas.setHighlighted(null);
304 public void windowClosed(WindowEvent evt)
308 public void windowActivated(WindowEvent evt)
312 public void windowDeactivated(WindowEvent evt)
316 public void windowIconified(WindowEvent evt)
320 public void windowDeiconified(WindowEvent evt)