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 float [] redundancy;
\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
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 String[] omitHidden = null;
\r
100 SequenceGroup sg = ap.av.getSelectionGroup();
\r
105 if ( (sg != null) && (sg.getSize(false) >= 1))
\r
107 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
\r
108 start = sg.getStartRes();
\r
109 end = sg.getEndRes();
\r
113 originalSequences = ap.av.alignment.getSequencesArray();
\r
115 end = ap.av.alignment.getWidth();
\r
118 height = originalSequences.length;
\r
120 redundancy = new float[height];
\r
121 for (int i = 0; i < height; i++)
\r
123 redundancy[i] = 0f;
\r
126 // if (ap.av.hasHiddenColumns)
\r
128 // 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
143 if(omitHidden==null)
\r
145 seqi = originalSequences[i].getSequence(start, end);
\r
146 seqj = originalSequences[j].getSequence(start, end);
\r
150 seqi = omitHidden[i];
\r
151 seqj = omitHidden[j];
\r
154 pid = jalview.util.Comparison.PID( seqi, seqj );
\r
156 if(seqj.length() < seqi.length())
\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 redundantSeqs.removeElement(originalSequences[i]);
\r
185 else if(!redundantSeqs.contains(originalSequences[i]))
\r
186 redundantSeqs.addElement(originalSequences[i]);
\r
189 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
\r
191 PaintRefresher.Refresh(null,ap.av.alignment);
\r
194 public void applyButton_actionPerformed()
\r
196 historyList.push(new HistoryItem("Remove redundancy",
\r
197 ap.av.alignment, HistoryItem.HIDE));
\r
199 if ((historyList.size() == 1) ||
\r
200 !ap.alignFrame.historyList.contains(historyList.firstElement()))
\r
202 ap.alignFrame.addHistoryItem((HistoryItem) historyList.firstElement());
\r
203 ap.alignFrame.updateEditMenuBar();
\r
206 Vector del = new Vector();
\r
208 undoButton.setEnabled(true);
\r
210 float value = slider.getValue();
\r
211 SequenceGroup sg = ap.av.getSelectionGroup();
\r
213 for (int i = 0; i < redundancy.length; i++)
\r
215 if (value <= redundancy[i])
\r
217 SequenceI seq = originalSequences[i];
\r
218 ap.av.alignment.deleteSequence(seq);
\r
219 del.addElement(seq);
\r
222 sg.deleteSequence(seq, false);
\r
228 // This has to be done before the restoreHistoryItem method of alignFrame will
\r
229 // actually restore these sequences.
\r
230 if (del.size() > 0)
\r
232 for (int i = 0, j = del.size(); i < j; i++)
\r
234 SequenceI sq = (SequenceI) del.elementAt(i);
\r
235 sq.deleteChars(0, sq.getLength());
\r
239 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
\r
240 ap.alignFrame.updateEditMenuBar();
\r
244 public void undoButton_actionPerformed()
\r
246 HistoryItem hi = (HistoryItem) historyList.pop();
\r
247 ap.alignFrame.restoreHistoryItem(hi);
\r
249 if (historyList.size() == 0)
\r
251 undoButton.setEnabled(false);
\r
253 ap.alignFrame.updateEditMenuBar();
\r
256 public void valueField_actionPerformed(ActionEvent e)
\r
260 int i = Integer.parseInt(valueField.getText());
\r
261 slider.setValue(i);
\r
263 catch (Exception ex)
\r
265 valueField.setText(slider.getValue() + "");
\r
270 public void windowOpened(WindowEvent evt)
\r
273 public void windowClosing(WindowEvent evt)
\r
275 ap.idPanel.idCanvas.setHighlighted(null);
\r
278 public void windowClosed(WindowEvent evt)
\r
281 public void windowActivated(WindowEvent evt)
\r
283 public void windowDeactivated(WindowEvent evt)
\r
285 public void windowIconified(WindowEvent evt)
\r
287 public void windowDeiconified(WindowEvent evt)
\r