2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.commands.*;
27 import jalview.datamodel.*;
29 public class RedundancyPanel extends SliderPanel implements Runnable,
34 Stack historyList = new Stack(); // simpler than synching with alignFrame.
38 SequenceI[] originalSequences;
44 public RedundancyPanel(AlignmentPanel ap)
46 super(ap, 0, false, null);
48 redundantSeqs = new Vector();
50 undoButton.setVisible(true);
51 applyButton.setVisible(true);
52 allGroupsCheck.setVisible(false);
54 label.setText("Enter the redundancy threshold");
55 valueField.setText("100");
57 slider.setVisibleAmount(1);
59 slider.setMaximum(100 + slider.getVisibleAmount());
62 slider.addAdjustmentListener(new AdjustmentListener()
64 public void adjustmentValueChanged(AdjustmentEvent evt)
66 valueField.setText(slider.getValue() + "");
73 jalview.bin.JalviewLite.addFrame(frame,
74 "Redundancy threshold selection", 400, 100);
76 frame.addWindowListener(this);
78 Thread worker = new Thread(this);
83 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
84 * we dont want to remove redundancy, just calculate once so we can use the
85 * slider to dynamically hide redundant sequences
92 * @return DOCUMENT ME!
96 label.setText("Calculating....");
98 slider.setVisible(false);
99 applyButton.setEnabled(false);
100 valueField.setVisible(false);
104 String[] omitHidden = null;
106 SequenceGroup sg = ap.av.getSelectionGroup();
111 if ((sg != null) && (sg.getSize() >= 1))
113 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
114 start = sg.getStartRes();
115 end = sg.getEndRes();
119 originalSequences = ap.av.alignment.getSequencesArray();
121 end = ap.av.alignment.getWidth();
124 height = originalSequences.length;
126 redundancy = new float[height];
127 for (int i = 0; i < height; i++)
132 // if (ap.av.hasHiddenColumns)
134 // omitHidden = ap.av.getSelectionAsString();
137 // long start = System.currentTimeMillis();
141 for (int i = 0; i < height; i++)
143 for (int j = 0; j < i; j++)
150 if (omitHidden == null)
152 seqi = originalSequences[i].getSequenceAsString(start, end);
153 seqj = originalSequences[j].getSequenceAsString(start, end);
157 seqi = omitHidden[i];
158 seqj = omitHidden[j];
161 pid = jalview.util.Comparison.PID(seqi, seqj);
163 if (seqj.length() < seqi.length())
165 redundancy[j] = Math.max(pid, redundancy[j]);
169 redundancy[i] = Math.max(pid, redundancy[i]);
175 label.setText("Enter the redundancy threshold");
176 slider.setVisible(true);
177 applyButton.setEnabled(true);
178 valueField.setVisible(true);
181 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
184 void sliderValueChanged()
186 if (redundancy == null)
191 float value = slider.getValue();
193 for (int i = 0; i < redundancy.length; i++)
195 if (value > redundancy[i])
197 redundantSeqs.removeElement(originalSequences[i]);
199 else if (!redundantSeqs.contains(originalSequences[i]))
201 redundantSeqs.addElement(originalSequences[i]);
205 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
206 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
210 public void applyButton_actionPerformed()
212 Vector del = new Vector();
214 undoButton.setEnabled(true);
216 float value = slider.getValue();
217 SequenceGroup sg = ap.av.getSelectionGroup();
219 for (int i = 0; i < redundancy.length; i++)
221 if (value <= redundancy[i])
223 del.addElement(originalSequences[i]);
227 // This has to be done before the restoreHistoryItem method of alignFrame
229 // actually restore these sequences.
232 SequenceI[] deleted = new SequenceI[del.size()];
235 for (int i = 0; i < del.size(); i++)
237 deleted[i] = (SequenceI) del.elementAt(i);
238 if (deleted[i].getLength() > width)
240 width = deleted[i].getLength();
244 EditCommand cut = new EditCommand("Remove Redundancy",
245 EditCommand.CUT, deleted, 0, width, ap.av.alignment);
247 for (int i = 0; i < del.size(); i++)
249 ap.av.alignment.deleteSequence(deleted[i]);
250 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
253 sg.deleteSequence(deleted[i], false);
257 historyList.push(cut);
259 ap.alignFrame.addHistoryItem(cut);
261 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
267 public void undoButton_actionPerformed()
269 CommandI command = (CommandI) historyList.pop();
270 command.undoCommand(null);
272 if (ap.av.historyList.contains(command))
274 ap.av.historyList.removeElement(command);
275 ap.alignFrame.updateEditMenuBar();
278 ap.paintAlignment(true);
280 if (historyList.size() == 0)
282 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() + "");
298 public void windowOpened(WindowEvent evt)
302 public void windowClosing(WindowEvent evt)
304 ap.idPanel.idCanvas.setHighlighted(null);
307 public void windowClosed(WindowEvent evt)
311 public void windowActivated(WindowEvent evt)
315 public void windowDeactivated(WindowEvent evt)
319 public void windowIconified(WindowEvent evt)
323 public void windowDeiconified(WindowEvent evt)