2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
24 import java.awt.event.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.appletgui.PaintRefresher;
\r
31 public class RedundancyPanel extends SliderPanel implements Runnable, WindowListener
\r
35 Stack historyList = new Stack(); // simpler than synching with alignFrame.
\r
36 Vector originalSequences;
\r
37 Hashtable originalColours;
\r
38 SequenceI[] oldAlignment;
\r
39 float [] redundancy;
\r
42 public RedundancyPanel(AlignmentPanel ap)
\r
44 super(ap, 0, false, null);
\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(40);
\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
79 * This is a copy of remove redundancy in jalivew.datamodel.Alignment
\r
80 * except we dont want to remove redundancy, just calculate once
\r
81 * so we can use the slider to dynamically hide redundant sequences
\r
83 * @param threshold DOCUMENT ME!
\r
84 * @param sel DOCUMENT ME!
\r
86 * @return DOCUMENT ME!
\r
90 label.setText("Calculating....");
\r
92 slider.setVisible(false);
\r
93 applyButton.setEnabled(false);
\r
94 valueField.setVisible(false);
\r
98 Vector sel = new Vector();
\r
99 SequenceGroup sg = ap.av.getSelectionGroup();
\r
101 originalSequences = new Vector();
\r
102 originalColours = new Hashtable();
\r
104 if ( (sg != null) && (sg.getSize(false) >= 1))
\r
106 height = sg.getSize(false);
\r
107 for (int i = 0; i < sg.getSize(false); i++)
\r
109 sel.addElement(sg.getSequenceAt(i));
\r
114 height = ap.av.alignment.getHeight();
\r
115 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
\r
117 sel.addElement(ap.av.alignment.getSequenceAt(i));
\r
121 redundancy = new float[height];
\r
122 for (int i = 0; i < height; i++)
\r
124 redundancy[i] = 0f;
\r
128 // long start = System.currentTimeMillis();
\r
131 SequenceI seqi, seqj;
\r
132 for (int i = 0; i < sel.size(); i++)
\r
134 originalSequences.addElement(sel.elementAt(i));
\r
135 originalColours.put(sel.elementAt(i),
\r
136 ((SequenceI) sel.elementAt(i)).getColor());
\r
138 for (int j = 0; j < i; j++)
\r
143 seqi = (SequenceI) sel.elementAt(i);
\r
144 seqj = (SequenceI) sel.elementAt(j);
\r
148 pid = jalview.util.Comparison.PID(seqi,
\r
150 sg.getStartRes(), sg.getEndRes());
\r
153 pid = jalview.util.Comparison.PID( seqi, seqj );
\r
156 if(seqj.getLength() < seqi.getLength())
\r
157 redundancy[j] = Math.max(pid, redundancy[j]);
\r
159 redundancy[i] = Math.max(pid, redundancy[i]);
\r
165 label.setText("Enter the redundancy threshold");
\r
166 slider.setVisible(true);
\r
167 applyButton.setEnabled(true);
\r
168 valueField.setVisible(true);
\r
171 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
\r
174 void sliderValueChanged()
\r
176 if(redundancy==null)
\r
179 float value = slider.getValue();
\r
181 for(int i=0; i<redundancy.length; i++)
\r
183 if (value > redundancy[i])
\r
184 ((SequenceI)originalSequences.elementAt(i)).setColor(java.awt.Color.white);
\r
186 ((SequenceI)originalSequences.elementAt(i)).setColor(java.awt.Color.red);
\r
189 PaintRefresher.Refresh(null,ap.av.alignment);
\r
192 public void applyButton_actionPerformed()
\r
194 historyList.push(new HistoryItem("Remove redundancy",
\r
195 ap.av.alignment, HistoryItem.HIDE));
\r
197 if ((historyList.size() == 1) ||
\r
198 !ap.alignFrame.historyList.contains(historyList.firstElement()))
\r
200 ap.alignFrame.addHistoryItem((HistoryItem) historyList.firstElement());
\r
201 ap.alignFrame.updateEditMenuBar();
\r
204 Vector del = new Vector();
\r
206 undoButton.setEnabled(true);
\r
208 float value = slider.getValue();
\r
209 SequenceGroup sg = ap.av.getSelectionGroup();
\r
211 for (int i = 0; i < redundancy.length; i++)
\r
213 if (value <= redundancy[i])
\r
215 SequenceI seq = (SequenceI) originalSequences.elementAt(i);
\r
216 ap.av.alignment.deleteSequence(seq);
\r
217 del.addElement(seq);
\r
220 sg.deleteSequence(seq, false);
\r
226 // This has to be done before the restoreHistoryItem method of alignFrame will
\r
227 // actually restore these sequences.
\r
228 if (del.size() > 0)
\r
230 for (int i = 0, j = del.size(); i < j; i++)
\r
232 SequenceI sq = (SequenceI) del.elementAt(i);
\r
233 sq.deleteChars(0, sq.getLength());
\r
237 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
\r
238 ap.alignFrame.updateEditMenuBar();
\r
242 public void undoButton_actionPerformed()
\r
244 HistoryItem hi = (HistoryItem) historyList.pop();
\r
245 ap.alignFrame.restoreHistoryItem(hi);
\r
247 if (historyList.size() == 0)
\r
249 undoButton.setEnabled(false);
\r
251 ap.alignFrame.updateEditMenuBar();
\r
254 public void valueField_actionPerformed(ActionEvent e)
\r
258 int i = Integer.parseInt(valueField.getText());
\r
259 slider.setValue(i);
\r
261 catch (Exception ex)
\r
263 valueField.setText(slider.getValue() + "");
\r
268 public void windowOpened(WindowEvent evt)
\r
271 public void windowClosing(WindowEvent evt)
\r
273 for(int i=0; i<originalSequences.size(); i++)
\r
275 SequenceI seq = (SequenceI)originalSequences.elementAt(i);
\r
276 seq.setColor( (java.awt.Color)originalColours.get(seq));
\r
279 PaintRefresher.Refresh(ap.av.alignment);
\r
282 public void windowClosed(WindowEvent evt)
\r
285 public void windowActivated(WindowEvent evt)
\r
287 public void windowDeactivated(WindowEvent evt)
\r
289 public void windowIconified(WindowEvent evt)
\r
291 public void windowDeiconified(WindowEvent evt)
\r