2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.NJTree;
24 import jalview.analysis.scoremodels.PIDModel;
25 import jalview.analysis.scoremodels.ScoreModels;
26 import jalview.analysis.scoremodels.SimilarityParams;
27 import jalview.api.analysis.ScoreModelI;
28 import jalview.api.analysis.SimilarityParamsI;
29 import jalview.util.MessageManager;
31 import java.awt.Color;
32 import java.awt.FlowLayout;
34 import java.awt.GridLayout;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.beans.PropertyVetoException;
40 import javax.swing.ButtonGroup;
41 import javax.swing.JButton;
42 import javax.swing.JCheckBox;
43 import javax.swing.JComboBox;
44 import javax.swing.JInternalFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JLayeredPane;
47 import javax.swing.JPanel;
48 import javax.swing.JRadioButton;
51 * A dialog to allow a user to select and action Tree calculation options
53 public class TreeChooser extends JPanel
55 private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
63 JRadioButton neighbourJoining;
65 JRadioButton averageDistance;
67 JComboBox<String> modelNames;
69 private JInternalFrame frame;
71 private ButtonGroup treeTypes;
73 private JCheckBox includeGaps;
75 private JCheckBox matchGaps;
77 private JCheckBox includeGappedColumns;
79 private JCheckBox shorterSequence;
86 public TreeChooser(AlignFrame alignFrame)
93 * Lays out the panel and adds it to the desktop
97 frame = new JInternalFrame();
98 frame.setContentPane(this);
99 this.setBackground(Color.white);
102 * Layout consists of 4 or 5 panels:
103 * - first with choice of Tree or PCA
104 * - second with choice of tree method NJ or AV
105 * - third with choice of score model
106 * - fourth with score model parameter options [suppressed]
107 * - fifth with OK and Cancel
109 tree = new JRadioButton(MessageManager.getString("label.tree"));
110 tree.setOpaque(false);
111 pca = new JRadioButton(
112 MessageManager.getString("label.principal_component_analysis"));
113 pca.setOpaque(false);
114 neighbourJoining = new JRadioButton(
115 MessageManager.getString("label.tree_calc_nj"));
116 averageDistance = new JRadioButton(
117 MessageManager.getString("label.tree_calc_av"));
118 ItemListener listener = new ItemListener()
121 public void itemStateChanged(ItemEvent e)
123 neighbourJoining.setEnabled(tree.isSelected());
124 averageDistance.setEnabled(tree.isSelected());
127 pca.addItemListener(listener);
128 tree.addItemListener(listener);
129 ButtonGroup calcTypes = new ButtonGroup();
132 JPanel calcChoicePanel = new JPanel();
133 calcChoicePanel.setOpaque(false);
134 tree.setSelected(true);
135 calcChoicePanel.add(tree);
136 calcChoicePanel.add(pca);
138 neighbourJoining.setOpaque(false);
139 treeTypes = new ButtonGroup();
140 treeTypes.add(neighbourJoining);
141 treeTypes.add(averageDistance);
142 neighbourJoining.setSelected(true);
143 JPanel treeChoicePanel = new JPanel();
144 treeChoicePanel.setOpaque(false);
145 treeChoicePanel.add(neighbourJoining);
146 treeChoicePanel.add(averageDistance);
149 * score model drop-down
151 modelNames = new JComboBox<String>();
152 ScoreModels scoreModels = ScoreModels.getInstance();
153 for (ScoreModelI sm : scoreModels.getModels())
155 boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
156 if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
158 modelNames.addItem(sm.getName());
162 JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
163 scoreModelPanel.setOpaque(false);
164 scoreModelPanel.add(modelNames, FlowLayout.LEFT);
167 * score model parameters
169 JPanel paramsPanel = new JPanel(new GridLayout(5, 1));
170 paramsPanel.setOpaque(false);
171 includeGaps = new JCheckBox("Include gaps");
172 matchGaps = new JCheckBox("Match gaps");
173 includeGappedColumns = new JCheckBox("Include gapped columns");
174 shorterSequence = new JCheckBox("Match on shorter sequence");
175 paramsPanel.add(new JLabel("Pairwise sequence scoring options"));
176 paramsPanel.add(includeGaps);
177 paramsPanel.add(matchGaps);
178 paramsPanel.add(includeGappedColumns);
179 paramsPanel.add(shorterSequence);
182 * OK / Cancel buttons
184 JButton ok = new JButton(MessageManager.getString("action.ok"));
185 ok.setFont(VERDANA_11PT);
186 ok.addActionListener(new java.awt.event.ActionListener()
189 public void actionPerformed(ActionEvent e)
191 ok_actionPerformed();
194 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
195 cancel.setFont(VERDANA_11PT);
196 cancel.addActionListener(new java.awt.event.ActionListener()
199 public void actionPerformed(ActionEvent e)
201 cancel_actionPerformed(e);
204 JPanel actionPanel = new JPanel();
205 actionPanel.setOpaque(false);
207 actionPanel.add(cancel);
209 boolean includeParams = false;
210 this.add(calcChoicePanel);
211 this.add(treeChoicePanel);
212 this.add(scoreModelPanel);
215 this.add(paramsPanel);
217 this.add(actionPanel);
220 int height = includeParams ? 400 : 220;
221 Desktop.addInternalFrame(frame,
222 MessageManager.getString("label.choose_tree"), width, height,
225 frame.setLayer(JLayeredPane.PALETTE_LAYER);
229 * Open and calculate the selected tree on 'OK'
231 protected void ok_actionPerformed()
233 boolean doPCA = pca.isSelected();
234 ScoreModelI sm = ScoreModels.getInstance().forName(
235 modelNames.getSelectedItem().toString());
236 SimilarityParamsI params = getSimilarityParameters(doPCA, sm);
240 AlignViewport viewport = af.getViewport();
241 if (((viewport.getSelectionGroup() != null)
242 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
243 .getSelectionGroup().getSize() > 0))
244 || (viewport.getAlignment().getHeight() < 4))
247 .showInternalMessageDialog(
250 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
252 .getString("label.sequence_selection_insufficient"),
253 JvOptionPane.WARNING_MESSAGE);
256 new PCAPanel(af.alignPanel, sm, params);
260 String treeType = neighbourJoining.isSelected() ? NJTree.NEIGHBOUR_JOINING
261 : NJTree.AVERAGE_DISTANCE;
262 af.newTreePanel(treeType, sm, params);
271 protected void closeFrame()
275 frame.setClosed(true);
276 } catch (PropertyVetoException ex)
282 * Returns a data bean holding parameters for similarity (or distance) model
289 protected SimilarityParamsI getSimilarityParameters(boolean doPCA,
292 // commented out: parameter choices read from gui widgets
293 // SimilarityParamsI params = new SimilarityParams(
294 // includeGappedColumns.isSelected(), matchGaps.isSelected(),
295 // includeGaps.isSelected(), shorterSequence.isSelected());
299 * includeGappedColumns = true
301 * matchOnShortestSequence = false
302 * matchGaps = true except false for PCA by PID (to match SeqSpace)
304 boolean includeGapGap = true;
305 boolean includeGapResidue = true;
306 boolean matchOnShortestLength = false;
307 boolean matchGap = true;
308 if (doPCA && (sm instanceof PIDModel))
312 return new SimilarityParams(includeGapGap, matchGap, includeGapResidue, matchOnShortestLength);
316 * Closes dialog on cancel
320 protected void cancel_actionPerformed(ActionEvent e)
324 frame.setClosed(true);
325 } catch (Exception ex)