/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.gui; import java.util.*; import java.awt.event.*; import javax.swing.event.*; import jalview.datamodel.*; import jalview.jbgui.*; public class RedundancyPanel extends GSliderPanel { AlignFrame af; AlignmentPanel ap; Stack historyList = new Stack(); // simpler than synching with alignFrame. public RedundancyPanel(AlignmentPanel ap, AlignFrame af) { this.ap = ap; this.af = af; label.setText("Enter the redundancy threshold"); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { valueField.setText(slider.getValue() + ""); } }); slider.setMinimum(0); slider.setMaximum(100); slider.setValue(100); } public void applyButton_actionPerformed(ActionEvent e) { float threshold = slider.getValue(); Vector del; HistoryItem it; historyList.push(it = new HistoryItem("Remove redundancy", ap.av.alignment, HistoryItem.HIDE)); if ( (historyList.size() == 1) || !af.historyList.contains(historyList.firstElement())) { af.addHistoryItem( (HistoryItem) historyList.firstElement()); af.updateEditMenuBar(); } undoButton.setEnabled(true); SequenceGroup sg = ap.av.getSelectionGroup(); if ( (sg != null) && (sg.getSize() >= 1)) { del = ap.av.alignment.removeRedundancy(threshold, sg.sequences); for (int i = 0; i < del.size(); i++) { if (sg.sequences.contains( (SequenceI) del.elementAt(i))) { sg.deleteSequence( (SequenceI) del.elementAt(i)); } } } else { Vector s = new Vector(); int i = 0; while (i < ap.av.alignment.getHeight()) { s.addElement(ap.av.alignment.getSequenceAt(i)); i++; } del = ap.av.alignment.removeRedundancy(threshold, s); } // This has to be done before the restoreHistoryItem method of alignFrame will // actually restore these sequences. if (del.size() > 0) { for (int i = 0, j = del.size(); i < j; i++) { SequenceI sq = (SequenceI) del.elementAt(i); sq.deleteChars(0, sq.getLength()); } } ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences()); ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight()); if (ap.av.getAlignment().getHeight() < 1) { try { af.setClosed(true); } catch (Exception ex) { } } ap.av.updateConservation(); ap.av.updateConsensus(); af.updateEditMenuBar(); ap.repaint(); } public void undoButton_actionPerformed(ActionEvent e) { HistoryItem hi = (HistoryItem) historyList.pop(); af.restoreHistoryItem(hi); if (historyList.size() == 0) { undoButton.setEnabled(false); if (af.historyList.contains(hi)) { af.historyList.remove(hi); af.updateEditMenuBar(); } } } public void valueField_actionPerformed(ActionEvent e) { try { int i = Integer.parseInt(valueField.getText()); slider.setValue(i); } catch (Exception ex) { valueField.setText(slider.getValue() + ""); } } }