Rectanuglar selection changed to Mouse Button 3 drag
[jalview.git] / src / jalview / gui / CalculationChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.gui;
22
23 import jalview.analysis.TreeBuilder;
24 import jalview.analysis.scoremodels.ScoreModels;
25 import jalview.analysis.scoremodels.SimilarityParams;
26 import jalview.api.analysis.ScoreModelI;
27 import jalview.api.analysis.SimilarityParamsI;
28 import jalview.bin.Cache;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.util.MessageManager;
31 import jalview.viewmodel.AlignmentViewport;
32 import java.awt.BorderLayout;
33 import java.awt.Color;
34 import java.awt.Component;
35 import java.awt.Dimension;
36 import java.awt.FlowLayout;
37 import java.awt.Font;
38 import java.awt.GridLayout;
39 import java.awt.Insets;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.FocusEvent;
43 import java.awt.event.FocusListener;
44 import java.awt.event.MouseAdapter;
45 import java.awt.event.MouseEvent;
46 import java.beans.PropertyVetoException;
47 import java.util.ArrayList;
48 import java.util.List;
49
50 import javax.swing.BorderFactory;
51 import javax.swing.ButtonGroup;
52 import javax.swing.DefaultComboBoxModel;
53 import javax.swing.JButton;
54 import javax.swing.JCheckBox;
55 import javax.swing.JComboBox;
56 import javax.swing.JInternalFrame;
57 import javax.swing.JLabel;
58 import javax.swing.JLayeredPane;
59 import javax.swing.JPanel;
60 import javax.swing.JRadioButton;
61 import javax.swing.event.InternalFrameAdapter;
62 import javax.swing.event.InternalFrameEvent;
63
64 import jalview.analysis.AlignmentUtils;
65 import jalview.analysis.TreeBuilder;
66 import jalview.analysis.scoremodels.ScoreModels;
67 import jalview.analysis.scoremodels.SimilarityParams;
68 import jalview.api.analysis.ScoreModelI;
69 import jalview.api.analysis.SimilarityParamsI;
70 import jalview.bin.Cache;
71 import jalview.datamodel.AlignmentAnnotation;
72 import jalview.datamodel.SequenceGroup;
73 import jalview.util.MessageManager;
74
75 /**
76  * A dialog where a user can choose and action Tree or PCA calculation options
77  */
78 public class CalculationChooser extends JPanel
79 {
80   /*
81    * flag for whether gap matches residue in the PID calculation for a Tree
82    * - true gives Jalview 2.10.1 behaviour
83    * - set to false (using Groovy) for a more correct tree
84    * (JAL-374)
85    */
86   private static boolean treeMatchGaps = true;
87
88   private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
89
90   private static final int MIN_TREE_SELECTION = 3;
91
92   private static final int MIN_PCA_SELECTION = 4;
93   
94   private String secondaryStructureModelName;
95   
96   private void getSecondaryStructureModelName() {
97     
98     ScoreModels scoreModels = ScoreModels.getInstance();
99     for (ScoreModelI sm : scoreModels.getModels())
100     {
101       if (sm.isSecondaryStructure())
102       {
103         secondaryStructureModelName = sm.getName();
104       }
105     }
106     
107   }
108
109   /**
110    * minimum number of sequences needed for PASIMAP is 9 (so each has 8 connections)
111    */
112   private static final int MIN_PASIMAP_SELECTION = 9; 
113
114   AlignFrame af;
115
116   JRadioButton pca;
117
118   JRadioButton pasimap; 
119
120   JRadioButton neighbourJoining;
121
122   JRadioButton averageDistance;
123
124   JComboBox<String> modelNames;
125   
126   JComboBox<String> ssSourceDropdown;
127
128   JButton calculate;
129
130   private JInternalFrame frame;
131
132   private JCheckBox includeGaps;
133
134   private JCheckBox matchGaps;
135
136   private JCheckBox includeGappedColumns;
137
138   private JCheckBox shorterSequence;
139
140   final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
141
142   List<String> tips = new ArrayList<>();
143
144   /*
145    * the most recently opened PCA results panel
146    */
147   private PCAPanel pcaPanel;
148
149   private PaSiMapPanel pasimapPanel;
150
151   /**
152    * Constructor
153    * 
154    * @param af
155    */
156   public CalculationChooser(AlignFrame alignFrame)
157   {
158     this.af = alignFrame;
159     init();
160     af.alignPanel.setCalculationDialog(this);
161     
162   }
163
164   /**
165    * Lays out the panel and adds it to the desktop
166    */
167   void init()
168   {
169     getSecondaryStructureModelName();
170     setLayout(new BorderLayout());
171     frame = new JInternalFrame();
172     frame.setFrameIcon(null);
173     frame.setContentPane(this);
174     this.setBackground(Color.white);
175     frame.addFocusListener(new FocusListener()
176     {
177
178       @Override
179       public void focusLost(FocusEvent e)
180       {
181       }
182
183       @Override
184       public void focusGained(FocusEvent e)
185       {
186         validateCalcTypes();
187       }
188     });
189     /*
190      * Layout consists of 3 or 4 panels:
191      * - first with choice of PCA or tree method NJ or AV
192      * - second with choice of score model
193      * - third with score model parameter options [suppressed]
194      * - fourth with OK and Cancel
195      */
196     pca = new JRadioButton(
197             MessageManager.getString("label.principal_component_analysis"));
198     pca.setOpaque(false);
199
200     pasimap = new JRadioButton(                 // create the JRadioButton for pasimap with label.pasimap as its text
201             MessageManager.getString("label.pasimap"));
202     pasimap.setOpaque(false);
203
204     neighbourJoining = new JRadioButton(
205             MessageManager.getString("label.tree_calc_nj"));
206     neighbourJoining.setSelected(true);
207     neighbourJoining.setOpaque(false);
208
209     averageDistance = new JRadioButton(
210             MessageManager.getString("label.tree_calc_av"));
211     averageDistance.setOpaque(false);
212
213     JPanel calcChoicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
214     calcChoicePanel.setOpaque(false);
215
216     // first create the Tree calculation's border panel
217     JPanel treePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
218     treePanel.setOpaque(false);
219
220     JvSwingUtils.createTitledBorder(treePanel,
221             MessageManager.getString("label.tree"), true);
222
223     // then copy the inset dimensions for the border-less PCA panel
224     JPanel pcaBorderless = new JPanel(new FlowLayout(FlowLayout.LEFT));
225     Insets b = treePanel.getBorder().getBorderInsets(treePanel);
226     pcaBorderless.setBorder(
227             BorderFactory.createEmptyBorder(2, b.left, 2, b.right));
228     pcaBorderless.setOpaque(false);
229
230     pcaBorderless.add(pca, FlowLayout.LEFT);
231     calcChoicePanel.add(pcaBorderless, FlowLayout.LEFT);
232
233     // create pasimap panel
234     JPanel pasimapBorderless = new JPanel(new FlowLayout(FlowLayout.LEFT));     // create new JPanel (button) for pasimap
235     pasimapBorderless.setBorder(
236             BorderFactory.createEmptyBorder(2, b.left, 2, b.right));    // set border (margin) for button (same as treePanel and pca)
237     pasimapBorderless.setOpaque(false);         // false -> stops every pixel inside border from being painted
238     pasimapBorderless.add(pasimap, FlowLayout.LEFT);    // add pasimap button to the JPanel
239     calcChoicePanel.add(pasimapBorderless, FlowLayout.LEFT);    // add button with border and everything to the overall ChoicePanel
240
241     treePanel.add(neighbourJoining);
242     treePanel.add(averageDistance);
243
244     calcChoicePanel.add(treePanel);
245
246     ButtonGroup calcTypes = new ButtonGroup();
247     calcTypes.add(pca);
248     calcTypes.add(pasimap);
249     calcTypes.add(neighbourJoining);
250     calcTypes.add(averageDistance);
251
252     ActionListener calcChanged = new ActionListener()
253     {
254       @Override
255       public void actionPerformed(ActionEvent e)
256       {
257         validateCalcTypes();
258       }
259     };
260     pca.addActionListener(calcChanged);
261     pasimap.addActionListener(calcChanged);     // add the calcChanged ActionListener to pasimap --> <++> idk
262     neighbourJoining.addActionListener(calcChanged);
263     averageDistance.addActionListener(calcChanged);
264     
265     
266     //to do    
267     ssSourceDropdown = buildSSSourcesOptionsList();
268     ssSourceDropdown.setVisible(false); // Initially hide the dropdown
269
270     /*
271      * score models drop-down - with added tooltips!
272      */
273     modelNames = buildModelOptionsList();
274     
275     // Step 3: Show or Hide Dropdown Based on Selection
276     modelNames.addActionListener(new ActionListener() {
277         @Override
278         public void actionPerformed(ActionEvent e) {
279             String selectedModel = modelNames.getSelectedItem().toString();
280             
281             if (selectedModel.equals(secondaryStructureModelName)) {
282               ssSourceDropdown.setVisible(true);
283             } else {
284               ssSourceDropdown.setVisible(false);
285             }
286         }
287     });
288
289
290     JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
291     scoreModelPanel.setOpaque(false);
292     scoreModelPanel.add(modelNames);
293     scoreModelPanel.add(ssSourceDropdown);
294     
295     /*
296      * score model parameters
297      */
298     JPanel paramsPanel = new JPanel(new GridLayout(5, 1));
299     paramsPanel.setOpaque(false);
300     includeGaps = new JCheckBox("Include gaps");
301     matchGaps = new JCheckBox("Match gaps");
302     includeGappedColumns = new JCheckBox("Include gapped columns");
303     shorterSequence = new JCheckBox("Match on shorter sequence");
304     paramsPanel.add(new JLabel("Pairwise sequence scoring options"));
305     paramsPanel.add(includeGaps);
306     paramsPanel.add(matchGaps);
307     paramsPanel.add(includeGappedColumns);
308     paramsPanel.add(shorterSequence);
309     
310     /*
311      * OK / Cancel buttons
312      */
313     calculate = new JButton(MessageManager.getString("action.calculate"));
314     calculate.setFont(VERDANA_11PT);
315     calculate.addActionListener(new java.awt.event.ActionListener()
316     {
317       @Override
318       public void actionPerformed(ActionEvent e)
319       {
320         calculate_actionPerformed();
321       }
322     });
323     JButton close = new JButton(MessageManager.getString("action.close"));
324     close.setFont(VERDANA_11PT);
325     close.addActionListener(new java.awt.event.ActionListener()
326     {
327       @Override
328       public void actionPerformed(ActionEvent e)
329       {
330         close_actionPerformed();
331       }
332     });
333     JPanel actionPanel = new JPanel();
334     actionPanel.setOpaque(false);
335     actionPanel.add(calculate);
336     actionPanel.add(close);
337
338     boolean includeParams = false;
339     this.add(calcChoicePanel, BorderLayout.CENTER);
340     calcChoicePanel.add(scoreModelPanel);
341     if (includeParams)
342     {
343       scoreModelPanel.add(paramsPanel);
344     }
345     this.add(actionPanel, BorderLayout.SOUTH);
346
347     int width = 365;
348     int height = includeParams ? 420 : 240;
349
350     setMinimumSize(new Dimension(325, height - 10));
351     String title = MessageManager.getString("label.choose_calculation");
352     if (af.getViewport().getViewName() != null)
353     {
354       title = title + " (" + af.getViewport().getViewName() + ")";
355     }
356
357     Desktop.addInternalFrame(frame, title, width, height, false);
358     calcChoicePanel.doLayout();
359     revalidate();
360     /*
361      * null the AlignmentPanel's reference to the dialog when it is closed
362      */
363     frame.addInternalFrameListener(new InternalFrameAdapter()
364     {
365       @Override
366       public void internalFrameClosed(InternalFrameEvent evt)
367       {
368         af.alignPanel.setCalculationDialog(null);
369       };
370     });
371
372     validateCalcTypes();
373     frame.setLayer(JLayeredPane.PALETTE_LAYER);
374   }
375
376   /**
377    * enable calculations applicable for the current alignment or selection.
378    */
379   protected void validateCalcTypes()
380   {
381     int size = af.getViewport().getAlignment().getHeight();
382     if (af.getViewport().getSelectionGroup() != null)
383     {
384       size = af.getViewport().getSelectionGroup().getSize();
385     }
386
387     /*
388      * disable calc options for which there is insufficient input data
389      * return value of true means enabled and selected
390      */
391     boolean checkPca = checkEnabled(pca, size, MIN_PCA_SELECTION);
392     boolean checkPasimap = checkEnabled(pasimap, size, MIN_PASIMAP_SELECTION);  // check if pasimap is enabled and min_size is fulfilled
393     boolean checkNeighbourJoining = checkEnabled(neighbourJoining, size,
394             MIN_TREE_SELECTION);
395     boolean checkAverageDistance = checkEnabled(averageDistance, size,
396             MIN_TREE_SELECTION);
397
398     if (checkPca || checkPasimap || checkNeighbourJoining || checkAverageDistance)
399     {
400       calculate.setToolTipText(null);
401       calculate.setEnabled(true);
402     }
403     else
404     {
405       calculate.setEnabled(false);
406     }
407     updateScoreModels(modelNames, tips);
408   }
409
410   /**
411    * Check the input and disable a calculation's radio button if necessary. A
412    * tooltip is shown for disabled calculations.
413    * 
414    * @param calc
415    *          - radio button for the calculation being validated
416    * @param size
417    *          - size of input to calculation
418    * @param minsize
419    *          - minimum size for calculation
420    * @return true if size >= minsize and calc.isSelected
421    */
422   private boolean checkEnabled(JRadioButton calc, int size, int minsize)
423   {
424     String ttip = MessageManager
425             .formatMessage("label.you_need_at_least_n_sequences", minsize);
426
427     calc.setEnabled(size >= minsize);
428     if (!calc.isEnabled())
429     {
430       calc.setToolTipText(ttip);
431     }
432     else
433     {
434       calc.setToolTipText(null);
435     }
436     if (calc.isSelected())
437     {
438       modelNames.setEnabled(calc.isEnabled());
439       if (calc.isEnabled())
440       {
441         return true;
442       }
443       else
444       {
445         calculate.setToolTipText(ttip);
446       }
447     }
448     return false;
449   }
450
451   /**
452    * A rather elaborate helper method (blame Swing, not me) that builds a
453    * drop-down list of score models (by name) with descriptions as tooltips.
454    * There is also a tooltip shown for the currently selected item when hovering
455    * over it (without opening the list).
456    */
457   protected JComboBox<String> buildModelOptionsList()
458   {
459     final JComboBox<String> scoreModelsCombo = new JComboBox<>();
460     scoreModelsCombo.setRenderer(renderer);
461
462     /*
463      * show tooltip on mouse over the combobox
464      * note the listener has to be on the components that make up
465      * the combobox, doesn't work if just on the combobox
466      */
467     final MouseAdapter mouseListener = new MouseAdapter()
468     {
469       @Override
470       public void mouseEntered(MouseEvent e)
471       {
472         scoreModelsCombo.setToolTipText(
473                 tips.get(scoreModelsCombo.getSelectedIndex()));
474       }
475
476       @Override
477       public void mouseExited(MouseEvent e)
478       {
479         scoreModelsCombo.setToolTipText(null);
480       }
481     };
482     for (Component c : scoreModelsCombo.getComponents())
483     {
484       c.addMouseListener(mouseListener);
485     }
486
487     updateScoreModels(scoreModelsCombo, tips);
488
489     /*
490      * set the list of tooltips on the combobox's renderer
491      */
492     renderer.setTooltips(tips);
493
494     return scoreModelsCombo;
495   }
496   
497
498   private JComboBox<String> buildSSSourcesOptionsList()
499   {
500     final JComboBox<String> comboBox = new JComboBox<>();
501     Object curSel = comboBox.getSelectedItem();
502     DefaultComboBoxModel<String> sourcesModel = new DefaultComboBoxModel<>();
503
504     List<String> ssSources = getApplicableSecondaryStructureSources();
505
506     boolean selectedIsPresent = false;
507     for (String source : ssSources)
508     {
509       if (curSel != null && source.equals(curSel))
510       {
511         selectedIsPresent = true;
512         curSel = source;
513       }
514       sourcesModel.addElement(source);
515       
516     }
517
518     if (selectedIsPresent)
519     {
520       sourcesModel.setSelectedItem(curSel);
521     }
522     comboBox.setModel(sourcesModel);
523     
524     return comboBox;
525   }
526   
527   
528   private void updateScoreModels(JComboBox<String> comboBox,
529           List<String> toolTips)
530   {
531     Object curSel = comboBox.getSelectedItem();
532     toolTips.clear();
533     DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
534
535     /*
536      * select the score models applicable to the alignment type
537      */
538     boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
539     AlignmentAnnotation[] alignmentAnnotations = af.getViewport().getAlignment().getAlignmentAnnotation();
540
541     boolean ssPresent = AlignmentUtils.isSecondaryStructurePresent(alignmentAnnotations);
542
543     List<ScoreModelI> models = getApplicableScoreModels(nucleotide, pca.isSelected(),
544             ssPresent, pasimap.isSelected());
545
546     /*
547      * now we can actually add entries to the combobox,
548      * remembering their descriptions for tooltips
549      */
550     boolean selectedIsPresent = false;
551     for (ScoreModelI sm : models)
552     {
553       if (curSel != null && sm.getName().equals(curSel))
554       {
555         selectedIsPresent = true;
556         curSel = sm.getName();
557       }
558       model.addElement(sm.getName());
559
560       /*
561        * tooltip is description if provided, else text lookup with
562        * fallback on the model name
563        */
564       String tooltip = sm.getDescription();
565       if (tooltip == null)
566       {
567         tooltip = MessageManager.getStringOrReturn("label.score_model_",
568                 sm.getName());
569       }
570       toolTips.add(tooltip);
571     }
572
573     if (selectedIsPresent)
574     {
575       model.setSelectedItem(curSel);
576     }
577     // finally, update the model
578     comboBox.setModel(model);
579     
580   }
581
582   /**
583    * Builds a list of score models which are applicable for the alignment and
584    * calculation type (peptide or generic models for protein, nucleotide or
585    * generic models for nucleotide).
586    * <p>
587    * As a special case, includes BLOSUM62 as an extra option for nucleotide PCA.
588    * This is for backwards compatibility with Jalview prior to 2.8 when BLOSUM62
589    * was the only score matrix supported. This is included if property
590    * BLOSUM62_PCA_FOR_NUCLEOTIDE is set to true in the Jalview properties file.
591    * 
592    * @param nucleotide
593    * @param forPca
594    * @return
595    */
596   protected static List<ScoreModelI> getApplicableScoreModels(
597           boolean nucleotide, boolean forPca, boolean ssPresent, boolean forPasimap)
598   {
599     List<ScoreModelI> filtered = new ArrayList<>();
600
601     ScoreModels scoreModels = ScoreModels.getInstance();
602     for (ScoreModelI sm : scoreModels.getModels())
603     {
604       if ((!nucleotide && sm.isProtein() || nucleotide && sm.isDNA() 
605               || sm.isSecondaryStructure() && ssPresent))
606               
607       {
608         filtered.add(sm);
609       }
610     }
611
612     /*
613      * special case: add BLOSUM62 as last option for nucleotide PCA, 
614      * for backwards compatibility with Jalview < 2.8 (JAL-2962)
615      */
616     if (!forPasimap && nucleotide && forPca
617             && Cache.getDefault("BLOSUM62_PCA_FOR_NUCLEOTIDE", false))
618     {
619       filtered.add(scoreModels.getBlosum62());
620     }
621     
622     return filtered;
623   }
624
625   
626   protected List<String> getApplicableSecondaryStructureSources()
627   {
628     AlignmentAnnotation[] annotations = af.getViewport().getAlignment().getAlignmentAnnotation();
629     
630     List<String> ssSources = AlignmentUtils.getSecondaryStructureSources(annotations);
631     //List<String> ssSources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(annotations);
632     
633                  
634     return ssSources;
635   }
636   
637   /**
638    * Open and calculate the selected tree or PCA on 'OK'
639    */
640   protected void calculate_actionPerformed()
641   {
642     boolean doPCA = pca.isSelected();
643     boolean doPaSiMap = pasimap.isSelected();
644     String modelName = modelNames.getSelectedItem() == null ? "" : modelNames.getSelectedItem().toString();
645     String ssSource = "";
646     Object selectedItem = ssSourceDropdown.getSelectedItem();
647     if (selectedItem != null) {
648         ssSource = selectedItem.toString();
649     }
650     SimilarityParams params = getSimilarityParameters(doPCA);
651     if(ssSource.length()>0)
652     {
653       params.setSecondaryStructureSource(ssSource);
654     }
655
656     if (doPCA && !doPaSiMap)
657     {
658       openPcaPanel(modelName, params);
659     }
660     else if (doPaSiMap && !doPCA)
661     {
662       openPasimapPanel(modelName, params);
663     }
664     else
665     {
666       openTreePanel(modelName, params);
667     }
668
669     closeFrame();
670   }
671
672   /**
673    * Open a new Tree panel on the desktop
674    * 
675    * @param modelName
676    * @param params
677    */
678   protected void openTreePanel(String modelName, SimilarityParamsI params)
679   {
680     /*
681      * gui validation shouldn't allow insufficient sequences here, but leave
682      * this check in in case this method gets exposed programmatically in future
683      */
684     AlignViewport viewport = af.getViewport();
685     SequenceGroup sg = viewport.getSelectionGroup();
686     if (sg != null && sg.getSize() < MIN_TREE_SELECTION)
687     {
688       JvOptionPane.showMessageDialog(Desktop.desktop,
689               MessageManager.formatMessage(
690                       "label.you_need_at_least_n_sequences",
691                       MIN_TREE_SELECTION),
692               MessageManager.getString("label.not_enough_sequences"),
693               JvOptionPane.WARNING_MESSAGE);
694       return;
695     }
696
697     String treeType = neighbourJoining.isSelected()
698             ? TreeBuilder.NEIGHBOUR_JOINING
699             : TreeBuilder.AVERAGE_DISTANCE;
700     af.newTreePanel(treeType, modelName, params);
701   }
702
703   /**
704    * Open a new PCA panel on the desktop
705    * 
706    * @param modelName
707    * @param params
708    */
709   protected void openPcaPanel(String modelName, SimilarityParamsI params)
710   {
711     AlignViewport viewport = af.getViewport();
712
713     /*
714      * gui validation shouldn't allow insufficient sequences here, but leave
715      * this check in in case this method gets exposed programmatically in future
716      */
717     if (((viewport.getSelectionGroup() != null)
718             && (viewport.getSelectionGroup().getSize() < MIN_PCA_SELECTION)
719             && (viewport.getSelectionGroup().getSize() > 0))
720             || (viewport.getAlignment().getHeight() < MIN_PCA_SELECTION))
721     {
722       JvOptionPane.showInternalMessageDialog(this,
723               MessageManager.formatMessage(
724                       "label.you_need_at_least_n_sequences",
725                       MIN_PCA_SELECTION),
726               MessageManager
727                       .getString("label.sequence_selection_insufficient"),
728               JvOptionPane.WARNING_MESSAGE);
729       return;
730     }
731
732     /*
733      * construct the panel and kick off its calculation thread
734      */
735     pcaPanel = new PCAPanel(af.alignPanel, modelName, params);
736     new Thread(pcaPanel).start();
737
738   }
739
740   /**
741    * Open a new PaSiMap panel on the desktop
742    * 
743    * @param modelName
744    * @param params
745    */
746   protected void openPasimapPanel(String modelName, SimilarityParamsI params)
747   {
748     AlignViewport viewport = af.getViewport();
749
750     /*
751      * gui validation shouldn't allow insufficient sequences here, but leave
752      * this check in in case this method gets exposed programmatically in future
753      */
754     if (((viewport.getSelectionGroup() != null)
755             && (viewport.getSelectionGroup().getSize() < MIN_PASIMAP_SELECTION)
756             && (viewport.getSelectionGroup().getSize() > 0))
757             || (viewport.getAlignment().getHeight() < MIN_PASIMAP_SELECTION))
758     {
759       JvOptionPane.showInternalMessageDialog(this,
760               MessageManager.formatMessage(
761                       "label.you_need_at_least_n_sequences",
762                       MIN_PASIMAP_SELECTION),
763               MessageManager
764                       .getString("label.sequence_selection_insufficient"),
765               JvOptionPane.WARNING_MESSAGE);
766       return;
767     }
768
769     /*
770      * construct the panel and kick off its calculation thread
771      */
772     pasimapPanel = new PaSiMapPanel(af.alignPanel, modelName, params);
773     new Thread(pasimapPanel).start();
774
775   }
776
777   /**
778    * 
779    */
780   protected void closeFrame()
781   {
782     try
783     {
784       frame.setClosed(true);
785     } catch (PropertyVetoException ex)
786     {
787     }
788   }
789
790   /**
791    * Returns a data bean holding parameters for similarity (or distance) model
792    * calculation
793    * 
794    * @param doPCA
795    * @return
796    */
797   protected SimilarityParams getSimilarityParameters(boolean doPCA)
798   {
799     // commented out: parameter choices read from gui widgets
800     // SimilarityParamsI params = new SimilarityParams(
801     // includeGappedColumns.isSelected(), matchGaps.isSelected(),
802     // includeGaps.isSelected(), shorterSequence.isSelected());
803
804     boolean includeGapGap = true;
805     boolean includeGapResidue = true;
806     boolean matchOnShortestLength = false;
807
808     /*
809      * 'matchGaps' flag is only used in the PID calculation
810      * - set to false for PCA so that PCA using PID reproduces SeqSpace PCA
811      * - set to true for Tree to reproduce Jalview 2.10.1 calculation
812      * - set to false for Tree for a more correct calculation (JAL-374)
813      */
814     boolean matchGap = doPCA ? false : treeMatchGaps;
815
816     return new SimilarityParams(includeGapGap, matchGap, includeGapResidue,
817             matchOnShortestLength);
818   }
819
820   /**
821    * Closes dialog on Close button press
822    */
823   protected void close_actionPerformed()
824   {
825     try
826     {
827       frame.setClosed(true);
828     } catch (Exception ex)
829     {
830     }
831   }
832
833   public PCAPanel getPcaPanel()
834   {
835     return pcaPanel;
836   }
837 }