2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.analysis.AlignSeq;
26 import jalview.commands.*;
27 import jalview.datamodel.*;
29 public class RedundancyPanel extends SliderPanel implements Runnable,
32 Stack historyList = new Stack(); // simpler than synching with alignFrame.
36 SequenceI[] originalSequences;
42 public RedundancyPanel(AlignmentPanel ap)
44 super(ap, 0, false, null);
46 redundantSeqs = new Vector();
48 undoButton.setVisible(true);
49 applyButton.setVisible(true);
50 allGroupsCheck.setVisible(false);
52 label.setText("Enter the redundancy threshold");
53 valueField.setText("100");
55 slider.setVisibleAmount(1);
57 slider.setMaximum(100 + slider.getVisibleAmount());
60 slider.addAdjustmentListener(new AdjustmentListener()
62 public void adjustmentValueChanged(AdjustmentEvent evt)
64 valueField.setText(slider.getValue() + "");
71 jalview.bin.JalviewLite.addFrame(frame,
72 "Redundancy threshold selection", 400, 100);
74 frame.addWindowListener(this);
76 Thread worker = new Thread(this);
81 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
82 * we dont want to remove redundancy, just calculate once so we can use the
83 * slider to dynamically hide redundant sequences
90 * @return DOCUMENT ME!
94 label.setText("Calculating....");
96 slider.setVisible(false);
97 applyButton.setEnabled(false);
98 valueField.setVisible(false);
102 String[] omitHidden = null;
104 SequenceGroup sg = ap.av.getSelectionGroup();
109 if ((sg != null) && (sg.getSize() >= 1))
111 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
112 start = sg.getStartRes();
113 end = sg.getEndRes();
117 originalSequences = ap.av.getAlignment().getSequencesArray();
119 end = ap.av.getAlignment().getWidth();
122 height = originalSequences.length;
124 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences, omitHidden, start, end, false);
125 label.setText("Enter the redundancy threshold");
126 slider.setVisible(true);
127 applyButton.setEnabled(true);
128 valueField.setVisible(true);
131 // System.out.println("blob done "+ (System.currentTimeMillis()-start));
134 void sliderValueChanged()
136 if (redundancy == null)
141 float value = slider.getValue();
143 for (int i = 0; i < redundancy.length; i++)
145 if (value > redundancy[i])
147 redundantSeqs.removeElement(originalSequences[i]);
149 else if (!redundantSeqs.contains(originalSequences[i]))
151 redundantSeqs.addElement(originalSequences[i]);
155 ap.idPanel.idCanvas.setHighlighted(redundantSeqs);
156 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
160 public void applyButton_actionPerformed()
162 Vector del = new Vector();
164 undoButton.setEnabled(true);
166 float value = slider.getValue();
167 SequenceGroup sg = ap.av.getSelectionGroup();
169 for (int i = 0; i < redundancy.length; i++)
171 if (value <= redundancy[i])
173 del.addElement(originalSequences[i]);
177 // This has to be done before the restoreHistoryItem method of alignFrame
179 // actually restore these sequences.
182 SequenceI[] deleted = new SequenceI[del.size()];
185 for (int i = 0; i < del.size(); i++)
187 deleted[i] = (SequenceI) del.elementAt(i);
188 if (deleted[i].getLength() > width)
190 width = deleted[i].getLength();
194 EditCommand cut = new EditCommand("Remove Redundancy",
195 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
196 AlignmentI alignment=ap.av.getAlignment();
197 for (int i = 0; i < del.size(); i++)
199 alignment.deleteSequence(deleted[i]);
202 sg.deleteSequence(deleted[i], false);
206 historyList.push(cut);
208 ap.alignFrame.addHistoryItem(cut);
210 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
211 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
217 public void undoButton_actionPerformed()
219 CommandI command = (CommandI) historyList.pop();
220 command.undoCommand(null);
222 if (ap.av.historyList.contains(command))
224 ap.av.historyList.removeElement(command);
225 ap.alignFrame.updateEditMenuBar();
228 ap.paintAlignment(true);
230 if (historyList.size() == 0)
232 undoButton.setEnabled(false);
236 public void valueField_actionPerformed(ActionEvent e)
240 int i = Integer.parseInt(valueField.getText());
242 } catch (Exception ex)
244 valueField.setText(slider.getValue() + "");
248 public void windowOpened(WindowEvent evt)
252 public void windowClosing(WindowEvent evt)
254 ap.idPanel.idCanvas.setHighlighted(null);
257 public void windowClosed(WindowEvent evt)
261 public void windowActivated(WindowEvent evt)
265 public void windowDeactivated(WindowEvent evt)
269 public void windowIconified(WindowEvent evt)
273 public void windowDeiconified(WindowEvent evt)