2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.commands.*;
28 import jalview.datamodel.*;
30 public class RedundancyPanel
31 extends SliderPanel implements Runnable, WindowListener
35 Stack historyList = new Stack(); // simpler than synching with alignFrame.
37 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, "Redundancy threshold selection",
73 frame.addWindowListener(this);
75 Thread worker = new Thread(this);
80 * This is a copy of remove redundancy in jalivew.datamodel.Alignment
81 * except we dont want to remove redundancy, just calculate once
82 * so we can use the slider to dynamically hide redundant sequences
84 * @param threshold DOCUMENT ME!
85 * @param sel DOCUMENT ME!
87 * @return DOCUMENT ME!
91 label.setText("Calculating....");
93 slider.setVisible(false);
94 applyButton.setEnabled(false);
95 valueField.setVisible(false);
99 String[] omitHidden = null;
101 SequenceGroup sg = ap.av.getSelectionGroup();
106 if ( (sg != null) && (sg.getSize() >= 1))
108 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
109 start = sg.getStartRes();
110 end = sg.getEndRes();
114 originalSequences = ap.av.alignment.getSequencesArray();
116 end = ap.av.alignment.getWidth();
119 height = originalSequences.length;
121 redundancy = new float[height];
122 for (int i = 0; i < height; i++)
127 // if (ap.av.hasHiddenColumns)
129 // omitHidden = ap.av.getSelectionAsString();
132 // long start = System.currentTimeMillis();
136 for (int i = 0; i < height; i++)
138 for (int j = 0; j < i; j++)
145 if (omitHidden == null)
147 seqi = originalSequences[i].getSequenceAsString(start, end);
148 seqj = originalSequences[j].getSequenceAsString(start, end);
152 seqi = omitHidden[i];
153 seqj = omitHidden[j];
156 pid = jalview.util.Comparison.PID(seqi, seqj);
158 if (seqj.length() < seqi.length())
160 redundancy[j] = Math.max(pid, redundancy[j]);
164 redundancy[i] = Math.max(pid, redundancy[i]);
170 label.setText("Enter the redundancy threshold");
171 slider.setVisible(true);
172 applyButton.setEnabled(true);
173 valueField.setVisible(true);
176 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
179 void sliderValueChanged()
181 if (redundancy == null)
186 float value = slider.getValue();
188 for (int i = 0; i < redundancy.length; i++)
190 if (value > redundancy[i])
192 redundantSeqs.removeElement(originalSequences[i]);
194 else if (!redundantSeqs.contains(originalSequences[i]))
196 redundantSeqs.addElement(originalSequences[i]);
200 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
201 PaintRefresher.Refresh(this,
202 ap.av.getSequenceSetId(),
208 public void applyButton_actionPerformed()
210 Vector del = new Vector();
212 undoButton.setEnabled(true);
214 float value = slider.getValue();
215 SequenceGroup sg = ap.av.getSelectionGroup();
217 for (int i = 0; i < redundancy.length; i++)
219 if (value <= redundancy[i])
221 del.addElement(originalSequences[i]);
225 // This has to be done before the restoreHistoryItem method of alignFrame will
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,
245 for (int i = 0; i < del.size(); i++)
247 ap.av.alignment.deleteSequence(deleted[i]);
248 PaintRefresher.Refresh(this,
249 ap.av.getSequenceSetId(),
254 sg.deleteSequence(deleted[i], false);
258 historyList.push(cut);
260 ap.alignFrame.addHistoryItem(cut);
262 ap.av.firePropertyChange("alignment", null,
263 ap.av.getAlignment().getSequences());
268 public void undoButton_actionPerformed()
270 CommandI command = (CommandI) historyList.pop();
271 command.undoCommand(null);
273 if (ap.av.historyList.contains(command))
275 ap.av.historyList.removeElement(command);
276 ap.alignFrame.updateEditMenuBar();
279 ap.paintAlignment(true);
281 if (historyList.size() == 0)
283 undoButton.setEnabled(false);
287 public void valueField_actionPerformed(ActionEvent e)
291 int i = Integer.parseInt(valueField.getText());
296 valueField.setText(slider.getValue() + "");
300 public void windowOpened(WindowEvent evt)
303 public void windowClosing(WindowEvent evt)
305 ap.idPanel.idCanvas.setHighlighted(null);
308 public void windowClosed(WindowEvent evt)
311 public void windowActivated(WindowEvent evt)
314 public void windowDeactivated(WindowEvent evt)
317 public void windowIconified(WindowEvent evt)
320 public void windowDeiconified(WindowEvent evt)