From: gmungoc Date: Mon, 27 Feb 2017 16:03:43 +0000 (+0000) Subject: JAL-1632 dialog to calculate either Tree or PCA X-Git-Tag: Release_2_10_2~3^2~105^2~2^2~79 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cee29c9fa89ed1d1df7b3af9f97055d8cd6eb77e;p=jalview.git JAL-1632 dialog to calculate either Tree or PCA --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index bfd48ed..a9418b5 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -79,6 +79,7 @@ action.scale_right = Scale Right action.by_tree_order = By Tree Order action.sort = Sort action.calculate_tree = Calculate Tree... +action.calculate_tree_pca = Calculate Tree or PCA... action.help = Help action.by_annotation = By Annotation... action.invert_sequence_selection = Invert Sequence Selection @@ -892,6 +893,7 @@ label.choose_filename_for_param_file = Choose a filename for this parameter file label.save_as_html = Save as HTML label.recently_opened = Recently Opened label.blasting_for_unidentified_sequence_jobs_running = BLASTing for unidentified sequences - {0} jobs running. +label.tree = Tree label.tree_from = Tree from {0} label.webservice_job_title = {0} using {1} label.select_visible_region_of = selected {0} region of {1} diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index d771dd5..def3998 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -823,6 +823,7 @@ label.choose_filename_for_param_file = Escoja un nombre de fichero para este fic label.save_as_html = Guardar como HTML label.recently_opened = Abiertos recientemente label.blasting_for_unidentified_sequence_jobs_running = Ejecutando BLAST de las secuencias no indentificadas - {0} trabajos en marcha. +label.tree = Árbol label.tree_from = Árbol de {0} label.webservice_job_title = {0} usando {1} label.select_visible_region_of = seleccionada {0} región de {1} diff --git a/src/jalview/appletgui/PCAPanel.java b/src/jalview/appletgui/PCAPanel.java index 21668d3..efb204e 100644 --- a/src/jalview/appletgui/PCAPanel.java +++ b/src/jalview/appletgui/PCAPanel.java @@ -20,7 +20,9 @@ */ package jalview.appletgui; +import jalview.analysis.scoremodels.ScoreModels; import jalview.analysis.scoremodels.SimilarityParams; +import jalview.api.analysis.ScoreModelI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; @@ -57,7 +59,7 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, int top = 0; - public PCAPanel(AlignViewport av) + public PCAPanel(AlignViewport viewport) { try { @@ -74,19 +76,19 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, zCombobox.addItem("dim " + i); } - this.av = av; - boolean selected = av.getSelectionGroup() != null - && av.getSelectionGroup().getSize() > 0; - AlignmentView seqstrings = av.getAlignmentView(selected); - boolean nucleotide = av.getAlignment().isNucleotide(); + this.av = viewport; + boolean selected = viewport.getSelectionGroup() != null + && viewport.getSelectionGroup().getSize() > 0; + AlignmentView seqstrings = viewport.getAlignmentView(selected); + boolean nucleotide = viewport.getAlignment().isNucleotide(); SequenceI[] seqs; if (!selected) { - seqs = av.getAlignment().getSequencesArray(); + seqs = viewport.getAlignment().getSequencesArray(); } else { - seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment()); + seqs = viewport.getSelectionGroup().getSequencesInOrder(viewport.getAlignment()); } SeqCigar sq[] = seqstrings.getSequences(); int length = sq[0].getWidth(); @@ -100,10 +102,14 @@ public class PCAPanel extends EmbmenuFrame implements Runnable, return; } } + + ScoreModelI scoreModel = ScoreModels.getInstance().getDefaultModel( + !nucleotide); pcaModel = new PCAModel(seqstrings, seqs, nucleotide, + scoreModel, SimilarityParams.SeqSpace); - rc = new RotatableCanvas(av); + rc = new RotatableCanvas(viewport); embedMenuIfNeeded(rc); add(rc, BorderLayout.CENTER); diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 57a7422..3b73c5a 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.analysis.scoremodels.ScoreModels; import jalview.analysis.scoremodels.SimilarityParams; import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.SimilarityParamsI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.bin.Cache; import jalview.datamodel.Alignment; @@ -77,18 +78,32 @@ public class PCAPanel extends GPCAPanel implements Runnable, int top = 0; /** - * Creates a new PCAPanel object. + * Creates a new PCAPanel object using default score model and parameters * - * @param av - * DOCUMENT ME! - * @param s - * DOCUMENT ME! + * @param alignPanel */ public PCAPanel(AlignmentPanel alignPanel) { + this(alignPanel, ScoreModels.getInstance().getDefaultModel( + !alignPanel.av.getAlignment().isNucleotide()), + SimilarityParams.SeqSpace); + } + + /** + * Constructor given sequence data, a similarity (or distance) score model, + * and score calculation parameters + * + * @param alignPanel + * @param scoreModel + * @param params + */ + public PCAPanel(AlignmentPanel alignPanel, ScoreModelI scoreModel, + SimilarityParamsI params) + { super(); this.av = alignPanel.av; this.ap = alignPanel; + boolean nucleotide = av.getAlignment().isNucleotide(); progressBar = new ProgressBar(statusPanel, statusBar); @@ -104,7 +119,6 @@ public class PCAPanel extends GPCAPanel implements Runnable, boolean selected = av.getSelectionGroup() != null && av.getSelectionGroup().getSize() > 0; AlignmentView seqstrings = av.getAlignmentView(selected); - boolean nucleotide = av.getAlignment().isNucleotide(); SequenceI[] seqs; if (!selected) { @@ -127,8 +141,8 @@ public class PCAPanel extends GPCAPanel implements Runnable, return; } - pcaModel = new PCAModel(seqstrings, seqs, nucleotide, - SimilarityParams.SeqSpace); + pcaModel = new PCAModel(seqstrings, seqs, nucleotide, scoreModel, + params); PaintRefresher.Register(this, av.getSequenceSetId()); rc = new RotatableCanvas(alignPanel); diff --git a/src/jalview/gui/TreeChooser.java b/src/jalview/gui/TreeChooser.java index 3542532..aafc1c0 100644 --- a/src/jalview/gui/TreeChooser.java +++ b/src/jalview/gui/TreeChooser.java @@ -32,6 +32,8 @@ import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.beans.PropertyVetoException; import javax.swing.ButtonGroup; @@ -53,6 +55,10 @@ public class TreeChooser extends JPanel AlignFrame af; + JRadioButton pca; + + JRadioButton tree; + JRadioButton neighbourJoining; JRadioButton averageDistance; @@ -92,17 +98,43 @@ public class TreeChooser extends JPanel this.setBackground(Color.white); /* - * Layout consists of 4 panels: - * - first with choice of tree method NJ or AV - * - second with choice of score model - * - third with score model parameter options - * - fourth with OK and Cancel + * Layout consists of 5 panels: + * - first with choice of Tree or PCA + * - second with choice of tree method NJ or AV + * - third with choice of score model + * - fourth with score model parameter options + * - fifth with OK and Cancel */ + tree = new JRadioButton(MessageManager.getString("label.tree")); + tree.setOpaque(false); + pca = new JRadioButton( + MessageManager.getString("label.principal_component_analysis")); + pca.setOpaque(false); neighbourJoining = new JRadioButton( MessageManager.getString("label.tree_calc_nj")); - neighbourJoining.setOpaque(false); averageDistance = new JRadioButton( MessageManager.getString("label.tree_calc_av")); + ItemListener listener = new ItemListener() + { + @Override + public void itemStateChanged(ItemEvent e) + { + neighbourJoining.setEnabled(tree.isSelected()); + averageDistance.setEnabled(tree.isSelected()); + } + }; + pca.addItemListener(listener); + tree.addItemListener(listener); + ButtonGroup calcTypes = new ButtonGroup(); + calcTypes.add(pca); + calcTypes.add(tree); + JPanel calcChoicePanel = new JPanel(); + calcChoicePanel.setOpaque(false); + tree.setSelected(true); + calcChoicePanel.add(tree); + calcChoicePanel.add(pca); + + neighbourJoining.setOpaque(false); treeTypes = new ButtonGroup(); treeTypes.add(neighbourJoining); treeTypes.add(averageDistance); @@ -172,6 +204,7 @@ public class TreeChooser extends JPanel actionPanel.add(ok); actionPanel.add(cancel); + this.add(calcChoicePanel); this.add(treeChoicePanel); this.add(scoreModelPanel); this.add(paramsPanel); @@ -190,13 +223,45 @@ public class TreeChooser extends JPanel */ protected void ok_actionPerformed(ActionEvent e) { - String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING - : NJTree.AVERAGE_DISTANCE; ScoreModelI sm = ScoreModels.getInstance().forName( matrixNames.getSelectedItem().toString()); SimilarityParamsI params = getSimilarityParameters(); - af.newTreePanel(treeType, sm, params); + if (pca.isSelected()) + { + AlignViewport viewport = af.getViewport(); + if (((viewport.getSelectionGroup() != null) + && (viewport.getSelectionGroup().getSize() < 4) && (viewport + .getSelectionGroup().getSize() > 0)) + || (viewport.getAlignment().getHeight() < 4)) + { + JvOptionPane + .showInternalMessageDialog( + this, + MessageManager + .getString("label.principal_component_analysis_must_take_least_four_input_sequences"), + MessageManager + .getString("label.sequence_selection_insufficient"), + JvOptionPane.WARNING_MESSAGE); + return; + } + new PCAPanel(af.alignPanel, sm, params); + } + else + { + String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING + : NJTree.AVERAGE_DISTANCE; + af.newTreePanel(treeType, sm, params); + } + + // closeFrame(); + } + + /** + * + */ + protected void closeFrame() + { try { frame.setClosed(true); diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 97dcfa0..f7fe1b6 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -1199,8 +1199,8 @@ public class GAlignFrame extends JInternalFrame }); sortByAnnotScore.setVisible(false); - calculateTree - .setText(MessageManager.getString("action.calculate_tree")); + calculateTree.setText(MessageManager + .getString("action.calculate_tree_pca")); padGapsMenuitem.setText(MessageManager.getString("label.pad_gaps")); padGapsMenuitem.setState(jalview.bin.Cache @@ -1801,7 +1801,7 @@ public class GAlignFrame extends JInternalFrame calculateMenu.add(calculateTree); calculateMenu.addSeparator(); calculateMenu.add(pairwiseAlignmentMenuItem); - calculateMenu.add(PCAMenuItem); + // calculateMenu.add(PCAMenuItem); calculateMenu.addSeparator(); calculateMenu.add(showTranslation); calculateMenu.add(showReverse); diff --git a/src/jalview/viewmodel/PCAModel.java b/src/jalview/viewmodel/PCAModel.java index 324c69a..f216009 100644 --- a/src/jalview/viewmodel/PCAModel.java +++ b/src/jalview/viewmodel/PCAModel.java @@ -21,7 +21,6 @@ package jalview.viewmodel; import jalview.analysis.PCA; -import jalview.analysis.scoremodels.ScoreModels; import jalview.api.RotatableCanvasI; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; @@ -55,22 +54,22 @@ public class PCAModel private SimilarityParamsI similarityParams; /** - * Constructor given sequence data and score calculation parameter options. - * The initial state is to compute PCA using a default score model (BLOSUM62 - * for peptide, DNA for nucleotide). + * Constructor given sequence data, score model and score calculation + * parameter options. * * @param seqData * @param sqs * @param nuc + * @param sm * @param params */ - public PCAModel(AlignmentView seqData, SequenceI[] sqs, boolean nuc, + public PCAModel(AlignmentView seqData, SequenceI[] sqs, boolean nuc, ScoreModelI sm, SimilarityParamsI params) { seqstrings = seqData; seqs = sqs; nucleotide = nuc; - scoreModel = ScoreModels.getInstance().getDefaultModel(!nucleotide); + scoreModel = sm; similarityParams = params; }