From ff6182d57892323e7764b84072835448acd3282e Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 15 Apr 2014 16:15:36 +0100 Subject: [PATCH] JAL-1473 show available score matrices for use in PCA calculation --- src/jalview/gui/PCAPanel.java | 32 ++++++++++++++++++++++++++++++-- src/jalview/jbgui/GPCAPanel.java | 25 +++++++++++++++++++++++++ src/jalview/viewmodel/PCAModel.java | 18 +++++++++++++++++- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 5c8d08b..fc32e54 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -19,14 +19,16 @@ 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(); diff --git a/src/jalview/jbgui/GPCAPanel.java b/src/jalview/jbgui/GPCAPanel.java index f2b8fe3..1eb73bd 100755 --- a/src/jalview/jbgui/GPCAPanel.java +++ b/src/jalview/jbgui/GPCAPanel.java @@ -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 diff --git a/src/jalview/viewmodel/PCAModel.java b/src/jalview/viewmodel/PCAModel.java index bb1519d..00cc94b 100644 --- a/src/jalview/viewmodel/PCAModel.java +++ b/src/jalview/viewmodel/PCAModel.java @@ -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; + } + } -- 1.7.10.2