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 java.awt.event.ActionEvent;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Stack;
27 import java.util.Vector;
29 import javax.swing.JInternalFrame;
30 import javax.swing.JProgressBar;
31 import javax.swing.event.ChangeEvent;
32 import javax.swing.event.ChangeListener;
33 import javax.swing.event.InternalFrameAdapter;
34 import javax.swing.event.InternalFrameEvent;
36 import jalview.analysis.AlignSeq;
37 import jalview.commands.CommandI;
38 import jalview.commands.EditCommand;
39 import jalview.commands.EditCommand.Action;
40 import jalview.datamodel.SequenceGroup;
41 import jalview.datamodel.SequenceI;
42 import jalview.jbgui.GSliderPanel;
43 import jalview.util.MessageManager;
51 public class RedundancyPanel extends GSliderPanel implements Runnable
57 Stack<CommandI> historyList = new Stack<>();
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.setFrameIcon(null);
104 frame.setContentPane(this);
105 Desktop.addInternalFrame(frame,
107 .getString("label.redundancy_threshold_selection"),
108 true, FRAME_WIDTH, FRAME_HEIGHT, false, true);
109 frame.addInternalFrameListener(new InternalFrameAdapter()
112 public void internalFrameClosing(InternalFrameEvent evt)
114 ap.getIdPanel().getIdCanvas().setHighlighted(null);
121 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
122 * we dont want to remove redundancy, just calculate once so we can use the
123 * slider to dynamically hide redundant sequences
130 * @return DOCUMENT ME!
135 JProgressBar progress = new JProgressBar();
136 progress.setIndeterminate(true);
137 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
139 label.setText(MessageManager.getString("label.calculating"));
141 slider.setVisible(false);
142 applyButton.setEnabled(false);
143 valueField.setVisible(false);
147 String[] omitHidden = null;
149 SequenceGroup sg = ap.av.getSelectionGroup();
154 if ((sg != null) && (sg.getSize() >= 1))
156 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
157 start = sg.getStartRes();
158 end = sg.getEndRes();
162 originalSequences = ap.av.getAlignment().getSequencesArray();
164 end = ap.av.getAlignment().getWidth();
167 height = originalSequences.length;
168 if (ap.av.hasHiddenColumns())
170 omitHidden = ap.av.getViewAsString(sg != null);
172 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
173 omitHidden, start, end, false);
175 progress.setIndeterminate(false);
176 progress.setVisible(false);
180 MessageManager.getString("label.enter_redundancy_threshold"));
181 slider.setVisible(true);
182 applyButton.setEnabled(true);
183 valueField.setVisible(true);
186 sliderValueChanged();
187 // jalview.bin.Console.outPrintln((System.currentTimeMillis()-start));
190 void sliderValueChanged()
192 if (redundancy == null)
197 float value = slider.getValue();
198 List<SequenceI> redundantSequences = new ArrayList<>();
199 for (int i = 0; i < redundancy.length; i++)
201 if (value <= redundancy[i])
203 redundantSequences.add(originalSequences[i]);
206 ap.getIdPanel().getIdCanvas().setHighlighted(redundantSequences);
216 public void applyButton_actionPerformed(ActionEvent e)
218 List<SequenceI> del = new ArrayList<>();
220 undoButton.setEnabled(true);
222 float value = slider.getValue();
223 SequenceGroup sg = ap.av.getSelectionGroup();
225 for (int i = 0; i < redundancy.length; i++)
227 if (value <= redundancy[i])
229 del.add(originalSequences[i]);
233 // This has to be done before the restoreHistoryItem method of alignFrame
234 // will actually restore these sequences.
237 SequenceI[] deleted = new SequenceI[del.size()];
240 for (int i = 0; i < del.size(); i++)
242 deleted[i] = del.get(i);
243 if (deleted[i].getLength() > width)
245 width = deleted[i].getLength();
249 EditCommand cut = new EditCommand(
250 MessageManager.getString("action.remove_redundancy"),
251 Action.CUT, deleted, 0, width, ap.av.getAlignment());
253 for (int i = 0; i < del.size(); i++)
255 ap.av.getAlignment().deleteSequence(deleted[i]);
258 sg.deleteSequence(deleted[i], false);
262 historyList.push(cut);
264 ap.alignFrame.addHistoryItem(cut);
266 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
267 ap.av.firePropertyChange("alignment", null,
268 ap.av.getAlignment().getSequences());
280 public void undoButton_actionPerformed(ActionEvent e)
282 if (historyList == null || historyList.isEmpty())
284 undoButton.setEnabled(false);
288 CommandI command = historyList.pop();
289 if (ap.av.getHistoryList().contains(command))
291 command.undoCommand(af.getViewAlignments());
292 ap.av.getHistoryList().remove(command);
293 ap.av.firePropertyChange("alignment", null,
294 ap.av.getAlignment().getSequences());
295 af.updateEditMenuBar();
298 ap.paintAlignment(true, true);
300 if (historyList.size() == 0)
302 undoButton.setEnabled(false);