/* * 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.appletgui; import java.util.*; import java.awt.event.*; import jalview.datamodel.*; import jalview.jbappletgui.*; public class RedundancyPanel extends GSliderPanel { AlignmentPanel ap; SequenceI[] oldAlignment; public RedundancyPanel(AlignmentPanel ap) { this.ap = ap; label.setText("Enter the redundancy threshold"); slider.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent 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; oldAlignment = new SequenceI[ap.av.alignment.getHeight()]; for (int i = 0; i < ap.av.alignment.getHeight(); i++) { oldAlignment[i] = new Sequence(ap.av.alignment.getSequenceAt(i).getName(), ap.av.alignment.getSequenceAt(i). getSequence()); } 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); for (int j = 0; j < del.size(); j++) { if (sg.sequences.contains( (SequenceI) del.elementAt(j))) { sg.deleteSequence( (SequenceI) del.elementAt(j)); } } } ap.repaint(); } public void undoButton_actionPerformed(ActionEvent e) { undoButton.setEnabled(false); ap.av.setAlignment(new Alignment(oldAlignment)); oldAlignment = null; ap.repaint(); } public void valueField_actionPerformed(ActionEvent e) { try { int i = Integer.parseInt(valueField.getText()); slider.setValue(i); } catch (Exception ex) { valueField.setText(slider.getValue() + ""); } } }