2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.archaeopteryx;
29 import java.awt.BorderLayout;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.net.MalformedURLException;
42 import java.util.ArrayList;
43 import java.util.HashSet;
44 import java.util.List;
47 import javax.swing.ButtonGroup;
48 import javax.swing.JCheckBoxMenuItem;
49 import javax.swing.JFileChooser;
50 import javax.swing.JMenu;
51 import javax.swing.JMenuBar;
52 import javax.swing.JMenuItem;
53 import javax.swing.JOptionPane;
54 import javax.swing.JRadioButtonMenuItem;
55 import javax.swing.UIManager;
56 import javax.swing.UnsupportedLookAndFeelException;
57 import javax.swing.WindowConstants;
58 import javax.swing.event.ChangeEvent;
59 import javax.swing.event.ChangeListener;
60 import javax.swing.filechooser.FileFilter;
61 import javax.swing.plaf.synth.SynthLookAndFeel;
63 import org.forester.analysis.TaxonomyDataManager;
64 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
65 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
66 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
67 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
68 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
69 import org.forester.archaeopteryx.tools.GoAnnotation;
70 import org.forester.archaeopteryx.tools.InferenceManager;
71 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
72 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
73 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
74 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
75 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
76 import org.forester.archaeopteryx.webservices.WebservicesManager;
77 import org.forester.io.parsers.FastaParser;
78 import org.forester.io.parsers.GeneralMsaParser;
79 import org.forester.io.parsers.PhylogenyParser;
80 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
81 import org.forester.io.parsers.nhx.NHXParser;
82 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
83 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
84 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
85 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
86 import org.forester.io.parsers.tol.TolParser;
87 import org.forester.io.parsers.util.ParserUtils;
88 import org.forester.io.writers.PhylogenyWriter;
89 import org.forester.io.writers.SequenceWriter;
90 import org.forester.msa.Msa;
91 import org.forester.msa.MsaFormatException;
92 import org.forester.phylogeny.Phylogeny;
93 import org.forester.phylogeny.PhylogenyMethods;
94 import org.forester.phylogeny.PhylogenyNode;
95 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
96 import org.forester.phylogeny.data.Confidence;
97 import org.forester.phylogeny.data.Taxonomy;
98 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
99 import org.forester.phylogeny.factories.PhylogenyFactory;
100 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
101 import org.forester.sdi.GSDI;
102 import org.forester.sdi.GSDIR;
103 import org.forester.sdi.SDIException;
104 import org.forester.sdi.SDIR;
105 import org.forester.sequence.Sequence;
106 import org.forester.util.BasicDescriptiveStatistics;
107 import org.forester.util.BasicTable;
108 import org.forester.util.BasicTableParser;
109 import org.forester.util.DescriptiveStatistics;
110 import org.forester.util.ForesterUtil;
111 import org.forester.util.WindowsUtils;
113 public final class MainFrameApplication extends MainFrame {
115 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
116 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
117 private final static int FRAME_X_SIZE = 800;
118 private final static int FRAME_Y_SIZE = 800;
119 // Filters for the file-open dialog (classes defined in this file)
120 private final static NHFilter nhfilter = new NHFilter();
121 private final static NHXFilter nhxfilter = new NHXFilter();
122 private final static XMLFilter xmlfilter = new XMLFilter();
123 private final static TolFilter tolfilter = new TolFilter();
124 private final static NexusFilter nexusfilter = new NexusFilter();
125 private final static PdfFilter pdffilter = new PdfFilter();
126 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
127 private final static MsaFileFilter msafilter = new MsaFileFilter();
128 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
129 private final static DefaultFilter defaultfilter = new DefaultFilter();
130 private static final long serialVersionUID = -799735726778865234L;
131 private final JFileChooser _values_filechooser;
132 private final JFileChooser _open_filechooser;
133 private final JFileChooser _msa_filechooser;
134 private final JFileChooser _seqs_filechooser;
135 private final JFileChooser _open_filechooser_for_species_tree;
136 private final JFileChooser _save_filechooser;
137 private final JFileChooser _writetopdf_filechooser;
138 private final JFileChooser _writetographics_filechooser;
140 private JMenu _analysis_menu;
141 private JMenuItem _load_species_tree_item;
142 private JMenuItem _gsdi_item;
143 private JMenuItem _gsdir_item;
144 private JMenuItem _root_min_dups_item;
145 private JMenuItem _root_min_cost_l_item;
146 private JMenuItem _lineage_inference;
147 private JMenuItem _function_analysis;
148 // Application-only print menu items
149 private JMenuItem _print_item;
150 private JMenuItem _write_to_pdf_item;
151 private JMenuItem _write_to_jpg_item;
152 private JMenuItem _write_to_gif_item;
153 private JMenuItem _write_to_tif_item;
154 private JMenuItem _write_to_png_item;
155 private JMenuItem _write_to_bmp_item;
156 private Phylogeny _species_tree;
157 private File _current_dir;
158 private ButtonGroup _radio_group_1;
159 private ButtonGroup _radio_group_2;
161 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
162 // Phylogeny Inference menu
163 private JMenu _inference_menu;
164 private JMenuItem _inference_from_msa_item;
165 private JMenuItem _inference_from_seqs_item;
166 // Phylogeny Inference
167 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
168 private Msa _msa = null;
169 private File _msa_file = null;
170 private List<Sequence> _seqs = null;
171 private File _seqs_file = null;
172 // expression values menu:
173 JMenuItem _read_values_jmi;
175 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
176 _configuration = config;
177 if ( _configuration == null ) {
178 throw new IllegalArgumentException( "configuration is null" );
181 setOptions( Options.createInstance( _configuration ) );
182 _mainpanel = new MainPanel( _configuration, this );
183 _open_filechooser = null;
184 _open_filechooser_for_species_tree = null;
185 _save_filechooser = null;
186 _writetopdf_filechooser = null;
187 _writetographics_filechooser = null;
188 _msa_filechooser = null;
189 _seqs_filechooser = null;
190 _values_filechooser = null;
191 _jmenubar = new JMenuBar();
194 _contentpane = getContentPane();
195 _contentpane.setLayout( new BorderLayout() );
196 _contentpane.add( _mainpanel, BorderLayout.CENTER );
198 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
199 // The window listener
200 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
201 addWindowListener( new WindowAdapter() {
204 public void windowClosing( final WindowEvent e ) {
208 // setVisible( true );
209 if ( ( phys != null ) && ( phys.length > 0 ) ) {
210 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
212 getMainPanel().getControlPanel().showWholeAll();
213 getMainPanel().getControlPanel().showWhole();
215 //activateSaveAllIfNeeded();
216 // ...and its children
217 _contentpane.repaint();
220 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
221 this( phys, config, title, null );
224 private MainFrameApplication( final Phylogeny[] phys,
225 final Configuration config,
227 final File current_dir ) {
229 _configuration = config;
230 if ( _configuration == null ) {
231 throw new IllegalArgumentException( "configuration is null" );
234 boolean synth_exception = false;
235 if ( Constants.__SYNTH_LF ) {
237 final SynthLookAndFeel synth = new SynthLookAndFeel();
238 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
239 MainFrameApplication.class );
240 UIManager.setLookAndFeel( synth );
242 catch ( final Exception ex ) {
243 synth_exception = true;
244 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
245 "could not create synth look and feel: "
246 + ex.getLocalizedMessage() );
249 if ( !Constants.__SYNTH_LF || synth_exception ) {
250 if ( _configuration.isUseNativeUI() ) {
251 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
254 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
257 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
259 catch ( final UnsupportedLookAndFeelException e ) {
260 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
262 catch ( final ClassNotFoundException e ) {
263 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
265 catch ( final InstantiationException e ) {
266 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
268 catch ( final IllegalAccessException e ) {
269 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
271 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
272 setCurrentDir( current_dir );
274 // hide until everything is ready
276 setOptions( Options.createInstance( _configuration ) );
277 setInferenceManager( InferenceManager.createInstance( _configuration ) );
278 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
279 // _textframe = null; #~~~~
280 _species_tree = null;
282 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
283 _mainpanel = new MainPanel( _configuration, this );
285 _open_filechooser = new JFileChooser();
286 _open_filechooser.setCurrentDirectory( new File( "." ) );
287 _open_filechooser.setMultiSelectionEnabled( false );
288 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
289 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
290 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
291 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
292 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
293 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
294 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
295 _open_filechooser_for_species_tree = new JFileChooser();
296 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
297 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
298 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
299 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
300 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
301 _save_filechooser = new JFileChooser();
302 _save_filechooser.setCurrentDirectory( new File( "." ) );
303 _save_filechooser.setMultiSelectionEnabled( false );
304 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
305 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
306 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
307 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
308 _writetopdf_filechooser = new JFileChooser();
309 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
310 _writetographics_filechooser = new JFileChooser();
311 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
313 _msa_filechooser = new JFileChooser();
314 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
315 _msa_filechooser.setCurrentDirectory( new File( "." ) );
316 _msa_filechooser.setMultiSelectionEnabled( false );
317 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
318 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
320 _seqs_filechooser = new JFileChooser();
321 _seqs_filechooser.setName( "Read Sequences File" );
322 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
323 _seqs_filechooser.setMultiSelectionEnabled( false );
324 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
325 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
327 _values_filechooser = new JFileChooser();
328 _values_filechooser.setCurrentDirectory( new File( "." ) );
329 _values_filechooser.setMultiSelectionEnabled( false );
330 // build the menu bar
331 _jmenubar = new JMenuBar();
332 if ( !_configuration.isUseNativeUI() ) {
333 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
336 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
337 buildPhylogeneticInferenceMenu();
346 setJMenuBar( _jmenubar );
347 _jmenubar.add( _help_jmenu );
348 _contentpane = getContentPane();
349 _contentpane.setLayout( new BorderLayout() );
350 _contentpane.add( _mainpanel, BorderLayout.CENTER );
352 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
353 // addWindowFocusListener( new WindowAdapter() {
356 // public void windowGainedFocus( WindowEvent e ) {
357 // requestFocusInWindow();
360 // The window listener
361 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
362 addWindowListener( new WindowAdapter() {
365 public void windowClosing( final WindowEvent e ) {
366 if ( isUnsavedDataPresent() ) {
367 final int r = JOptionPane.showConfirmDialog( null,
368 "Exit despite potentially unsaved changes?",
370 JOptionPane.YES_NO_OPTION );
371 if ( r != JOptionPane.YES_OPTION ) {
376 final int r = JOptionPane.showConfirmDialog( null,
377 "Exit Archaeopteryx?",
379 JOptionPane.YES_NO_OPTION );
380 if ( r != JOptionPane.YES_OPTION ) {
387 // The component listener
388 addComponentListener( new ComponentAdapter() {
391 public void componentResized( final ComponentEvent e ) {
392 if ( _mainpanel.getCurrentTreePanel() != null ) {
393 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
395 _mainpanel.getCurrentTreePanel()
401 requestFocusInWindow();
402 // addKeyListener( this );
404 if ( ( phys != null ) && ( phys.length > 0 ) ) {
405 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
407 getMainPanel().getControlPanel().showWholeAll();
408 getMainPanel().getControlPanel().showWhole();
410 activateSaveAllIfNeeded();
411 // ...and its children
412 _contentpane.repaint();
416 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
417 // Reads the config file (false, false => not url, not applet):
418 this( phys, new Configuration( config_file, false, false, true ), title );
422 public void actionPerformed( final ActionEvent e ) {
424 super.actionPerformed( e );
425 final Object o = e.getSource();
426 // Handle app-specific actions here:
427 if ( o == _open_item ) {
428 readPhylogeniesFromFile();
430 else if ( o == _save_item ) {
431 writeToFile( _mainpanel.getCurrentPhylogeny() );
432 // If subtree currently displayed, save it, instead of complete
435 else if ( o == _new_item ) {
438 else if ( o == _save_all_item ) {
441 else if ( o == _close_item ) {
444 else if ( o == _write_to_pdf_item ) {
445 writeToPdf( _mainpanel.getCurrentPhylogeny() );
447 else if ( o == _write_to_jpg_item ) {
448 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
450 else if ( o == _write_to_png_item ) {
451 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
453 else if ( o == _write_to_gif_item ) {
454 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
456 else if ( o == _write_to_tif_item ) {
457 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
459 else if ( o == _write_to_bmp_item ) {
460 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
462 else if ( o == _print_item ) {
465 else if ( o == _load_species_tree_item ) {
466 readSpeciesTreeFromFile();
468 else if ( o == _lineage_inference ) {
469 if ( isSubtreeDisplayed() ) {
470 JOptionPane.showMessageDialog( this,
472 "Cannot infer ancestral taxonomies",
473 JOptionPane.ERROR_MESSAGE );
476 executeLineageInference();
478 else if ( o == _function_analysis ) {
479 executeFunctionAnalysis();
481 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
482 if ( isSubtreeDisplayed() ) {
485 obtainDetailedTaxonomicInformation();
487 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
488 if ( isSubtreeDisplayed() ) {
491 obtainDetailedTaxonomicInformationDelete();
493 else if ( o == _obtain_seq_information_jmi ) {
494 obtainSequenceInformation();
496 else if ( o == _read_values_jmi ) {
497 if ( isSubtreeDisplayed() ) {
500 addExpressionValuesFromFile();
502 else if ( o == _move_node_names_to_tax_sn_jmi ) {
503 moveNodeNamesToTaxSn();
505 else if ( o == _move_node_names_to_seq_names_jmi ) {
506 moveNodeNamesToSeqNames();
508 else if ( o == _extract_tax_code_from_node_names_jmi ) {
509 extractTaxDataFromNodeNames();
511 else if ( o == _gsdi_item ) {
512 if ( isSubtreeDisplayed() ) {
517 else if ( o == _gsdir_item ) {
518 if ( isSubtreeDisplayed() ) {
523 else if ( o == _root_min_dups_item ) {
524 if ( isSubtreeDisplayed() ) {
527 executeSDIR( false );
529 else if ( o == _root_min_cost_l_item ) {
530 if ( isSubtreeDisplayed() ) {
535 else if ( o == _graphics_export_visible_only_cbmi ) {
536 updateOptions( getOptions() );
538 else if ( o == _antialias_print_cbmi ) {
539 updateOptions( getOptions() );
541 else if ( o == _print_black_and_white_cbmi ) {
542 updateOptions( getOptions() );
544 else if ( o == _print_using_actual_size_cbmi ) {
545 updateOptions( getOptions() );
547 else if ( o == _graphics_export_using_actual_size_cbmi ) {
548 updateOptions( getOptions() );
550 else if ( o == _print_size_mi ) {
553 else if ( o == _choose_pdf_width_mi ) {
556 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
557 updateOptions( getOptions() );
559 else if ( o == _replace_underscores_cbmi ) {
560 if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
561 _extract_taxonomy_no_rbmi.setSelected( true );
563 updateOptions( getOptions() );
565 else if ( o == _collapse_below_threshold ) {
566 if ( isSubtreeDisplayed() ) {
569 collapseBelowThreshold();
571 else if ( ( o == _extract_taxonomy_pfam_rbmi ) || ( o == _extract_taxonomy_yes_rbmi ) ) {
572 if ( _replace_underscores_cbmi != null ) {
573 _replace_underscores_cbmi.setSelected( false );
575 updateOptions( getOptions() );
577 else if ( o == _inference_from_msa_item ) {
578 executePhyleneticInference( false );
580 else if ( o == _inference_from_seqs_item ) {
581 executePhyleneticInference( true );
583 _contentpane.repaint();
585 catch ( final Exception ex ) {
586 AptxUtil.unexpectedException( ex );
588 catch ( final Error err ) {
589 AptxUtil.unexpectedError( err );
594 _mainpanel.terminate();
595 _contentpane.removeAll();
601 public MainPanel getMainPanel() {
605 public Msa getMsa() {
609 public File getMsaFile() {
613 public List<Sequence> getSeqs() {
617 public File getSeqsFile() {
621 public void readMsaFromFile() {
622 // Set an initial directory if none set yet
623 final File my_dir = getCurrentDir();
624 _msa_filechooser.setMultiSelectionEnabled( false );
625 // Open file-open dialog and set current directory
626 if ( my_dir != null ) {
627 _msa_filechooser.setCurrentDirectory( my_dir );
629 final int result = _msa_filechooser.showOpenDialog( _contentpane );
630 // All done: get the msa
631 final File file = _msa_filechooser.getSelectedFile();
632 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
633 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
638 final InputStream is = new FileInputStream( file );
639 if ( FastaParser.isLikelyFasta( file ) ) {
640 msa = FastaParser.parseMsa( is );
643 msa = GeneralMsaParser.parse( is );
646 catch ( final MsaFormatException e ) {
648 _mainpanel.getCurrentTreePanel().setArrowCursor();
650 catch ( final Exception ex ) {
653 JOptionPane.showMessageDialog( this,
654 e.getLocalizedMessage(),
655 "Multiple sequence alignment format error",
656 JOptionPane.ERROR_MESSAGE );
659 catch ( final IOException e ) {
661 _mainpanel.getCurrentTreePanel().setArrowCursor();
663 catch ( final Exception ex ) {
666 JOptionPane.showMessageDialog( this,
667 e.getLocalizedMessage(),
668 "Failed to read multiple sequence alignment",
669 JOptionPane.ERROR_MESSAGE );
672 catch ( final IllegalArgumentException e ) {
674 _mainpanel.getCurrentTreePanel().setArrowCursor();
676 catch ( final Exception ex ) {
679 JOptionPane.showMessageDialog( this,
680 e.getLocalizedMessage(),
681 "Unexpected error during reading of multiple sequence alignment",
682 JOptionPane.ERROR_MESSAGE );
685 catch ( final Exception e ) {
687 _mainpanel.getCurrentTreePanel().setArrowCursor();
689 catch ( final Exception ex ) {
693 JOptionPane.showMessageDialog( this,
694 e.getLocalizedMessage(),
695 "Unexpected error during reading of multiple sequence alignment",
696 JOptionPane.ERROR_MESSAGE );
699 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
700 JOptionPane.showMessageDialog( this,
701 "Multiple sequence alignment is empty",
702 "Illegal Multiple Sequence Alignment",
703 JOptionPane.ERROR_MESSAGE );
706 if ( msa.getNumberOfSequences() < 4 ) {
707 JOptionPane.showMessageDialog( this,
708 "Multiple sequence alignment needs to contain at least 3 sequences",
709 "Illegal multiple sequence alignment",
710 JOptionPane.ERROR_MESSAGE );
713 if ( msa.getLength() < 2 ) {
714 JOptionPane.showMessageDialog( this,
715 "Multiple sequence alignment needs to contain at least 2 residues",
716 "Illegal multiple sequence alignment",
717 JOptionPane.ERROR_MESSAGE );
721 setMsaFile( _msa_filechooser.getSelectedFile() );
726 public void readSeqsFromFile() {
727 // Set an initial directory if none set yet
728 final File my_dir = getCurrentDir();
729 _seqs_filechooser.setMultiSelectionEnabled( false );
730 // Open file-open dialog and set current directory
731 if ( my_dir != null ) {
732 _seqs_filechooser.setCurrentDirectory( my_dir );
734 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
735 // All done: get the seqs
736 final File file = _seqs_filechooser.getSelectedFile();
737 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
738 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
741 List<Sequence> seqs = null;
743 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
744 seqs = FastaParser.parse( new FileInputStream( file ) );
745 for( final Sequence seq : seqs ) {
746 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
753 catch ( final MsaFormatException e ) {
755 _mainpanel.getCurrentTreePanel().setArrowCursor();
757 catch ( final Exception ex ) {
760 JOptionPane.showMessageDialog( this,
761 e.getLocalizedMessage(),
762 "Multiple sequence file format error",
763 JOptionPane.ERROR_MESSAGE );
766 catch ( final IOException e ) {
768 _mainpanel.getCurrentTreePanel().setArrowCursor();
770 catch ( final Exception ex ) {
773 JOptionPane.showMessageDialog( this,
774 e.getLocalizedMessage(),
775 "Failed to read multiple sequence file",
776 JOptionPane.ERROR_MESSAGE );
779 catch ( final IllegalArgumentException e ) {
781 _mainpanel.getCurrentTreePanel().setArrowCursor();
783 catch ( final Exception ex ) {
786 JOptionPane.showMessageDialog( this,
787 e.getLocalizedMessage(),
788 "Unexpected error during reading of multiple sequence file",
789 JOptionPane.ERROR_MESSAGE );
792 catch ( final Exception e ) {
794 _mainpanel.getCurrentTreePanel().setArrowCursor();
796 catch ( final Exception ex ) {
800 JOptionPane.showMessageDialog( this,
801 e.getLocalizedMessage(),
802 "Unexpected error during reading of multiple sequence file",
803 JOptionPane.ERROR_MESSAGE );
806 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
807 JOptionPane.showMessageDialog( this,
808 "Multiple sequence file is empty",
809 "Illegal multiple sequence file",
810 JOptionPane.ERROR_MESSAGE );
813 if ( seqs.size() < 4 ) {
814 JOptionPane.showMessageDialog( this,
815 "Multiple sequence file needs to contain at least 3 sequences",
816 "Illegal multiple sequence file",
817 JOptionPane.ERROR_MESSAGE );
820 // if ( msa.getLength() < 2 ) {
821 // JOptionPane.showMessageDialog( this,
822 // "Multiple sequence alignment needs to contain at least 2 residues",
823 // "Illegal multiple sequence file",
824 // JOptionPane.ERROR_MESSAGE );
828 setSeqsFile( _seqs_filechooser.getSelectedFile() );
833 void buildAnalysisMenu() {
834 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
835 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
836 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (re-rooting)" ) );
837 _analysis_menu.addSeparator();
838 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
839 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
840 _analysis_menu.addSeparator();
841 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
842 customizeJMenuItem( _gsdi_item );
843 customizeJMenuItem( _gsdir_item );
844 customizeJMenuItem( _root_min_dups_item );
845 customizeJMenuItem( _root_min_cost_l_item );
846 customizeJMenuItem( _load_species_tree_item );
847 _analysis_menu.addSeparator();
848 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
849 customizeJMenuItem( _lineage_inference );
850 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
851 _jmenubar.add( _analysis_menu );
855 void buildFileMenu() {
856 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
857 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
858 _file_jmenu.addSeparator();
859 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
860 _file_jmenu.addSeparator();
861 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
862 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
863 .getAvailablePhylogeniesWebserviceClients().size() ];
864 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
865 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
866 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
867 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
869 if ( getConfiguration().isEditable() ) {
870 _file_jmenu.addSeparator();
871 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
872 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
874 _file_jmenu.addSeparator();
875 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
876 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
877 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
878 _save_all_item.setEnabled( false );
879 _file_jmenu.addSeparator();
880 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
881 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
882 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
884 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
885 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
886 if ( AptxUtil.canWriteFormat( "gif" ) ) {
887 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
889 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
890 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
892 _file_jmenu.addSeparator();
893 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
894 _file_jmenu.addSeparator();
895 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
896 _close_item.setToolTipText( "To close the current pane." );
897 _close_item.setEnabled( true );
898 _file_jmenu.addSeparator();
899 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
900 // For print in color option item
901 customizeJMenuItem( _open_item );
903 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
904 customizeJMenuItem( _open_url_item );
905 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
906 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
908 customizeJMenuItem( _save_item );
909 if ( getConfiguration().isEditable() ) {
910 customizeJMenuItem( _new_item );
912 customizeJMenuItem( _close_item );
913 customizeJMenuItem( _save_all_item );
914 customizeJMenuItem( _write_to_pdf_item );
915 customizeJMenuItem( _write_to_png_item );
916 customizeJMenuItem( _write_to_jpg_item );
917 customizeJMenuItem( _write_to_gif_item );
918 customizeJMenuItem( _write_to_tif_item );
919 customizeJMenuItem( _write_to_bmp_item );
920 customizeJMenuItem( _print_item );
921 customizeJMenuItem( _exit_item );
922 _jmenubar.add( _file_jmenu );
925 void buildOptionsMenu() {
926 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
927 _options_jmenu.addChangeListener( new ChangeListener() {
930 public void stateChanged( final ChangeEvent e ) {
931 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
932 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
934 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
935 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
936 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
937 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
938 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
939 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
941 _show_branch_length_values_cbmi,
942 _non_lined_up_cladograms_rbmi,
943 _uniform_cladograms_rbmi,
944 _ext_node_dependent_cladogram_rbmi,
945 _label_direction_cbmi );
946 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
947 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
948 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
951 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
953 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
954 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
955 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
956 _radio_group_1 = new ButtonGroup();
957 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
958 _radio_group_1.add( _uniform_cladograms_rbmi );
959 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
960 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
961 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
963 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
964 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
965 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
967 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
968 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
969 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
970 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
971 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
972 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
973 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
974 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
975 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
976 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
977 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
978 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
979 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
981 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
982 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
983 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
984 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
985 _options_jmenu.addSeparator();
986 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
987 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
988 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
989 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
990 _options_jmenu.addSeparator();
991 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
992 getConfiguration() ) );
993 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
994 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
996 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
998 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
1000 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
1001 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
1002 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
1003 _options_jmenu.addSeparator();
1004 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
1006 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
1007 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
1009 _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
1011 .add( _extract_taxonomy_pfam_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Pfam-style Node Names" ) );
1012 _extract_taxonomy_pfam_rbmi
1013 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE/134-298\"" );
1015 .add( _extract_taxonomy_yes_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Node Names" ) );
1016 _extract_taxonomy_yes_rbmi
1017 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE\" or \"BCL2_MOUSE B-cell lymphoma 2...\"" );
1018 _radio_group_2 = new ButtonGroup();
1019 _radio_group_2.add( _extract_taxonomy_no_rbmi );
1020 _radio_group_2.add( _extract_taxonomy_pfam_rbmi );
1021 _radio_group_2.add( _extract_taxonomy_yes_rbmi );
1023 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
1025 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
1026 _use_brackets_for_conf_in_nh_export_cbmi
1027 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
1029 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
1030 customizeJMenuItem( _choose_font_mi );
1031 customizeJMenuItem( _choose_minimal_confidence_mi );
1032 customizeJMenuItem( _switch_colors_mi );
1033 customizeJMenuItem( _print_size_mi );
1034 customizeJMenuItem( _choose_pdf_width_mi );
1035 customizeJMenuItem( _overview_placment_mi );
1036 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
1037 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
1038 customizeJMenuItem( _cycle_node_shape_mi );
1039 customizeJMenuItem( _cycle_node_fill_mi );
1040 customizeJMenuItem( _choose_node_size_mi );
1041 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
1042 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
1043 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
1044 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
1045 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
1046 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
1047 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
1048 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
1049 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
1050 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
1051 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1052 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
1053 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1054 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
1055 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
1056 customizeCheckBoxMenuItem( _label_direction_cbmi,
1057 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
1058 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
1059 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
1060 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
1061 .isInternalNumberAreConfidenceForNhParsing() );
1062 customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
1063 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
1064 customizeRadioButtonMenuItem( _extract_taxonomy_yes_rbmi,
1065 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.YES );
1066 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_rbmi,
1067 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
1068 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
1069 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1070 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1071 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
1072 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
1073 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
1074 .isGraphicsExportUsingActualSize() );
1075 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1076 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
1077 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1078 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
1079 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1080 _jmenubar.add( _options_jmenu );
1083 void buildPhylogeneticInferenceMenu() {
1084 final InferenceManager im = getInferenceManager();
1085 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
1086 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
1087 customizeJMenuItem( _inference_from_msa_item );
1088 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
1089 if ( im.canDoMsa() ) {
1090 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
1091 customizeJMenuItem( _inference_from_seqs_item );
1092 _inference_from_seqs_item
1093 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
1097 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
1098 customizeJMenuItem( _inference_from_seqs_item );
1099 _inference_from_seqs_item.setEnabled( false );
1101 _jmenubar.add( _inference_menu );
1104 void buildToolsMenu() {
1105 _tools_menu = createMenu( "Tools", getConfiguration() );
1106 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1107 customizeJMenuItem( _confcolor_item );
1108 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
1109 customizeJMenuItem( _color_rank_jmi );
1110 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
1111 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1112 customizeJMenuItem( _taxcolor_item );
1113 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
1114 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
1115 customizeJMenuItem( _remove_branch_color_item );
1116 _tools_menu.addSeparator();
1117 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
1118 customizeJMenuItem( _annotate_item );
1119 _tools_menu.addSeparator();
1120 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1121 customizeJMenuItem( _midpoint_root_item );
1122 _tools_menu.addSeparator();
1123 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1124 customizeJMenuItem( _collapse_species_specific_subtrees );
1126 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
1127 customizeJMenuItem( _collapse_below_threshold );
1128 _collapse_below_threshold
1129 .setToolTipText( "To 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)" );
1130 _tools_menu.addSeparator();
1132 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );
1133 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
1134 _extract_tax_code_from_node_names_jmi
1135 .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'" );
1137 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
1138 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
1139 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
1140 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
1141 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
1142 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
1143 _tools_menu.addSeparator();
1145 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
1146 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
1147 _obtain_detailed_taxonomic_information_jmi
1148 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
1150 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
1151 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
1152 _obtain_detailed_taxonomic_information_deleting_jmi
1153 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
1154 _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
1155 customizeJMenuItem( _obtain_seq_information_jmi );
1156 _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
1157 _tools_menu.addSeparator();
1158 if ( !Constants.__RELEASE ) {
1159 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
1160 customizeJMenuItem( _function_analysis );
1162 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
1163 _tools_menu.addSeparator();
1165 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
1166 customizeJMenuItem( _read_values_jmi );
1167 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
1168 _jmenubar.add( _tools_menu );
1173 if ( isUnsavedDataPresent() ) {
1174 final int r = JOptionPane.showConfirmDialog( this,
1175 "Exit despite potentially unsaved changes?",
1177 JOptionPane.YES_NO_OPTION );
1178 if ( r != JOptionPane.YES_OPTION ) {
1185 void executeFunctionAnalysis() {
1186 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1189 final GoAnnotation a = new GoAnnotation( this,
1190 _mainpanel.getCurrentTreePanel(),
1191 _mainpanel.getCurrentPhylogeny() );
1192 new Thread( a ).start();
1195 void executeGSDI() {
1196 if ( !isOKforSDI( false, true ) ) {
1199 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1200 JOptionPane.showMessageDialog( this,
1201 "Gene tree is not rooted.",
1202 "Cannot execute GSDI",
1203 JOptionPane.ERROR_MESSAGE );
1206 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1207 gene_tree.setAllNodesToNotCollapse();
1208 gene_tree.recalculateNumberOfExternalDescendants( false );
1210 final Phylogeny species_tree = _species_tree.copy();
1212 gsdi = new GSDI( gene_tree, species_tree, false, true, true );
1214 catch ( final SDIException e ) {
1215 JOptionPane.showMessageDialog( this,
1216 e.getLocalizedMessage(),
1217 "Error during GSDI",
1218 JOptionPane.ERROR_MESSAGE );
1221 catch ( final Exception e ) {
1222 AptxUtil.unexpectedException( e );
1225 gene_tree.setRerootable( false );
1226 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1227 _mainpanel.getCurrentPhylogeny().clearHashIdToNodeMap();
1228 _mainpanel.getCurrentPhylogeny().recalculateNumberOfExternalDescendants( true );
1229 _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1230 _mainpanel.getCurrentTreePanel().setEdited( true );
1231 getControlPanel().setShowEvents( true );
1233 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1234 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1236 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1238 _mainpanel.getCurrentTreePanel().setEdited( true );
1239 JOptionPane.showMessageDialog( this, "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1240 + "Potential duplications: " + gsdi.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
1241 + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
1244 void executeGSDIR() {
1245 if ( !isOKforSDI( false, true ) ) {
1248 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1249 gene_tree.setAllNodesToNotCollapse();
1250 gene_tree.recalculateNumberOfExternalDescendants( false );
1252 final Phylogeny species_tree = _species_tree.copy();
1254 gsdir = new GSDIR( gene_tree, species_tree, true, true );
1256 catch ( final SDIException e ) {
1257 JOptionPane.showMessageDialog( this,
1258 e.getLocalizedMessage(),
1259 "Error during GSDIR",
1260 JOptionPane.ERROR_MESSAGE );
1263 catch ( final Exception e ) {
1264 AptxUtil.unexpectedException( e );
1267 final List<Phylogeny> assigned_trees = gsdir.getMinDuplicationsSumGeneTrees();
1268 final List<Integer> shortests = GSDIR.getIndexesOfShortestTree( assigned_trees );
1269 final Phylogeny result_gene_tree = assigned_trees.get( shortests.get( 0 ) );
1270 result_gene_tree.setRerootable( false );
1271 result_gene_tree.clearHashIdToNodeMap();
1272 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1273 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1274 getControlPanel().setShowEvents( true );
1276 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1277 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1279 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1281 _mainpanel.getCurrentTreePanel().setEdited( true );
1282 JOptionPane.showMessageDialog( this,
1283 "Duplications (min): " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: "
1284 + gsdir.getSpeciationsSum() + "\n"
1285 + "Number of root positions minimizing duplications sum: "
1286 + gsdir.getMinDuplicationsSumGeneTrees().size() + "\n"
1287 + "Number of shortest trees: " + shortests.size(),
1288 "GSDIR successfully completed",
1289 JOptionPane.INFORMATION_MESSAGE );
1292 void executeLineageInference() {
1293 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1296 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1297 JOptionPane.showMessageDialog( this,
1298 "Phylogeny is not rooted.",
1299 "Cannot infer ancestral taxonomies",
1300 JOptionPane.ERROR_MESSAGE );
1303 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1304 _mainpanel.getCurrentTreePanel(),
1305 _mainpanel.getCurrentPhylogeny()
1307 new Thread( inferrer ).start();
1310 void executeSDIR( final boolean minimize_cost ) {
1311 if ( !isOKforSDI( true, true ) ) {
1314 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1315 final SDIR sdiunrooted = new SDIR();
1316 gene_tree.setAllNodesToNotCollapse();
1317 gene_tree.recalculateNumberOfExternalDescendants( false );
1319 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1320 !minimize_cost, // minimize sum of dups
1321 true, // minimize height
1322 true, // return tree(s)
1323 1 )[ 0 ]; // # of trees to return
1325 catch ( final Exception e ) {
1326 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1329 final int duplications = sdiunrooted.getMinimalDuplications();
1330 gene_tree.setRerootable( false );
1331 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1332 getControlPanel().setShowEvents( true );
1334 _mainpanel.getCurrentTreePanel().setEdited( true );
1335 JOptionPane.showMessageDialog( this,
1336 "Number of duplications: " + duplications,
1337 "SDIR successfully completed",
1338 JOptionPane.INFORMATION_MESSAGE );
1342 removeAllTextFrames();
1343 _mainpanel.terminate();
1344 _contentpane.removeAll();
1345 setVisible( false );
1350 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1351 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1354 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1355 JOptionPane.showMessageDialog( this,
1356 "No species tree loaded",
1357 "Cannot execute SDI",
1358 JOptionPane.ERROR_MESSAGE );
1361 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1362 JOptionPane.showMessageDialog( this,
1363 "Species tree is not completely binary",
1364 "Cannot execute SDI",
1365 JOptionPane.ERROR_MESSAGE );
1368 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1369 JOptionPane.showMessageDialog( this,
1370 "Gene tree is not completely binary",
1371 "Cannot execute SDI",
1372 JOptionPane.ERROR_MESSAGE );
1381 void readPhylogeniesFromURL() {
1383 Phylogeny[] phys = null;
1384 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1385 final String url_string = JOptionPane.showInputDialog( this,
1387 "Use URL/webservice to obtain a phylogeny",
1388 JOptionPane.QUESTION_MESSAGE );
1389 boolean nhx_or_nexus = false;
1390 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1392 url = new URL( url_string );
1393 PhylogenyParser parser = null;
1394 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1395 parser = new TolParser();
1398 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
1399 .isValidatePhyloXmlAgainstSchema() );
1401 if ( parser instanceof NexusPhylogeniesParser ) {
1402 nhx_or_nexus = true;
1404 else if ( parser instanceof NHXParser ) {
1405 nhx_or_nexus = true;
1407 if ( _mainpanel.getCurrentTreePanel() != null ) {
1408 _mainpanel.getCurrentTreePanel().setWaitCursor();
1411 _mainpanel.setWaitCursor();
1413 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1414 phys = factory.create( url.openStream(), parser );
1416 catch ( final MalformedURLException e ) {
1417 JOptionPane.showMessageDialog( this,
1418 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1420 JOptionPane.ERROR_MESSAGE );
1422 catch ( final IOException e ) {
1423 JOptionPane.showMessageDialog( this,
1424 "Could not read from " + url + "\n"
1425 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1426 "Failed to read URL",
1427 JOptionPane.ERROR_MESSAGE );
1429 catch ( final Exception e ) {
1430 JOptionPane.showMessageDialog( this,
1431 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1432 "Unexpected Exception",
1433 JOptionPane.ERROR_MESSAGE );
1436 if ( _mainpanel.getCurrentTreePanel() != null ) {
1437 _mainpanel.getCurrentTreePanel().setArrowCursor();
1440 _mainpanel.setArrowCursor();
1443 if ( ( phys != null ) && ( phys.length > 0 ) ) {
1444 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1445 for( final Phylogeny phy : phys ) {
1446 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
1449 AptxUtil.addPhylogeniesToTabs( phys,
1450 new File( url.getFile() ).getName(),
1451 new File( url.getFile() ).toString(),
1454 _mainpanel.getControlPanel().showWhole();
1457 activateSaveAllIfNeeded();
1461 void setMsa( final Msa msa ) {
1465 void setMsaFile( final File msa_file ) {
1466 _msa_file = msa_file;
1469 void setSeqs( final List<Sequence> seqs ) {
1473 void setSeqsFile( final File seqs_file ) {
1474 _seqs_file = seqs_file;
1477 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
1478 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
1479 _mainpanel.getCurrentTreePanel().getHeight(),
1481 String file_written_to = "";
1482 boolean error = false;
1484 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
1485 _mainpanel.getCurrentTreePanel().getWidth(),
1486 _mainpanel.getCurrentTreePanel().getHeight(),
1487 _mainpanel.getCurrentTreePanel(),
1488 _mainpanel.getControlPanel(),
1492 catch ( final IOException e ) {
1494 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1497 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
1498 JOptionPane.showMessageDialog( this,
1499 "Wrote image to: " + file_written_to,
1501 JOptionPane.INFORMATION_MESSAGE );
1504 JOptionPane.showMessageDialog( this,
1505 "There was an unknown problem when attempting to write to an image file: \""
1508 JOptionPane.ERROR_MESSAGE );
1511 _contentpane.repaint();
1514 private void addExpressionValuesFromFile() {
1515 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1516 JOptionPane.showMessageDialog( this,
1517 "Need to load evolutionary tree first",
1518 "Can Not Read Expression Values",
1519 JOptionPane.WARNING_MESSAGE );
1522 final File my_dir = getCurrentDir();
1523 if ( my_dir != null ) {
1524 _values_filechooser.setCurrentDirectory( my_dir );
1526 final int result = _values_filechooser.showOpenDialog( _contentpane );
1527 final File file = _values_filechooser.getSelectedFile();
1528 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1529 BasicTable<String> t = null;
1531 t = BasicTableParser.parse( file, "\t" );
1532 if ( t.getNumberOfColumns() < 2 ) {
1533 t = BasicTableParser.parse( file, "," );
1535 if ( t.getNumberOfColumns() < 2 ) {
1536 t = BasicTableParser.parse( file, " " );
1539 catch ( final IOException e ) {
1540 JOptionPane.showMessageDialog( this,
1542 "Could Not Read Expression Value Table",
1543 JOptionPane.ERROR_MESSAGE );
1546 if ( t.getNumberOfColumns() < 2 ) {
1547 JOptionPane.showMessageDialog( this,
1548 "Table contains " + t.getNumberOfColumns() + " column(s)",
1549 "Problem with Expression Value Table",
1550 JOptionPane.ERROR_MESSAGE );
1553 if ( t.getNumberOfRows() < 1 ) {
1554 JOptionPane.showMessageDialog( this,
1555 "Table contains zero rows",
1556 "Problem with Expression Value Table",
1557 JOptionPane.ERROR_MESSAGE );
1560 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1561 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1562 JOptionPane.showMessageDialog( this,
1563 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1564 + phy.getNumberOfExternalNodes() + " external nodes",
1566 JOptionPane.WARNING_MESSAGE );
1568 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1570 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1571 final PhylogenyNode node = iter.next();
1572 final String node_name = node.getName();
1573 if ( !ForesterUtil.isEmpty( node_name ) ) {
1576 row = t.findRow( node_name );
1578 catch ( final IllegalArgumentException e ) {
1580 .showMessageDialog( this,
1582 "Error Mapping Node Identifiers to Expression Value Identifiers",
1583 JOptionPane.ERROR_MESSAGE );
1587 if ( node.isExternal() ) {
1592 final List<Double> l = new ArrayList<Double>();
1593 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1596 d = Double.parseDouble( t.getValueAsString( col, row ) );
1598 catch ( final NumberFormatException e ) {
1599 JOptionPane.showMessageDialog( this,
1600 "Could not parse \"" + t.getValueAsString( col, row )
1601 + "\" into a decimal value",
1602 "Issue with Expression Value Table",
1603 JOptionPane.ERROR_MESSAGE );
1606 stats.addValue( d );
1609 if ( !l.isEmpty() ) {
1610 if ( node.getNodeData().getProperties() != null ) {
1611 node.getNodeData().getProperties()
1612 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1614 node.getNodeData().setVector( l );
1618 if ( not_found > 0 ) {
1619 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1620 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1622 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1626 private void choosePdfWidth() {
1627 final String s = ( String ) JOptionPane.showInputDialog( this,
1628 "Please enter the default line width for PDF export.\n"
1629 + "[current value: "
1630 + getOptions().getPrintLineWidth() + "]\n",
1631 "Line Width for PDF Export",
1632 JOptionPane.QUESTION_MESSAGE,
1635 getOptions().getPrintLineWidth() );
1636 if ( !ForesterUtil.isEmpty( s ) ) {
1637 boolean success = true;
1639 final String m_str = s.trim();
1640 if ( !ForesterUtil.isEmpty( m_str ) ) {
1642 f = Float.parseFloat( m_str );
1644 catch ( final Exception ex ) {
1651 if ( success && ( f > 0.0 ) ) {
1652 getOptions().setPrintLineWidth( f );
1657 private void choosePrintSize() {
1658 final String s = ( String ) JOptionPane.showInputDialog( this,
1659 "Please enter values for width and height,\nseparated by a comma.\n"
1660 + "[current values: "
1661 + getOptions().getPrintSizeX() + ", "
1662 + getOptions().getPrintSizeY() + "]\n"
1663 + "[A4: " + Constants.A4_SIZE_X + ", "
1664 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
1665 + Constants.US_LETTER_SIZE_X + ", "
1666 + Constants.US_LETTER_SIZE_Y + "]",
1667 "Default Size for Graphics Export",
1668 JOptionPane.QUESTION_MESSAGE,
1671 getOptions().getPrintSizeX() + ", "
1672 + getOptions().getPrintSizeY() );
1673 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
1674 boolean success = true;
1677 final String[] str_ary = s.split( "," );
1678 if ( str_ary.length == 2 ) {
1679 final String x_str = str_ary[ 0 ].trim();
1680 final String y_str = str_ary[ 1 ].trim();
1681 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
1683 x = Integer.parseInt( x_str );
1684 y = Integer.parseInt( y_str );
1686 catch ( final Exception ex ) {
1697 if ( success && ( x > 1 ) && ( y > 1 ) ) {
1698 getOptions().setPrintSizeX( x );
1699 getOptions().setPrintSizeY( y );
1704 private void closeCurrentPane() {
1705 if ( getMainPanel().getCurrentTreePanel() != null ) {
1706 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1707 final int r = JOptionPane.showConfirmDialog( this,
1708 "Close tab despite potentially unsaved changes?",
1710 JOptionPane.YES_NO_OPTION );
1711 if ( r != JOptionPane.YES_OPTION ) {
1715 getMainPanel().closeCurrentPane();
1716 activateSaveAllIfNeeded();
1720 private void collapse( final Phylogeny phy, final double m ) {
1721 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1722 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1723 double min_support = Double.MAX_VALUE;
1724 boolean conf_present = false;
1725 while ( it.hasNext() ) {
1726 final PhylogenyNode n = it.next();
1727 if ( !n.isExternal() && !n.isRoot() ) {
1728 final List<Confidence> c = n.getBranchData().getConfidences();
1729 if ( ( c != null ) && ( c.size() > 0 ) ) {
1730 conf_present = true;
1732 for( final Confidence confidence : c ) {
1733 if ( confidence.getValue() > max ) {
1734 max = confidence.getValue();
1737 if ( max < getMinNotCollapseConfidenceValue() ) {
1738 to_be_removed.add( n );
1740 if ( max < min_support ) {
1746 if ( conf_present ) {
1747 for( final PhylogenyNode node : to_be_removed ) {
1748 PhylogenyMethods.removeNode( node, phy );
1750 if ( to_be_removed.size() > 0 ) {
1751 phy.externalNodesHaveChanged();
1752 phy.clearHashIdToNodeMap();
1753 phy.recalculateNumberOfExternalDescendants( true );
1754 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1755 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1756 getCurrentTreePanel().calculateLongestExtNodeInfo();
1757 getCurrentTreePanel().setNodeInPreorderToNull();
1758 getCurrentTreePanel().recalculateMaxDistanceToRoot();
1759 getCurrentTreePanel().resetPreferredSize();
1760 getCurrentTreePanel().setEdited( true );
1761 getCurrentTreePanel().repaint();
1764 if ( to_be_removed.size() > 0 ) {
1765 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1766 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1767 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1770 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1771 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1775 JOptionPane.showMessageDialog( this,
1776 "No branch collapsed because no confidence values present",
1777 "No confidence values present",
1778 JOptionPane.INFORMATION_MESSAGE );
1782 private void collapseBelowThreshold() {
1783 if ( getCurrentTreePanel() != null ) {
1784 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1785 if ( ( phy != null ) && !phy.isEmpty() ) {
1786 final String s = ( String ) JOptionPane.showInputDialog( this,
1787 "Please enter the minimum confidence value\n",
1788 "Minimal Confidence Value",
1789 JOptionPane.QUESTION_MESSAGE,
1792 getMinNotCollapseConfidenceValue() );
1793 if ( !ForesterUtil.isEmpty( s ) ) {
1794 boolean success = true;
1796 final String m_str = s.trim();
1797 if ( !ForesterUtil.isEmpty( m_str ) ) {
1799 m = Double.parseDouble( m_str );
1801 catch ( final Exception ex ) {
1808 if ( success && ( m >= 0.0 ) ) {
1809 setMinNotCollapseConfidenceValue( m );
1817 private PhyloXmlParser createPhyloXmlParser() {
1818 PhyloXmlParser xml_parser = null;
1819 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1821 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1823 catch ( final Exception e ) {
1824 JOptionPane.showMessageDialog( this,
1825 e.getLocalizedMessage(),
1826 "failed to create validating XML parser",
1827 JOptionPane.WARNING_MESSAGE );
1830 if ( xml_parser == null ) {
1831 xml_parser = new PhyloXmlParser();
1836 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1837 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1838 getPhylogeneticInferenceOptions(),
1839 from_unaligned_seqs );
1841 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1842 if ( !from_unaligned_seqs ) {
1843 if ( getMsa() != null ) {
1844 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1845 getPhylogeneticInferenceOptions()
1847 new Thread( inferrer ).start();
1850 JOptionPane.showMessageDialog( this,
1851 "No multiple sequence alignment selected",
1852 "Phylogenetic Inference Not Launched",
1853 JOptionPane.WARNING_MESSAGE );
1857 if ( getSeqs() != null ) {
1858 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1859 getPhylogeneticInferenceOptions()
1861 new Thread( inferrer ).start();
1864 JOptionPane.showMessageDialog( this,
1865 "No input sequences selected",
1866 "Phylogenetic Inference Not Launched",
1867 JOptionPane.WARNING_MESSAGE );
1873 private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
1874 final StringBuilder sb = new StringBuilder();
1875 final StringBuilder sb_failed = new StringBuilder();
1877 int counter_failed = 0;
1878 if ( getCurrentTreePanel() != null ) {
1879 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1880 if ( ( phy != null ) && !phy.isEmpty() ) {
1881 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
1882 while ( it.hasNext() ) {
1883 final PhylogenyNode n = it.next();
1884 final String name = n.getName().trim();
1885 if ( !ForesterUtil.isEmpty( name ) ) {
1886 final String nt = ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.YES );
1887 if ( !ForesterUtil.isEmpty( nt ) ) {
1888 if ( counter < 15 ) {
1889 sb.append( name + ": " + nt + "\n" );
1891 else if ( counter == 15 ) {
1892 sb.append( "...\n" );
1897 if ( counter_failed < 15 ) {
1898 sb_failed.append( name + "\n" );
1900 else if ( counter_failed == 15 ) {
1901 sb_failed.append( "...\n" );
1907 if ( counter > 0 ) {
1909 String all = "all ";
1910 if ( counter_failed > 0 ) {
1912 failed = "\nCould not extract taxonomic data for " + counter_failed
1913 + " named external nodes:\n" + sb_failed;
1915 JOptionPane.showMessageDialog( this,
1916 "Extracted taxonomic data from " + all + counter
1917 + " named external nodes:\n" + sb.toString() + failed,
1918 "Taxonomic Data Extraction Completed",
1919 counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
1920 : JOptionPane.INFORMATION_MESSAGE );
1924 .showMessageDialog( this,
1925 "Could not extract any taxonomic data.\nMaybe node names are empty\n"
1926 + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
1927 + "or nodes already have taxonomic data?\n",
1928 "No Taxonomic Data Extracted",
1929 JOptionPane.ERROR_MESSAGE );
1935 private ControlPanel getControlPanel() {
1936 return getMainPanel().getControlPanel();
1939 private File getCurrentDir() {
1940 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1941 if ( ForesterUtil.isWindowns() ) {
1943 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1945 catch ( final Exception e ) {
1946 _current_dir = null;
1950 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1951 if ( System.getProperty( "user.home" ) != null ) {
1952 _current_dir = new File( System.getProperty( "user.home" ) );
1954 else if ( System.getProperty( "user.dir" ) != null ) {
1955 _current_dir = new File( System.getProperty( "user.dir" ) );
1958 return _current_dir;
1961 private double getMinNotCollapseConfidenceValue() {
1962 return _min_not_collapse;
1965 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
1966 if ( _phylogenetic_inference_options == null ) {
1967 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
1969 return _phylogenetic_inference_options;
1972 private boolean isUnsavedDataPresent() {
1973 final List<TreePanel> tps = getMainPanel().getTreePanels();
1974 for( final TreePanel tp : tps ) {
1975 if ( tp.isEdited() ) {
1982 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
1983 if ( getCurrentTreePanel() != null ) {
1984 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1985 if ( ( phy != null ) && !phy.isEmpty() ) {
1987 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
1992 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
1993 if ( getCurrentTreePanel() != null ) {
1994 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1995 if ( ( phy != null ) && !phy.isEmpty() ) {
1996 PhylogenyMethods.transferNodeNameToField( phy,
1997 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
2003 private void newTree() {
2004 final Phylogeny[] phys = new Phylogeny[ 1 ];
2005 final Phylogeny phy = new Phylogeny();
2006 final PhylogenyNode node = new PhylogenyNode();
2007 phy.setRoot( node );
2008 phy.setRooted( true );
2010 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
2011 _mainpanel.getControlPanel().showWhole();
2012 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2013 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2014 if ( getMainPanel().getMainFrame() == null ) {
2015 // Must be "E" applet version.
2016 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
2017 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2020 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2022 activateSaveAllIfNeeded();
2026 private void obtainDetailedTaxonomicInformation() {
2027 if ( getCurrentTreePanel() != null ) {
2028 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2029 if ( ( phy != null ) && !phy.isEmpty() ) {
2030 final TaxonomyDataManager t = new TaxonomyDataManager( this,
2031 _mainpanel.getCurrentTreePanel(),
2035 new Thread( t ).start();
2040 private void obtainDetailedTaxonomicInformationDelete() {
2041 if ( getCurrentTreePanel() != null ) {
2042 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2043 if ( ( phy != null ) && !phy.isEmpty() ) {
2044 final TaxonomyDataManager t = new TaxonomyDataManager( this,
2045 _mainpanel.getCurrentTreePanel(),
2049 new Thread( t ).start();
2054 private void obtainSequenceInformation() {
2055 if ( getCurrentTreePanel() != null ) {
2056 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2057 if ( ( phy != null ) && !phy.isEmpty() ) {
2058 final SequenceDataRetriver u = new SequenceDataRetriver( this,
2059 _mainpanel.getCurrentTreePanel(),
2061 new Thread( u ).start();
2066 private void print() {
2067 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
2068 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
2071 if ( !getOptions().isPrintUsingActualSize() ) {
2072 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
2073 getOptions().getPrintSizeY() - 140,
2075 getCurrentTreePanel().resetPreferredSize();
2076 getCurrentTreePanel().repaint();
2078 final String job_name = Constants.PRG_NAME;
2079 boolean error = false;
2080 String printer_name = null;
2082 printer_name = Printer.print( getCurrentTreePanel(), job_name );
2084 catch ( final Exception e ) {
2086 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2088 if ( !error && ( printer_name != null ) ) {
2089 String msg = "Printing data sent to printer";
2090 if ( printer_name.length() > 1 ) {
2091 msg += " [" + printer_name + "]";
2093 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2095 if ( !getOptions().isPrintUsingActualSize() ) {
2096 getControlPanel().showWhole();
2100 private void printPhylogenyToPdf( final String file_name ) {
2101 if ( !getOptions().isPrintUsingActualSize() ) {
2102 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
2103 getOptions().getPrintSizeY(),
2105 getCurrentTreePanel().resetPreferredSize();
2106 getCurrentTreePanel().repaint();
2108 String pdf_written_to = "";
2109 boolean error = false;
2111 if ( getOptions().isPrintUsingActualSize() ) {
2112 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
2113 getCurrentTreePanel(),
2114 getCurrentTreePanel().getWidth(),
2115 getCurrentTreePanel().getHeight() );
2118 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
2119 .getPrintSizeX(), getOptions().getPrintSizeY() );
2122 catch ( final IOException e ) {
2124 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2127 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2128 JOptionPane.showMessageDialog( this,
2129 "Wrote PDF to: " + pdf_written_to,
2131 JOptionPane.INFORMATION_MESSAGE );
2134 JOptionPane.showMessageDialog( this,
2135 "There was an unknown problem when attempting to write to PDF file: \""
2138 JOptionPane.ERROR_MESSAGE );
2141 if ( !getOptions().isPrintUsingActualSize() ) {
2142 getControlPanel().showWhole();
2146 private void readPhylogeniesFromFile() {
2147 boolean exception = false;
2148 Phylogeny[] phys = null;
2149 // Set an initial directory if none set yet
2150 final File my_dir = getCurrentDir();
2151 _open_filechooser.setMultiSelectionEnabled( true );
2152 // Open file-open dialog and set current directory
2153 if ( my_dir != null ) {
2154 _open_filechooser.setCurrentDirectory( my_dir );
2156 final int result = _open_filechooser.showOpenDialog( _contentpane );
2157 // All done: get the file
2158 final File[] files = _open_filechooser.getSelectedFiles();
2159 setCurrentDir( _open_filechooser.getCurrentDirectory() );
2160 boolean nhx_or_nexus = false;
2161 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2162 for( final File file : files ) {
2163 if ( ( file != null ) && !file.isDirectory() ) {
2164 if ( _mainpanel.getCurrentTreePanel() != null ) {
2165 _mainpanel.getCurrentTreePanel().setWaitCursor();
2168 _mainpanel.setWaitCursor();
2170 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
2171 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
2173 final NHXParser nhx = new NHXParser();
2174 setSpecialOptionsForNhxParser( nhx );
2175 phys = PhylogenyMethods.readPhylogenies( nhx, file );
2176 nhx_or_nexus = true;
2178 catch ( final Exception e ) {
2180 exceptionOccuredDuringOpenFile( e );
2183 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2184 warnIfNotPhyloXmlValidation( getConfiguration() );
2186 final PhyloXmlParser xml_parser = createPhyloXmlParser();
2187 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
2189 catch ( final Exception e ) {
2191 exceptionOccuredDuringOpenFile( e );
2194 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
2196 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2198 catch ( final Exception e ) {
2200 exceptionOccuredDuringOpenFile( e );
2203 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2205 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
2206 setSpecialOptionsForNexParser( nex );
2207 phys = PhylogenyMethods.readPhylogenies( nex, file );
2208 nhx_or_nexus = true;
2210 catch ( final Exception e ) {
2212 exceptionOccuredDuringOpenFile( e );
2218 final PhylogenyParser parser = ParserUtils
2219 .createParserDependingOnFileType( file, getConfiguration()
2220 .isValidatePhyloXmlAgainstSchema() );
2221 if ( parser instanceof NexusPhylogeniesParser ) {
2222 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
2223 setSpecialOptionsForNexParser( nex );
2224 nhx_or_nexus = true;
2226 else if ( parser instanceof NHXParser ) {
2227 final NHXParser nhx = ( NHXParser ) parser;
2228 setSpecialOptionsForNhxParser( nhx );
2229 nhx_or_nexus = true;
2231 else if ( parser instanceof PhyloXmlParser ) {
2232 warnIfNotPhyloXmlValidation( getConfiguration() );
2234 phys = PhylogenyMethods.readPhylogenies( parser, file );
2236 catch ( final Exception e ) {
2238 exceptionOccuredDuringOpenFile( e );
2241 if ( _mainpanel.getCurrentTreePanel() != null ) {
2242 _mainpanel.getCurrentTreePanel().setArrowCursor();
2245 _mainpanel.setArrowCursor();
2247 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
2248 boolean one_desc = false;
2249 if ( nhx_or_nexus ) {
2250 for( final Phylogeny phy : phys ) {
2251 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2252 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
2254 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
2260 AptxUtil.addPhylogeniesToTabs( phys,
2262 file.getAbsolutePath(),
2265 _mainpanel.getControlPanel().showWhole();
2266 if ( nhx_or_nexus && one_desc ) {
2268 .showMessageDialog( this,
2269 "One or more trees contain (a) node(s) with one descendant, "
2270 + ForesterUtil.LINE_SEPARATOR
2271 + "possibly indicating illegal parentheses within node names.",
2272 "Warning: Possible Error in New Hampshire Formatted Data",
2273 JOptionPane.WARNING_MESSAGE );
2279 activateSaveAllIfNeeded();
2283 private void readSpeciesTreeFromFile() {
2285 boolean exception = false;
2286 final File my_dir = getCurrentDir();
2287 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2288 if ( my_dir != null ) {
2289 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2291 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2292 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2293 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2294 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2296 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2299 catch ( final Exception e ) {
2301 exceptionOccuredDuringOpenFile( e );
2304 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2306 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2309 catch ( final Exception e ) {
2311 exceptionOccuredDuringOpenFile( e );
2317 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2320 catch ( final Exception e ) {
2322 exceptionOccuredDuringOpenFile( e );
2325 if ( !exception && ( t != null ) && !t.isRooted() ) {
2328 JOptionPane.showMessageDialog( this,
2329 "Species tree is not rooted",
2330 "Species tree not loaded",
2331 JOptionPane.ERROR_MESSAGE );
2333 if ( !exception && ( t != null ) ) {
2334 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2335 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2336 final PhylogenyNode node = it.next();
2337 if ( !node.getNodeData().isHasTaxonomy() ) {
2341 .showMessageDialog( this,
2342 "Species tree contains external node(s) without taxonomy information",
2343 "Species tree not loaded",
2344 JOptionPane.ERROR_MESSAGE );
2348 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2351 JOptionPane.showMessageDialog( this,
2353 + node.getNodeData().getTaxonomy().asSimpleText()
2354 + "] is not unique in species tree",
2355 "Species tree not loaded",
2356 JOptionPane.ERROR_MESSAGE );
2360 tax_set.add( node.getNodeData().getTaxonomy() );
2365 if ( !exception && ( t != null ) ) {
2367 JOptionPane.showMessageDialog( this,
2368 "Species tree successfully loaded",
2369 "Species tree loaded",
2370 JOptionPane.INFORMATION_MESSAGE );
2372 _contentpane.repaint();
2377 private void setCurrentDir( final File current_dir ) {
2378 _current_dir = current_dir;
2381 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2382 _min_not_collapse = min_not_collapse;
2385 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2386 _phylogenetic_inference_options = phylogenetic_inference_options;
2389 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2390 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2391 nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2394 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2395 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2396 nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2399 private void writeAllToFile() {
2400 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2403 final File my_dir = getCurrentDir();
2404 if ( my_dir != null ) {
2405 _save_filechooser.setCurrentDirectory( my_dir );
2407 _save_filechooser.setSelectedFile( new File( "" ) );
2408 final int result = _save_filechooser.showSaveDialog( _contentpane );
2409 final File file = _save_filechooser.getSelectedFile();
2410 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2411 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2412 if ( file.exists() ) {
2413 final int i = JOptionPane.showConfirmDialog( this,
2414 file + " already exists. Overwrite?",
2416 JOptionPane.OK_CANCEL_OPTION,
2417 JOptionPane.WARNING_MESSAGE );
2418 if ( i != JOptionPane.OK_OPTION ) {
2425 catch ( final Exception e ) {
2426 JOptionPane.showMessageDialog( this,
2427 "Failed to delete: " + file,
2429 JOptionPane.WARNING_MESSAGE );
2433 final int count = getMainPanel().getTabbedPane().getTabCount();
2434 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2435 for( int i = 0; i < count; ++i ) {
2436 trees.add( getMainPanel().getPhylogeny( i ) );
2437 getMainPanel().getTreePanels().get( i ).setEdited( false );
2439 final PhylogenyWriter writer = new PhylogenyWriter();
2441 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2443 catch ( final IOException e ) {
2444 JOptionPane.showMessageDialog( this,
2445 "Failed to write to: " + file,
2447 JOptionPane.WARNING_MESSAGE );
2452 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2454 final PhylogenyWriter writer = new PhylogenyWriter();
2455 writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
2457 catch ( final Exception e ) {
2459 exceptionOccuredDuringSaveAs( e );
2464 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2466 final PhylogenyWriter writer = new PhylogenyWriter();
2467 writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
2469 catch ( final Exception e ) {
2471 exceptionOccuredDuringSaveAs( e );
2476 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2478 final PhylogenyWriter writer = new PhylogenyWriter();
2479 writer.toPhyloXML( file, t, 0 );
2481 catch ( final Exception e ) {
2483 exceptionOccuredDuringSaveAs( e );
2488 private void writeToFile( final Phylogeny t ) {
2492 String initial_filename = null;
2493 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2495 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2497 catch ( final IOException e ) {
2498 initial_filename = null;
2501 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2502 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2505 _save_filechooser.setSelectedFile( new File( "" ) );
2507 final File my_dir = getCurrentDir();
2508 if ( my_dir != null ) {
2509 _save_filechooser.setCurrentDirectory( my_dir );
2511 final int result = _save_filechooser.showSaveDialog( _contentpane );
2512 final File file = _save_filechooser.getSelectedFile();
2513 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2514 boolean exception = false;
2515 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2516 if ( file.exists() ) {
2517 final int i = JOptionPane.showConfirmDialog( this,
2518 file + " already exists.\nOverwrite?",
2520 JOptionPane.OK_CANCEL_OPTION,
2521 JOptionPane.QUESTION_MESSAGE );
2522 if ( i != JOptionPane.OK_OPTION ) {
2526 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2528 ForesterUtil.copyFile( file, to );
2530 catch ( final Exception e ) {
2531 JOptionPane.showMessageDialog( this,
2532 "Failed to create backup copy " + to,
2533 "Failed to Create Backup Copy",
2534 JOptionPane.WARNING_MESSAGE );
2539 catch ( final Exception e ) {
2540 JOptionPane.showMessageDialog( this,
2541 "Failed to delete: " + file,
2543 JOptionPane.WARNING_MESSAGE );
2547 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2548 exception = writeAsNewHampshire( t, exception, file );
2550 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2551 exception = writeAsPhyloXml( t, exception, file );
2553 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2554 exception = writeAsNexus( t, exception, file );
2558 final String file_name = file.getName().trim().toLowerCase();
2559 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2560 || file_name.endsWith( ".tree" ) ) {
2561 exception = writeAsNewHampshire( t, exception, file );
2563 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2564 exception = writeAsNexus( t, exception, file );
2568 exception = writeAsPhyloXml( t, exception, file );
2572 getMainPanel().setTitleOfSelectedTab( file.getName() );
2573 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2574 getMainPanel().getCurrentTreePanel().setEdited( false );
2579 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2580 if ( ( t == null ) || t.isEmpty() ) {
2583 String initial_filename = "";
2584 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2585 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2587 if ( initial_filename.indexOf( '.' ) > 0 ) {
2588 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2590 initial_filename = initial_filename + "." + type;
2591 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2592 final File my_dir = getCurrentDir();
2593 if ( my_dir != null ) {
2594 _writetographics_filechooser.setCurrentDirectory( my_dir );
2596 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2597 File file = _writetographics_filechooser.getSelectedFile();
2598 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2599 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2600 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2601 file = new File( file.toString() + "." + type );
2603 if ( file.exists() ) {
2604 final int i = JOptionPane.showConfirmDialog( this,
2605 file + " already exists. Overwrite?",
2607 JOptionPane.OK_CANCEL_OPTION,
2608 JOptionPane.WARNING_MESSAGE );
2609 if ( i != JOptionPane.OK_OPTION ) {
2616 catch ( final Exception e ) {
2617 JOptionPane.showMessageDialog( this,
2618 "Failed to delete: " + file,
2620 JOptionPane.WARNING_MESSAGE );
2624 writePhylogenyToGraphicsFile( file.toString(), type );
2628 private void writeToPdf( final Phylogeny t ) {
2629 if ( ( t == null ) || t.isEmpty() ) {
2632 String initial_filename = "";
2633 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2634 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2636 if ( initial_filename.indexOf( '.' ) > 0 ) {
2637 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2639 initial_filename = initial_filename + ".pdf";
2640 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2641 final File my_dir = getCurrentDir();
2642 if ( my_dir != null ) {
2643 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2645 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2646 File file = _writetopdf_filechooser.getSelectedFile();
2647 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2648 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2649 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2650 file = new File( file.toString() + ".pdf" );
2652 if ( file.exists() ) {
2653 final int i = JOptionPane.showConfirmDialog( this,
2654 file + " already exists. Overwrite?",
2656 JOptionPane.OK_CANCEL_OPTION,
2657 JOptionPane.WARNING_MESSAGE );
2658 if ( i != JOptionPane.OK_OPTION ) {
2662 printPhylogenyToPdf( file.toString() );
2666 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
2667 return new MainFrameApplication( phys, config );
2670 public static MainFrame createInstance( final Phylogeny[] phys,
2671 final Configuration config,
2673 final File current_dir ) {
2674 return new MainFrameApplication( phys, config, title, current_dir );
2677 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2678 return new MainFrameApplication( phys, config, title );
2681 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2682 return new MainFrameApplication( phys, config_file_name, title );
2685 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2686 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2687 + o.getPrintSizeY() + ")" );
2690 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2691 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2694 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2695 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2697 .showMessageDialog( null,
2699 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2702 JOptionPane.WARNING_MESSAGE );
2705 } // MainFrameApplication.
2707 class DefaultFilter extends FileFilter {
2710 public boolean accept( final File f ) {
2711 final String file_name = f.getName().trim().toLowerCase();
2712 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2713 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2714 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2715 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2716 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2717 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2718 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2719 || file_name.endsWith( ".con" ) || f.isDirectory();
2723 public String getDescription() {
2724 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2728 class GraphicsFileFilter extends FileFilter {
2731 public boolean accept( final File f ) {
2732 final String file_name = f.getName().trim().toLowerCase();
2733 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2734 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2738 public String getDescription() {
2739 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2743 class MsaFileFilter extends FileFilter {
2746 public boolean accept( final File f ) {
2747 final String file_name = f.getName().trim().toLowerCase();
2748 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2749 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2753 public String getDescription() {
2754 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2758 class NexusFilter extends FileFilter {
2761 public boolean accept( final File f ) {
2762 final String file_name = f.getName().trim().toLowerCase();
2763 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2764 || file_name.endsWith( ".tre" ) || f.isDirectory();
2768 public String getDescription() {
2769 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2773 class NHFilter extends FileFilter {
2776 public boolean accept( final File f ) {
2777 final String file_name = f.getName().trim().toLowerCase();
2778 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2779 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2780 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2785 public String getDescription() {
2786 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2790 class NHXFilter extends FileFilter {
2793 public boolean accept( final File f ) {
2794 final String file_name = f.getName().trim().toLowerCase();
2795 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2799 public String getDescription() {
2800 return "NHX files (*.nhx) [deprecated]";
2804 class PdfFilter extends FileFilter {
2807 public boolean accept( final File f ) {
2808 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2812 public String getDescription() {
2813 return "PDF files (*.pdf)";
2817 class SequencesFileFilter extends FileFilter {
2820 public boolean accept( final File f ) {
2821 final String file_name = f.getName().trim().toLowerCase();
2822 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2823 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2827 public String getDescription() {
2828 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2832 class TolFilter extends FileFilter {
2835 public boolean accept( final File f ) {
2836 final String file_name = f.getName().trim().toLowerCase();
2837 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2838 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2842 public String getDescription() {
2843 return "Tree of Life files (*.tol, *.tolxml)";
2847 class XMLFilter extends FileFilter {
2850 public boolean accept( final File f ) {
2851 final String file_name = f.getName().trim().toLowerCase();
2852 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2853 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2857 public String getDescription() {
2858 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";