2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignSeq;
24 import jalview.commands.CommandI;
25 import jalview.commands.EditCommand;
26 import jalview.commands.EditCommand.Action;
27 import jalview.datamodel.SequenceGroup;
28 import jalview.datamodel.SequenceI;
29 import jalview.jbgui.GSliderPanel;
30 import jalview.util.MessageManager;
32 import java.awt.event.ActionEvent;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Stack;
36 import java.util.Vector;
38 import javax.swing.JInternalFrame;
39 import javax.swing.JProgressBar;
40 import javax.swing.event.ChangeEvent;
41 import javax.swing.event.ChangeListener;
42 import javax.swing.event.InternalFrameAdapter;
43 import javax.swing.event.InternalFrameEvent;
51 public class RedundancyPanel extends GSliderPanel implements Runnable
57 Stack<CommandI> historyList = new Stack<CommandI>();
59 // simpler than synching with alignFrame.
63 SequenceI[] originalSequences;
70 * Creates a new RedundancyPanel object.
77 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
81 redundantSeqs = new Vector();
83 slider.addChangeListener(new ChangeListener()
86 public void stateChanged(ChangeEvent evt)
88 valueField.setText(slider.getValue() + "");
93 applyButton.setText(MessageManager.getString("action.remove"));
94 allGroupsCheck.setVisible(false);
96 slider.setMaximum(100);
99 Thread worker = new Thread(this);
102 frame = new JInternalFrame();
103 frame.setContentPane(this);
104 Desktop.addInternalFrame(frame, MessageManager
105 .getString("label.redundancy_threshold_selection"), 400, 100,
107 frame.addInternalFrameListener(new InternalFrameAdapter()
110 public void internalFrameClosing(InternalFrameEvent evt)
112 ap.getIdPanel().getIdCanvas().setHighlighted(null);
119 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
120 * we dont want to remove redundancy, just calculate once so we can use the
121 * slider to dynamically hide redundant sequences
128 * @return DOCUMENT ME!
133 JProgressBar progress = new JProgressBar();
134 progress.setIndeterminate(true);
135 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
137 label.setText(MessageManager.getString("label.calculating"));
139 slider.setVisible(false);
140 applyButton.setEnabled(false);
141 valueField.setVisible(false);
145 String[] omitHidden = null;
147 SequenceGroup sg = ap.av.getSelectionGroup();
152 if ((sg != null) && (sg.getSize() >= 1))
154 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
155 start = sg.getStartRes();
156 end = sg.getEndRes();
160 originalSequences = ap.av.getAlignment().getSequencesArray();
162 end = ap.av.getAlignment().getWidth();
165 height = originalSequences.length;
166 if (ap.av.hasHiddenColumns())
168 omitHidden = ap.av.getViewAsString(sg != null);
170 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
171 omitHidden, start, end, false);
173 progress.setIndeterminate(false);
174 progress.setVisible(false);
177 label.setText(MessageManager
178 .getString("label.enter_redundancy_threshold"));
179 slider.setVisible(true);
180 applyButton.setEnabled(true);
181 valueField.setVisible(true);
184 sliderValueChanged();
185 // System.out.println((System.currentTimeMillis()-start));
188 void sliderValueChanged()
190 if (redundancy == null)
195 float value = slider.getValue();
196 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
197 for (int i = 0; i < redundancy.length; i++)
199 if (value <= redundancy[i])
201 redundantSequences.add(originalSequences[i]);
204 ap.getIdPanel().getIdCanvas().setHighlighted(redundantSequences);
214 public void applyButton_actionPerformed(ActionEvent e)
216 Vector del = new Vector();
218 undoButton.setEnabled(true);
220 float value = slider.getValue();
221 SequenceGroup sg = ap.av.getSelectionGroup();
223 for (int i = 0; i < redundancy.length; i++)
225 if (value <= redundancy[i])
227 del.addElement(originalSequences[i]);
231 // This has to be done before the restoreHistoryItem method of alignFrame
233 // actually restore these sequences.
236 SequenceI[] deleted = new SequenceI[del.size()];
239 for (int i = 0; i < del.size(); i++)
241 deleted[i] = (SequenceI) del.elementAt(i);
242 if (deleted[i].getLength() > width)
244 width = deleted[i].getLength();
248 EditCommand cut = new EditCommand(
249 MessageManager.getString("action.remove_redundancy"),
250 Action.CUT, deleted, 0, width, ap.av.getAlignment());
252 for (int i = 0; i < del.size(); i++)
254 ap.av.getAlignment().deleteSequence(deleted[i]);
257 sg.deleteSequence(deleted[i], false);
261 historyList.push(cut);
263 ap.alignFrame.addHistoryItem(cut);
265 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
266 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
279 public void undoButton_actionPerformed(ActionEvent e)
281 if (historyList == null || historyList.isEmpty())
283 undoButton.setEnabled(false);
287 CommandI command = historyList.pop();
288 if (ap.av.getHistoryList().contains(command))
290 command.undoCommand(af.getViewAlignments());
291 ap.av.getHistoryList().remove(command);
292 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
294 af.updateEditMenuBar();
297 ap.paintAlignment(true);
299 if (historyList.size() == 0)
301 undoButton.setEnabled(false);