JAL-1473 show available score matrices for use in PCA calculation
authorJim Procter <jprocter@dundee.ac.uk>
Tue, 15 Apr 2014 15:15:36 +0000 (16:15 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Mon, 21 Apr 2014 13:09:16 +0000 (14:09 +0100)
src/jalview/gui/PCAPanel.java
src/jalview/jbgui/GPCAPanel.java
src/jalview/viewmodel/PCAModel.java

index 5c8d08b..fc32e54 100644 (file)
 package jalview.gui;
 
 import java.util.*;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.print.*;
+
 import javax.swing.*;
 
 import jalview.datamodel.*;
 import jalview.jbgui.*;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.ScoreMatrix;
 import jalview.util.MessageManager;
 import jalview.viewmodel.PCAModel;
 
@@ -109,7 +111,32 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     Thread worker = new Thread(this);
     worker.start();
   }
-
+  @Override
+  protected void scoreMatrix_menuSelected()
+  {
+    scoreMatrixMenu.removeAll();
+    for (final Object sm:ResidueProperties.scoreMatrices.keySet())
+    {
+      JMenuItem jm=new JMenuItem();
+      jm.setText((String)sm);
+      jm.setSelected(pcaModel.getScore_matrix().equals((String)sm));
+      final PCAPanel us = this;
+      jm.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          if (!pcaModel.getScore_matrix().equals((String)sm))
+          {
+            pcaModel.setScore_matrix((String) sm);
+            Thread worker = new Thread(us);
+            worker.start();
+          }
+        }
+      });
+      scoreMatrixMenu.add(jm);   
+    }
+  }
   public void bgcolour_actionPerformed(ActionEvent e)
   {
     Color col = JColorChooser.showDialog(this, "Select Background Colour",
@@ -446,6 +473,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     }
   }
 
+  
   public void viewMenu_menuSelected()
   {
     buildAssociatedViewMenu();
index f2b8fe3..1eb73bd 100755 (executable)
@@ -53,6 +53,8 @@ public class GPCAPanel extends JInternalFrame
   JMenu fileMenu = new JMenu();
 
   JMenu saveMenu = new JMenu();
+  
+  protected JMenu scoreMatrixMenu = new JMenu();
 
   JMenuItem eps = new JMenuItem();
 
@@ -221,6 +223,22 @@ public class GPCAPanel extends JInternalFrame
       {
       }
     });
+    scoreMatrixMenu.setText(MessageManager.getString("label.score_matrices"));
+    scoreMatrixMenu.addMenuListener(new MenuListener()
+    {
+      public void menuSelected(MenuEvent e)
+      {
+        scoreMatrix_menuSelected();
+      }
+
+      public void menuDeselected(MenuEvent e)
+      {
+      }
+
+      public void menuCanceled(MenuEvent e)
+      {
+      }
+    });
     showLabels.setText(MessageManager.getString("label.show_labels"));
     showLabels.addActionListener(new ActionListener()
     {
@@ -280,6 +298,7 @@ public class GPCAPanel extends JInternalFrame
     calcSettings.add(jvVersionSetting);
     calcSettings.add(nuclSetting);
     calcSettings.add(protSetting);
+    calcSettings.add(scoreMatrixMenu);
     statusPanel.setLayout(statusPanelLayout);
     statusBar.setFont(new java.awt.Font("Verdana", 0, 12));
     // statusPanel.setBackground(Color.lightGray);
@@ -312,6 +331,12 @@ public class GPCAPanel extends JInternalFrame
     viewMenu.add(associateViewsMenu);
   }
 
+  protected void scoreMatrix_menuSelected()
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
   protected void resetButton_actionPerformed(ActionEvent e)
   {
     // TODO Auto-generated method stub
index bb1519d..00cc94b 100644 (file)
@@ -35,6 +35,7 @@ public class PCAModel
     seqstrings = seqstrings2;
     seqs = seqs2;
     nucleotide = nucleotide2;
+    score_matrix = nucleotide2 ? "PID" : "BLOSUM62";
   }
 
   private volatile PCA pca;
@@ -44,6 +45,11 @@ public class PCAModel
   AlignmentView seqstrings;
 
   SequenceI[] seqs;
+  
+  /**
+   * Score matrix used to calculate PC
+   */
+  String score_matrix;
 
   /**
    * use the identity matrix for calculating similarity between sequences.
@@ -62,7 +68,7 @@ public class PCAModel
   public void run()
   {
 
-    pca = new PCA(seqstrings.getSequenceStrings(' '), nucleotide);
+    pca = new PCA(seqstrings.getSequenceStrings(' '), nucleotide, score_matrix);
     pca.setJvCalcMode(jvCalcMode);
     pca.run();
 
@@ -224,4 +230,14 @@ public class PCAModel
     jvCalcMode = state;
   }
 
+  public String getScore_matrix()
+  {
+    return score_matrix;
+  }
+
+  public void setScore_matrix(String score_matrix)
+  {
+    this.score_matrix = score_matrix;
+  }
+  
 }