2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
22 import jalview.jbgui.*;
\r
23 import jalview.util.Comparison;
\r
24 import jalview.commands.*;
\r
26 import java.awt.event.*;
\r
30 import javax.swing.event.*;
\r
32 import javax.swing.*;
\r
39 * @version $Revision$
\r
41 public class RedundancyPanel extends GSliderPanel implements Runnable
\r
45 Stack historyList = new Stack(); // simpler than synching with alignFrame.
\r
46 float [] redundancy;
\r
47 SequenceI [] originalSequences;
\r
48 JInternalFrame frame;
\r
49 Vector redundantSeqs;
\r
52 * Creates a new RedundancyPanel object.
\r
54 * @param ap DOCUMENT ME!
\r
55 * @param af DOCUMENT ME!
\r
57 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
\r
61 redundantSeqs = new Vector();
\r
63 slider.addChangeListener(new ChangeListener()
\r
65 public void stateChanged(ChangeEvent evt)
\r
67 valueField.setText(slider.getValue() + "");
\r
68 sliderValueChanged();
\r
72 applyButton.setText("Remove");
\r
73 allGroupsCheck.setVisible(false);
\r
74 slider.setMinimum(0);
\r
75 slider.setMaximum(100);
\r
76 slider.setValue(100);
\r
78 Thread worker = new Thread(this);
\r
81 frame = new JInternalFrame();
\r
82 frame.setContentPane(this);
\r
83 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400,
\r
85 frame.addInternalFrameListener(new InternalFrameAdapter()
\r
87 public void internalFrameClosing(InternalFrameEvent evt)
\r
89 ap.idPanel.idCanvas.setHighlighted(null);
\r
98 * This is a copy of remove redundancy in jalivew.datamodel.Alignment
\r
99 * except we dont want to remove redundancy, just calculate once
\r
100 * so we can use the slider to dynamically hide redundant sequences
\r
102 * @param threshold DOCUMENT ME!
\r
103 * @param sel DOCUMENT ME!
\r
105 * @return DOCUMENT ME!
\r
109 JProgressBar progress = new JProgressBar();
\r
110 progress.setIndeterminate(true);
\r
111 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
\r
113 label.setText("Calculating....");
\r
115 slider.setVisible(false);
\r
116 applyButton.setEnabled(false);
\r
117 valueField.setVisible(false);
\r
121 String[] omitHidden = null;
\r
123 SequenceGroup sg = ap.av.getSelectionGroup();
\r
128 if ( (sg != null) && (sg.getSize(false) >= 1))
\r
130 originalSequences = sg.getSequencesInOrder(ap.av.alignment);
\r
131 start = sg.getStartRes();
\r
132 end = sg.getEndRes();
\r
136 originalSequences = ap.av.alignment.getSequencesArray();
\r
138 end = ap.av.alignment.getWidth();
\r
141 height = originalSequences.length;
\r
143 redundancy = new float[height];
\r
144 for (int i = 0; i < height; i++)
\r
146 redundancy[i] = 0f;
\r
149 if (ap.av.hasHiddenColumns)
\r
151 omitHidden = ap.av.getViewAsString(sg!=null);
\r
155 // long start = System.currentTimeMillis();
\r
159 for (int i = 0; i < height; i++)
\r
162 for (int j = 0; j < i; j++)
\r
167 if(omitHidden==null)
\r
169 seqi = originalSequences[i].getSequence(start, end);
\r
170 seqj = originalSequences[j].getSequence(start, end);
\r
174 seqi = omitHidden[i];
\r
175 seqj = omitHidden[j];
\r
178 pid = Comparison.PID( seqi, seqj );
\r
180 if(seqj.length() < seqi.length())
\r
181 redundancy[j] = Math.max(pid, redundancy[j]);
\r
183 redundancy[i] = Math.max(pid, redundancy[i]);
\r
188 progress.setIndeterminate(false);
\r
189 progress.setVisible(false);
\r
192 label.setText("Enter the redundancy threshold");
\r
193 slider.setVisible(true);
\r
194 applyButton.setEnabled(true);
\r
195 valueField.setVisible(true);
\r
198 // System.out.println((System.currentTimeMillis()-start));
\r
201 void sliderValueChanged()
\r
203 if(redundancy==null)
\r
206 float value = slider.getValue();
\r
208 for(int i=0; i<redundancy.length; i++)
\r
210 if (value > redundancy[i])
\r
211 redundantSeqs.remove(originalSequences[i]);
\r
212 else if(!redundantSeqs.contains(originalSequences[i]))
\r
213 redundantSeqs.add(originalSequences[i]);
\r
217 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
\r
223 * @param e DOCUMENT ME!
\r
225 public void applyButton_actionPerformed(ActionEvent e)
\r
227 Vector del = new Vector();
\r
229 undoButton.setEnabled(true);
\r
231 float value = slider.getValue();
\r
232 SequenceGroup sg = ap.av.getSelectionGroup();
\r
234 for (int i = 0; i < redundancy.length; i++)
\r
236 if (value <= redundancy[i])
\r
238 del.addElement(originalSequences[i]);
\r
242 // This has to be done before the restoreHistoryItem method of alignFrame will
\r
243 // actually restore these sequences.
\r
244 if (del.size() > 0)
\r
246 SequenceI [] deleted = new SequenceI[del.size()];
\r
249 for (int i = 0; i < del.size(); i++)
\r
251 deleted[i] = (SequenceI)del.elementAt(i);
\r
252 if(deleted[i].getLength()>width)
\r
253 width = deleted[i].getLength();
\r
256 EditCommand cut = new EditCommand("Remove Redundancy",
\r
257 EditCommand.CUT, deleted,0,width,ap.av.alignment);
\r
259 for (int i = 0; i < del.size(); i++)
\r
261 ap.av.alignment.deleteSequence( deleted[i] );
\r
262 PaintRefresher.Refresh(this,
\r
263 ap.av.getSequenceSetId(),
\r
267 sg.deleteSequence(deleted[i], false);
\r
271 historyList.push(cut);
\r
273 ap.alignFrame.addHistoryItem(cut);
\r
275 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences());
\r
285 * @param e DOCUMENT ME!
\r
287 public void undoButton_actionPerformed(ActionEvent e)
\r
289 CommandI command = (CommandI) historyList.pop();
\r
290 command.undoCommand();
\r
292 if (af.historyList.contains(command))
\r
294 af.historyList.remove(command);
\r
295 af.updateEditMenuBar();
\r
300 if (historyList.size() == 0)
\r
302 undoButton.setEnabled(false);
\r
309 * @param e DOCUMENT ME!
\r
311 public void valueField_actionPerformed(ActionEvent e)
\r
315 int i = Integer.parseInt(valueField.getText());
\r
316 slider.setValue(i);
\r
318 catch (Exception ex)
\r
320 valueField.setText(slider.getValue() + "");
\r