2 // FORESTER -- software libraries and applications
\r
3 // for evolutionary biology research and applications.
\r
5 // Copyright (C) 2008-2009 Christian M. Zmasek
\r
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
\r
7 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
\r
8 // All rights reserved
\r
10 // This library is free software; you can redistribute it and/or
\r
11 // modify it under the terms of the GNU Lesser General Public
\r
12 // License as published by the Free Software Foundation; either
\r
13 // version 2.1 of the License, or (at your option) any later version.
\r
15 // This library is distributed in the hope that it will be useful,
\r
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
18 // Lesser General Public License for more details.
\r
20 // You should have received a copy of the GNU Lesser General Public
\r
21 // License along with this library; if not, write to the Free Software
\r
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
24 // Contact: phylosoft @ gmail . com
\r
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
\r
27 package org.forester.archaeopteryx;
\r
29 import java.awt.BorderLayout;
\r
30 import java.awt.Font;
\r
31 import java.awt.event.ActionEvent;
\r
32 import java.awt.event.ComponentAdapter;
\r
33 import java.awt.event.ComponentEvent;
\r
34 import java.awt.event.WindowAdapter;
\r
35 import java.awt.event.WindowEvent;
\r
36 import java.io.File;
\r
37 import java.io.FileInputStream;
\r
38 import java.io.IOException;
\r
39 import java.io.InputStream;
\r
40 import java.net.MalformedURLException;
\r
41 import java.net.URL;
\r
42 import java.util.ArrayList;
\r
43 import java.util.HashSet;
\r
44 import java.util.List;
\r
45 import java.util.Set;
\r
47 import javax.swing.ButtonGroup;
\r
48 import javax.swing.JCheckBoxMenuItem;
\r
49 import javax.swing.JFileChooser;
\r
50 import javax.swing.JMenu;
\r
51 import javax.swing.JMenuBar;
\r
52 import javax.swing.JMenuItem;
\r
53 import javax.swing.JOptionPane;
\r
54 import javax.swing.JRadioButtonMenuItem;
\r
55 import javax.swing.UIManager;
\r
56 import javax.swing.UnsupportedLookAndFeelException;
\r
57 import javax.swing.WindowConstants;
\r
58 import javax.swing.event.ChangeEvent;
\r
59 import javax.swing.event.ChangeListener;
\r
60 import javax.swing.plaf.synth.SynthLookAndFeel;
\r
62 import org.forester.analysis.TaxonomyDataManager;
\r
63 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
\r
64 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
\r
65 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
\r
66 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
\r
67 import org.forester.archaeopteryx.tools.InferenceManager;
\r
68 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
\r
69 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
\r
70 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
\r
71 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
\r
72 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
\r
73 import org.forester.archaeopteryx.webservices.WebservicesManager;
\r
74 import org.forester.io.parsers.FastaParser;
\r
75 import org.forester.io.parsers.GeneralMsaParser;
\r
76 import org.forester.io.parsers.PhylogenyParser;
\r
77 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
\r
78 import org.forester.io.parsers.nhx.NHXParser;
\r
79 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
\r
80 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
\r
81 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
\r
82 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
\r
83 import org.forester.io.parsers.tol.TolParser;
\r
84 import org.forester.io.parsers.util.ParserUtils;
\r
85 import org.forester.io.writers.SequenceWriter;
\r
86 import org.forester.msa.Msa;
\r
87 import org.forester.msa.MsaFormatException;
\r
88 import org.forester.phylogeny.Phylogeny;
\r
89 import org.forester.phylogeny.PhylogenyMethods;
\r
90 import org.forester.phylogeny.PhylogenyNode;
\r
91 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
\r
92 import org.forester.phylogeny.data.Confidence;
\r
93 import org.forester.phylogeny.data.PhylogenyDataUtil;
\r
94 import org.forester.phylogeny.data.Sequence;
\r
95 import org.forester.phylogeny.data.Taxonomy;
\r
96 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
\r
97 import org.forester.phylogeny.factories.PhylogenyFactory;
\r
98 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
\r
99 import org.forester.sequence.MolecularSequence;
\r
100 import org.forester.util.BasicDescriptiveStatistics;
\r
101 import org.forester.util.BasicTable;
\r
102 import org.forester.util.BasicTableParser;
\r
103 import org.forester.util.DescriptiveStatistics;
\r
104 import org.forester.util.ForesterUtil;
\r
106 public final class MainFrameApplication extends MainFrame {
\r
108 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
\r
109 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
\r
110 private final static int FRAME_X_SIZE = 800;
\r
111 private final static int FRAME_Y_SIZE = 800;
\r
112 // Filters for the file-open dialog (classes defined in this file)
\r
113 private static final long serialVersionUID = -799735726778865234L;
\r
114 private static final boolean PREPROCESS_TREES = false;
\r
115 private final JFileChooser _values_filechooser;
\r
116 private final JFileChooser _sequences_filechooser;
\r
117 private final JFileChooser _open_filechooser;
\r
118 private final JFileChooser _msa_filechooser;
\r
119 private final JFileChooser _seqs_pi_filechooser;
\r
120 private final JFileChooser _open_filechooser_for_species_tree;
\r
121 // Application-only print menu items
\r
122 private JMenuItem _collapse_below_threshold;
\r
123 private JMenuItem _collapse_below_branch_length;
\r
124 private ButtonGroup _radio_group_1;
\r
125 private ButtonGroup _radio_group_2;
\r
127 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
\r
128 double _min_not_collapse_bl = 0.001;
\r
129 // Phylogeny Inference menu
\r
130 private JMenu _inference_menu;
\r
131 private JMenuItem _inference_from_msa_item;
\r
132 private JMenuItem _inference_from_seqs_item;
\r
133 // Phylogeny Inference
\r
134 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
\r
135 private Msa _msa = null;
\r
136 private File _msa_file = null;
\r
137 private List<MolecularSequence> _seqs = null;
\r
138 private File _seqs_file = null;
\r
139 JMenuItem _read_values_jmi;
\r
140 JMenuItem _read_seqs_jmi;
\r
142 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
\r
143 _configuration = config;
\r
144 if ( _configuration == null ) {
\r
145 throw new IllegalArgumentException( "configuration is null" );
\r
147 setVisible( false );
\r
148 setOptions( Options.createInstance( _configuration ) );
\r
149 _mainpanel = new MainPanel( _configuration, this );
\r
150 _open_filechooser = null;
\r
151 _open_filechooser_for_species_tree = null;
\r
152 _save_filechooser = null;
\r
153 _writetopdf_filechooser = null;
\r
154 _writetographics_filechooser = null;
\r
155 _msa_filechooser = null;
\r
156 _seqs_pi_filechooser = null;
\r
157 _values_filechooser = null;
\r
158 _sequences_filechooser = null;
\r
159 _jmenubar = new JMenuBar();
\r
162 _contentpane = getContentPane();
\r
163 _contentpane.setLayout( new BorderLayout() );
\r
164 _contentpane.add( _mainpanel, BorderLayout.CENTER );
\r
166 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
\r
167 // The window listener
\r
168 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
\r
169 addWindowListener( new WindowAdapter() {
\r
172 public void windowClosing( final WindowEvent e ) {
\r
176 // setVisible( true );
\r
177 if ( ( phys != null ) && ( phys.length > 0 ) ) {
\r
178 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
\r
180 getMainPanel().getControlPanel().showWholeAll();
\r
181 getMainPanel().getControlPanel().showWhole();
\r
183 //activateSaveAllIfNeeded();
\r
184 // ...and its children
\r
185 _contentpane.repaint();
\r
188 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
\r
189 this( phys, config, title, null );
\r
192 private MainFrameApplication( final Phylogeny[] phys,
\r
193 final Configuration config,
\r
194 final String title,
\r
195 final File current_dir ) {
\r
197 _configuration = config;
\r
198 if ( _configuration == null ) {
\r
199 throw new IllegalArgumentException( "configuration is null" );
\r
202 boolean synth_exception = false;
\r
203 if ( Constants.__SYNTH_LF ) {
\r
205 final SynthLookAndFeel synth = new SynthLookAndFeel();
\r
206 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
\r
207 MainFrameApplication.class );
\r
208 UIManager.setLookAndFeel( synth );
\r
210 catch ( final Exception ex ) {
\r
211 synth_exception = true;
\r
212 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
\r
213 "could not create synth look and feel: "
\r
214 + ex.getLocalizedMessage() );
\r
217 if ( !Constants.__SYNTH_LF || synth_exception ) {
\r
218 if ( _configuration.isUseNativeUI() ) {
\r
219 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
\r
222 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
\r
225 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
\r
227 catch ( final UnsupportedLookAndFeelException e ) {
\r
228 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
\r
230 catch ( final ClassNotFoundException e ) {
\r
231 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
\r
233 catch ( final InstantiationException e ) {
\r
234 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
\r
236 catch ( final IllegalAccessException e ) {
\r
237 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
\r
239 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
\r
240 setCurrentDir( current_dir );
\r
242 // hide until everything is ready
\r
243 setVisible( false );
\r
244 setOptions( Options.createInstance( _configuration ) );
\r
245 setInferenceManager( InferenceManager.createInstance( _configuration ) );
\r
246 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
\r
248 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
\r
249 _mainpanel = new MainPanel( _configuration, this );
\r
250 // The file dialogs
\r
251 _open_filechooser = new JFileChooser();
\r
252 _open_filechooser.setMultiSelectionEnabled( true );
\r
253 _open_filechooser.addChoosableFileFilter( MainFrame.xmlfilter );
\r
254 _open_filechooser.addChoosableFileFilter( MainFrame.nhxfilter );
\r
255 _open_filechooser.addChoosableFileFilter( MainFrame.nhfilter );
\r
256 _open_filechooser.addChoosableFileFilter( MainFrame.nexusfilter );
\r
257 _open_filechooser.addChoosableFileFilter( MainFrame.tolfilter );
\r
258 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
\r
259 _open_filechooser.setFileFilter( MainFrame.defaultfilter );
\r
260 _open_filechooser_for_species_tree = new JFileChooser();
\r
261 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
\r
262 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrame.xmlfilter );
\r
263 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrame.tolfilter );
\r
264 _open_filechooser_for_species_tree.setFileFilter( MainFrame.xmlfilter );
\r
266 _msa_filechooser = new JFileChooser();
\r
267 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
\r
268 _msa_filechooser.setMultiSelectionEnabled( false );
\r
269 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
\r
270 _msa_filechooser.addChoosableFileFilter( MainFrame.msafilter );
\r
272 _seqs_pi_filechooser = new JFileChooser();
\r
273 _seqs_pi_filechooser.setName( "Read Sequences File" );
\r
274 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
\r
275 _seqs_pi_filechooser.addChoosableFileFilter( _seqs_pi_filechooser.getAcceptAllFileFilter() );
\r
276 _seqs_pi_filechooser.addChoosableFileFilter( MainFrame.seqsfilter );
\r
278 _values_filechooser = new JFileChooser();
\r
279 _values_filechooser.setMultiSelectionEnabled( false );
\r
281 _sequences_filechooser = new JFileChooser();
\r
282 _sequences_filechooser.setMultiSelectionEnabled( false );
\r
284 final String home_dir = System.getProperty( "user.home" );
\r
285 _open_filechooser.setCurrentDirectory( new File( home_dir ) );
\r
286 _open_filechooser_for_species_tree.setCurrentDirectory( new File( home_dir ) );
\r
287 _msa_filechooser.setCurrentDirectory( new File( home_dir ) );
\r
288 _seqs_pi_filechooser.setCurrentDirectory( new File( home_dir ) );
\r
289 _values_filechooser.setCurrentDirectory( new File( home_dir ) );
\r
290 _sequences_filechooser.setCurrentDirectory( new File( home_dir ) );
\r
292 catch ( final Exception e ) {
\r
293 e.printStackTrace();
\r
294 // Do nothing. Not important.
\r
296 // build the menu bar
\r
297 _jmenubar = new JMenuBar();
\r
298 if ( !_configuration.isUseNativeUI() ) {
\r
299 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
\r
302 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
\r
303 buildPhylogeneticInferenceMenu();
\r
305 buildAnalysisMenu();
\r
308 buildFontSizeMenu();
\r
309 buildOptionsMenu();
\r
312 setJMenuBar( _jmenubar );
\r
313 _jmenubar.add( _help_jmenu );
\r
314 _contentpane = getContentPane();
\r
315 _contentpane.setLayout( new BorderLayout() );
\r
316 _contentpane.add( _mainpanel, BorderLayout.CENTER );
\r
318 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
\r
319 // addWindowFocusListener( new WindowAdapter() {
\r
322 // public void windowGainedFocus( WindowEvent e ) {
\r
323 // requestFocusInWindow();
\r
326 // The window listener
\r
327 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
\r
328 addWindowListener( new WindowAdapter() {
\r
331 public void windowClosing( final WindowEvent e ) {
\r
332 if ( isUnsavedDataPresent() ) {
\r
333 final int r = JOptionPane.showConfirmDialog( null,
\r
334 "Exit despite potentially unsaved changes?",
\r
336 JOptionPane.YES_NO_OPTION );
\r
337 if ( r != JOptionPane.YES_OPTION ) {
\r
342 final int r = JOptionPane.showConfirmDialog( null,
\r
343 "Exit Archaeopteryx?",
\r
345 JOptionPane.YES_NO_OPTION );
\r
346 if ( r != JOptionPane.YES_OPTION ) {
\r
353 // The component listener
\r
354 addComponentListener( new ComponentAdapter() {
\r
357 public void componentResized( final ComponentEvent e ) {
\r
358 if ( _mainpanel.getCurrentTreePanel() != null ) {
\r
359 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel()
\r
361 _mainpanel.getCurrentTreePanel()
\r
366 requestFocusInWindow();
\r
367 // addKeyListener( this );
\r
368 setVisible( true );
\r
369 if ( ( phys != null ) && ( phys.length > 0 ) ) {
\r
370 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
\r
372 getMainPanel().getControlPanel().showWholeAll();
\r
373 getMainPanel().getControlPanel().showWhole();
\r
375 activateSaveAllIfNeeded();
\r
376 // ...and its children
\r
377 _contentpane.repaint();
\r
381 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
\r
382 // Reads the config file (false, false => not url, not applet):
\r
383 this( phys, new Configuration( config_file, false, false, true ), title );
\r
387 public void actionPerformed( final ActionEvent e ) {
\r
389 super.actionPerformed( e );
\r
390 final Object o = e.getSource();
\r
391 // Handle app-specific actions here:
\r
392 if ( o == _open_item ) {
\r
393 readPhylogeniesFromFile();
\r
395 if ( o == _open_url_item ) {
\r
396 readPhylogeniesFromURL();
\r
398 else if ( o == _new_item ) {
\r
401 else if ( o == _close_item ) {
\r
402 closeCurrentPane();
\r
404 else if ( o == _load_species_tree_item ) {
\r
405 readSpeciesTreeFromFile();
\r
407 else if ( o == _lineage_inference ) {
\r
408 if ( isSubtreeDisplayed() ) {
\r
409 JOptionPane.showMessageDialog( this,
\r
410 "Subtree is shown.",
\r
411 "Cannot infer ancestral taxonomies",
\r
412 JOptionPane.ERROR_MESSAGE );
\r
415 executeLineageInference();
\r
417 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
\r
418 if ( isSubtreeDisplayed() ) {
\r
421 obtainDetailedTaxonomicInformation();
\r
423 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
\r
424 if ( isSubtreeDisplayed() ) {
\r
427 obtainDetailedTaxonomicInformationDelete();
\r
429 else if ( o == _obtain_seq_information_jmi ) {
\r
430 obtainSequenceInformation();
\r
432 else if ( o == _read_values_jmi ) {
\r
433 if ( isSubtreeDisplayed() ) {
\r
436 addExpressionValuesFromFile();
\r
438 else if ( o == _read_seqs_jmi ) {
\r
439 if ( isSubtreeDisplayed() ) {
\r
442 addSequencesFromFile();
\r
444 else if ( o == _move_node_names_to_tax_sn_jmi ) {
\r
445 moveNodeNamesToTaxSn();
\r
447 else if ( o == _move_node_names_to_seq_names_jmi ) {
\r
448 moveNodeNamesToSeqNames();
\r
450 else if ( o == _extract_tax_code_from_node_names_jmi ) {
\r
451 extractTaxDataFromNodeNames();
\r
453 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
\r
454 updateOptions( getOptions() );
\r
456 else if ( o == _replace_underscores_cbmi ) {
\r
457 if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
\r
458 _extract_taxonomy_no_rbmi.setSelected( true );
\r
460 updateOptions( getOptions() );
\r
462 else if ( o == _allow_errors_in_distance_to_parent_cbmi ) {
\r
463 updateOptions( getOptions() );
\r
465 else if ( o == _collapse_below_threshold ) {
\r
466 if ( isSubtreeDisplayed() ) {
\r
469 collapseBelowThreshold();
\r
471 else if ( o == _collapse_below_branch_length ) {
\r
472 if ( isSubtreeDisplayed() ) {
\r
475 collapseBelowBranchLengthThreshold();
\r
477 else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi )
\r
478 || ( o == _extract_taxonomy_agressive_rbmi ) ) {
\r
479 if ( _replace_underscores_cbmi != null ) {
\r
480 _replace_underscores_cbmi.setSelected( false );
\r
482 updateOptions( getOptions() );
\r
484 else if ( o == _extract_taxonomy_no_rbmi ) {
\r
485 updateOptions( getOptions() );
\r
487 else if ( o == _inference_from_msa_item ) {
\r
488 executePhyleneticInference( false );
\r
490 else if ( o == _inference_from_seqs_item ) {
\r
491 executePhyleneticInference( true );
\r
493 _contentpane.repaint();
\r
495 catch ( final Exception ex ) {
\r
496 AptxUtil.unexpectedException( ex );
\r
498 catch ( final Error err ) {
\r
499 AptxUtil.unexpectedError( err );
\r
503 public void end() {
\r
504 _mainpanel.terminate();
\r
505 _contentpane.removeAll();
\r
506 setVisible( false );
\r
511 public MainPanel getMainPanel() {
\r
515 public Msa getMsa() {
\r
519 public File getMsaFile() {
\r
523 public List<MolecularSequence> getSeqs() {
\r
527 public File getSeqsFile() {
\r
531 public void readMsaFromFile() {
\r
532 // Set an initial directory if none set yet
\r
533 final File my_dir = getCurrentDir();
\r
534 _msa_filechooser.setMultiSelectionEnabled( false );
\r
535 // Open file-open dialog and set current directory
\r
536 if ( my_dir != null ) {
\r
537 _msa_filechooser.setCurrentDirectory( my_dir );
\r
539 final int result = _msa_filechooser.showOpenDialog( _contentpane );
\r
540 // All done: get the msa
\r
541 final File file = _msa_filechooser.getSelectedFile();
\r
542 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
\r
543 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
\r
544 setMsaFile( null );
\r
548 final InputStream is = new FileInputStream( file );
\r
549 if ( FastaParser.isLikelyFasta( file ) ) {
\r
550 msa = FastaParser.parseMsa( is );
\r
553 msa = GeneralMsaParser.parse( is );
\r
556 catch ( final MsaFormatException e ) {
\r
558 JOptionPane.showMessageDialog( this,
\r
559 e.getLocalizedMessage(),
\r
560 "Multiple sequence alignment format error",
\r
561 JOptionPane.ERROR_MESSAGE );
\r
564 catch ( final IOException e ) {
\r
566 JOptionPane.showMessageDialog( this,
\r
567 e.getLocalizedMessage(),
\r
568 "Failed to read multiple sequence alignment",
\r
569 JOptionPane.ERROR_MESSAGE );
\r
572 catch ( final IllegalArgumentException e ) {
\r
574 JOptionPane.showMessageDialog( this,
\r
575 e.getLocalizedMessage(),
\r
576 "Unexpected error during reading of multiple sequence alignment",
\r
577 JOptionPane.ERROR_MESSAGE );
\r
580 catch ( final Exception e ) {
\r
582 e.printStackTrace();
\r
583 JOptionPane.showMessageDialog( this,
\r
584 e.getLocalizedMessage(),
\r
585 "Unexpected error during reading of multiple sequence alignment",
\r
586 JOptionPane.ERROR_MESSAGE );
\r
589 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
\r
590 JOptionPane.showMessageDialog( this,
\r
591 "Multiple sequence alignment is empty",
\r
592 "Illegal Multiple Sequence Alignment",
\r
593 JOptionPane.ERROR_MESSAGE );
\r
596 if ( msa.getNumberOfSequences() < 4 ) {
\r
597 JOptionPane.showMessageDialog( this,
\r
598 "Multiple sequence alignment needs to contain at least 3 sequences",
\r
599 "Illegal multiple sequence alignment",
\r
600 JOptionPane.ERROR_MESSAGE );
\r
603 if ( msa.getLength() < 2 ) {
\r
604 JOptionPane.showMessageDialog( this,
\r
605 "Multiple sequence alignment needs to contain at least 2 residues",
\r
606 "Illegal multiple sequence alignment",
\r
607 JOptionPane.ERROR_MESSAGE );
\r
611 setMsaFile( _msa_filechooser.getSelectedFile() );
\r
616 public void readSeqsFromFileforPI() {
\r
617 // Set an initial directory if none set yet
\r
618 final File my_dir = getCurrentDir();
\r
619 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
\r
620 // Open file-open dialog and set current directory
\r
621 if ( my_dir != null ) {
\r
622 _seqs_pi_filechooser.setCurrentDirectory( my_dir );
\r
624 final int result = _seqs_pi_filechooser.showOpenDialog( _contentpane );
\r
625 // All done: get the seqs
\r
626 final File file = _seqs_pi_filechooser.getSelectedFile();
\r
627 setCurrentDir( _seqs_pi_filechooser.getCurrentDirectory() );
\r
628 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
\r
629 setSeqsFile( null );
\r
631 List<MolecularSequence> seqs = null;
\r
633 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
\r
634 seqs = FastaParser.parse( new FileInputStream( file ) );
\r
635 for( final MolecularSequence seq : seqs ) {
\r
636 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
\r
643 catch ( final MsaFormatException e ) {
\r
645 JOptionPane.showMessageDialog( this,
\r
646 e.getLocalizedMessage(),
\r
647 "Multiple sequence file format error",
\r
648 JOptionPane.ERROR_MESSAGE );
\r
651 catch ( final IOException e ) {
\r
653 JOptionPane.showMessageDialog( this,
\r
654 e.getLocalizedMessage(),
\r
655 "Failed to read multiple sequence file",
\r
656 JOptionPane.ERROR_MESSAGE );
\r
659 catch ( final IllegalArgumentException e ) {
\r
661 JOptionPane.showMessageDialog( this,
\r
662 e.getLocalizedMessage(),
\r
663 "Unexpected error during reading of multiple sequence file",
\r
664 JOptionPane.ERROR_MESSAGE );
\r
667 catch ( final Exception e ) {
\r
669 e.printStackTrace();
\r
670 JOptionPane.showMessageDialog( this,
\r
671 e.getLocalizedMessage(),
\r
672 "Unexpected error during reading of multiple sequence file",
\r
673 JOptionPane.ERROR_MESSAGE );
\r
676 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
\r
677 JOptionPane.showMessageDialog( this,
\r
678 "Multiple sequence file is empty",
\r
679 "Illegal multiple sequence file",
\r
680 JOptionPane.ERROR_MESSAGE );
\r
683 if ( seqs.size() < 4 ) {
\r
684 JOptionPane.showMessageDialog( this,
\r
685 "Multiple sequence file needs to contain at least 3 sequences",
\r
686 "Illegal multiple sequence file",
\r
687 JOptionPane.ERROR_MESSAGE );
\r
690 // if ( msa.getLength() < 2 ) {
\r
691 // JOptionPane.showMessageDialog( this,
\r
692 // "Multiple sequence alignment needs to contain at least 2 residues",
\r
693 // "Illegal multiple sequence file",
\r
694 // JOptionPane.ERROR_MESSAGE );
\r
698 setSeqsFile( _seqs_pi_filechooser.getSelectedFile() );
\r
703 private void addExpressionValuesFromFile() {
\r
704 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
\r
705 JOptionPane.showMessageDialog( this,
\r
706 "Need to load evolutionary tree first",
\r
707 "Can Not Read Expression Values",
\r
708 JOptionPane.WARNING_MESSAGE );
\r
711 final File my_dir = getCurrentDir();
\r
712 if ( my_dir != null ) {
\r
713 _values_filechooser.setCurrentDirectory( my_dir );
\r
715 final int result = _values_filechooser.showOpenDialog( _contentpane );
\r
716 final File file = _values_filechooser.getSelectedFile();
\r
717 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
\r
718 BasicTable<String> t = null;
\r
720 t = BasicTableParser.parse( file, '\t' );
\r
721 if ( t.getNumberOfColumns() < 2 ) {
\r
722 t = BasicTableParser.parse( file, ',' );
\r
724 if ( t.getNumberOfColumns() < 2 ) {
\r
725 t = BasicTableParser.parse( file, ' ' );
\r
728 catch ( final IOException e ) {
\r
729 JOptionPane.showMessageDialog( this,
\r
731 "Could Not Read Expression Value Table",
\r
732 JOptionPane.ERROR_MESSAGE );
\r
735 if ( t.getNumberOfColumns() < 2 ) {
\r
736 JOptionPane.showMessageDialog( this,
\r
737 "Table contains " + t.getNumberOfColumns() + " column(s)",
\r
738 "Problem with Expression Value Table",
\r
739 JOptionPane.ERROR_MESSAGE );
\r
742 if ( t.getNumberOfRows() < 1 ) {
\r
743 JOptionPane.showMessageDialog( this,
\r
744 "Table contains zero rows",
\r
745 "Problem with Expression Value Table",
\r
746 JOptionPane.ERROR_MESSAGE );
\r
749 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
750 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
\r
751 JOptionPane.showMessageDialog( this,
\r
752 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
\r
753 + phy.getNumberOfExternalNodes() + " external nodes",
\r
755 JOptionPane.WARNING_MESSAGE );
\r
757 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
\r
759 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
\r
760 final PhylogenyNode node = iter.next();
\r
761 final String node_name = node.getName();
\r
762 if ( !ForesterUtil.isEmpty( node_name ) ) {
\r
765 row = t.findRow( node_name );
\r
767 catch ( final IllegalArgumentException e ) {
\r
769 .showMessageDialog( this,
\r
771 "Error Mapping Node Identifiers to Expression Value Identifiers",
\r
772 JOptionPane.ERROR_MESSAGE );
\r
776 if ( node.isExternal() ) {
\r
781 final List<Double> l = new ArrayList<Double>();
\r
782 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
\r
785 d = Double.parseDouble( t.getValueAsString( col, row ) );
\r
787 catch ( final NumberFormatException e ) {
\r
788 JOptionPane.showMessageDialog( this,
\r
789 "Could not parse \"" + t.getValueAsString( col, row )
\r
790 + "\" into a decimal value",
\r
791 "Issue with Expression Value Table",
\r
792 JOptionPane.ERROR_MESSAGE );
\r
795 stats.addValue( d );
\r
798 if ( !l.isEmpty() ) {
\r
799 if ( node.getNodeData().getProperties() != null ) {
\r
800 node.getNodeData().getProperties()
\r
801 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
\r
803 node.getNodeData().setVector( l );
\r
807 if ( not_found > 0 ) {
\r
808 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
\r
809 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
\r
811 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
\r
815 private void addSequencesFromFile() {
\r
816 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
\r
817 JOptionPane.showMessageDialog( this,
\r
818 "Need to load evolutionary tree first",
\r
819 "Can Not Read Sequences",
\r
820 JOptionPane.WARNING_MESSAGE );
\r
823 final File my_dir = getCurrentDir();
\r
824 if ( my_dir != null ) {
\r
825 _sequences_filechooser.setCurrentDirectory( my_dir );
\r
827 final int result = _sequences_filechooser.showOpenDialog( _contentpane );
\r
828 final File file = _sequences_filechooser.getSelectedFile();
\r
829 List<MolecularSequence> seqs = null;
\r
830 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
\r
832 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
\r
833 seqs = FastaParser.parse( new FileInputStream( file ) );
\r
836 JOptionPane.showMessageDialog( this,
\r
837 "Format does not appear to be Fasta",
\r
838 "Multiple sequence file format error",
\r
839 JOptionPane.ERROR_MESSAGE );
\r
843 catch ( final MsaFormatException e ) {
\r
845 JOptionPane.showMessageDialog( this,
\r
846 e.getLocalizedMessage(),
\r
847 "Multiple sequence file format error",
\r
848 JOptionPane.ERROR_MESSAGE );
\r
851 catch ( final IOException e ) {
\r
853 JOptionPane.showMessageDialog( this,
\r
854 e.getLocalizedMessage(),
\r
855 "Failed to read multiple sequence file",
\r
856 JOptionPane.ERROR_MESSAGE );
\r
859 catch ( final Exception e ) {
\r
861 e.printStackTrace();
\r
862 JOptionPane.showMessageDialog( this,
\r
863 e.getLocalizedMessage(),
\r
864 "Unexpected error during reading of multiple sequence file",
\r
865 JOptionPane.ERROR_MESSAGE );
\r
868 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
\r
869 JOptionPane.showMessageDialog( this,
\r
870 "Multiple sequence file is empty",
\r
871 "Empty multiple sequence file",
\r
872 JOptionPane.ERROR_MESSAGE );
\r
877 if ( seqs != null ) {
\r
878 for( final MolecularSequence seq : seqs ) {
\r
879 System.out.println( seq.getIdentifier() );
\r
881 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
882 int total_counter = 0;
\r
883 int attached_counter = 0;
\r
884 for( final MolecularSequence seq : seqs ) {
\r
886 final String seq_name = seq.getIdentifier();
\r
887 if ( !ForesterUtil.isEmpty( seq_name ) ) {
\r
888 List<PhylogenyNode> nodes = phy.getNodesViaSequenceName( seq_name );
\r
889 if ( nodes.isEmpty() ) {
\r
890 nodes = phy.getNodesViaSequenceSymbol( seq_name );
\r
892 if ( nodes.isEmpty() ) {
\r
893 nodes = phy.getNodesViaGeneName( seq_name );
\r
895 if ( nodes.isEmpty() ) {
\r
896 nodes = phy.getNodes( seq_name );
\r
898 if ( nodes.size() > 1 ) {
\r
899 JOptionPane.showMessageDialog( this,
\r
900 "Sequence name \"" + seq_name + "\" is not unique",
\r
901 "Sequence name not unique",
\r
902 JOptionPane.ERROR_MESSAGE );
\r
906 final String[] a = seq_name.split( "\\s" );
\r
907 if ( nodes.isEmpty() && ( a.length > 1 ) ) {
\r
908 final String seq_name_split = a[ 0 ];
\r
909 nodes = phy.getNodesViaSequenceName( seq_name_split );
\r
910 if ( nodes.isEmpty() ) {
\r
911 nodes = phy.getNodesViaSequenceSymbol( seq_name_split );
\r
913 if ( nodes.isEmpty() ) {
\r
914 nodes = phy.getNodes( seq_name_split );
\r
916 if ( nodes.size() > 1 ) {
\r
917 JOptionPane.showMessageDialog( this, "Split sequence name \"" + seq_name_split
\r
918 + "\" is not unique", "Sequence name not unique", JOptionPane.ERROR_MESSAGE );
\r
923 if ( nodes.size() == 1 ) {
\r
924 ++attached_counter;
\r
925 final PhylogenyNode n = nodes.get( 0 );
\r
926 if ( !n.getNodeData().isHasSequence() ) {
\r
927 n.getNodeData().addSequence( new org.forester.phylogeny.data.Sequence() );
\r
929 n.getNodeData().getSequence().setMolecularSequence( seq.getMolecularSequenceAsString() );
\r
930 if ( ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
\r
931 n.getNodeData().getSequence().setName( seq_name );
\r
936 if ( attached_counter > 0 ) {
\r
938 int ext_nodes_with_seq = 0;
\r
939 for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
\r
941 final PhylogenyNode n = iter.next();
\r
942 if ( n.getNodeData().isHasSequence()
\r
943 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
\r
944 ++ext_nodes_with_seq;
\r
948 if ( ext_nodes == ext_nodes_with_seq ) {
\r
949 s = "All " + ext_nodes_with_seq + " external nodes now have a molecular sequence attached to them.";
\r
952 s = ext_nodes_with_seq + " out of " + ext_nodes
\r
953 + " external nodes now have a molecular sequence attached to them.";
\r
955 if ( ( attached_counter == total_counter ) && ( ext_nodes == ext_nodes_with_seq ) ) {
\r
956 JOptionPane.showMessageDialog( this,
\r
957 "Attached all " + total_counter + " sequences to tree nodes.\n" + s,
\r
958 "All sequences attached",
\r
959 JOptionPane.INFORMATION_MESSAGE );
\r
962 JOptionPane.showMessageDialog( this, "Attached " + attached_counter
\r
963 + " sequences out of a total of " + total_counter + " sequences.\n" + s, attached_counter
\r
964 + " sequences attached", JOptionPane.WARNING_MESSAGE );
\r
968 JOptionPane.showMessageDialog( this, "No maching tree node for any of the " + total_counter
\r
969 + " sequences", "Could not attach any sequences", JOptionPane.ERROR_MESSAGE );
\r
974 private void closeCurrentPane() {
\r
975 if ( getMainPanel().getCurrentTreePanel() != null ) {
\r
976 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
\r
977 final int r = JOptionPane.showConfirmDialog( this,
\r
978 "Close tab despite potentially unsaved changes?",
\r
980 JOptionPane.YES_NO_OPTION );
\r
981 if ( r != JOptionPane.YES_OPTION ) {
\r
985 getMainPanel().closeCurrentPane();
\r
986 activateSaveAllIfNeeded();
\r
990 private void collapse( final Phylogeny phy ) {
\r
991 final PhylogenyNodeIterator it = phy.iteratorPostorder();
\r
992 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
\r
993 double min_support = Double.MAX_VALUE;
\r
994 boolean conf_present = false;
\r
995 while ( it.hasNext() ) {
\r
996 final PhylogenyNode n = it.next();
\r
997 if ( !n.isExternal() && !n.isRoot() ) {
\r
998 final List<Confidence> c = n.getBranchData().getConfidences();
\r
999 if ( ( c != null ) && ( c.size() > 0 ) ) {
\r
1000 conf_present = true;
\r
1002 for( final Confidence confidence : c ) {
\r
1003 if ( confidence.getValue() > max ) {
\r
1004 max = confidence.getValue();
\r
1007 if ( max < getMinNotCollapseConfidenceValue() ) {
\r
1008 to_be_removed.add( n );
\r
1010 if ( max < min_support ) {
\r
1011 min_support = max;
\r
1016 if ( conf_present ) {
\r
1017 for( final PhylogenyNode node : to_be_removed ) {
\r
1018 PhylogenyMethods.removeNode( node, phy );
\r
1020 if ( to_be_removed.size() > 0 ) {
\r
1021 phy.externalNodesHaveChanged();
\r
1022 phy.clearHashIdToNodeMap();
\r
1023 phy.recalculateNumberOfExternalDescendants( true );
\r
1024 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
\r
1025 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
\r
1026 getCurrentTreePanel().calculateLongestExtNodeInfo();
\r
1027 getCurrentTreePanel().setNodeInPreorderToNull();
\r
1028 getCurrentTreePanel().recalculateMaxDistanceToRoot();
\r
1029 getCurrentTreePanel().resetPreferredSize();
\r
1030 getCurrentTreePanel().setEdited( true );
\r
1031 getCurrentTreePanel().repaint();
\r
1034 if ( to_be_removed.size() > 0 ) {
\r
1035 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
\r
1036 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
\r
1037 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
\r
1040 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
\r
1041 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
\r
1045 JOptionPane.showMessageDialog( this,
\r
1046 "No branch collapsed because no confidence values present",
\r
1047 "No confidence values present",
\r
1048 JOptionPane.INFORMATION_MESSAGE );
\r
1052 private void collapseBelowBranchLengthThreshold() {
\r
1053 if ( getCurrentTreePanel() != null ) {
\r
1054 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1055 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1056 final String s = ( String ) JOptionPane
\r
1057 .showInputDialog( this,
\r
1058 "Please enter the minimum branch length value\n",
\r
1059 "Minimal Branch Length Value",
\r
1060 JOptionPane.QUESTION_MESSAGE,
\r
1063 getMinNotCollapseBlValue() );
\r
1064 if ( !ForesterUtil.isEmpty( s ) ) {
\r
1065 boolean success = true;
\r
1067 final String m_str = s.trim();
\r
1068 if ( !ForesterUtil.isEmpty( m_str ) ) {
\r
1070 m = Double.parseDouble( m_str );
\r
1072 catch ( final Exception ex ) {
\r
1079 if ( success && ( m >= 0.0 ) ) {
\r
1080 setMinNotCollapseBlValue( m );
\r
1081 collapseBl( phy );
\r
1088 private void collapseBelowThreshold() {
\r
1089 if ( getCurrentTreePanel() != null ) {
\r
1090 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1091 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1092 final String s = ( String ) JOptionPane.showInputDialog( this,
\r
1093 "Please enter the minimum confidence value\n",
\r
1094 "Minimal Confidence Value",
\r
1095 JOptionPane.QUESTION_MESSAGE,
\r
1098 getMinNotCollapseConfidenceValue() );
\r
1099 if ( !ForesterUtil.isEmpty( s ) ) {
\r
1100 boolean success = true;
\r
1102 final String m_str = s.trim();
\r
1103 if ( !ForesterUtil.isEmpty( m_str ) ) {
\r
1105 m = Double.parseDouble( m_str );
\r
1107 catch ( final Exception ex ) {
\r
1114 if ( success && ( m >= 0.0 ) ) {
\r
1115 setMinNotCollapseConfidenceValue( m );
\r
1123 private void collapseBl( final Phylogeny phy ) {
\r
1124 final PhylogenyNodeIterator it = phy.iteratorPostorder();
\r
1125 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
\r
1126 double min_bl = Double.MAX_VALUE;
\r
1127 boolean bl_present = false;
\r
1128 while ( it.hasNext() ) {
\r
1129 final PhylogenyNode n = it.next();
\r
1130 if ( !n.isExternal() && !n.isRoot() ) {
\r
1131 final double bl = n.getDistanceToParent();
\r
1132 if ( bl != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
\r
1133 bl_present = true;
\r
1134 if ( bl < getMinNotCollapseBlValue() ) {
\r
1135 to_be_removed.add( n );
\r
1137 if ( bl < min_bl ) {
\r
1143 if ( bl_present ) {
\r
1144 for( final PhylogenyNode node : to_be_removed ) {
\r
1145 PhylogenyMethods.removeNode( node, phy );
\r
1147 if ( to_be_removed.size() > 0 ) {
\r
1148 phy.externalNodesHaveChanged();
\r
1149 phy.clearHashIdToNodeMap();
\r
1150 phy.recalculateNumberOfExternalDescendants( true );
\r
1151 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
\r
1152 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
\r
1153 getCurrentTreePanel().calculateLongestExtNodeInfo();
\r
1154 getCurrentTreePanel().setNodeInPreorderToNull();
\r
1155 getCurrentTreePanel().recalculateMaxDistanceToRoot();
\r
1156 getCurrentTreePanel().resetPreferredSize();
\r
1157 getCurrentTreePanel().setEdited( true );
\r
1158 getCurrentTreePanel().repaint();
\r
1161 if ( to_be_removed.size() > 0 ) {
\r
1162 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
\r
1163 + " branches with\nbranch length values below " + getMinNotCollapseBlValue(), "Collapsed "
\r
1164 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
\r
1167 JOptionPane.showMessageDialog( this,
\r
1168 "No branch collapsed,\nminimum branch length is " + min_bl,
\r
1169 "No branch collapsed",
\r
1170 JOptionPane.INFORMATION_MESSAGE );
\r
1174 JOptionPane.showMessageDialog( this,
\r
1175 "No branch collapsed because no branch length values present",
\r
1176 "No branch length values present",
\r
1177 JOptionPane.INFORMATION_MESSAGE );
\r
1181 private PhyloXmlParser createPhyloXmlParser() {
\r
1182 PhyloXmlParser xml_parser = null;
\r
1183 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
\r
1185 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
\r
1187 catch ( final Exception e ) {
\r
1188 JOptionPane.showMessageDialog( this,
\r
1189 e.getLocalizedMessage(),
\r
1190 "failed to create validating XML parser",
\r
1191 JOptionPane.WARNING_MESSAGE );
\r
1194 if ( xml_parser == null ) {
\r
1195 xml_parser = PhyloXmlParser.createPhyloXmlParser();
\r
1197 return xml_parser;
\r
1200 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
\r
1201 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
\r
1202 getPhylogeneticInferenceOptions(),
\r
1203 from_unaligned_seqs );
\r
1204 dialog.activate();
\r
1205 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
\r
1206 if ( !from_unaligned_seqs ) {
\r
1207 if ( getMsa() != null ) {
\r
1208 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
\r
1209 getPhylogeneticInferenceOptions()
\r
1211 new Thread( inferrer ).start();
\r
1214 JOptionPane.showMessageDialog( this,
\r
1215 "No multiple sequence alignment selected",
\r
1216 "Phylogenetic Inference Not Launched",
\r
1217 JOptionPane.WARNING_MESSAGE );
\r
1221 if ( getSeqs() != null ) {
\r
1222 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
\r
1223 getPhylogeneticInferenceOptions()
\r
1225 new Thread( inferrer ).start();
\r
1228 JOptionPane.showMessageDialog( this,
\r
1229 "No input sequences selected",
\r
1230 "Phylogenetic Inference Not Launched",
\r
1231 JOptionPane.WARNING_MESSAGE );
\r
1237 private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
\r
1238 final StringBuilder sb = new StringBuilder();
\r
1239 final StringBuilder sb_failed = new StringBuilder();
\r
1241 int counter_failed = 0;
\r
1242 if ( getCurrentTreePanel() != null ) {
\r
1243 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1244 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1245 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
\r
1246 while ( it.hasNext() ) {
\r
1247 final PhylogenyNode n = it.next();
\r
1248 final String name = n.getName().trim();
\r
1249 if ( !ForesterUtil.isEmpty( name ) ) {
\r
1250 final String nt = ParserUtils.extractTaxonomyDataFromNodeName( n,
\r
1251 TAXONOMY_EXTRACTION.AGGRESSIVE );
\r
1252 if ( !ForesterUtil.isEmpty( nt ) ) {
\r
1253 if ( counter < 15 ) {
\r
1254 sb.append( name + ": " + nt + "\n" );
\r
1256 else if ( counter == 15 ) {
\r
1257 sb.append( "...\n" );
\r
1262 if ( counter_failed < 15 ) {
\r
1263 sb_failed.append( name + "\n" );
\r
1265 else if ( counter_failed == 15 ) {
\r
1266 sb_failed.append( "...\n" );
\r
1272 if ( counter > 0 ) {
\r
1273 String failed = "";
\r
1274 String all = "all ";
\r
1275 if ( counter_failed > 0 ) {
\r
1277 failed = "\nCould not extract taxonomic data for " + counter_failed
\r
1278 + " named external nodes:\n" + sb_failed;
\r
1280 JOptionPane.showMessageDialog( this,
\r
1281 "Extracted taxonomic data from " + all + counter
\r
1282 + " named external nodes:\n" + sb.toString() + failed,
\r
1283 "Taxonomic Data Extraction Completed",
\r
1284 counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
\r
1285 : JOptionPane.INFORMATION_MESSAGE );
\r
1289 .showMessageDialog( this,
\r
1290 "Could not extract any taxonomic data.\nMaybe node names are empty\n"
\r
1291 + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
\r
1292 + "or nodes already have taxonomic data?\n",
\r
1293 "No Taxonomic Data Extracted",
\r
1294 JOptionPane.ERROR_MESSAGE );
\r
1300 private double getMinNotCollapseBlValue() {
\r
1301 return _min_not_collapse_bl;
\r
1304 private double getMinNotCollapseConfidenceValue() {
\r
1305 return _min_not_collapse;
\r
1308 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
\r
1309 if ( _phylogenetic_inference_options == null ) {
\r
1310 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
\r
1312 return _phylogenetic_inference_options;
\r
1315 private boolean isUnsavedDataPresent() {
\r
1316 final List<TreePanel> tps = getMainPanel().getTreePanels();
\r
1317 for( final TreePanel tp : tps ) {
\r
1318 if ( tp.isEdited() ) {
\r
1325 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
\r
1326 if ( getCurrentTreePanel() != null ) {
\r
1327 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1328 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1330 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
\r
1335 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
\r
1336 if ( getCurrentTreePanel() != null ) {
\r
1337 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1338 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1339 PhylogenyMethods.transferNodeNameToField( phy,
\r
1340 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
\r
1346 private void newTree() {
\r
1347 final Phylogeny[] phys = new Phylogeny[ 1 ];
\r
1348 final Phylogeny phy = new Phylogeny();
\r
1349 final PhylogenyNode node = new PhylogenyNode();
\r
1350 phy.setRoot( node );
\r
1351 phy.setRooted( true );
\r
1353 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
\r
1354 _mainpanel.getControlPanel().showWhole();
\r
1355 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
\r
1356 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
\r
1357 if ( getMainPanel().getMainFrame() == null ) {
\r
1358 // Must be "E" applet version.
\r
1359 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
\r
1360 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
\r
1363 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
\r
1365 activateSaveAllIfNeeded();
\r
1369 private void obtainDetailedTaxonomicInformation() {
\r
1370 if ( getCurrentTreePanel() != null ) {
\r
1371 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1372 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1373 final TaxonomyDataManager t = new TaxonomyDataManager( this,
\r
1374 _mainpanel.getCurrentTreePanel(),
\r
1378 new Thread( t ).start();
\r
1383 private void obtainDetailedTaxonomicInformationDelete() {
\r
1384 if ( getCurrentTreePanel() != null ) {
\r
1385 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1386 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1387 final TaxonomyDataManager t = new TaxonomyDataManager( this,
\r
1388 _mainpanel.getCurrentTreePanel(),
\r
1392 new Thread( t ).start();
\r
1397 private void obtainSequenceInformation() {
\r
1398 if ( getCurrentTreePanel() != null ) {
\r
1399 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
\r
1400 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1401 final SequenceDataRetriver u = new SequenceDataRetriver( this,
\r
1402 _mainpanel.getCurrentTreePanel(),
\r
1404 new Thread( u ).start();
\r
1409 private void preProcessTreesUponReading( final Phylogeny[] phys ) {
\r
1410 for( final Phylogeny phy : phys ) {
\r
1411 if ( ( phy != null ) && !phy.isEmpty() ) {
\r
1412 for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
\r
1413 final PhylogenyNode n = it.next();
\r
1414 if ( n.isExternal() ) {
\r
1415 if ( n.getNodeData().isHasSequence() ) {
\r
1416 final Sequence s = n.getNodeData().getSequence();
\r
1417 if ( ForesterUtil.isEmpty( s.getGeneName() ) || s.getGeneName().startsWith( "LOC" ) ) {
\r
1418 if ( ( s.getAccession() != null )
\r
1419 && !ForesterUtil.isEmpty( s.getAccession().getValue() ) ) {
\r
1420 s.setGeneName( s.getAccession().getValue() );
\r
1422 else if ( !ForesterUtil.isEmpty( n.getName() ) ) {
\r
1423 s.setGeneName( n.getName() );
\r
1433 private void readPhylogeniesFromFile() {
\r
1434 boolean exception = false;
\r
1435 Phylogeny[] phys = null;
\r
1436 // Set an initial directory if none set yet
\r
1437 final File my_dir = getCurrentDir();
\r
1438 // Open file-open dialog and set current directory
\r
1439 if ( my_dir != null ) {
\r
1440 _open_filechooser.setCurrentDirectory( my_dir );
\r
1442 final int result = _open_filechooser.showOpenDialog( _contentpane );
\r
1443 // All done: get the file
\r
1444 final File[] files = _open_filechooser.getSelectedFiles();
\r
1445 setCurrentDir( _open_filechooser.getCurrentDirectory() );
\r
1446 boolean nhx_or_nexus = false;
\r
1447 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
\r
1448 for( final File file : files ) {
\r
1449 if ( ( file != null ) && !file.isDirectory() ) {
\r
1450 if ( _mainpanel.getCurrentTreePanel() != null ) {
\r
1451 _mainpanel.getCurrentTreePanel().setWaitCursor();
\r
1454 _mainpanel.setWaitCursor();
\r
1456 if ( ( _open_filechooser.getFileFilter() == MainFrame.nhfilter )
\r
1457 || ( _open_filechooser.getFileFilter() == MainFrame.nhxfilter ) ) {
\r
1459 final NHXParser nhx = new NHXParser();
\r
1460 setSpecialOptionsForNhxParser( nhx );
\r
1461 phys = PhylogenyMethods.readPhylogenies( nhx, file );
\r
1462 nhx_or_nexus = true;
\r
1464 catch ( final Exception e ) {
\r
1466 exceptionOccuredDuringOpenFile( e );
\r
1469 else if ( _open_filechooser.getFileFilter() == MainFrame.xmlfilter ) {
\r
1470 warnIfNotPhyloXmlValidation( getConfiguration() );
\r
1472 final PhyloXmlParser xml_parser = createPhyloXmlParser();
\r
1473 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
\r
1475 catch ( final Exception e ) {
\r
1477 exceptionOccuredDuringOpenFile( e );
\r
1480 else if ( _open_filechooser.getFileFilter() == MainFrame.tolfilter ) {
\r
1482 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
\r
1484 catch ( final Exception e ) {
\r
1486 exceptionOccuredDuringOpenFile( e );
\r
1489 else if ( _open_filechooser.getFileFilter() == MainFrame.nexusfilter ) {
\r
1491 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
\r
1492 setSpecialOptionsForNexParser( nex );
\r
1493 phys = PhylogenyMethods.readPhylogenies( nex, file );
\r
1494 nhx_or_nexus = true;
\r
1496 catch ( final Exception e ) {
\r
1498 exceptionOccuredDuringOpenFile( e );
\r
1504 final PhylogenyParser parser = ParserUtils
\r
1505 .createParserDependingOnFileType( file, getConfiguration()
\r
1506 .isValidatePhyloXmlAgainstSchema() );
\r
1507 if ( parser instanceof NexusPhylogeniesParser ) {
\r
1508 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
\r
1509 setSpecialOptionsForNexParser( nex );
\r
1510 nhx_or_nexus = true;
\r
1512 else if ( parser instanceof NHXParser ) {
\r
1513 final NHXParser nhx = ( NHXParser ) parser;
\r
1514 setSpecialOptionsForNhxParser( nhx );
\r
1515 nhx_or_nexus = true;
\r
1517 else if ( parser instanceof PhyloXmlParser ) {
\r
1518 warnIfNotPhyloXmlValidation( getConfiguration() );
\r
1520 phys = PhylogenyMethods.readPhylogenies( parser, file );
\r
1522 catch ( final Exception e ) {
\r
1524 exceptionOccuredDuringOpenFile( e );
\r
1527 if ( _mainpanel.getCurrentTreePanel() != null ) {
\r
1528 _mainpanel.getCurrentTreePanel().setArrowCursor();
\r
1531 _mainpanel.setArrowCursor();
\r
1533 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
\r
1534 boolean one_desc = false;
\r
1535 if ( nhx_or_nexus ) {
\r
1536 for( final Phylogeny phy : phys ) {
\r
1537 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
\r
1538 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
\r
1540 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
\r
1546 if ( PREPROCESS_TREES ) {
\r
1547 preProcessTreesUponReading( phys );
\r
1549 AptxUtil.addPhylogeniesToTabs( phys,
\r
1551 file.getAbsolutePath(),
\r
1552 getConfiguration(),
\r
1554 _mainpanel.getControlPanel().showWhole();
\r
1555 if ( nhx_or_nexus && one_desc ) {
\r
1557 .showMessageDialog( this,
\r
1558 "One or more trees contain (a) node(s) with one descendant, "
\r
1559 + ForesterUtil.LINE_SEPARATOR
\r
1560 + "possibly indicating illegal parentheses within node names.",
\r
1561 "Warning: Possible Error in New Hampshire Formatted Data",
\r
1562 JOptionPane.WARNING_MESSAGE );
\r
1568 activateSaveAllIfNeeded();
\r
1572 private void readSpeciesTreeFromFile() {
\r
1573 Phylogeny t = null;
\r
1574 boolean exception = false;
\r
1575 final File my_dir = getCurrentDir();
\r
1576 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
\r
1577 if ( my_dir != null ) {
\r
1578 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
\r
1580 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
\r
1581 final File file = _open_filechooser_for_species_tree.getSelectedFile();
\r
1582 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
\r
1583 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrame.xmlfilter ) {
\r
1585 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser
\r
1586 .createPhyloXmlParserXsdValidating(), file );
\r
1589 catch ( final Exception e ) {
\r
1591 exceptionOccuredDuringOpenFile( e );
\r
1594 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrame.tolfilter ) {
\r
1596 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
\r
1599 catch ( final Exception e ) {
\r
1601 exceptionOccuredDuringOpenFile( e );
\r
1607 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser
\r
1608 .createPhyloXmlParserXsdValidating(), file );
\r
1611 catch ( final Exception e ) {
\r
1613 exceptionOccuredDuringOpenFile( e );
\r
1616 if ( !exception && ( t != null ) && !t.isRooted() ) {
\r
1619 JOptionPane.showMessageDialog( this,
\r
1620 "Species tree is not rooted",
\r
1621 "Species tree not loaded",
\r
1622 JOptionPane.ERROR_MESSAGE );
\r
1624 if ( !exception && ( t != null ) ) {
\r
1625 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
\r
1626 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
\r
1627 final PhylogenyNode node = it.next();
\r
1628 if ( !node.getNodeData().isHasTaxonomy() ) {
\r
1632 .showMessageDialog( this,
\r
1633 "Species tree contains external node(s) without taxonomy information",
\r
1634 "Species tree not loaded",
\r
1635 JOptionPane.ERROR_MESSAGE );
\r
1639 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
\r
1642 JOptionPane.showMessageDialog( this,
\r
1644 + node.getNodeData().getTaxonomy().asSimpleText()
\r
1645 + "] is not unique in species tree",
\r
1646 "Species tree not loaded",
\r
1647 JOptionPane.ERROR_MESSAGE );
\r
1651 tax_set.add( node.getNodeData().getTaxonomy() );
\r
1656 if ( !exception && ( t != null ) ) {
\r
1657 setSpeciesTree( t );
\r
1658 JOptionPane.showMessageDialog( this,
\r
1659 "Species tree successfully loaded",
\r
1660 "Species tree loaded",
\r
1661 JOptionPane.INFORMATION_MESSAGE );
\r
1663 _contentpane.repaint();
\r
1668 private void setArrowCursor() {
\r
1670 _mainpanel.getCurrentTreePanel().setArrowCursor();
\r
1672 catch ( final Exception ex ) {
\r
1677 private void setMinNotCollapseBlValue( final double min_not_collapse_bl ) {
\r
1678 _min_not_collapse_bl = min_not_collapse_bl;
\r
1681 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
\r
1682 _min_not_collapse = min_not_collapse;
\r
1685 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
\r
1686 _phylogenetic_inference_options = phylogenetic_inference_options;
\r
1689 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
\r
1690 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
\r
1691 nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
\r
1694 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
\r
1695 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
\r
1696 nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
\r
1697 nhx.setAllowErrorsInDistanceToParent( getOptions().isAllowErrorsInDistanceToParent() );
\r
1700 void buildAnalysisMenu() {
\r
1701 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
\r
1702 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
\r
1703 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
\r
1704 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
\r
1705 customizeJMenuItem( _gsdi_item );
\r
1706 customizeJMenuItem( _gsdir_item );
\r
1707 customizeJMenuItem( _load_species_tree_item );
\r
1708 _analysis_menu.addSeparator();
\r
1709 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
\r
1710 customizeJMenuItem( _lineage_inference );
\r
1711 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
\r
1712 _jmenubar.add( _analysis_menu );
\r
1716 void buildFileMenu() {
\r
1717 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
\r
1718 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
\r
1719 _file_jmenu.addSeparator();
\r
1720 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
\r
1721 _file_jmenu.addSeparator();
\r
1722 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
\r
1723 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
\r
1724 .getAvailablePhylogeniesWebserviceClients().size() ];
\r
1725 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
\r
1726 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
\r
1727 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
\r
1728 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
\r
1730 if ( getConfiguration().isEditable() ) {
\r
1731 _file_jmenu.addSeparator();
\r
1732 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
\r
1733 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
\r
1735 _file_jmenu.addSeparator();
\r
1736 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
\r
1737 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
\r
1738 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
\r
1739 _save_all_item.setEnabled( false );
\r
1740 _file_jmenu.addSeparator();
\r
1741 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
\r
1742 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
\r
1743 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
\r
1745 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
\r
1746 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
\r
1747 if ( AptxUtil.canWriteFormat( "gif" ) ) {
\r
1748 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
\r
1750 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
\r
1751 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
\r
1753 _file_jmenu.addSeparator();
\r
1754 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
\r
1755 _file_jmenu.addSeparator();
\r
1756 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
\r
1757 _close_item.setToolTipText( "To close the current pane." );
\r
1758 _close_item.setEnabled( true );
\r
1759 _file_jmenu.addSeparator();
\r
1760 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
\r
1761 customizeJMenuItem( _open_item );
\r
1763 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
\r
1764 customizeJMenuItem( _open_url_item );
\r
1765 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
\r
1766 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
\r
1768 customizeJMenuItem( _save_item );
\r
1769 if ( getConfiguration().isEditable() ) {
\r
1770 customizeJMenuItem( _new_item );
\r
1772 customizeJMenuItem( _close_item );
\r
1773 customizeJMenuItem( _save_all_item );
\r
1774 customizeJMenuItem( _write_to_pdf_item );
\r
1775 customizeJMenuItem( _write_to_png_item );
\r
1776 customizeJMenuItem( _write_to_jpg_item );
\r
1777 customizeJMenuItem( _write_to_gif_item );
\r
1778 customizeJMenuItem( _write_to_tif_item );
\r
1779 customizeJMenuItem( _write_to_bmp_item );
\r
1780 customizeJMenuItem( _print_item );
\r
1781 customizeJMenuItem( _exit_item );
\r
1782 _jmenubar.add( _file_jmenu );
\r
1785 void buildOptionsMenu() {
\r
1786 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
\r
1787 _options_jmenu.addChangeListener( new ChangeListener() {
\r
1790 public void stateChanged( final ChangeEvent e ) {
\r
1791 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
\r
1792 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
\r
1794 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
\r
1795 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
\r
1796 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
\r
1797 MainFrame.setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
\r
1798 MainFrame.setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
\r
1799 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
\r
1800 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
\r
1801 MainFrame.setCycleDataReturnMenuItem( _cycle_data_return, getOptions() );
\r
1802 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
\r
1804 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
\r
1805 getMainPanel().getControlPanel().setVisibilityOfX();
\r
1807 catch ( final Exception ignore ) {
\r
1808 // do nothing, not important.
\r
1812 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
\r
1814 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
\r
1815 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
\r
1816 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
\r
1817 _radio_group_1 = new ButtonGroup();
\r
1818 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
\r
1819 _radio_group_1.add( _uniform_cladograms_rbmi );
\r
1820 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
\r
1821 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
\r
1822 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
\r
1824 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) );
\r
1826 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) );
\r
1828 .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) );
\r
1829 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
\r
1830 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
\r
1831 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
\r
1832 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
\r
1834 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) );
\r
1835 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
\r
1836 _options_jmenu.add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( COLOR_BY_TAXONOMIC_GROUP ) );
\r
1837 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
\r
1838 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
\r
1839 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
\r
1840 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
\r
1841 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
\r
1842 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
\r
1843 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
\r
1844 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
\r
1845 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
\r
1846 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
\r
1847 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
\r
1848 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
\r
1849 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
\r
1850 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
\r
1851 _options_jmenu.addSeparator();
\r
1852 _options_jmenu.add( _cycle_data_return = new JMenuItem( "Cycle Data Return" ) );
\r
1853 _options_jmenu.addSeparator();
\r
1854 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
\r
1855 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
\r
1856 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
\r
1857 _options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
\r
1858 _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP );
\r
1859 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
\r
1860 _options_jmenu.addSeparator();
\r
1861 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
\r
1862 getConfiguration() ) );
\r
1863 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
\r
1864 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
\r
1866 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
\r
1868 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
\r
1870 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
\r
1871 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
\r
1872 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
\r
1873 _options_jmenu.addSeparator();
\r
1874 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
\r
1876 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
\r
1877 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
\r
1879 .add( _allow_errors_in_distance_to_parent_cbmi = new JCheckBoxMenuItem( "Ignore Distance Values Format Errors" ) );
\r
1880 _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
\r
1882 .add( _extract_taxonomy_pfam_strict_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style Node Names" ) );
\r
1884 .add( _extract_taxonomy_pfam_relaxed_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style like Node Names" ) );
\r
1886 .add( _extract_taxonomy_agressive_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids/Scientific Names from Node Names" ) );
\r
1887 _extract_taxonomy_pfam_strict_rbmi
\r
1888 .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"BCL2_MOUSE/123-304\" or \"BCL2_10090/123-304\"" );
\r
1889 _extract_taxonomy_pfam_relaxed_rbmi
\r
1890 .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"bax_MOUSE\" or \"bax_10090\"" );
\r
1891 _extract_taxonomy_agressive_rbmi
\r
1892 .setToolTipText( "To extract taxonomy codes/ids or scientific names from node names in the form of e.g. \"MOUSE\" or \"10090\" or \"xyz_Nematostella_vectensis\"" );
\r
1893 _radio_group_2 = new ButtonGroup();
\r
1894 _radio_group_2.add( _extract_taxonomy_no_rbmi );
\r
1895 _radio_group_2.add( _extract_taxonomy_pfam_strict_rbmi );
\r
1896 _radio_group_2.add( _extract_taxonomy_pfam_relaxed_rbmi );
\r
1897 _radio_group_2.add( _extract_taxonomy_agressive_rbmi );
\r
1898 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
\r
1900 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
\r
1901 _use_brackets_for_conf_in_nh_export_cbmi
\r
1902 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
\r
1904 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
\r
1905 customizeJMenuItem( _choose_font_mi );
\r
1906 customizeJMenuItem( _choose_minimal_confidence_mi );
\r
1907 customizeJMenuItem( _switch_colors_mi );
\r
1908 customizeJMenuItem( _print_size_mi );
\r
1909 customizeJMenuItem( _choose_pdf_width_mi );
\r
1910 customizeJMenuItem( _overview_placment_mi );
\r
1911 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
\r
1912 .isShowDefaultNodeShapesExternal() );
\r
1913 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
\r
1914 .isShowDefaultNodeShapesInternal() );
\r
1915 customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
\r
1916 .isShowDefaultNodeShapesForMarkedNodes() );
\r
1917 customizeJMenuItem( _cycle_node_shape_mi );
\r
1918 customizeJMenuItem( _cycle_node_fill_mi );
\r
1919 customizeJMenuItem( _choose_node_size_mi );
\r
1920 customizeJMenuItem( _cycle_data_return );
\r
1921 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
\r
1922 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
\r
1923 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
\r
1924 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
\r
1925 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
\r
1926 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
\r
1927 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
\r
1928 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
\r
1929 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
\r
1930 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
\r
1931 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
\r
1932 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
\r
1933 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
\r
1934 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
\r
1935 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
\r
1936 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
\r
1937 customizeCheckBoxMenuItem( _label_direction_cbmi,
\r
1938 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
\r
1939 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
\r
1940 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
\r
1941 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
\r
1942 .isInternalNumberAreConfidenceForNhParsing() );
\r
1943 customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
\r
1944 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
\r
1945 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_strict_rbmi,
\r
1946 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
\r
1947 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_relaxed_rbmi,
\r
1948 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
\r
1949 customizeRadioButtonMenuItem( _extract_taxonomy_agressive_rbmi,
\r
1950 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.AGGRESSIVE );
\r
1951 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
\r
1952 customizeCheckBoxMenuItem( _allow_errors_in_distance_to_parent_cbmi, getOptions()
\r
1953 .isReplaceUnderscoresInNhParsing() );
\r
1954 customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
\r
1955 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
\r
1956 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
\r
1957 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
\r
1958 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
\r
1959 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
\r
1960 .isGraphicsExportUsingActualSize() );
\r
1961 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
\r
1962 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
\r
1963 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
\r
1964 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
\r
1965 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
\r
1966 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
\r
1967 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
\r
1968 _jmenubar.add( _options_jmenu );
\r
1971 void buildPhylogeneticInferenceMenu() {
\r
1972 final InferenceManager im = getInferenceManager();
\r
1973 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
\r
1974 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
\r
1975 customizeJMenuItem( _inference_from_msa_item );
\r
1976 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
\r
1977 if ( im.canDoMsa() ) {
\r
1978 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
\r
1979 customizeJMenuItem( _inference_from_seqs_item );
\r
1980 _inference_from_seqs_item
\r
1981 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
\r
1985 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
\r
1986 customizeJMenuItem( _inference_from_seqs_item );
\r
1987 _inference_from_seqs_item.setEnabled( false );
\r
1989 _jmenubar.add( _inference_menu );
\r
1992 void buildToolsMenu() {
\r
1993 _tools_menu = createMenu( "Tools", getConfiguration() );
\r
1994 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
\r
1995 customizeJMenuItem( _confcolor_item );
\r
1996 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
\r
1997 customizeJMenuItem( _color_rank_jmi );
\r
1998 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
\r
1999 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
\r
2000 customizeJMenuItem( _taxcolor_item );
\r
2001 _tools_menu.addSeparator();
\r
2002 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
\r
2003 _remove_visual_styles_item
\r
2004 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny" );
\r
2005 customizeJMenuItem( _remove_visual_styles_item );
\r
2006 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
\r
2007 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny" );
\r
2008 customizeJMenuItem( _remove_branch_color_item );
\r
2009 _tools_menu.addSeparator();
\r
2010 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
\r
2011 customizeJMenuItem( _annotate_item );
\r
2012 _tools_menu.addSeparator();
\r
2013 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
\r
2014 customizeJMenuItem( _midpoint_root_item );
\r
2015 _tools_menu.addSeparator();
\r
2016 _tools_menu.add( _delete_selected_nodes_item = new JMenuItem( "Delete Selected Nodes" ) );
\r
2017 _delete_selected_nodes_item.setToolTipText( "To delete all selected external nodes" );
\r
2018 customizeJMenuItem( _delete_selected_nodes_item );
\r
2019 _tools_menu.add( _delete_not_selected_nodes_item = new JMenuItem( "Retain Selected Nodes" ) );
\r
2020 _delete_not_selected_nodes_item.setToolTipText( "To delete all not selected external nodes" );
\r
2021 customizeJMenuItem( _delete_not_selected_nodes_item );
\r
2022 _tools_menu.addSeparator();
\r
2023 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
\r
2024 customizeJMenuItem( _collapse_species_specific_subtrees );
\r
2025 _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse species-specific subtrees" );
\r
2027 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
\r
2028 customizeJMenuItem( _collapse_below_threshold );
\r
2029 _collapse_below_threshold
\r
2030 .setToolTipText( "To (permanently) collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );
\r
2033 .add( _collapse_below_branch_length = new JMenuItem( "Collapse Branches with Branch Lengths Below Threshold into Multifurcations" ) );
\r
2034 customizeJMenuItem( _collapse_below_branch_length );
\r
2035 _collapse_below_branch_length
\r
2036 .setToolTipText( "To (permanently) collapse branches with branches with branch lengths below a threshold into multifurcations" );
\r
2038 _tools_menu.addSeparator();
\r
2040 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );
\r
2041 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
\r
2042 _extract_tax_code_from_node_names_jmi
\r
2043 .setToolTipText( "To extract SwissProt/Uniprot taxonomic codes (mnemonics) from nodes names in the form of 'xyz_CAEEL', Uniprot/NCBI identifiers form of 'xyz_6239', or scientific names form of 'xyz_Caenorhabditis_elegans'" );
\r
2045 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
\r
2046 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
\r
2047 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
\r
2048 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
\r
2049 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
\r
2050 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
\r
2051 _tools_menu.addSeparator();
\r
2052 _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
\r
2053 customizeJMenuItem( _obtain_seq_information_jmi );
\r
2054 _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
\r
2056 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
\r
2057 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
\r
2058 _obtain_detailed_taxonomic_information_jmi
\r
2059 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
\r
2061 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
\r
2062 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
\r
2063 _obtain_detailed_taxonomic_information_deleting_jmi
\r
2064 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
\r
2065 _tools_menu.addSeparator();
\r
2066 _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) );
\r
2067 customizeJMenuItem( _read_values_jmi );
\r
2068 _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" );
\r
2069 _jmenubar.add( _tools_menu );
\r
2070 _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) );
\r
2071 customizeJMenuItem( _read_seqs_jmi );
\r
2073 .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" );
\r
2074 _jmenubar.add( _tools_menu );
\r
2079 if ( isUnsavedDataPresent() ) {
\r
2080 final int r = JOptionPane.showConfirmDialog( this,
\r
2081 "Exit despite potentially unsaved changes?",
\r
2083 JOptionPane.YES_NO_OPTION );
\r
2084 if ( r != JOptionPane.YES_OPTION ) {
\r
2091 void executeLineageInference() {
\r
2092 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
\r
2095 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
\r
2096 JOptionPane.showMessageDialog( this,
\r
2097 "Phylogeny is not rooted.",
\r
2098 "Cannot infer ancestral taxonomies",
\r
2099 JOptionPane.ERROR_MESSAGE );
\r
2102 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
\r
2103 _mainpanel.getCurrentTreePanel(),
\r
2104 _mainpanel.getCurrentPhylogeny()
\r
2106 new Thread( inferrer ).start();
\r
2110 removeAllTextFrames();
\r
2111 _mainpanel.terminate();
\r
2112 _contentpane.removeAll();
\r
2113 setVisible( false );
\r
2115 // System.exit( 0 ); //TODO reconfirm that this is OK, then remove.
\r
2118 void readPhylogeniesFromURL() {
\r
2120 Phylogeny[] phys = null;
\r
2121 final String message = "Please enter a complete URL, for example \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";
\r
2122 final String url_string = JOptionPane.showInputDialog( this,
\r
2124 "Use URL/webservice to obtain a phylogeny",
\r
2125 JOptionPane.QUESTION_MESSAGE );
\r
2126 boolean nhx_or_nexus = false;
\r
2127 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
\r
2129 url = new URL( url_string );
\r
2130 PhylogenyParser parser = null;
\r
2131 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
\r
2132 parser = new TolParser();
\r
2135 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
\r
2136 .isValidatePhyloXmlAgainstSchema() );
\r
2138 if ( parser instanceof NexusPhylogeniesParser ) {
\r
2139 nhx_or_nexus = true;
\r
2141 else if ( parser instanceof NHXParser ) {
\r
2142 nhx_or_nexus = true;
\r
2144 if ( _mainpanel.getCurrentTreePanel() != null ) {
\r
2145 _mainpanel.getCurrentTreePanel().setWaitCursor();
\r
2148 _mainpanel.setWaitCursor();
\r
2150 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
\r
2151 phys = factory.create( url.openStream(), parser );
\r
2153 catch ( final MalformedURLException e ) {
\r
2154 JOptionPane.showMessageDialog( this,
\r
2155 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
\r
2157 JOptionPane.ERROR_MESSAGE );
\r
2159 catch ( final IOException e ) {
\r
2160 JOptionPane.showMessageDialog( this,
\r
2161 "Could not read from " + url + "\n"
\r
2162 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
\r
2163 "Failed to read URL",
\r
2164 JOptionPane.ERROR_MESSAGE );
\r
2166 catch ( final Exception e ) {
\r
2167 JOptionPane.showMessageDialog( this,
\r
2168 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
\r
2169 "Unexpected Exception",
\r
2170 JOptionPane.ERROR_MESSAGE );
\r
2173 if ( _mainpanel.getCurrentTreePanel() != null ) {
\r
2174 _mainpanel.getCurrentTreePanel().setArrowCursor();
\r
2177 _mainpanel.setArrowCursor();
\r
2180 if ( ( phys != null ) && ( phys.length > 0 ) ) {
\r
2181 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
\r
2182 for( final Phylogeny phy : phys ) {
\r
2183 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );
\r
2186 AptxUtil.addPhylogeniesToTabs( phys,
\r
2187 new File( url.getFile() ).getName(),
\r
2188 new File( url.getFile() ).toString(),
\r
2189 getConfiguration(),
\r
2191 _mainpanel.getControlPanel().showWhole();
\r
2194 activateSaveAllIfNeeded();
\r
2198 void setMsa( final Msa msa ) {
\r
2202 void setMsaFile( final File msa_file ) {
\r
2203 _msa_file = msa_file;
\r
2206 void setSeqs( final List<MolecularSequence> seqs ) {
\r
2210 void setSeqsFile( final File seqs_file ) {
\r
2211 _seqs_file = seqs_file;
\r
2214 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
\r
2215 return new MainFrameApplication( phys, config );
\r
2218 public static MainFrame createInstance( final Phylogeny[] phys,
\r
2219 final Configuration config,
\r
2220 final String title,
\r
2221 final File current_dir ) {
\r
2222 return new MainFrameApplication( phys, config, title, current_dir );
\r
2225 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
\r
2226 return new MainFrameApplication( phys, config, title );
\r
2229 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
\r
2230 return new MainFrameApplication( phys, config_file_name, title );
\r
2233 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
\r
2234 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
\r
2236 .showMessageDialog( null,
\r
2238 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
\r
2241 JOptionPane.WARNING_MESSAGE );
\r
2244 } // MainFrameApplication.
\r