2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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;
24 import java.awt.event.*;
28 import jalview.datamodel.*;
29 import jalview.appletgui.PaintRefresher;
31 public class RedundancyPanel 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);
79 * This is a copy of remove redundancy in jalivew.datamodel.Alignment
80 * except we dont want to remove redundancy, just calculate once
81 * so we can use the slider to dynamically hide redundant sequences
83 * @param threshold DOCUMENT ME!
84 * @param sel DOCUMENT ME!
86 * @return DOCUMENT ME!
90 label.setText("Calculating....");
92 slider.setVisible(false);
93 applyButton.setEnabled(false);
94 valueField.setVisible(false);
98 String[] omitHidden = null;
100 SequenceGroup sg = ap.av.getSelectionGroup();
105 if ( (sg != null) && (sg.getSize(false) >= 1))
107 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
108 start = sg.getStartRes();
109 end = sg.getEndRes();
113 originalSequences = ap.av.alignment.getSequencesArray();
115 end = ap.av.alignment.getWidth();
118 height = originalSequences.length;
120 redundancy = new float[height];
121 for (int i = 0; i < height; i++)
126 // if (ap.av.hasHiddenColumns)
128 // 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 seqi = originalSequences[i].getSequence(start, end);
146 seqj = originalSequences[j].getSequence(start, end);
150 seqi = omitHidden[i];
151 seqj = omitHidden[j];
154 pid = jalview.util.Comparison.PID( seqi, seqj );
156 if(seqj.length() < seqi.length())
157 redundancy[j] = Math.max(pid, redundancy[j]);
159 redundancy[i] = Math.max(pid, redundancy[i]);
165 label.setText("Enter the redundancy threshold");
166 slider.setVisible(true);
167 applyButton.setEnabled(true);
168 valueField.setVisible(true);
171 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
174 void sliderValueChanged()
179 float value = slider.getValue();
181 for(int i=0; i<redundancy.length; i++)
183 if (value > redundancy[i])
184 redundantSeqs.removeElement(originalSequences[i]);
185 else if(!redundantSeqs.contains(originalSequences[i]))
186 redundantSeqs.addElement(originalSequences[i]);
189 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
191 PaintRefresher.Refresh(null,ap.av.alignment);
194 public void applyButton_actionPerformed()
196 historyList.push(new HistoryItem("Remove redundancy",
197 ap.av.alignment, HistoryItem.HIDE));
199 if ((historyList.size() == 1) ||
200 !ap.alignFrame.historyList.contains(historyList.firstElement()))
202 ap.alignFrame.addHistoryItem((HistoryItem) historyList.firstElement());
203 ap.alignFrame.updateEditMenuBar();
206 Vector del = new Vector();
208 undoButton.setEnabled(true);
210 float value = slider.getValue();
211 SequenceGroup sg = ap.av.getSelectionGroup();
213 for (int i = 0; i < redundancy.length; i++)
215 if (value <= redundancy[i])
217 SequenceI seq = originalSequences[i];
218 ap.av.alignment.deleteSequence(seq);
222 sg.deleteSequence(seq, false);
228 // This has to be done before the restoreHistoryItem method of alignFrame will
229 // actually restore these sequences.
232 for (int i = 0, j = del.size(); i < j; i++)
234 SequenceI sq = (SequenceI) del.elementAt(i);
235 sq.deleteChars(0, sq.getLength());
239 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
240 ap.alignFrame.updateEditMenuBar();
244 public void undoButton_actionPerformed()
246 HistoryItem hi = (HistoryItem) historyList.pop();
247 ap.alignFrame.restoreHistoryItem(hi);
249 if (historyList.size() == 0)
251 undoButton.setEnabled(false);
253 ap.alignFrame.updateEditMenuBar();
256 public void valueField_actionPerformed(ActionEvent e)
260 int i = Integer.parseInt(valueField.getText());
265 valueField.setText(slider.getValue() + "");
270 public void windowOpened(WindowEvent evt)
273 public void windowClosing(WindowEvent evt)
275 ap.idPanel.idCanvas.setHighlighted(null);
278 public void windowClosed(WindowEvent evt)
281 public void windowActivated(WindowEvent evt)
283 public void windowDeactivated(WindowEvent evt)
285 public void windowIconified(WindowEvent evt)
287 public void windowDeiconified(WindowEvent evt)