2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.event.*;
25 import javax.swing.event.*;
27 import jalview.analysis.AlignSeq;
28 import jalview.commands.*;
29 import jalview.datamodel.*;
30 import jalview.jbgui.*;
31 import jalview.util.MessageManager;
39 public class RedundancyPanel extends GSliderPanel implements Runnable
45 Stack historyList = new Stack(); // simpler than synching with alignFrame.
49 SequenceI[] originalSequences;
56 * Creates a new RedundancyPanel object.
63 public RedundancyPanel(final AlignmentPanel ap, AlignFrame af)
67 redundantSeqs = new Vector();
69 slider.addChangeListener(new ChangeListener()
71 public void stateChanged(ChangeEvent evt)
73 valueField.setText(slider.getValue() + "");
78 applyButton.setText(MessageManager.getString("action.remove"));
79 allGroupsCheck.setVisible(false);
81 slider.setMaximum(100);
84 Thread worker = new Thread(this);
87 frame = new JInternalFrame();
88 frame.setContentPane(this);
89 Desktop.addInternalFrame(frame, MessageManager.getString("label.redundancy_threshold_selection"), 400,
91 frame.addInternalFrameListener(new InternalFrameAdapter()
93 public void internalFrameClosing(InternalFrameEvent evt)
95 ap.idPanel.idCanvas.setHighlighted(null);
102 * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
103 * we dont want to remove redundancy, just calculate once so we can use the
104 * slider to dynamically hide redundant sequences
111 * @return DOCUMENT ME!
115 JProgressBar progress = new JProgressBar();
116 progress.setIndeterminate(true);
117 southPanel.add(progress, java.awt.BorderLayout.SOUTH);
119 label.setText(MessageManager.getString("label.calculating"));
121 slider.setVisible(false);
122 applyButton.setEnabled(false);
123 valueField.setVisible(false);
127 String[] omitHidden = null;
129 SequenceGroup sg = ap.av.getSelectionGroup();
134 if ((sg != null) && (sg.getSize() >= 1))
136 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
137 start = sg.getStartRes();
138 end = sg.getEndRes();
142 originalSequences = ap.av.getAlignment().getSequencesArray();
144 end = ap.av.getAlignment().getWidth();
147 height = originalSequences.length;
148 if (ap.av.hasHiddenColumns())
150 omitHidden = ap.av.getViewAsString(sg != null);
152 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
153 omitHidden, start, end, false);
155 progress.setIndeterminate(false);
156 progress.setVisible(false);
159 label.setText("Enter the redundancy threshold");
160 slider.setVisible(true);
161 applyButton.setEnabled(true);
162 valueField.setVisible(true);
165 sliderValueChanged();
166 // System.out.println((System.currentTimeMillis()-start));
169 void sliderValueChanged()
171 if (redundancy == null)
176 float value = slider.getValue();
177 List<SequenceI> redundantSequences = new ArrayList<SequenceI>();
178 for (int i = 0; i < redundancy.length; i++)
180 if (value <= redundancy[i])
182 redundantSequences.add(originalSequences[i]);
185 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
194 public void applyButton_actionPerformed(ActionEvent e)
196 Vector del = new Vector();
198 undoButton.setEnabled(true);
200 float value = slider.getValue();
201 SequenceGroup sg = ap.av.getSelectionGroup();
203 for (int i = 0; i < redundancy.length; i++)
205 if (value <= redundancy[i])
207 del.addElement(originalSequences[i]);
211 // This has to be done before the restoreHistoryItem method of alignFrame
213 // actually restore these sequences.
216 SequenceI[] deleted = new SequenceI[del.size()];
219 for (int i = 0; i < del.size(); i++)
221 deleted[i] = (SequenceI) del.elementAt(i);
222 if (deleted[i].getLength() > width)
224 width = deleted[i].getLength();
228 EditCommand cut = new EditCommand("Remove Redundancy",
229 EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
231 for (int i = 0; i < del.size(); i++)
233 ap.av.getAlignment().deleteSequence(deleted[i]);
236 sg.deleteSequence(deleted[i], false);
240 historyList.push(cut);
242 ap.alignFrame.addHistoryItem(cut);
244 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
245 // ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
257 public void undoButton_actionPerformed(ActionEvent e)
259 CommandI command = (CommandI) historyList.pop();
260 command.undoCommand(af.getViewAlignments());
262 if (ap.av.historyList.contains(command))
264 ap.av.historyList.remove(command);
265 af.updateEditMenuBar();
268 ap.paintAlignment(true);
270 if (historyList.size() == 0)
272 undoButton.setEnabled(false);
282 public void valueField_actionPerformed(ActionEvent e)
286 int i = Integer.parseInt(valueField.getText());
288 } catch (Exception ex)
290 valueField.setText(slider.getValue() + "");