2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.commands.*;
\r
28 import jalview.datamodel.*;
\r
30 public class RedundancyPanel
\r
31 extends SliderPanel implements Runnable, WindowListener
\r
35 Stack historyList = new Stack(); // simpler than synching with alignFrame.
\r
37 SequenceI[] originalSequences;
\r
39 Vector redundantSeqs;
\r
41 public RedundancyPanel(AlignmentPanel ap)
\r
43 super(ap, 0, false, null);
\r
45 redundantSeqs = new Vector();
\r
47 undoButton.setVisible(true);
\r
48 applyButton.setVisible(true);
\r
49 allGroupsCheck.setVisible(false);
\r
51 label.setText("Enter the redundancy threshold");
\r
52 valueField.setText("100");
\r
54 slider.setVisibleAmount(1);
\r
55 slider.setMinimum(0);
\r
56 slider.setMaximum(100 + slider.getVisibleAmount());
\r
57 slider.setValue(100);
\r
59 slider.addAdjustmentListener(new AdjustmentListener()
\r
61 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
63 valueField.setText(slider.getValue() + "");
\r
64 sliderValueChanged();
\r
68 frame = new Frame();
\r
70 jalview.bin.JalviewLite.addFrame(frame, "Redundancy threshold selection",
\r
73 frame.addWindowListener(this);
\r
75 Thread worker = new Thread(this);
\r
80 * This is a copy of remove redundancy in jalivew.datamodel.Alignment
\r
81 * except we dont want to remove redundancy, just calculate once
\r
82 * so we can use the slider to dynamically hide redundant sequences
\r
84 * @param threshold DOCUMENT ME!
\r
85 * @param sel DOCUMENT ME!
\r
87 * @return DOCUMENT ME!
\r
91 label.setText("Calculating....");
\r
93 slider.setVisible(false);
\r
94 applyButton.setEnabled(false);
\r
95 valueField.setVisible(false);
\r
99 String[] omitHidden = null;
\r
101 SequenceGroup sg = ap.av.getSelectionGroup();
\r
106 if ( (sg != null) && (sg.getSize() >= 1))
\r
108 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
\r
109 start = sg.getStartRes();
\r
110 end = sg.getEndRes();
\r
114 originalSequences = ap.av.alignment.getSequencesArray();
\r
116 end = ap.av.alignment.getWidth();
\r
119 height = originalSequences.length;
\r
121 redundancy = new float[height];
\r
122 for (int i = 0; i < height; i++)
\r
124 redundancy[i] = 0f;
\r
127 // if (ap.av.hasHiddenColumns)
\r
129 // omitHidden = ap.av.getSelectionAsString();
\r
132 // long start = System.currentTimeMillis();
\r
136 for (int i = 0; i < height; i++)
\r
138 for (int j = 0; j < i; j++)
\r
145 if (omitHidden == null)
\r
147 seqi = originalSequences[i].getSequenceAsString(start, end);
\r
148 seqj = originalSequences[j].getSequenceAsString(start, end);
\r
152 seqi = omitHidden[i];
\r
153 seqj = omitHidden[j];
\r
156 pid = jalview.util.Comparison.PID(seqi, seqj);
\r
158 if (seqj.length() < seqi.length())
\r
160 redundancy[j] = Math.max(pid, redundancy[j]);
\r
164 redundancy[i] = Math.max(pid, redundancy[i]);
\r
170 label.setText("Enter the redundancy threshold");
\r
171 slider.setVisible(true);
\r
172 applyButton.setEnabled(true);
\r
173 valueField.setVisible(true);
\r
176 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
\r
179 void sliderValueChanged()
\r
181 if (redundancy == null)
\r
186 float value = slider.getValue();
\r
188 for (int i = 0; i < redundancy.length; i++)
\r
190 if (value > redundancy[i])
\r
192 redundantSeqs.removeElement(originalSequences[i]);
\r
194 else if (!redundantSeqs.contains(originalSequences[i]))
\r
196 redundantSeqs.addElement(originalSequences[i]);
\r
200 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
\r
201 PaintRefresher.Refresh(this,
\r
202 ap.av.getSequenceSetId(),
\r
208 public void applyButton_actionPerformed()
\r
210 Vector del = new Vector();
\r
212 undoButton.setEnabled(true);
\r
214 float value = slider.getValue();
\r
215 SequenceGroup sg = ap.av.getSelectionGroup();
\r
217 for (int i = 0; i < redundancy.length; i++)
\r
219 if (value <= redundancy[i])
\r
221 del.addElement(originalSequences[i]);
\r
225 // This has to be done before the restoreHistoryItem method of alignFrame will
\r
226 // actually restore these sequences.
\r
227 if (del.size() > 0)
\r
229 SequenceI[] deleted = new SequenceI[del.size()];
\r
232 for (int i = 0; i < del.size(); i++)
\r
234 deleted[i] = (SequenceI) del.elementAt(i);
\r
235 if (deleted[i].getLength() > width)
\r
237 width = deleted[i].getLength();
\r
241 EditCommand cut = new EditCommand("Remove Redundancy",
\r
242 EditCommand.CUT, deleted, 0, width,
\r
245 for (int i = 0; i < del.size(); i++)
\r
247 ap.av.alignment.deleteSequence(deleted[i]);
\r
248 PaintRefresher.Refresh(this,
\r
249 ap.av.getSequenceSetId(),
\r
254 sg.deleteSequence(deleted[i], false);
\r
258 historyList.push(cut);
\r
260 ap.alignFrame.addHistoryItem(cut);
\r
262 ap.av.firePropertyChange("alignment", null,
\r
263 ap.av.getAlignment().getSequences());
\r
268 public void undoButton_actionPerformed()
\r
270 CommandI command = (CommandI) historyList.pop();
\r
271 command.undoCommand();
\r
273 if (ap.av.historyList.contains(command))
\r
275 ap.av.historyList.removeElement(command);
\r
276 ap.alignFrame.updateEditMenuBar();
\r
279 ap.paintAlignment(true);
\r
281 if (historyList.size() == 0)
\r
283 undoButton.setEnabled(false);
\r
287 public void valueField_actionPerformed(ActionEvent e)
\r
291 int i = Integer.parseInt(valueField.getText());
\r
292 slider.setValue(i);
\r
294 catch (Exception ex)
\r
296 valueField.setText(slider.getValue() + "");
\r
300 public void windowOpened(WindowEvent evt)
\r
303 public void windowClosing(WindowEvent evt)
\r
305 ap.idPanel.idCanvas.setHighlighted(null);
\r
308 public void windowClosed(WindowEvent evt)
\r
311 public void windowActivated(WindowEvent evt)
\r
314 public void windowDeactivated(WindowEvent evt)
\r
317 public void windowIconified(WindowEvent evt)
\r
320 public void windowDeiconified(WindowEvent evt)
\r