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: www.phylosoft.org/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.net.MalformedURLException;
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.List;
46 import javax.swing.ButtonGroup;
47 import javax.swing.JCheckBoxMenuItem;
48 import javax.swing.JFileChooser;
49 import javax.swing.JMenu;
50 import javax.swing.JMenuBar;
51 import javax.swing.JMenuItem;
52 import javax.swing.JOptionPane;
53 import javax.swing.JRadioButtonMenuItem;
54 import javax.swing.UIManager;
55 import javax.swing.UnsupportedLookAndFeelException;
56 import javax.swing.WindowConstants;
57 import javax.swing.event.ChangeEvent;
58 import javax.swing.event.ChangeListener;
59 import javax.swing.filechooser.FileFilter;
61 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
62 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
63 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
64 import org.forester.archaeopteryx.Util.GraphicsExportType;
65 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
66 import org.forester.archaeopteryx.tools.GoAnnotation;
67 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
68 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
69 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
70 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
71 import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
72 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
73 import org.forester.archaeopteryx.webservices.WebservicesManager;
74 import org.forester.io.parsers.FastaParser;
75 import org.forester.io.parsers.GeneralMsaParser;
76 import org.forester.io.parsers.PhylogenyParser;
77 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
78 import org.forester.io.parsers.nhx.NHXParser;
79 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
80 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
81 import org.forester.io.parsers.tol.TolParser;
82 import org.forester.io.writers.PhylogenyWriter;
83 import org.forester.io.writers.SequenceWriter;
84 import org.forester.msa.Msa;
85 import org.forester.msa.MsaFormatException;
86 import org.forester.phylogeny.Phylogeny;
87 import org.forester.phylogeny.PhylogenyMethods;
88 import org.forester.phylogeny.PhylogenyNode;
89 import org.forester.phylogeny.data.Confidence;
90 import org.forester.phylogeny.data.Taxonomy;
91 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
92 import org.forester.phylogeny.factories.PhylogenyFactory;
93 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
94 import org.forester.sdi.GSDI;
95 import org.forester.sdi.SDI;
96 import org.forester.sdi.SDIR;
97 import org.forester.sdi.SDIse;
98 import org.forester.sequence.Sequence;
99 import org.forester.util.BasicDescriptiveStatistics;
100 import org.forester.util.BasicTable;
101 import org.forester.util.BasicTableParser;
102 import org.forester.util.DescriptiveStatistics;
103 import org.forester.util.ForesterUtil;
104 import org.forester.util.ForesterUtil.PhylogenyNodeField;
105 import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
106 import org.forester.util.WindowsUtils;
108 class DefaultFilter extends FileFilter {
111 public boolean accept( final File f ) {
112 final String file_name = f.getName().trim().toLowerCase();
113 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
114 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
115 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
116 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
117 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
118 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
119 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
120 || file_name.endsWith( ".con" ) || f.isDirectory();
124 public String getDescription() {
125 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
129 class GraphicsFileFilter extends FileFilter {
132 public boolean accept( final File f ) {
133 final String file_name = f.getName().trim().toLowerCase();
134 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
135 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
139 public String getDescription() {
140 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
144 class MsaFileFilter extends FileFilter {
147 public boolean accept( final File f ) {
148 final String file_name = f.getName().trim().toLowerCase();
149 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
150 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
154 public String getDescription() {
155 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
159 class SequencesFileFilter extends FileFilter {
162 public boolean accept( final File f ) {
163 final String file_name = f.getName().trim().toLowerCase();
164 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
165 || file_name.endsWith( ".seqs" ) || f.isDirectory();
169 public String getDescription() {
170 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
174 public final class MainFrameApplication extends MainFrame {
176 private final static int FRAME_X_SIZE = 800;
177 private final static int FRAME_Y_SIZE = 800;
178 // Filters for the file-open dialog (classes defined in this file)
179 private final static NHFilter nhfilter = new NHFilter();
180 private final static NHXFilter nhxfilter = new NHXFilter();
181 private final static XMLFilter xmlfilter = new XMLFilter();
182 private final static TolFilter tolfilter = new TolFilter();
183 private final static NexusFilter nexusfilter = new NexusFilter();
184 private final static PdfFilter pdffilter = new PdfFilter();
185 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
186 private final static MsaFileFilter msafilter = new MsaFileFilter();
187 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
188 private final static DefaultFilter defaultfilter = new DefaultFilter();
189 private static final long serialVersionUID = -799735726778865234L;
190 private final JFileChooser _values_filechooser;
191 private final JFileChooser _open_filechooser;
192 private final JFileChooser _msa_filechooser;
193 private final JFileChooser _seqs_filechooser;
194 private final JFileChooser _open_filechooser_for_species_tree;
195 private final JFileChooser _save_filechooser;
196 private final JFileChooser _writetopdf_filechooser;
197 private final JFileChooser _writetographics_filechooser;
199 private JMenu _analysis_menu;
200 private JMenuItem _load_species_tree_item;
201 private JMenuItem _sdi_item;
202 private JMenuItem _gsdi_item;
203 private JMenuItem _root_min_dups_item;
204 private JMenuItem _root_min_cost_l_item;
205 private JMenuItem _lineage_inference;
206 private JMenuItem _function_analysis;
207 // Application-only print menu items
208 private JMenuItem _print_item;
209 private JMenuItem _write_to_pdf_item;
210 private JMenuItem _write_to_jpg_item;
211 private JMenuItem _write_to_gif_item;
212 private JMenuItem _write_to_tif_item;
213 private JMenuItem _write_to_png_item;
214 private JMenuItem _write_to_bmp_item;
215 private Phylogeny _species_tree;
216 private File _current_dir;
217 private ButtonGroup _radio_group_1;
219 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
220 // Phylogeny Inference menu
221 private JMenu _inference_menu;
222 private JMenuItem _inference_from_msa_item;
223 private JMenuItem _inference_from_seqs_item;
224 // Phylogeny Inference
225 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
226 private Msa _msa = null;
227 private File _msa_file = null;
228 private List<Sequence> _seqs = null;
229 private File _seqs_file = null;
230 // expression values menu:
231 JMenuItem _read_values_jmi;
233 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
234 _configuration = config;
235 if ( _configuration == null ) {
236 throw new IllegalArgumentException( "configuration is null" );
239 if ( _configuration.isUseNativeUI() ) {
240 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
243 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
245 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
247 catch ( final UnsupportedLookAndFeelException e ) {
248 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
250 catch ( final ClassNotFoundException e ) {
251 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
253 catch ( final InstantiationException e ) {
254 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
256 catch ( final IllegalAccessException e ) {
257 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
259 catch ( final Exception e ) {
260 Util.dieWithSystemError( e.toString() );
262 // hide until everything is ready
264 setOptions( Options.createInstance( _configuration ) );
265 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
267 _species_tree = null;
269 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
270 _mainpanel = new MainPanel( _configuration, this );
272 _open_filechooser = new JFileChooser();
273 _open_filechooser.setCurrentDirectory( new File( "." ) );
274 _open_filechooser.setMultiSelectionEnabled( false );
275 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
276 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
277 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
278 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
279 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
280 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
281 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
282 _open_filechooser_for_species_tree = new JFileChooser();
283 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
284 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
285 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
286 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
287 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
288 _save_filechooser = new JFileChooser();
289 _save_filechooser.setCurrentDirectory( new File( "." ) );
290 _save_filechooser.setMultiSelectionEnabled( false );
291 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
292 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
293 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
294 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
295 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
296 _writetopdf_filechooser = new JFileChooser();
297 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
298 _writetographics_filechooser = new JFileChooser();
299 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
301 _msa_filechooser = new JFileChooser();
302 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
303 _msa_filechooser.setCurrentDirectory( new File( "." ) );
304 _msa_filechooser.setMultiSelectionEnabled( false );
305 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
306 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
308 _seqs_filechooser = new JFileChooser();
309 _seqs_filechooser.setName( "Read Sequences File" );
310 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
311 _seqs_filechooser.setMultiSelectionEnabled( false );
312 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
313 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
315 _values_filechooser = new JFileChooser();
316 _values_filechooser.setCurrentDirectory( new File( "." ) );
317 _values_filechooser.setMultiSelectionEnabled( false );
318 // build the menu bar
319 _jmenubar = new JMenuBar();
320 if ( !_configuration.isUseNativeUI() ) {
321 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
324 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
325 buildPhylogeneticInferenceMenu();
334 setJMenuBar( _jmenubar );
335 _jmenubar.add( _help_jmenu );
336 _contentpane = getContentPane();
337 _contentpane.setLayout( new BorderLayout() );
338 _contentpane.add( _mainpanel, BorderLayout.CENTER );
340 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
341 // addWindowFocusListener( new WindowAdapter() {
344 // public void windowGainedFocus( WindowEvent e ) {
345 // requestFocusInWindow();
348 // The window listener
349 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
350 addWindowListener( new WindowAdapter() {
353 public void windowClosing( final WindowEvent e ) {
354 if ( isUnsavedDataPresent() ) {
355 final int r = JOptionPane.showConfirmDialog( null,
356 "Exit despite potentially unsaved changes?",
358 JOptionPane.YES_NO_OPTION );
359 if ( r != JOptionPane.YES_OPTION ) {
364 final int r = JOptionPane.showConfirmDialog( null,
365 "Exit Archaeopteryx?",
367 JOptionPane.YES_NO_OPTION );
368 if ( r != JOptionPane.YES_OPTION ) {
375 // The component listener
376 addComponentListener( new ComponentAdapter() {
379 public void componentResized( final ComponentEvent e ) {
380 if ( _mainpanel.getCurrentTreePanel() != null ) {
381 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
383 _mainpanel.getCurrentTreePanel()
389 requestFocusInWindow();
390 // addKeyListener( this );
392 if ( ( phys != null ) && ( phys.length > 0 ) ) {
393 Util.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
395 getMainPanel().getControlPanel().showWholeAll();
396 getMainPanel().getControlPanel().showWhole();
398 activateSaveAllIfNeeded();
399 // ...and its children
400 _contentpane.repaint();
404 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
405 // Reads the config file (false, false => not url, not applet):
406 this( phys, new Configuration( config_file, false, false ), title );
410 public void actionPerformed( final ActionEvent e ) {
412 super.actionPerformed( e );
413 final Object o = e.getSource();
414 // Handle app-specific actions here:
415 if ( o == _open_item ) {
416 readPhylogeniesFromFile();
418 else if ( o == _save_item ) {
419 writeToFile( _mainpanel.getCurrentPhylogeny() );
420 // If subtree currently displayed, save it, instead of complete
423 else if ( o == _new_item ) {
426 else if ( o == _save_all_item ) {
429 else if ( o == _close_item ) {
432 else if ( o == _write_to_pdf_item ) {
433 writeToPdf( _mainpanel.getCurrentPhylogeny() );
435 else if ( o == _write_to_jpg_item ) {
436 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
438 else if ( o == _write_to_png_item ) {
439 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
441 else if ( o == _write_to_gif_item ) {
442 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
444 else if ( o == _write_to_tif_item ) {
445 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
447 else if ( o == _write_to_bmp_item ) {
448 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
450 else if ( o == _print_item ) {
453 else if ( o == _load_species_tree_item ) {
454 readSpeciesTreeFromFile();
456 else if ( o == _sdi_item ) {
457 if ( isSubtreeDisplayed() ) {
462 else if ( o == _lineage_inference ) {
463 if ( isSubtreeDisplayed() ) {
464 JOptionPane.showMessageDialog( this,
466 "Cannot infer ancestral taxonomies",
467 JOptionPane.ERROR_MESSAGE );
470 executeLineageInference();
472 else if ( o == _function_analysis ) {
473 executeFunctionAnalysis();
475 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
476 if ( isSubtreeDisplayed() ) {
479 obtainDetailedTaxonomicInformation();
481 else if ( o == _obtain_uniprot_seq_information_jmi ) {
482 obtainUniProtSequenceInformation();
484 else if ( o == _read_values_jmi ) {
485 if ( isSubtreeDisplayed() ) {
488 addExpressionValuesFromFile();
490 else if ( o == _move_node_names_to_tax_sn_jmi ) {
491 moveNodeNamesToTaxSn();
493 else if ( o == _move_node_names_to_seq_names_jmi ) {
494 moveNodeNamesToSeqNames();
496 else if ( o == _extract_tax_code_from_node_names_jmi ) {
497 extractTaxCodeFromNodeNames();
499 else if ( o == _gsdi_item ) {
500 if ( isSubtreeDisplayed() ) {
505 else if ( o == _root_min_dups_item ) {
506 if ( isSubtreeDisplayed() ) {
509 executeSDIR( false );
511 else if ( o == _root_min_cost_l_item ) {
512 if ( isSubtreeDisplayed() ) {
517 else if ( o == _graphics_export_visible_only_cbmi ) {
518 updateOptions( getOptions() );
520 else if ( o == _antialias_print_cbmi ) {
521 updateOptions( getOptions() );
523 else if ( o == _print_black_and_white_cbmi ) {
524 updateOptions( getOptions() );
526 else if ( o == _print_using_actual_size_cbmi ) {
527 updateOptions( getOptions() );
529 else if ( o == _graphics_export_using_actual_size_cbmi ) {
530 updateOptions( getOptions() );
532 else if ( o == _print_size_mi ) {
535 else if ( o == _choose_pdf_width_mi ) {
538 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
539 updateOptions( getOptions() );
541 else if ( o == _replace_underscores_cbmi ) {
542 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
543 _extract_pfam_style_tax_codes_cbmi.setSelected( false );
545 updateOptions( getOptions() );
547 else if ( o == _collapse_below_threshold ) {
548 if ( isSubtreeDisplayed() ) {
551 collapseBelowThreshold();
553 else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
554 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
555 _replace_underscores_cbmi.setSelected( false );
557 updateOptions( getOptions() );
559 else if ( o == _inference_from_msa_item ) {
560 executePhyleneticInference( false );
562 else if ( o == _inference_from_seqs_item ) {
563 executePhyleneticInference( true );
565 _contentpane.repaint();
567 catch ( final Exception ex ) {
568 Util.unexpectedException( ex );
570 catch ( final Error err ) {
571 Util.unexpectedError( err );
575 void buildAnalysisMenu() {
576 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
577 _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
578 if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
579 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
581 _analysis_menu.addSeparator();
582 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
583 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
584 _analysis_menu.addSeparator();
585 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
586 customizeJMenuItem( _sdi_item );
587 customizeJMenuItem( _gsdi_item );
588 customizeJMenuItem( _root_min_dups_item );
589 customizeJMenuItem( _root_min_cost_l_item );
590 customizeJMenuItem( _load_species_tree_item );
591 _analysis_menu.addSeparator();
592 _analysis_menu.add( _lineage_inference = new JMenuItem( "Infer Ancestor Taxonomies" ) );
593 customizeJMenuItem( _lineage_inference );
594 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
595 _jmenubar.add( _analysis_menu );
598 void buildPhylogeneticInferenceMenu() {
599 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
601 .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
602 customizeJMenuItem( _inference_from_msa_item );
603 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
605 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
606 customizeJMenuItem( _inference_from_seqs_item );
607 _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
608 _jmenubar.add( _inference_menu );
612 void buildFileMenu() {
613 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
614 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
615 _file_jmenu.addSeparator();
616 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
617 _file_jmenu.addSeparator();
618 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
619 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
620 .getAvailablePhylogeniesWebserviceClients().size() ];
621 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
622 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
623 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
624 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
626 if ( getConfiguration().isEditable() ) {
627 _file_jmenu.addSeparator();
628 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
629 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
631 _file_jmenu.addSeparator();
632 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
633 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
634 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
635 _save_all_item.setEnabled( false );
636 _file_jmenu.addSeparator();
637 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
638 if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
639 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
641 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
642 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
643 if ( Util.canWriteFormat( "gif" ) ) {
644 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
646 if ( Util.canWriteFormat( "bmp" ) ) {
647 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
649 _file_jmenu.addSeparator();
650 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
651 _file_jmenu.addSeparator();
652 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
653 _close_item.setToolTipText( "To close the current pane." );
654 _close_item.setEnabled( true );
655 _file_jmenu.addSeparator();
656 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
657 // For print in color option item
658 customizeJMenuItem( _open_item );
660 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
661 customizeJMenuItem( _open_url_item );
662 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
663 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
665 customizeJMenuItem( _save_item );
666 if ( getConfiguration().isEditable() ) {
667 customizeJMenuItem( _new_item );
669 customizeJMenuItem( _close_item );
670 customizeJMenuItem( _save_all_item );
671 customizeJMenuItem( _write_to_pdf_item );
672 customizeJMenuItem( _write_to_png_item );
673 customizeJMenuItem( _write_to_jpg_item );
674 customizeJMenuItem( _write_to_gif_item );
675 customizeJMenuItem( _write_to_tif_item );
676 customizeJMenuItem( _write_to_bmp_item );
677 customizeJMenuItem( _print_item );
678 customizeJMenuItem( _exit_item );
679 _jmenubar.add( _file_jmenu );
682 void buildOptionsMenu() {
683 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
684 _options_jmenu.addChangeListener( new ChangeListener() {
687 public void stateChanged( final ChangeEvent e ) {
688 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
689 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
691 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
692 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
693 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
694 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
695 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
696 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
698 _show_branch_length_values_cbmi,
699 _non_lined_up_cladograms_rbmi,
700 _uniform_cladograms_rbmi,
701 _ext_node_dependent_cladogram_rbmi,
702 _label_direction_cbmi );
703 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
704 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
705 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
708 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
710 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
711 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
712 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
713 _radio_group_1 = new ButtonGroup();
714 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
715 _radio_group_1.add( _uniform_cladograms_rbmi );
716 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
717 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
719 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
720 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
721 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
722 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
723 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
725 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
726 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
727 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
728 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
729 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
730 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
731 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
732 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
733 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
734 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
735 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
737 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
738 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
739 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
740 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
741 _options_jmenu.addSeparator();
742 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
743 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
744 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
745 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
746 _options_jmenu.addSeparator();
747 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
748 getConfiguration() ) );
749 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
750 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
752 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
754 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
756 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
757 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
758 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
759 _options_jmenu.addSeparator();
761 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
763 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
764 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
766 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
767 customizeJMenuItem( _choose_font_mi );
768 customizeJMenuItem( _choose_minimal_confidence_mi );
769 customizeJMenuItem( _switch_colors_mi );
770 customizeJMenuItem( _print_size_mi );
771 customizeJMenuItem( _choose_pdf_width_mi );
772 customizeJMenuItem( _overview_placment_mi );
773 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
774 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
775 customizeJMenuItem( _cycle_node_shape_mi );
776 customizeJMenuItem( _cycle_node_fill_mi );
777 customizeJMenuItem( _choose_node_size_mi );
778 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
779 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
780 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
781 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
782 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
783 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
784 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
785 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
786 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
787 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
788 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
789 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
790 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
791 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
792 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
793 customizeCheckBoxMenuItem( _label_direction_cbmi,
794 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
795 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
796 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
797 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
798 .isInternalNumberAreConfidenceForNhParsing() );
799 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
800 .isExtractPfamTaxonomyCodesInNhParsing() );
801 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
802 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
803 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
804 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
805 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
806 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
807 .isGraphicsExportUsingActualSize() );
808 _jmenubar.add( _options_jmenu );
811 void buildToolsMenu() {
812 _tools_menu = createMenu( "Tools", getConfiguration() );
813 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
814 customizeJMenuItem( _confcolor_item );
815 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
816 customizeJMenuItem( _taxcolor_item );
817 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
818 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
819 customizeJMenuItem( _remove_branch_color_item );
820 _tools_menu.addSeparator();
821 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
822 customizeJMenuItem( _midpoint_root_item );
823 _tools_menu.addSeparator();
824 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
825 customizeJMenuItem( _collapse_species_specific_subtrees );
827 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
828 customizeJMenuItem( _collapse_below_threshold );
829 _collapse_below_threshold
830 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
831 _tools_menu.addSeparator();
833 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
834 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
835 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
836 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
837 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
838 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
840 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
841 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
842 _extract_tax_code_from_node_names_jmi
843 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
844 _tools_menu.addSeparator();
846 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
847 customizeJMenuItem( _infer_common_sn_names_item );
848 _tools_menu.addSeparator();
850 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
851 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
852 _obtain_detailed_taxonomic_information_jmi
853 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
855 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
856 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
857 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
858 _tools_menu.addSeparator();
859 if ( !Constants.__RELEASE ) {
860 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
861 customizeJMenuItem( _function_analysis );
863 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
864 _tools_menu.addSeparator();
866 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
867 customizeJMenuItem( _read_values_jmi );
868 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
869 _jmenubar.add( _tools_menu );
872 private void choosePdfWidth() {
873 final String s = ( String ) JOptionPane.showInputDialog( this,
874 "Please enter the default line width for PDF export.\n"
876 + getOptions().getPrintLineWidth() + "]\n",
877 "Line Width for PDF Export",
878 JOptionPane.QUESTION_MESSAGE,
881 getOptions().getPrintLineWidth() );
882 if ( !ForesterUtil.isEmpty( s ) ) {
883 boolean success = true;
885 final String m_str = s.trim();
886 if ( !ForesterUtil.isEmpty( m_str ) ) {
888 f = Float.parseFloat( m_str );
890 catch ( final Exception ex ) {
897 if ( success && ( f > 0.0 ) ) {
898 getOptions().setPrintLineWidth( f );
903 private void choosePrintSize() {
904 final String s = ( String ) JOptionPane.showInputDialog( this,
905 "Please enter values for width and height,\nseparated by a comma.\n"
906 + "[current values: "
907 + getOptions().getPrintSizeX() + ", "
908 + getOptions().getPrintSizeY() + "]\n"
909 + "[A4: " + Constants.A4_SIZE_X + ", "
910 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
911 + Constants.US_LETTER_SIZE_X + ", "
912 + Constants.US_LETTER_SIZE_Y + "]",
913 "Default Size for Graphics Export",
914 JOptionPane.QUESTION_MESSAGE,
917 getOptions().getPrintSizeX() + ", "
918 + getOptions().getPrintSizeY() );
919 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
920 boolean success = true;
923 final String[] str_ary = s.split( "," );
924 if ( str_ary.length == 2 ) {
925 final String x_str = str_ary[ 0 ].trim();
926 final String y_str = str_ary[ 1 ].trim();
927 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
929 x = Integer.parseInt( x_str );
930 y = Integer.parseInt( y_str );
932 catch ( final Exception ex ) {
943 if ( success && ( x > 1 ) && ( y > 1 ) ) {
944 getOptions().setPrintSizeX( x );
945 getOptions().setPrintSizeY( y );
952 if ( isUnsavedDataPresent() ) {
953 final int r = JOptionPane.showConfirmDialog( this,
954 "Exit despite potentially unsaved changes?",
956 JOptionPane.YES_NO_OPTION );
957 if ( r != JOptionPane.YES_OPTION ) {
964 private void closeCurrentPane() {
965 if ( getMainPanel().getCurrentTreePanel() != null ) {
966 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
967 final int r = JOptionPane.showConfirmDialog( this,
968 "Close tab despite potentially unsaved changes?",
970 JOptionPane.YES_NO_OPTION );
971 if ( r != JOptionPane.YES_OPTION ) {
975 getMainPanel().closeCurrentPane();
976 activateSaveAllIfNeeded();
980 private void collapse( final Phylogeny phy, final double m ) {
981 final PhylogenyNodeIterator it = phy.iteratorPostorder();
982 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
983 double min_support = Double.MAX_VALUE;
984 boolean conf_present = false;
985 while ( it.hasNext() ) {
986 final PhylogenyNode n = it.next();
987 if ( !n.isExternal() && !n.isRoot() ) {
988 final List<Confidence> c = n.getBranchData().getConfidences();
989 if ( ( c != null ) && ( c.size() > 0 ) ) {
992 for( final Confidence confidence : c ) {
993 if ( confidence.getValue() > max ) {
994 max = confidence.getValue();
997 if ( max < getMinNotCollapseConfidenceValue() ) {
998 to_be_removed.add( n );
1000 if ( max < min_support ) {
1006 if ( conf_present ) {
1007 for( final PhylogenyNode node : to_be_removed ) {
1008 PhylogenyMethods.removeNode( node, phy );
1010 if ( to_be_removed.size() > 0 ) {
1011 phy.externalNodesHaveChanged();
1013 phy.recalculateNumberOfExternalDescendants( true );
1014 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1015 getCurrentTreePanel().setEdited( true );
1016 getCurrentTreePanel().repaint();
1018 if ( to_be_removed.size() > 0 ) {
1019 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1020 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1021 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1024 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1025 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1029 JOptionPane.showMessageDialog( this,
1030 "No branch collapsed because no confidence values present",
1031 "No confidence values present",
1032 JOptionPane.INFORMATION_MESSAGE );
1036 private void collapseBelowThreshold() {
1037 if ( getCurrentTreePanel() != null ) {
1038 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1039 if ( ( phy != null ) && !phy.isEmpty() ) {
1040 final String s = ( String ) JOptionPane.showInputDialog( this,
1041 "Please enter the minimum confidence value\n",
1042 "Minimal Confidence Value",
1043 JOptionPane.QUESTION_MESSAGE,
1046 getMinNotCollapseConfidenceValue() );
1047 if ( !ForesterUtil.isEmpty( s ) ) {
1048 boolean success = true;
1050 final String m_str = s.trim();
1051 if ( !ForesterUtil.isEmpty( m_str ) ) {
1053 m = Double.parseDouble( m_str );
1055 catch ( final Exception ex ) {
1062 if ( success && ( m >= 0.0 ) ) {
1063 setMinNotCollapseConfidenceValue( m );
1071 private PhyloXmlParser createPhyloXmlParser() {
1072 PhyloXmlParser xml_parser = null;
1073 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1075 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1077 catch ( final Exception e ) {
1078 JOptionPane.showMessageDialog( this,
1079 e.getLocalizedMessage(),
1080 "failed to create validating XML parser",
1081 JOptionPane.WARNING_MESSAGE );
1084 if ( xml_parser == null ) {
1085 xml_parser = new PhyloXmlParser();
1090 void executeGSDI() {
1091 if ( !isOKforSDI( false, true ) ) {
1094 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1095 JOptionPane.showMessageDialog( this,
1096 "Gene tree is not rooted.",
1097 "Cannot execute GSDI",
1098 JOptionPane.ERROR_MESSAGE );
1101 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1102 gene_tree.setAllNodesToNotCollapse();
1103 gene_tree.recalculateNumberOfExternalDescendants( false );
1105 int duplications = -1;
1107 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1108 duplications = gsdi.getDuplicationsSum();
1110 catch ( final Exception e ) {
1111 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1113 gene_tree.setRerootable( false );
1114 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1115 getControlPanel().setShowEvents( true );
1117 _mainpanel.getCurrentTreePanel().setEdited( true );
1118 JOptionPane.showMessageDialog( this,
1119 "Number of duplications: " + duplications,
1120 "GSDI successfully completed",
1121 JOptionPane.INFORMATION_MESSAGE );
1124 void executeFunctionAnalysis() {
1125 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1128 final GoAnnotation a = new GoAnnotation( this,
1129 _mainpanel.getCurrentTreePanel(),
1130 _mainpanel.getCurrentPhylogeny() );
1131 new Thread( a ).start();
1134 void executeLineageInference() {
1135 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1138 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1139 JOptionPane.showMessageDialog( this,
1140 "Phylogeny is not rooted.",
1141 "Cannot infer ancestral taxonomies",
1142 JOptionPane.ERROR_MESSAGE );
1145 final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1146 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1147 _mainpanel.getCurrentTreePanel(),
1149 new Thread( inferrer ).start();
1152 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1153 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1154 getPhylogeneticInferenceOptions(),
1155 from_unaligned_seqs );
1157 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1158 if ( !from_unaligned_seqs ) {
1159 if ( getMsa() != null ) {
1160 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1161 getPhylogeneticInferenceOptions()
1163 new Thread( inferrer ).start();
1166 JOptionPane.showMessageDialog( this,
1167 "No multiple sequence alignment selected",
1168 "Phylogenetic Inference Not Launched",
1169 JOptionPane.WARNING_MESSAGE );
1173 if ( getSeqs() != null ) {
1174 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1175 getPhylogeneticInferenceOptions()
1177 new Thread( inferrer ).start();
1180 JOptionPane.showMessageDialog( this,
1181 "No input sequences selected",
1182 "Phylogenetic Inference Not Launched",
1183 JOptionPane.WARNING_MESSAGE );
1190 if ( !isOKforSDI( true, true ) ) {
1193 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1194 JOptionPane.showMessageDialog( this,
1195 "Gene tree is not rooted",
1196 "Cannot execute SDI",
1197 JOptionPane.ERROR_MESSAGE );
1200 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1201 gene_tree.setAllNodesToNotCollapse();
1202 gene_tree.recalculateNumberOfExternalDescendants( false );
1204 int duplications = -1;
1206 sdi = new SDIse( gene_tree, _species_tree.copy() );
1207 duplications = sdi.getDuplicationsSum();
1209 catch ( final Exception e ) {
1210 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1212 gene_tree.setRerootable( false );
1213 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1214 getControlPanel().setShowEvents( true );
1216 _mainpanel.getCurrentTreePanel().setEdited( true );
1217 JOptionPane.showMessageDialog( this,
1218 "Number of duplications: " + duplications,
1219 "SDI successfully completed",
1220 JOptionPane.INFORMATION_MESSAGE );
1223 void executeSDIR( final boolean minimize_cost ) {
1224 if ( !isOKforSDI( true, true ) ) {
1227 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1228 final SDIR sdiunrooted = new SDIR();
1229 gene_tree.setAllNodesToNotCollapse();
1230 gene_tree.recalculateNumberOfExternalDescendants( false );
1232 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1233 !minimize_cost, // minimize sum of dups
1234 true, // minimize height
1235 true, // return tree(s)
1236 1 )[ 0 ]; // # of trees to return
1238 catch ( final Exception e ) {
1239 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1242 final int duplications = sdiunrooted.getMinimalDuplications();
1243 gene_tree.setRerootable( false );
1244 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1245 getControlPanel().setShowEvents( true );
1247 _mainpanel.getCurrentTreePanel().setEdited( true );
1248 JOptionPane.showMessageDialog( this,
1249 "Number of duplications: " + duplications,
1250 "SDIR successfully completed",
1251 JOptionPane.INFORMATION_MESSAGE );
1256 _mainpanel.terminate();
1257 _contentpane.removeAll();
1258 setVisible( false );
1263 private void extractTaxCodeFromNodeNames() {
1264 if ( getCurrentTreePanel() != null ) {
1265 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1266 if ( ( phy != null ) && !phy.isEmpty() ) {
1267 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1268 while ( it.hasNext() ) {
1269 final PhylogenyNode n = it.next();
1270 final String name = n.getName().trim();
1271 if ( !ForesterUtil.isEmpty( name ) ) {
1272 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1274 TAXONOMY_EXTRACTION.YES );
1275 if ( !ForesterUtil.isEmpty( code ) ) {
1276 PhylogenyMethods.setTaxonomyCode( n, code );
1284 private ControlPanel getControlPanel() {
1285 return getMainPanel().getControlPanel();
1288 private File getCurrentDir() {
1289 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1290 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1292 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1294 catch ( final Exception e ) {
1295 _current_dir = null;
1299 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1300 if ( System.getProperty( "user.home" ) != null ) {
1301 _current_dir = new File( System.getProperty( "user.home" ) );
1303 else if ( System.getProperty( "user.dir" ) != null ) {
1304 _current_dir = new File( System.getProperty( "user.dir" ) );
1307 return _current_dir;
1311 public MainPanel getMainPanel() {
1315 private double getMinNotCollapseConfidenceValue() {
1316 return _min_not_collapse;
1319 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1320 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1323 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1324 JOptionPane.showMessageDialog( this,
1325 "No species tree loaded",
1326 "Cannot execute SDI",
1327 JOptionPane.ERROR_MESSAGE );
1330 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1331 JOptionPane.showMessageDialog( this,
1332 "Species tree is not completely binary",
1333 "Cannot execute SDI",
1334 JOptionPane.ERROR_MESSAGE );
1337 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1338 JOptionPane.showMessageDialog( this,
1339 "Gene tree is not completely binary",
1340 "Cannot execute SDI",
1341 JOptionPane.ERROR_MESSAGE );
1349 private boolean isUnsavedDataPresent() {
1350 final List<TreePanel> tps = getMainPanel().getTreePanels();
1351 for( final TreePanel tp : tps ) {
1352 if ( tp.isEdited() ) {
1359 private void moveNodeNamesToSeqNames() {
1360 if ( getCurrentTreePanel() != null ) {
1361 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1362 if ( ( phy != null ) && !phy.isEmpty() ) {
1363 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1368 private void moveNodeNamesToTaxSn() {
1369 if ( getCurrentTreePanel() != null ) {
1370 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1371 if ( ( phy != null ) && !phy.isEmpty() ) {
1372 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1377 private void newTree() {
1378 final Phylogeny[] phys = new Phylogeny[ 1 ];
1379 final Phylogeny phy = new Phylogeny();
1380 final PhylogenyNode node = new PhylogenyNode();
1381 phy.setRoot( node );
1382 phy.setRooted( true );
1384 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1385 _mainpanel.getControlPanel().showWhole();
1386 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1387 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1388 if ( getMainPanel().getMainFrame() == null ) {
1389 // Must be "E" applet version.
1390 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1391 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1394 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1396 activateSaveAllIfNeeded();
1400 private void obtainDetailedTaxonomicInformation() {
1401 if ( getCurrentTreePanel() != null ) {
1402 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1403 if ( ( phy != null ) && !phy.isEmpty() ) {
1404 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1405 _mainpanel.getCurrentTreePanel(),
1407 new Thread( t ).start();
1412 private void obtainUniProtSequenceInformation() {
1413 if ( getCurrentTreePanel() != null ) {
1414 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1415 if ( ( phy != null ) && !phy.isEmpty() ) {
1416 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1417 _mainpanel.getCurrentTreePanel(),
1419 new Thread( u ).start();
1424 private void print() {
1425 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1426 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1429 if ( !getOptions().isPrintUsingActualSize() ) {
1430 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1431 getOptions().getPrintSizeY() - 140,
1433 getCurrentTreePanel().resetPreferredSize();
1434 getCurrentTreePanel().repaint();
1436 final String job_name = Constants.PRG_NAME;
1437 boolean error = false;
1438 String printer_name = null;
1440 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1442 catch ( final Exception e ) {
1444 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1446 if ( !error && ( printer_name != null ) ) {
1447 String msg = "Printing data sent to printer";
1448 if ( printer_name.length() > 1 ) {
1449 msg += " [" + printer_name + "]";
1451 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1453 if ( !getOptions().isPrintUsingActualSize() ) {
1454 getControlPanel().showWhole();
1458 private void printPhylogenyToPdf( final String file_name ) {
1459 if ( !getOptions().isPrintUsingActualSize() ) {
1460 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1461 getOptions().getPrintSizeY(),
1463 getCurrentTreePanel().resetPreferredSize();
1464 getCurrentTreePanel().repaint();
1466 String pdf_written_to = "";
1467 boolean error = false;
1469 if ( getOptions().isPrintUsingActualSize() ) {
1470 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1471 getCurrentTreePanel(),
1472 getCurrentTreePanel().getWidth(),
1473 getCurrentTreePanel().getHeight() );
1476 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1477 .getPrintSizeX(), getOptions().getPrintSizeY() );
1480 catch ( final IOException e ) {
1482 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1485 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1486 JOptionPane.showMessageDialog( this,
1487 "Wrote PDF to: " + pdf_written_to,
1489 JOptionPane.INFORMATION_MESSAGE );
1492 JOptionPane.showMessageDialog( this,
1493 "There was an unknown problem when attempting to write to PDF file: \""
1496 JOptionPane.ERROR_MESSAGE );
1499 if ( !getOptions().isPrintUsingActualSize() ) {
1500 getControlPanel().showWhole();
1504 private void addExpressionValuesFromFile() {
1505 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1506 JOptionPane.showMessageDialog( this,
1507 "Need to load evolutionary tree first",
1508 "Can Not Read Expression Values",
1509 JOptionPane.WARNING_MESSAGE );
1512 final File my_dir = getCurrentDir();
1513 if ( my_dir != null ) {
1514 _values_filechooser.setCurrentDirectory( my_dir );
1516 final int result = _values_filechooser.showOpenDialog( _contentpane );
1517 final File file = _values_filechooser.getSelectedFile();
1518 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1519 BasicTable<String> t = null;
1521 t = BasicTableParser.parse( file, "\t" );
1522 if ( t.getNumberOfColumns() < 2 ) {
1523 t = BasicTableParser.parse( file, "," );
1525 if ( t.getNumberOfColumns() < 2 ) {
1526 t = BasicTableParser.parse( file, " " );
1529 catch ( final IOException e ) {
1530 JOptionPane.showMessageDialog( this,
1532 "Could Not Read Expression Value Table",
1533 JOptionPane.ERROR_MESSAGE );
1536 if ( t.getNumberOfColumns() < 2 ) {
1537 JOptionPane.showMessageDialog( this,
1538 "Table contains " + t.getNumberOfColumns() + " column(s)",
1539 "Problem with Expression Value Table",
1540 JOptionPane.ERROR_MESSAGE );
1543 if ( t.getNumberOfRows() < 1 ) {
1544 JOptionPane.showMessageDialog( this,
1545 "Table contains zero rows",
1546 "Problem with Expression Value Table",
1547 JOptionPane.ERROR_MESSAGE );
1550 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1551 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1552 JOptionPane.showMessageDialog( this,
1553 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1554 + phy.getNumberOfExternalNodes() + " external nodes",
1556 JOptionPane.WARNING_MESSAGE );
1558 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1560 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1561 final PhylogenyNode node = iter.next();
1562 final String node_name = node.getName();
1563 if ( !ForesterUtil.isEmpty( node_name ) ) {
1566 row = t.findRow( node_name );
1568 catch ( final IllegalArgumentException e ) {
1570 .showMessageDialog( this,
1572 "Error Mapping Node Identifiers to Expression Value Identifiers",
1573 JOptionPane.ERROR_MESSAGE );
1577 if ( node.isExternal() ) {
1582 final List<Double> l = new ArrayList<Double>();
1583 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1586 d = Double.parseDouble( t.getValueAsString( col, row ) );
1588 catch ( final NumberFormatException e ) {
1589 JOptionPane.showMessageDialog( this,
1590 "Could not parse \"" + t.getValueAsString( col, row )
1591 + "\" into a decimal value",
1592 "Issue with Expression Value Table",
1593 JOptionPane.ERROR_MESSAGE );
1596 stats.addValue( d );
1599 if ( !l.isEmpty() ) {
1600 if ( node.getNodeData().getProperties() != null ) {
1601 node.getNodeData().getProperties()
1602 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1604 node.getNodeData().setVector( l );
1608 if ( not_found > 0 ) {
1609 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1610 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1612 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1616 private void readPhylogeniesFromFile() {
1617 boolean exception = false;
1618 Phylogeny[] phys = null;
1619 // Set an initial directory if none set yet
1620 final File my_dir = getCurrentDir();
1621 _open_filechooser.setMultiSelectionEnabled( true );
1622 // Open file-open dialog and set current directory
1623 if ( my_dir != null ) {
1624 _open_filechooser.setCurrentDirectory( my_dir );
1626 final int result = _open_filechooser.showOpenDialog( _contentpane );
1627 // All done: get the file
1628 final File[] files = _open_filechooser.getSelectedFiles();
1629 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1630 boolean nhx_or_nexus = false;
1631 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1632 for( final File file : files ) {
1633 if ( ( file != null ) && !file.isDirectory() ) {
1634 if ( _mainpanel.getCurrentTreePanel() != null ) {
1635 _mainpanel.getCurrentTreePanel().setWaitCursor();
1638 _mainpanel.setWaitCursor();
1640 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1641 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1643 final NHXParser nhx = new NHXParser();
1644 setSpecialOptionsForNhxParser( nhx );
1645 phys = ForesterUtil.readPhylogenies( nhx, file );
1646 nhx_or_nexus = true;
1648 catch ( final Exception e ) {
1650 exceptionOccuredDuringOpenFile( e );
1653 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1654 warnIfNotPhyloXmlValidation( getConfiguration() );
1656 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1657 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1659 catch ( final Exception e ) {
1661 exceptionOccuredDuringOpenFile( e );
1664 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1666 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1668 catch ( final Exception e ) {
1670 exceptionOccuredDuringOpenFile( e );
1673 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1675 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1676 setSpecialOptionsForNexParser( nex );
1677 phys = ForesterUtil.readPhylogenies( nex, file );
1678 nhx_or_nexus = true;
1680 catch ( final Exception e ) {
1682 exceptionOccuredDuringOpenFile( e );
1688 final PhylogenyParser parser = ForesterUtil
1689 .createParserDependingOnFileType( file, getConfiguration()
1690 .isValidatePhyloXmlAgainstSchema() );
1691 if ( parser instanceof NexusPhylogeniesParser ) {
1692 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1693 setSpecialOptionsForNexParser( nex );
1694 nhx_or_nexus = true;
1696 else if ( parser instanceof NHXParser ) {
1697 final NHXParser nhx = ( NHXParser ) parser;
1698 setSpecialOptionsForNhxParser( nhx );
1699 nhx_or_nexus = true;
1701 else if ( parser instanceof PhyloXmlParser ) {
1702 warnIfNotPhyloXmlValidation( getConfiguration() );
1704 phys = ForesterUtil.readPhylogenies( parser, file );
1706 catch ( final Exception e ) {
1708 exceptionOccuredDuringOpenFile( e );
1711 if ( _mainpanel.getCurrentTreePanel() != null ) {
1712 _mainpanel.getCurrentTreePanel().setArrowCursor();
1715 _mainpanel.setArrowCursor();
1717 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1718 boolean one_desc = false;
1719 if ( nhx_or_nexus ) {
1720 for( final Phylogeny phy : phys ) {
1721 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1722 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1724 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1730 Util.addPhylogeniesToTabs( phys,
1732 file.getAbsolutePath(),
1735 _mainpanel.getControlPanel().showWhole();
1736 if ( nhx_or_nexus && one_desc ) {
1738 .showMessageDialog( this,
1739 "One or more trees contain (a) node(s) with one descendant, "
1740 + ForesterUtil.LINE_SEPARATOR
1741 + "possibly indicating illegal parentheses within node names.",
1742 "Warning: Possible Error in New Hampshire Formatted Data",
1743 JOptionPane.WARNING_MESSAGE );
1749 activateSaveAllIfNeeded();
1753 public void readSeqsFromFile() {
1754 // Set an initial directory if none set yet
1755 final File my_dir = getCurrentDir();
1756 _seqs_filechooser.setMultiSelectionEnabled( false );
1757 // Open file-open dialog and set current directory
1758 if ( my_dir != null ) {
1759 _seqs_filechooser.setCurrentDirectory( my_dir );
1761 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1762 // All done: get the seqs
1763 final File file = _seqs_filechooser.getSelectedFile();
1764 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1765 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1766 setSeqsFile( null );
1768 List<Sequence> seqs = null;
1770 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1771 seqs = FastaParser.parse( new FileInputStream( file ) );
1772 for( final Sequence seq : seqs ) {
1773 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1780 catch ( final MsaFormatException e ) {
1782 _mainpanel.getCurrentTreePanel().setArrowCursor();
1784 catch ( final Exception ex ) {
1787 JOptionPane.showMessageDialog( this,
1788 e.getLocalizedMessage(),
1789 "Multiple sequence file format error",
1790 JOptionPane.ERROR_MESSAGE );
1793 catch ( final IOException e ) {
1795 _mainpanel.getCurrentTreePanel().setArrowCursor();
1797 catch ( final Exception ex ) {
1800 JOptionPane.showMessageDialog( this,
1801 e.getLocalizedMessage(),
1802 "Failed to read multiple sequence file",
1803 JOptionPane.ERROR_MESSAGE );
1806 catch ( final IllegalArgumentException e ) {
1808 _mainpanel.getCurrentTreePanel().setArrowCursor();
1810 catch ( final Exception ex ) {
1813 JOptionPane.showMessageDialog( this,
1814 e.getLocalizedMessage(),
1815 "Unexpected error during reading of multiple sequence file",
1816 JOptionPane.ERROR_MESSAGE );
1819 catch ( final Exception e ) {
1821 _mainpanel.getCurrentTreePanel().setArrowCursor();
1823 catch ( final Exception ex ) {
1826 e.printStackTrace();
1827 JOptionPane.showMessageDialog( this,
1828 e.getLocalizedMessage(),
1829 "Unexpected error during reading of multiple sequence file",
1830 JOptionPane.ERROR_MESSAGE );
1833 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1834 JOptionPane.showMessageDialog( this,
1835 "Multiple sequence file is empty",
1836 "Illegal multiple sequence file",
1837 JOptionPane.ERROR_MESSAGE );
1840 if ( seqs.size() < 4 ) {
1841 JOptionPane.showMessageDialog( this,
1842 "Multiple sequence file needs to contain at least 3 sequences",
1843 "Illegal multiple sequence file",
1844 JOptionPane.ERROR_MESSAGE );
1847 // if ( msa.getLength() < 2 ) {
1848 // JOptionPane.showMessageDialog( this,
1849 // "Multiple sequence alignment needs to contain at least 2 residues",
1850 // "Illegal multiple sequence file",
1851 // JOptionPane.ERROR_MESSAGE );
1855 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1860 public void readMsaFromFile() {
1861 // Set an initial directory if none set yet
1862 final File my_dir = getCurrentDir();
1863 _msa_filechooser.setMultiSelectionEnabled( false );
1864 // Open file-open dialog and set current directory
1865 if ( my_dir != null ) {
1866 _msa_filechooser.setCurrentDirectory( my_dir );
1868 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1869 // All done: get the msa
1870 final File file = _msa_filechooser.getSelectedFile();
1871 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1872 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1877 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1878 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1879 System.out.println( msa.toString() );
1882 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1885 catch ( final MsaFormatException e ) {
1887 _mainpanel.getCurrentTreePanel().setArrowCursor();
1889 catch ( final Exception ex ) {
1892 JOptionPane.showMessageDialog( this,
1893 e.getLocalizedMessage(),
1894 "Multiple sequence alignment format error",
1895 JOptionPane.ERROR_MESSAGE );
1898 catch ( final IOException e ) {
1900 _mainpanel.getCurrentTreePanel().setArrowCursor();
1902 catch ( final Exception ex ) {
1905 JOptionPane.showMessageDialog( this,
1906 e.getLocalizedMessage(),
1907 "Failed to read multiple sequence alignment",
1908 JOptionPane.ERROR_MESSAGE );
1911 catch ( final IllegalArgumentException e ) {
1913 _mainpanel.getCurrentTreePanel().setArrowCursor();
1915 catch ( final Exception ex ) {
1918 JOptionPane.showMessageDialog( this,
1919 e.getLocalizedMessage(),
1920 "Unexpected error during reading of multiple sequence alignment",
1921 JOptionPane.ERROR_MESSAGE );
1924 catch ( final Exception e ) {
1926 _mainpanel.getCurrentTreePanel().setArrowCursor();
1928 catch ( final Exception ex ) {
1931 e.printStackTrace();
1932 JOptionPane.showMessageDialog( this,
1933 e.getLocalizedMessage(),
1934 "Unexpected error during reading of multiple sequence alignment",
1935 JOptionPane.ERROR_MESSAGE );
1938 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1939 JOptionPane.showMessageDialog( this,
1940 "Multiple sequence alignment is empty",
1941 "Illegal Multiple Sequence Alignment",
1942 JOptionPane.ERROR_MESSAGE );
1945 if ( msa.getNumberOfSequences() < 4 ) {
1946 JOptionPane.showMessageDialog( this,
1947 "Multiple sequence alignment needs to contain at least 3 sequences",
1948 "Illegal multiple sequence alignment",
1949 JOptionPane.ERROR_MESSAGE );
1952 if ( msa.getLength() < 2 ) {
1953 JOptionPane.showMessageDialog( this,
1954 "Multiple sequence alignment needs to contain at least 2 residues",
1955 "Illegal multiple sequence alignment",
1956 JOptionPane.ERROR_MESSAGE );
1960 setMsaFile( _msa_filechooser.getSelectedFile() );
1966 void readPhylogeniesFromURL() {
1968 Phylogeny[] phys = null;
1969 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1970 final String url_string = JOptionPane.showInputDialog( this,
1972 "Use URL/webservice to obtain a phylogeny",
1973 JOptionPane.QUESTION_MESSAGE );
1974 boolean nhx_or_nexus = false;
1975 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1977 url = new URL( url_string );
1978 PhylogenyParser parser = null;
1979 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1980 parser = new TolParser();
1983 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
1984 .isValidatePhyloXmlAgainstSchema() );
1986 if ( parser instanceof NexusPhylogeniesParser ) {
1987 nhx_or_nexus = true;
1989 else if ( parser instanceof NHXParser ) {
1990 nhx_or_nexus = true;
1992 if ( _mainpanel.getCurrentTreePanel() != null ) {
1993 _mainpanel.getCurrentTreePanel().setWaitCursor();
1996 _mainpanel.setWaitCursor();
1998 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1999 phys = factory.create( url.openStream(), parser );
2001 catch ( final MalformedURLException e ) {
2002 JOptionPane.showMessageDialog( this,
2003 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2005 JOptionPane.ERROR_MESSAGE );
2007 catch ( final IOException e ) {
2008 JOptionPane.showMessageDialog( this,
2009 "Could not read from " + url + "\n"
2010 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2011 "Failed to read URL",
2012 JOptionPane.ERROR_MESSAGE );
2014 catch ( final Exception e ) {
2015 JOptionPane.showMessageDialog( this,
2016 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2017 "Unexpected Exception",
2018 JOptionPane.ERROR_MESSAGE );
2021 if ( _mainpanel.getCurrentTreePanel() != null ) {
2022 _mainpanel.getCurrentTreePanel().setArrowCursor();
2025 _mainpanel.setArrowCursor();
2028 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2029 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2030 for( final Phylogeny phy : phys ) {
2031 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2034 Util.addPhylogeniesToTabs( phys,
2035 new File( url.getFile() ).getName(),
2036 new File( url.getFile() ).toString(),
2039 _mainpanel.getControlPanel().showWhole();
2042 activateSaveAllIfNeeded();
2046 private void readSpeciesTreeFromFile() {
2048 boolean exception = false;
2049 final File my_dir = getCurrentDir();
2050 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2051 if ( my_dir != null ) {
2052 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2054 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2055 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2056 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2057 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2059 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2062 catch ( final Exception e ) {
2064 exceptionOccuredDuringOpenFile( e );
2067 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2069 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2072 catch ( final Exception e ) {
2074 exceptionOccuredDuringOpenFile( e );
2080 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2083 catch ( final Exception e ) {
2085 exceptionOccuredDuringOpenFile( e );
2088 if ( !exception && ( t != null ) && !t.isRooted() ) {
2091 JOptionPane.showMessageDialog( this,
2092 "Species tree is not rooted",
2093 "Species tree not loaded",
2094 JOptionPane.ERROR_MESSAGE );
2096 if ( !exception && ( t != null ) ) {
2097 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2098 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2099 final PhylogenyNode node = it.next();
2100 if ( !node.getNodeData().isHasTaxonomy() ) {
2104 .showMessageDialog( this,
2105 "Species tree contains external node(s) without taxonomy information",
2106 "Species tree not loaded",
2107 JOptionPane.ERROR_MESSAGE );
2111 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2114 JOptionPane.showMessageDialog( this,
2116 + node.getNodeData().getTaxonomy().asSimpleText()
2117 + "] is not unique in species tree",
2118 "Species tree not loaded",
2119 JOptionPane.ERROR_MESSAGE );
2123 tax_set.add( node.getNodeData().getTaxonomy() );
2128 if ( !exception && ( t != null ) ) {
2130 JOptionPane.showMessageDialog( this,
2131 "Species tree successfully loaded",
2132 "Species tree loaded",
2133 JOptionPane.INFORMATION_MESSAGE );
2135 _contentpane.repaint();
2140 private void setCurrentDir( final File current_dir ) {
2141 _current_dir = current_dir;
2144 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2145 _min_not_collapse = min_not_collapse;
2148 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2149 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2152 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2153 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2154 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2155 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2156 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2158 nhx.setTaxonomyExtraction( te );
2161 private void writeAllToFile() {
2162 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2165 final File my_dir = getCurrentDir();
2166 if ( my_dir != null ) {
2167 _save_filechooser.setCurrentDirectory( my_dir );
2169 _save_filechooser.setSelectedFile( new File( "" ) );
2170 final int result = _save_filechooser.showSaveDialog( _contentpane );
2171 final File file = _save_filechooser.getSelectedFile();
2172 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2173 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2174 if ( file.exists() ) {
2175 final int i = JOptionPane.showConfirmDialog( this,
2176 file + " already exists. Overwrite?",
2178 JOptionPane.OK_CANCEL_OPTION,
2179 JOptionPane.WARNING_MESSAGE );
2180 if ( i != JOptionPane.OK_OPTION ) {
2187 catch ( final Exception e ) {
2188 JOptionPane.showMessageDialog( this,
2189 "Failed to delete: " + file,
2191 JOptionPane.WARNING_MESSAGE );
2195 final int count = getMainPanel().getTabbedPane().getTabCount();
2196 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2197 for( int i = 0; i < count; ++i ) {
2198 trees.add( getMainPanel().getPhylogeny( i ) );
2199 getMainPanel().getTreePanels().get( i ).setEdited( false );
2201 final PhylogenyWriter writer = new PhylogenyWriter();
2203 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2205 catch ( final IOException e ) {
2206 JOptionPane.showMessageDialog( this,
2207 "Failed to write to: " + file,
2209 JOptionPane.WARNING_MESSAGE );
2214 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2216 final PhylogenyWriter writer = new PhylogenyWriter();
2217 writer.toNewHampshire( t, false, true, file );
2219 catch ( final Exception e ) {
2221 exceptionOccuredDuringSaveAs( e );
2226 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2228 final PhylogenyWriter writer = new PhylogenyWriter();
2229 writer.toNexus( file, t );
2231 catch ( final Exception e ) {
2233 exceptionOccuredDuringSaveAs( e );
2238 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2240 final PhylogenyWriter writer = new PhylogenyWriter();
2241 writer.toNewHampshireX( t, file );
2243 catch ( final Exception e ) {
2245 exceptionOccuredDuringSaveAs( e );
2250 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2252 final PhylogenyWriter writer = new PhylogenyWriter();
2253 writer.toPhyloXML( file, t, 0 );
2255 catch ( final Exception e ) {
2257 exceptionOccuredDuringSaveAs( e );
2262 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2263 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2264 _mainpanel.getCurrentTreePanel().getHeight(),
2266 String file_written_to = "";
2267 boolean error = false;
2269 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2270 _mainpanel.getCurrentTreePanel().getWidth(),
2271 _mainpanel.getCurrentTreePanel().getHeight(),
2272 _mainpanel.getCurrentTreePanel(),
2273 _mainpanel.getControlPanel(),
2277 catch ( final IOException e ) {
2279 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2282 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2283 JOptionPane.showMessageDialog( this,
2284 "Wrote image to: " + file_written_to,
2286 JOptionPane.INFORMATION_MESSAGE );
2289 JOptionPane.showMessageDialog( this,
2290 "There was an unknown problem when attempting to write to an image file: \""
2293 JOptionPane.ERROR_MESSAGE );
2296 _contentpane.repaint();
2299 private void writeToFile( final Phylogeny t ) {
2303 String initial_filename = null;
2304 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2306 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2308 catch ( final IOException e ) {
2309 initial_filename = null;
2312 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2313 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2316 _save_filechooser.setSelectedFile( new File( "" ) );
2318 final File my_dir = getCurrentDir();
2319 if ( my_dir != null ) {
2320 _save_filechooser.setCurrentDirectory( my_dir );
2322 final int result = _save_filechooser.showSaveDialog( _contentpane );
2323 final File file = _save_filechooser.getSelectedFile();
2324 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2325 boolean exception = false;
2326 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2327 if ( file.exists() ) {
2328 final int i = JOptionPane.showConfirmDialog( this,
2329 file + " already exists.\nOverwrite?",
2331 JOptionPane.OK_CANCEL_OPTION,
2332 JOptionPane.QUESTION_MESSAGE );
2333 if ( i != JOptionPane.OK_OPTION ) {
2337 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2339 ForesterUtil.copyFile( file, to );
2341 catch ( final Exception e ) {
2342 JOptionPane.showMessageDialog( this,
2343 "Failed to create backup copy " + to,
2344 "Failed to Create Backup Copy",
2345 JOptionPane.WARNING_MESSAGE );
2350 catch ( final Exception e ) {
2351 JOptionPane.showMessageDialog( this,
2352 "Failed to delete: " + file,
2354 JOptionPane.WARNING_MESSAGE );
2358 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2359 exception = writeAsNewHampshire( t, exception, file );
2361 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2362 exception = writeAsNHX( t, exception, file );
2364 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2365 exception = writeAsPhyloXml( t, exception, file );
2367 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2368 exception = writeAsNexus( t, exception, file );
2372 final String file_name = file.getName().trim().toLowerCase();
2373 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2374 || file_name.endsWith( ".tree" ) ) {
2375 exception = writeAsNewHampshire( t, exception, file );
2377 else if ( file_name.endsWith( ".nhx" ) ) {
2378 exception = writeAsNHX( t, exception, file );
2380 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2381 exception = writeAsNexus( t, exception, file );
2385 exception = writeAsPhyloXml( t, exception, file );
2389 getMainPanel().setTitleOfSelectedTab( file.getName() );
2390 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2391 getMainPanel().getCurrentTreePanel().setEdited( false );
2396 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2397 if ( ( t == null ) || t.isEmpty() ) {
2400 String initial_filename = "";
2401 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2402 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2404 if ( initial_filename.indexOf( '.' ) > 0 ) {
2405 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2407 initial_filename = initial_filename + "." + type;
2408 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2409 final File my_dir = getCurrentDir();
2410 if ( my_dir != null ) {
2411 _writetographics_filechooser.setCurrentDirectory( my_dir );
2413 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2414 File file = _writetographics_filechooser.getSelectedFile();
2415 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2416 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2417 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2418 file = new File( file.toString() + "." + type );
2420 if ( file.exists() ) {
2421 final int i = JOptionPane.showConfirmDialog( this,
2422 file + " already exists. Overwrite?",
2424 JOptionPane.OK_CANCEL_OPTION,
2425 JOptionPane.WARNING_MESSAGE );
2426 if ( i != JOptionPane.OK_OPTION ) {
2433 catch ( final Exception e ) {
2434 JOptionPane.showMessageDialog( this,
2435 "Failed to delete: " + file,
2437 JOptionPane.WARNING_MESSAGE );
2441 writePhylogenyToGraphicsFile( file.toString(), type );
2445 private void writeToPdf( final Phylogeny t ) {
2446 if ( ( t == null ) || t.isEmpty() ) {
2449 String initial_filename = "";
2450 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2451 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2453 if ( initial_filename.indexOf( '.' ) > 0 ) {
2454 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2456 initial_filename = initial_filename + ".pdf";
2457 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2458 final File my_dir = getCurrentDir();
2459 if ( my_dir != null ) {
2460 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2462 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2463 File file = _writetopdf_filechooser.getSelectedFile();
2464 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2465 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2466 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2467 file = new File( file.toString() + ".pdf" );
2469 if ( file.exists() ) {
2470 final int i = JOptionPane.showConfirmDialog( this,
2471 file + " already exists. Overwrite?",
2473 JOptionPane.OK_CANCEL_OPTION,
2474 JOptionPane.WARNING_MESSAGE );
2475 if ( i != JOptionPane.OK_OPTION ) {
2479 printPhylogenyToPdf( file.toString() );
2483 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2484 return new MainFrameApplication( phys, config, title );
2487 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2488 return new MainFrameApplication( phys, config_file_name, title );
2491 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2492 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2493 + o.getPrintSizeY() + ")" );
2496 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2497 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2500 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2501 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2503 .showMessageDialog( null,
2505 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2508 JOptionPane.WARNING_MESSAGE );
2512 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2513 _phylogenetic_inference_options = phylogenetic_inference_options;
2516 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2517 if ( _phylogenetic_inference_options == null ) {
2518 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2520 return _phylogenetic_inference_options;
2523 public Msa getMsa() {
2527 void setMsa( final Msa msa ) {
2531 void setMsaFile( final File msa_file ) {
2532 _msa_file = msa_file;
2535 public File getMsaFile() {
2539 public List<Sequence> getSeqs() {
2543 void setSeqs( final List<Sequence> seqs ) {
2547 void setSeqsFile( final File seqs_file ) {
2548 _seqs_file = seqs_file;
2551 public File getSeqsFile() {
2554 } // MainFrameApplication.
2556 class NexusFilter extends FileFilter {
2559 public boolean accept( final File f ) {
2560 final String file_name = f.getName().trim().toLowerCase();
2561 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2562 || file_name.endsWith( ".tre" ) || f.isDirectory();
2566 public String getDescription() {
2567 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2571 class NHFilter extends FileFilter {
2574 public boolean accept( final File f ) {
2575 final String file_name = f.getName().trim().toLowerCase();
2576 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2577 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2578 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2583 public String getDescription() {
2584 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2588 class NHXFilter extends FileFilter {
2591 public boolean accept( final File f ) {
2592 final String file_name = f.getName().trim().toLowerCase();
2593 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2597 public String getDescription() {
2598 return "NHX files (*.nhx)";
2602 class PdfFilter extends FileFilter {
2605 public boolean accept( final File f ) {
2606 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2610 public String getDescription() {
2611 return "PDF files (*.pdf)";
2615 class TolFilter extends FileFilter {
2618 public boolean accept( final File f ) {
2619 final String file_name = f.getName().trim().toLowerCase();
2620 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2621 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2625 public String getDescription() {
2626 return "Tree of Life files (*.tol, *.tolxml)";
2630 class XMLFilter extends FileFilter {
2633 public boolean accept( final File f ) {
2634 final String file_name = f.getName().trim().toLowerCase();
2635 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2636 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2640 public String getDescription() {
2641 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";