From a013236e12d46fbb87df79447cc3031c542606e1 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 16 Dec 2004 13:19:14 +0000 Subject: [PATCH] Remove redundancy implemented --- src/jalview/datamodel/Alignment.java | 31 +++++------ src/jalview/gui/AlignFrame.java | 8 +++ src/jalview/gui/RedundancyPanel.java | 102 ++++++++++++++++++++++++++++++++++ src/jalview/jbgui/GSliderPanel.java | 49 ++++++++++++++-- 4 files changed, 169 insertions(+), 21 deletions(-) create mode 100755 src/jalview/gui/RedundancyPanel.java diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index abf4874..3fa1379 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -217,35 +217,34 @@ public class Alignment implements AlignmentI public Vector removeRedundancy(float threshold, Vector sel) { Vector del = new Vector(); - for (int i=1; i < sel.size(); i++) { - for (int j = 0; j < i; j++) { + for (int i = 1; i < sel.size(); i++) + { + for (int j = 0; j < i; j++) + { // Only do the comparison if either have not been deleted - if (!del.contains((SequenceI)sel.elementAt(i)) || - !del.contains((SequenceI)sel.elementAt(j))) { + if (!del.contains( (SequenceI) sel.elementAt(i)) || + !del.contains( (SequenceI) sel.elementAt(j))) + { - float pid = Comparison.compare((SequenceI)sel.elementAt(j), - (SequenceI)sel.elementAt(i)); + float pid = Comparison.compare( (SequenceI) sel.elementAt(j), + (SequenceI) sel.elementAt(i)); - if (pid >= threshold) { + if (pid >= threshold) + { // Delete the shortest one - if (((SequenceI)sel.elementAt(j)).getSequence().length() > - ((SequenceI)sel.elementAt(i)).getSequence().length()) { + if ( ( (SequenceI) sel.elementAt(j)).getSequence().length() > + ( (SequenceI) sel.elementAt(i)).getSequence().length()) del.addElement(sel.elementAt(i)); - System.out.println("Deleting sequence " + ((SequenceI)sel.elementAt(i)).getName()); - } else { + else del.addElement(sel.elementAt(i)); - System.out.println("Deleting sequence " + ((SequenceI)sel.elementAt(i)).getName()); - } } } } } // Now delete the sequences - for (int i=0; i < del.size(); i++) { - System.out.println("Deleting sequence " + ((SequenceI)del.elementAt(i)).getName()); + for (int i=0; i < del.size(); i++) deleteSequence((SequenceI)del.elementAt(i)); - } return del; } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ec75ee5..7feadb9 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -521,6 +521,7 @@ public class AlignFrame extends GAlignFrame frame.setContentPane(sp); Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400, 90); frame.setMaximizable(false); + frame.setResizable(false); } } @@ -535,6 +536,7 @@ public class AlignFrame extends GAlignFrame frame.setContentPane(sp); Desktop.addInternalFrame(frame, "Percentage Identity Threshold", 400, 90); frame.setMaximizable(false); + frame.setResizable(false); } } @@ -606,6 +608,12 @@ public class AlignFrame extends GAlignFrame public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) { + RedundancyPanel sp = new RedundancyPanel(alignPanel); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(sp); + Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100); + frame.setMaximizable(false); + frame.setResizable(false); } diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java new file mode 100755 index 0000000..6cb2c22 --- /dev/null +++ b/src/jalview/gui/RedundancyPanel.java @@ -0,0 +1,102 @@ +package jalview.gui; + +import jalview.jbgui.*; +import jalview.datamodel.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.event.*; + +public class RedundancyPanel extends GSliderPanel +{ + AlignmentPanel ap; + + SequenceI[] oldAlignment; + + + public RedundancyPanel(AlignmentPanel ap) + { + this.ap = ap; + + 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; + + 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); + + if (ap.av.sel != null && ap.av.sel.size() > 1) + { + + del = ap.av.alignment.removeRedundancy(threshold, ap.av.sel.asVector()); + for (int i = 0; i < del.size(); i++) + if (ap.av.sel.contains( (SequenceI) del.elementAt(i))) + ap.av.sel.removeElement( (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 (ap.av.sel.contains((SequenceI)del.elementAt(j))) + ap.av.sel.removeElement((SequenceI)del.elementAt(j)); + + } + } + + ap.RefreshPanels(); + + } + + public void undoButton_actionPerformed(ActionEvent e) + { + undoButton.setEnabled(false); + ap.av.setAlignment( new Alignment(oldAlignment) ); + oldAlignment = null; + ap.RefreshPanels(); + } + + + public void valueField_actionPerformed(ActionEvent e) + { + try{ + int i = Integer.parseInt(valueField.getText()); + slider.setValue(i); + } + catch(Exception ex) + { + valueField.setText( slider.getValue()+"" ); + } + } +} diff --git a/src/jalview/jbgui/GSliderPanel.java b/src/jalview/jbgui/GSliderPanel.java index e53870f..7921487 100755 --- a/src/jalview/jbgui/GSliderPanel.java +++ b/src/jalview/jbgui/GSliderPanel.java @@ -6,12 +6,17 @@ import java.awt.event.*; public class GSliderPanel extends JPanel { + // this is used for conservation colours, PID colours and redundancy threshold protected JSlider slider = new JSlider(); protected JTextField valueField = new JTextField(); protected JLabel label = new JLabel(); JPanel jPanel1 = new JPanel(); BorderLayout borderLayout1 = new BorderLayout(); GridLayout gridLayout1 = new GridLayout(); + JPanel jPanel2 = new JPanel(); + protected JButton applyButton = new JButton(); + protected JButton undoButton = new JButton(); + FlowLayout flowLayout1 = new FlowLayout(); public GSliderPanel() { @@ -28,15 +33,15 @@ public class GSliderPanel extends JPanel { this.setLayout(gridLayout1); slider.setMajorTickSpacing(10); - slider.setMaximum(50); slider.setMinorTickSpacing(1); slider.setPaintTicks(true); - slider.setBackground(new Color(212, 208, 236)); + slider.setBackground(new Color(177, 177, 217)); slider.setFont(new java.awt.Font("Verdana", 0, 11)); valueField.setFont(new java.awt.Font("Verdana", 0, 11)); valueField.setMinimumSize(new Dimension(6, 21)); valueField.setPreferredSize(new Dimension(60, 21)); valueField.setText(""); + valueField.setHorizontalAlignment(SwingConstants.CENTER); valueField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) @@ -44,17 +49,41 @@ public class GSliderPanel extends JPanel valueField_actionPerformed(e); } }); - label.setBackground(new Color(212, 208, 236)); + label.setBackground(new Color(177, 177, 217)); label.setFont(new java.awt.Font("Verdana", 0, 11)); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); label.setText("set this label text"); jPanel1.setLayout(borderLayout1); gridLayout1.setRows(2); - this.add(label, null); - this.add(jPanel1, null); + jPanel2.setLayout(flowLayout1); + applyButton.setBackground(new Color(177, 177, 217)); + applyButton.setText("Apply"); + applyButton.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + applyButton_actionPerformed(e); + } + }); + undoButton.setBackground(new Color(177, 177, 217)); + undoButton.setEnabled(false); + undoButton.setText("Undo"); + undoButton.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + undoButton_actionPerformed(e); + } + }); + jPanel2.setBackground(new Color(177, 177, 217)); + this.add(jPanel2, null); + jPanel2.add(label, null); + jPanel2.add(applyButton, null); + jPanel2.add(undoButton, null);this.add(jPanel1, null); jPanel1.add(valueField, BorderLayout.EAST); jPanel1.add(slider, BorderLayout.CENTER); + } protected void valueField_actionPerformed(ActionEvent e) @@ -62,4 +91,14 @@ public class GSliderPanel extends JPanel } + protected void applyButton_actionPerformed(ActionEvent e) + { + + } + + protected void undoButton_actionPerformed(ActionEvent e) + { + + } + } -- 1.7.10.2