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, getCurrentTreePanel() );
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 );
705 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
707 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
708 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
709 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
710 _radio_group_1 = new ButtonGroup();
711 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
712 _radio_group_1.add( _uniform_cladograms_rbmi );
713 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
714 _options_jmenu.add( _show_node_boxes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
715 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
717 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
718 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
719 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
720 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
721 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
722 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
723 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
724 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
725 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
726 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
727 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
729 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
730 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
731 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
732 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
733 _options_jmenu.addSeparator();
734 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
735 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
736 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
737 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
738 _options_jmenu.addSeparator();
739 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
740 getConfiguration() ) );
741 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
742 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
744 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
746 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
748 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
749 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
750 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
751 _options_jmenu.addSeparator();
753 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
755 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
756 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
758 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
759 customizeJMenuItem( _choose_font_mi );
760 customizeJMenuItem( _choose_minimal_confidence_mi );
761 customizeJMenuItem( _switch_colors_mi );
762 customizeJMenuItem( _print_size_mi );
763 customizeJMenuItem( _choose_pdf_width_mi );
764 customizeJMenuItem( _overview_placment_mi );
766 //customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().getDefaultNodeShape() );
768 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
769 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
770 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
771 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
772 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
773 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
774 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
775 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
776 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
777 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
778 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
779 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
780 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
781 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
782 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
783 customizeCheckBoxMenuItem( _label_direction_cbmi,
784 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
785 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
786 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
787 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
788 .isInternalNumberAreConfidenceForNhParsing() );
789 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
790 .isExtractPfamTaxonomyCodesInNhParsing() );
791 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
792 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
793 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
794 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
795 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
796 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
797 .isGraphicsExportUsingActualSize() );
798 _jmenubar.add( _options_jmenu );
801 void buildToolsMenu() {
802 _tools_menu = createMenu( "Tools", getConfiguration() );
803 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
804 customizeJMenuItem( _confcolor_item );
805 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
806 customizeJMenuItem( _taxcolor_item );
807 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
808 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
809 customizeJMenuItem( _remove_branch_color_item );
810 _tools_menu.addSeparator();
811 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
812 customizeJMenuItem( _midpoint_root_item );
813 _tools_menu.addSeparator();
814 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
815 customizeJMenuItem( _collapse_species_specific_subtrees );
817 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
818 customizeJMenuItem( _collapse_below_threshold );
819 _collapse_below_threshold
820 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
821 _tools_menu.addSeparator();
823 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
824 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
825 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
826 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
827 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
828 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
830 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
831 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
832 _extract_tax_code_from_node_names_jmi
833 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
834 _tools_menu.addSeparator();
836 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
837 customizeJMenuItem( _infer_common_sn_names_item );
838 _tools_menu.addSeparator();
840 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
841 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
842 _obtain_detailed_taxonomic_information_jmi
843 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
845 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
846 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
847 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
848 _tools_menu.addSeparator();
849 if ( !Constants.__RELEASE ) {
850 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
851 customizeJMenuItem( _function_analysis );
853 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
854 _tools_menu.addSeparator();
856 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
857 customizeJMenuItem( _read_values_jmi );
858 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
859 _jmenubar.add( _tools_menu );
862 private void choosePdfWidth() {
863 final String s = ( String ) JOptionPane.showInputDialog( this,
864 "Please enter the default line width for PDF export.\n"
866 + getOptions().getPrintLineWidth() + "]\n",
867 "Line Width for PDF Export",
868 JOptionPane.QUESTION_MESSAGE,
871 getOptions().getPrintLineWidth() );
872 if ( !ForesterUtil.isEmpty( s ) ) {
873 boolean success = true;
875 final String m_str = s.trim();
876 if ( !ForesterUtil.isEmpty( m_str ) ) {
878 f = Float.parseFloat( m_str );
880 catch ( final Exception ex ) {
887 if ( success && ( f > 0.0 ) ) {
888 getOptions().setPrintLineWidth( f );
893 private void choosePrintSize() {
894 final String s = ( String ) JOptionPane.showInputDialog( this,
895 "Please enter values for width and height,\nseparated by a comma.\n"
896 + "[current values: "
897 + getOptions().getPrintSizeX() + ", "
898 + getOptions().getPrintSizeY() + "]\n"
899 + "[A4: " + Constants.A4_SIZE_X + ", "
900 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
901 + Constants.US_LETTER_SIZE_X + ", "
902 + Constants.US_LETTER_SIZE_Y + "]",
903 "Default Size for Graphics Export",
904 JOptionPane.QUESTION_MESSAGE,
907 getOptions().getPrintSizeX() + ", "
908 + getOptions().getPrintSizeY() );
909 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
910 boolean success = true;
913 final String[] str_ary = s.split( "," );
914 if ( str_ary.length == 2 ) {
915 final String x_str = str_ary[ 0 ].trim();
916 final String y_str = str_ary[ 1 ].trim();
917 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
919 x = Integer.parseInt( x_str );
920 y = Integer.parseInt( y_str );
922 catch ( final Exception ex ) {
933 if ( success && ( x > 1 ) && ( y > 1 ) ) {
934 getOptions().setPrintSizeX( x );
935 getOptions().setPrintSizeY( y );
942 if ( isUnsavedDataPresent() ) {
943 final int r = JOptionPane.showConfirmDialog( this,
944 "Exit despite potentially unsaved changes?",
946 JOptionPane.YES_NO_OPTION );
947 if ( r != JOptionPane.YES_OPTION ) {
954 private void closeCurrentPane() {
955 if ( getMainPanel().getCurrentTreePanel() != null ) {
956 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
957 final int r = JOptionPane.showConfirmDialog( this,
958 "Close tab despite potentially unsaved changes?",
960 JOptionPane.YES_NO_OPTION );
961 if ( r != JOptionPane.YES_OPTION ) {
965 getMainPanel().closeCurrentPane();
966 activateSaveAllIfNeeded();
970 private void collapse( final Phylogeny phy, final double m ) {
971 final PhylogenyNodeIterator it = phy.iteratorPostorder();
972 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
973 double min_support = Double.MAX_VALUE;
974 boolean conf_present = false;
975 while ( it.hasNext() ) {
976 final PhylogenyNode n = it.next();
977 if ( !n.isExternal() && !n.isRoot() ) {
978 final List<Confidence> c = n.getBranchData().getConfidences();
979 if ( ( c != null ) && ( c.size() > 0 ) ) {
982 for( final Confidence confidence : c ) {
983 if ( confidence.getValue() > max ) {
984 max = confidence.getValue();
987 if ( max < getMinNotCollapseConfidenceValue() ) {
988 to_be_removed.add( n );
990 if ( max < min_support ) {
996 if ( conf_present ) {
997 for( final PhylogenyNode node : to_be_removed ) {
998 PhylogenyMethods.removeNode( node, phy );
1000 if ( to_be_removed.size() > 0 ) {
1001 phy.externalNodesHaveChanged();
1003 phy.recalculateNumberOfExternalDescendants( true );
1004 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1005 getCurrentTreePanel().setEdited( true );
1006 getCurrentTreePanel().repaint();
1008 if ( to_be_removed.size() > 0 ) {
1009 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1010 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1011 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1014 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1015 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1019 JOptionPane.showMessageDialog( this,
1020 "No branch collapsed because no confidence values present",
1021 "No confidence values present",
1022 JOptionPane.INFORMATION_MESSAGE );
1026 private void collapseBelowThreshold() {
1027 if ( getCurrentTreePanel() != null ) {
1028 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1029 if ( ( phy != null ) && !phy.isEmpty() ) {
1030 final String s = ( String ) JOptionPane.showInputDialog( this,
1031 "Please enter the minimum confidence value\n",
1032 "Minimal Confidence Value",
1033 JOptionPane.QUESTION_MESSAGE,
1036 getMinNotCollapseConfidenceValue() );
1037 if ( !ForesterUtil.isEmpty( s ) ) {
1038 boolean success = true;
1040 final String m_str = s.trim();
1041 if ( !ForesterUtil.isEmpty( m_str ) ) {
1043 m = Double.parseDouble( m_str );
1045 catch ( final Exception ex ) {
1052 if ( success && ( m >= 0.0 ) ) {
1053 setMinNotCollapseConfidenceValue( m );
1061 private PhyloXmlParser createPhyloXmlParser() {
1062 PhyloXmlParser xml_parser = null;
1063 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1065 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1067 catch ( final Exception e ) {
1068 JOptionPane.showMessageDialog( this,
1069 e.getLocalizedMessage(),
1070 "failed to create validating XML parser",
1071 JOptionPane.WARNING_MESSAGE );
1074 if ( xml_parser == null ) {
1075 xml_parser = new PhyloXmlParser();
1080 void executeGSDI() {
1081 if ( !isOKforSDI( false, true ) ) {
1084 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1085 JOptionPane.showMessageDialog( this,
1086 "Gene tree is not rooted.",
1087 "Cannot execute GSDI",
1088 JOptionPane.ERROR_MESSAGE );
1091 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1092 gene_tree.setAllNodesToNotCollapse();
1093 gene_tree.recalculateNumberOfExternalDescendants( false );
1095 int duplications = -1;
1097 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1098 duplications = gsdi.getDuplicationsSum();
1100 catch ( final Exception e ) {
1101 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1103 gene_tree.setRerootable( false );
1104 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1105 getControlPanel().setShowEvents( true );
1107 _mainpanel.getCurrentTreePanel().setEdited( true );
1108 JOptionPane.showMessageDialog( this,
1109 "Number of duplications: " + duplications,
1110 "GSDI successfully completed",
1111 JOptionPane.INFORMATION_MESSAGE );
1114 void executeFunctionAnalysis() {
1115 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1118 final GoAnnotation a = new GoAnnotation( this,
1119 _mainpanel.getCurrentTreePanel(),
1120 _mainpanel.getCurrentPhylogeny() );
1121 new Thread( a ).start();
1124 void executeLineageInference() {
1125 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1128 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1129 JOptionPane.showMessageDialog( this,
1130 "Phylogeny is not rooted.",
1131 "Cannot infer ancestral taxonomies",
1132 JOptionPane.ERROR_MESSAGE );
1135 final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1136 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1137 _mainpanel.getCurrentTreePanel(),
1139 new Thread( inferrer ).start();
1142 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1143 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1144 getPhylogeneticInferenceOptions(),
1145 from_unaligned_seqs );
1147 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1148 if ( !from_unaligned_seqs ) {
1149 if ( getMsa() != null ) {
1150 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1151 getPhylogeneticInferenceOptions()
1153 new Thread( inferrer ).start();
1156 JOptionPane.showMessageDialog( this,
1157 "No multiple sequence alignment selected",
1158 "Phylogenetic Inference Not Launched",
1159 JOptionPane.WARNING_MESSAGE );
1163 if ( getSeqs() != null ) {
1164 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1165 getPhylogeneticInferenceOptions()
1167 new Thread( inferrer ).start();
1170 JOptionPane.showMessageDialog( this,
1171 "No input sequences selected",
1172 "Phylogenetic Inference Not Launched",
1173 JOptionPane.WARNING_MESSAGE );
1180 if ( !isOKforSDI( true, true ) ) {
1183 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1184 JOptionPane.showMessageDialog( this,
1185 "Gene tree is not rooted",
1186 "Cannot execute SDI",
1187 JOptionPane.ERROR_MESSAGE );
1190 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1191 gene_tree.setAllNodesToNotCollapse();
1192 gene_tree.recalculateNumberOfExternalDescendants( false );
1194 int duplications = -1;
1196 sdi = new SDIse( gene_tree, _species_tree.copy() );
1197 duplications = sdi.getDuplicationsSum();
1199 catch ( final Exception e ) {
1200 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1202 gene_tree.setRerootable( false );
1203 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1204 getControlPanel().setShowEvents( true );
1206 _mainpanel.getCurrentTreePanel().setEdited( true );
1207 JOptionPane.showMessageDialog( this,
1208 "Number of duplications: " + duplications,
1209 "SDI successfully completed",
1210 JOptionPane.INFORMATION_MESSAGE );
1213 void executeSDIR( final boolean minimize_cost ) {
1214 if ( !isOKforSDI( true, true ) ) {
1217 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1218 final SDIR sdiunrooted = new SDIR();
1219 gene_tree.setAllNodesToNotCollapse();
1220 gene_tree.recalculateNumberOfExternalDescendants( false );
1222 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1223 !minimize_cost, // minimize sum of dups
1224 true, // minimize height
1225 true, // return tree(s)
1226 1 )[ 0 ]; // # of trees to return
1228 catch ( final Exception e ) {
1229 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1232 final int duplications = sdiunrooted.getMinimalDuplications();
1233 gene_tree.setRerootable( false );
1234 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1235 getControlPanel().setShowEvents( true );
1237 _mainpanel.getCurrentTreePanel().setEdited( true );
1238 JOptionPane.showMessageDialog( this,
1239 "Number of duplications: " + duplications,
1240 "SDIR successfully completed",
1241 JOptionPane.INFORMATION_MESSAGE );
1246 _mainpanel.terminate();
1247 _contentpane.removeAll();
1248 setVisible( false );
1253 private void extractTaxCodeFromNodeNames() {
1254 if ( getCurrentTreePanel() != null ) {
1255 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1256 if ( ( phy != null ) && !phy.isEmpty() ) {
1257 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1258 while ( it.hasNext() ) {
1259 final PhylogenyNode n = it.next();
1260 final String name = n.getName().trim();
1261 if ( !ForesterUtil.isEmpty( name ) ) {
1262 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1264 TAXONOMY_EXTRACTION.YES );
1265 if ( !ForesterUtil.isEmpty( code ) ) {
1266 PhylogenyMethods.setTaxonomyCode( n, code );
1274 private ControlPanel getControlPanel() {
1275 return getMainPanel().getControlPanel();
1278 private File getCurrentDir() {
1279 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1280 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1282 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1284 catch ( final Exception e ) {
1285 _current_dir = null;
1289 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1290 if ( System.getProperty( "user.home" ) != null ) {
1291 _current_dir = new File( System.getProperty( "user.home" ) );
1293 else if ( System.getProperty( "user.dir" ) != null ) {
1294 _current_dir = new File( System.getProperty( "user.dir" ) );
1297 return _current_dir;
1301 public MainPanel getMainPanel() {
1305 private double getMinNotCollapseConfidenceValue() {
1306 return _min_not_collapse;
1309 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1310 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1313 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1314 JOptionPane.showMessageDialog( this,
1315 "No species tree loaded",
1316 "Cannot execute SDI",
1317 JOptionPane.ERROR_MESSAGE );
1320 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1321 JOptionPane.showMessageDialog( this,
1322 "Species tree is not completely binary",
1323 "Cannot execute SDI",
1324 JOptionPane.ERROR_MESSAGE );
1327 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1328 JOptionPane.showMessageDialog( this,
1329 "Gene tree is not completely binary",
1330 "Cannot execute SDI",
1331 JOptionPane.ERROR_MESSAGE );
1339 private boolean isUnsavedDataPresent() {
1340 final List<TreePanel> tps = getMainPanel().getTreePanels();
1341 for( final TreePanel tp : tps ) {
1342 if ( tp.isEdited() ) {
1349 private void moveNodeNamesToSeqNames() {
1350 if ( getCurrentTreePanel() != null ) {
1351 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1352 if ( ( phy != null ) && !phy.isEmpty() ) {
1353 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1358 private void moveNodeNamesToTaxSn() {
1359 if ( getCurrentTreePanel() != null ) {
1360 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1361 if ( ( phy != null ) && !phy.isEmpty() ) {
1362 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1367 private void newTree() {
1368 final Phylogeny[] phys = new Phylogeny[ 1 ];
1369 final Phylogeny phy = new Phylogeny();
1370 final PhylogenyNode node = new PhylogenyNode();
1371 phy.setRoot( node );
1372 phy.setRooted( true );
1374 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1375 _mainpanel.getControlPanel().showWhole();
1376 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1377 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1378 if ( getMainPanel().getMainFrame() == null ) {
1379 // Must be "E" applet version.
1380 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1381 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1384 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1386 activateSaveAllIfNeeded();
1390 private void obtainDetailedTaxonomicInformation() {
1391 if ( getCurrentTreePanel() != null ) {
1392 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1393 if ( ( phy != null ) && !phy.isEmpty() ) {
1394 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1395 _mainpanel.getCurrentTreePanel(),
1397 new Thread( t ).start();
1402 private void obtainUniProtSequenceInformation() {
1403 if ( getCurrentTreePanel() != null ) {
1404 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1405 if ( ( phy != null ) && !phy.isEmpty() ) {
1406 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1407 _mainpanel.getCurrentTreePanel(),
1409 new Thread( u ).start();
1414 private void print() {
1415 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1416 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1419 if ( !getOptions().isPrintUsingActualSize() ) {
1420 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1421 getOptions().getPrintSizeY() - 140,
1423 getCurrentTreePanel().resetPreferredSize();
1424 getCurrentTreePanel().repaint();
1426 final String job_name = Constants.PRG_NAME;
1427 boolean error = false;
1428 String printer_name = null;
1430 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1432 catch ( final Exception e ) {
1434 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1436 if ( !error && ( printer_name != null ) ) {
1437 String msg = "Printing data sent to printer";
1438 if ( printer_name.length() > 1 ) {
1439 msg += " [" + printer_name + "]";
1441 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1443 if ( !getOptions().isPrintUsingActualSize() ) {
1444 getControlPanel().showWhole();
1448 private void printPhylogenyToPdf( final String file_name ) {
1449 if ( !getOptions().isPrintUsingActualSize() ) {
1450 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1451 getOptions().getPrintSizeY(),
1453 getCurrentTreePanel().resetPreferredSize();
1454 getCurrentTreePanel().repaint();
1456 String pdf_written_to = "";
1457 boolean error = false;
1459 if ( getOptions().isPrintUsingActualSize() ) {
1460 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1461 getCurrentTreePanel(),
1462 getCurrentTreePanel().getWidth(),
1463 getCurrentTreePanel().getHeight() );
1466 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1467 .getPrintSizeX(), getOptions().getPrintSizeY() );
1470 catch ( final IOException e ) {
1472 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1475 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1476 JOptionPane.showMessageDialog( this,
1477 "Wrote PDF to: " + pdf_written_to,
1479 JOptionPane.INFORMATION_MESSAGE );
1482 JOptionPane.showMessageDialog( this,
1483 "There was an unknown problem when attempting to write to PDF file: \""
1486 JOptionPane.ERROR_MESSAGE );
1489 if ( !getOptions().isPrintUsingActualSize() ) {
1490 getControlPanel().showWhole();
1494 private void addExpressionValuesFromFile() {
1495 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1496 JOptionPane.showMessageDialog( this,
1497 "Need to load evolutionary tree first",
1498 "Can Not Read Expression Values",
1499 JOptionPane.WARNING_MESSAGE );
1502 final File my_dir = getCurrentDir();
1503 if ( my_dir != null ) {
1504 _values_filechooser.setCurrentDirectory( my_dir );
1506 final int result = _values_filechooser.showOpenDialog( _contentpane );
1507 final File file = _values_filechooser.getSelectedFile();
1508 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1509 BasicTable<String> t = null;
1511 t = BasicTableParser.parse( file, "\t" );
1512 if ( t.getNumberOfColumns() < 2 ) {
1513 t = BasicTableParser.parse( file, "," );
1515 if ( t.getNumberOfColumns() < 2 ) {
1516 t = BasicTableParser.parse( file, " " );
1519 catch ( final IOException e ) {
1520 JOptionPane.showMessageDialog( this,
1522 "Could Not Read Expression Value Table",
1523 JOptionPane.ERROR_MESSAGE );
1526 if ( t.getNumberOfColumns() < 2 ) {
1527 JOptionPane.showMessageDialog( this,
1528 "Table contains " + t.getNumberOfColumns() + " column(s)",
1529 "Problem with Expression Value Table",
1530 JOptionPane.ERROR_MESSAGE );
1533 if ( t.getNumberOfRows() < 1 ) {
1534 JOptionPane.showMessageDialog( this,
1535 "Table contains zero rows",
1536 "Problem with Expression Value Table",
1537 JOptionPane.ERROR_MESSAGE );
1540 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1541 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1542 JOptionPane.showMessageDialog( this,
1543 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1544 + phy.getNumberOfExternalNodes() + " external nodes",
1546 JOptionPane.WARNING_MESSAGE );
1548 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1550 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1551 final PhylogenyNode node = iter.next();
1552 final String node_name = node.getName();
1553 if ( !ForesterUtil.isEmpty( node_name ) ) {
1556 row = t.findRow( node_name );
1558 catch ( final IllegalArgumentException e ) {
1560 .showMessageDialog( this,
1562 "Error Mapping Node Identifiers to Expression Value Identifiers",
1563 JOptionPane.ERROR_MESSAGE );
1567 if ( node.isExternal() ) {
1572 final List<Double> l = new ArrayList<Double>();
1573 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1576 d = Double.parseDouble( t.getValueAsString( col, row ) );
1578 catch ( final NumberFormatException e ) {
1579 JOptionPane.showMessageDialog( this,
1580 "Could not parse \"" + t.getValueAsString( col, row )
1581 + "\" into a decimal value",
1582 "Issue with Expression Value Table",
1583 JOptionPane.ERROR_MESSAGE );
1586 stats.addValue( d );
1589 if ( !l.isEmpty() ) {
1590 if ( node.getNodeData().getProperties() != null ) {
1591 node.getNodeData().getProperties()
1592 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1594 node.getNodeData().setVector( l );
1598 if ( not_found > 0 ) {
1599 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1600 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1602 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1606 private void readPhylogeniesFromFile() {
1607 boolean exception = false;
1608 Phylogeny[] phys = null;
1609 // Set an initial directory if none set yet
1610 final File my_dir = getCurrentDir();
1611 _open_filechooser.setMultiSelectionEnabled( true );
1612 // Open file-open dialog and set current directory
1613 if ( my_dir != null ) {
1614 _open_filechooser.setCurrentDirectory( my_dir );
1616 final int result = _open_filechooser.showOpenDialog( _contentpane );
1617 // All done: get the file
1618 final File[] files = _open_filechooser.getSelectedFiles();
1619 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1620 boolean nhx_or_nexus = false;
1621 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1622 for( final File file : files ) {
1623 if ( ( file != null ) && !file.isDirectory() ) {
1624 if ( _mainpanel.getCurrentTreePanel() != null ) {
1625 _mainpanel.getCurrentTreePanel().setWaitCursor();
1628 _mainpanel.setWaitCursor();
1630 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1631 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1633 final NHXParser nhx = new NHXParser();
1634 setSpecialOptionsForNhxParser( nhx );
1635 phys = ForesterUtil.readPhylogenies( nhx, file );
1636 nhx_or_nexus = true;
1638 catch ( final Exception e ) {
1640 exceptionOccuredDuringOpenFile( e );
1643 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1644 warnIfNotPhyloXmlValidation( getConfiguration() );
1646 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1647 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1649 catch ( final Exception e ) {
1651 exceptionOccuredDuringOpenFile( e );
1654 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1656 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1658 catch ( final Exception e ) {
1660 exceptionOccuredDuringOpenFile( e );
1663 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1665 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1666 setSpecialOptionsForNexParser( nex );
1667 phys = ForesterUtil.readPhylogenies( nex, file );
1668 nhx_or_nexus = true;
1670 catch ( final Exception e ) {
1672 exceptionOccuredDuringOpenFile( e );
1678 final PhylogenyParser parser = ForesterUtil
1679 .createParserDependingOnFileType( file, getConfiguration()
1680 .isValidatePhyloXmlAgainstSchema() );
1681 if ( parser instanceof NexusPhylogeniesParser ) {
1682 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1683 setSpecialOptionsForNexParser( nex );
1684 nhx_or_nexus = true;
1686 else if ( parser instanceof NHXParser ) {
1687 final NHXParser nhx = ( NHXParser ) parser;
1688 setSpecialOptionsForNhxParser( nhx );
1689 nhx_or_nexus = true;
1691 else if ( parser instanceof PhyloXmlParser ) {
1692 warnIfNotPhyloXmlValidation( getConfiguration() );
1694 phys = ForesterUtil.readPhylogenies( parser, file );
1696 catch ( final Exception e ) {
1698 exceptionOccuredDuringOpenFile( e );
1701 if ( _mainpanel.getCurrentTreePanel() != null ) {
1702 _mainpanel.getCurrentTreePanel().setArrowCursor();
1705 _mainpanel.setArrowCursor();
1707 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1708 boolean one_desc = false;
1709 if ( nhx_or_nexus ) {
1710 for( final Phylogeny phy : phys ) {
1711 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1712 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1714 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1720 Util.addPhylogeniesToTabs( phys,
1722 file.getAbsolutePath(),
1725 _mainpanel.getControlPanel().showWhole();
1726 if ( nhx_or_nexus && one_desc ) {
1728 .showMessageDialog( this,
1729 "One or more trees contain (a) node(s) with one descendant, "
1730 + ForesterUtil.LINE_SEPARATOR
1731 + "possibly indicating illegal parentheses within node names.",
1732 "Warning: Possible Error in New Hampshire Formatted Data",
1733 JOptionPane.WARNING_MESSAGE );
1739 activateSaveAllIfNeeded();
1743 public void readSeqsFromFile() {
1744 // Set an initial directory if none set yet
1745 final File my_dir = getCurrentDir();
1746 _seqs_filechooser.setMultiSelectionEnabled( false );
1747 // Open file-open dialog and set current directory
1748 if ( my_dir != null ) {
1749 _seqs_filechooser.setCurrentDirectory( my_dir );
1751 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1752 // All done: get the seqs
1753 final File file = _seqs_filechooser.getSelectedFile();
1754 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1755 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1756 setSeqsFile( null );
1758 List<Sequence> seqs = null;
1760 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1761 seqs = FastaParser.parse( new FileInputStream( file ) );
1762 for( final Sequence seq : seqs ) {
1763 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1770 catch ( final MsaFormatException e ) {
1772 _mainpanel.getCurrentTreePanel().setArrowCursor();
1774 catch ( final Exception ex ) {
1777 JOptionPane.showMessageDialog( this,
1778 e.getLocalizedMessage(),
1779 "Multiple sequence file format error",
1780 JOptionPane.ERROR_MESSAGE );
1783 catch ( final IOException e ) {
1785 _mainpanel.getCurrentTreePanel().setArrowCursor();
1787 catch ( final Exception ex ) {
1790 JOptionPane.showMessageDialog( this,
1791 e.getLocalizedMessage(),
1792 "Failed to read multiple sequence file",
1793 JOptionPane.ERROR_MESSAGE );
1796 catch ( final IllegalArgumentException e ) {
1798 _mainpanel.getCurrentTreePanel().setArrowCursor();
1800 catch ( final Exception ex ) {
1803 JOptionPane.showMessageDialog( this,
1804 e.getLocalizedMessage(),
1805 "Unexpected error during reading of multiple sequence file",
1806 JOptionPane.ERROR_MESSAGE );
1809 catch ( final Exception e ) {
1811 _mainpanel.getCurrentTreePanel().setArrowCursor();
1813 catch ( final Exception ex ) {
1816 e.printStackTrace();
1817 JOptionPane.showMessageDialog( this,
1818 e.getLocalizedMessage(),
1819 "Unexpected error during reading of multiple sequence file",
1820 JOptionPane.ERROR_MESSAGE );
1823 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1824 JOptionPane.showMessageDialog( this,
1825 "Multiple sequence file is empty",
1826 "Illegal multiple sequence file",
1827 JOptionPane.ERROR_MESSAGE );
1830 if ( seqs.size() < 4 ) {
1831 JOptionPane.showMessageDialog( this,
1832 "Multiple sequence file needs to contain at least 3 sequences",
1833 "Illegal multiple sequence file",
1834 JOptionPane.ERROR_MESSAGE );
1837 // if ( msa.getLength() < 2 ) {
1838 // JOptionPane.showMessageDialog( this,
1839 // "Multiple sequence alignment needs to contain at least 2 residues",
1840 // "Illegal multiple sequence file",
1841 // JOptionPane.ERROR_MESSAGE );
1845 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1850 public void readMsaFromFile() {
1851 // Set an initial directory if none set yet
1852 final File my_dir = getCurrentDir();
1853 _msa_filechooser.setMultiSelectionEnabled( false );
1854 // Open file-open dialog and set current directory
1855 if ( my_dir != null ) {
1856 _msa_filechooser.setCurrentDirectory( my_dir );
1858 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1859 // All done: get the msa
1860 final File file = _msa_filechooser.getSelectedFile();
1861 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1862 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1867 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1868 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1869 System.out.println( msa.toString() );
1872 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1875 catch ( final MsaFormatException e ) {
1877 _mainpanel.getCurrentTreePanel().setArrowCursor();
1879 catch ( final Exception ex ) {
1882 JOptionPane.showMessageDialog( this,
1883 e.getLocalizedMessage(),
1884 "Multiple sequence alignment format error",
1885 JOptionPane.ERROR_MESSAGE );
1888 catch ( final IOException e ) {
1890 _mainpanel.getCurrentTreePanel().setArrowCursor();
1892 catch ( final Exception ex ) {
1895 JOptionPane.showMessageDialog( this,
1896 e.getLocalizedMessage(),
1897 "Failed to read multiple sequence alignment",
1898 JOptionPane.ERROR_MESSAGE );
1901 catch ( final IllegalArgumentException e ) {
1903 _mainpanel.getCurrentTreePanel().setArrowCursor();
1905 catch ( final Exception ex ) {
1908 JOptionPane.showMessageDialog( this,
1909 e.getLocalizedMessage(),
1910 "Unexpected error during reading of multiple sequence alignment",
1911 JOptionPane.ERROR_MESSAGE );
1914 catch ( final Exception e ) {
1916 _mainpanel.getCurrentTreePanel().setArrowCursor();
1918 catch ( final Exception ex ) {
1921 e.printStackTrace();
1922 JOptionPane.showMessageDialog( this,
1923 e.getLocalizedMessage(),
1924 "Unexpected error during reading of multiple sequence alignment",
1925 JOptionPane.ERROR_MESSAGE );
1928 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1929 JOptionPane.showMessageDialog( this,
1930 "Multiple sequence alignment is empty",
1931 "Illegal Multiple Sequence Alignment",
1932 JOptionPane.ERROR_MESSAGE );
1935 if ( msa.getNumberOfSequences() < 4 ) {
1936 JOptionPane.showMessageDialog( this,
1937 "Multiple sequence alignment needs to contain at least 3 sequences",
1938 "Illegal multiple sequence alignment",
1939 JOptionPane.ERROR_MESSAGE );
1942 if ( msa.getLength() < 2 ) {
1943 JOptionPane.showMessageDialog( this,
1944 "Multiple sequence alignment needs to contain at least 2 residues",
1945 "Illegal multiple sequence alignment",
1946 JOptionPane.ERROR_MESSAGE );
1950 setMsaFile( _msa_filechooser.getSelectedFile() );
1956 void readPhylogeniesFromURL() {
1958 Phylogeny[] phys = null;
1959 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1960 final String url_string = JOptionPane.showInputDialog( this,
1962 "Use URL/webservice to obtain a phylogeny",
1963 JOptionPane.QUESTION_MESSAGE );
1964 boolean nhx_or_nexus = false;
1965 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1967 url = new URL( url_string );
1968 PhylogenyParser parser = null;
1969 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1970 parser = new TolParser();
1973 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
1974 .isValidatePhyloXmlAgainstSchema() );
1976 if ( parser instanceof NexusPhylogeniesParser ) {
1977 nhx_or_nexus = true;
1979 else if ( parser instanceof NHXParser ) {
1980 nhx_or_nexus = true;
1982 if ( _mainpanel.getCurrentTreePanel() != null ) {
1983 _mainpanel.getCurrentTreePanel().setWaitCursor();
1986 _mainpanel.setWaitCursor();
1988 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1989 phys = factory.create( url.openStream(), parser );
1991 catch ( final MalformedURLException e ) {
1992 JOptionPane.showMessageDialog( this,
1993 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1995 JOptionPane.ERROR_MESSAGE );
1997 catch ( final IOException e ) {
1998 JOptionPane.showMessageDialog( this,
1999 "Could not read from " + url + "\n"
2000 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2001 "Failed to read URL",
2002 JOptionPane.ERROR_MESSAGE );
2004 catch ( final Exception e ) {
2005 JOptionPane.showMessageDialog( this,
2006 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2007 "Unexpected Exception",
2008 JOptionPane.ERROR_MESSAGE );
2011 if ( _mainpanel.getCurrentTreePanel() != null ) {
2012 _mainpanel.getCurrentTreePanel().setArrowCursor();
2015 _mainpanel.setArrowCursor();
2018 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2019 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2020 for( final Phylogeny phy : phys ) {
2021 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2024 Util.addPhylogeniesToTabs( phys,
2025 new File( url.getFile() ).getName(),
2026 new File( url.getFile() ).toString(),
2029 _mainpanel.getControlPanel().showWhole();
2032 activateSaveAllIfNeeded();
2036 private void readSpeciesTreeFromFile() {
2038 boolean exception = false;
2039 final File my_dir = getCurrentDir();
2040 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2041 if ( my_dir != null ) {
2042 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2044 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2045 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2046 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2047 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2049 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2052 catch ( final Exception e ) {
2054 exceptionOccuredDuringOpenFile( e );
2057 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2059 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2062 catch ( final Exception e ) {
2064 exceptionOccuredDuringOpenFile( e );
2070 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2073 catch ( final Exception e ) {
2075 exceptionOccuredDuringOpenFile( e );
2078 if ( !exception && ( t != null ) && !t.isRooted() ) {
2081 JOptionPane.showMessageDialog( this,
2082 "Species tree is not rooted",
2083 "Species tree not loaded",
2084 JOptionPane.ERROR_MESSAGE );
2086 if ( !exception && ( t != null ) ) {
2087 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2088 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2089 final PhylogenyNode node = it.next();
2090 if ( !node.getNodeData().isHasTaxonomy() ) {
2094 .showMessageDialog( this,
2095 "Species tree contains external node(s) without taxonomy information",
2096 "Species tree not loaded",
2097 JOptionPane.ERROR_MESSAGE );
2101 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2104 JOptionPane.showMessageDialog( this,
2106 + node.getNodeData().getTaxonomy().asSimpleText()
2107 + "] is not unique in species tree",
2108 "Species tree not loaded",
2109 JOptionPane.ERROR_MESSAGE );
2113 tax_set.add( node.getNodeData().getTaxonomy() );
2118 if ( !exception && ( t != null ) ) {
2120 JOptionPane.showMessageDialog( this,
2121 "Species tree successfully loaded",
2122 "Species tree loaded",
2123 JOptionPane.INFORMATION_MESSAGE );
2125 _contentpane.repaint();
2130 private void setCurrentDir( final File current_dir ) {
2131 _current_dir = current_dir;
2134 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2135 _min_not_collapse = min_not_collapse;
2138 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2139 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2142 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2143 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2144 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2145 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2146 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2148 nhx.setTaxonomyExtraction( te );
2151 private void writeAllToFile() {
2152 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2155 final File my_dir = getCurrentDir();
2156 if ( my_dir != null ) {
2157 _save_filechooser.setCurrentDirectory( my_dir );
2159 _save_filechooser.setSelectedFile( new File( "" ) );
2160 final int result = _save_filechooser.showSaveDialog( _contentpane );
2161 final File file = _save_filechooser.getSelectedFile();
2162 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2163 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2164 if ( file.exists() ) {
2165 final int i = JOptionPane.showConfirmDialog( this,
2166 file + " already exists. Overwrite?",
2168 JOptionPane.OK_CANCEL_OPTION,
2169 JOptionPane.WARNING_MESSAGE );
2170 if ( i != JOptionPane.OK_OPTION ) {
2177 catch ( final Exception e ) {
2178 JOptionPane.showMessageDialog( this,
2179 "Failed to delete: " + file,
2181 JOptionPane.WARNING_MESSAGE );
2185 final int count = getMainPanel().getTabbedPane().getTabCount();
2186 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2187 for( int i = 0; i < count; ++i ) {
2188 trees.add( getMainPanel().getPhylogeny( i ) );
2189 getMainPanel().getTreePanels().get( i ).setEdited( false );
2191 final PhylogenyWriter writer = new PhylogenyWriter();
2193 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2195 catch ( final IOException e ) {
2196 JOptionPane.showMessageDialog( this,
2197 "Failed to write to: " + file,
2199 JOptionPane.WARNING_MESSAGE );
2204 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2206 final PhylogenyWriter writer = new PhylogenyWriter();
2207 writer.toNewHampshire( t, false, true, file );
2209 catch ( final Exception e ) {
2211 exceptionOccuredDuringSaveAs( e );
2216 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2218 final PhylogenyWriter writer = new PhylogenyWriter();
2219 writer.toNexus( file, t );
2221 catch ( final Exception e ) {
2223 exceptionOccuredDuringSaveAs( e );
2228 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2230 final PhylogenyWriter writer = new PhylogenyWriter();
2231 writer.toNewHampshireX( t, file );
2233 catch ( final Exception e ) {
2235 exceptionOccuredDuringSaveAs( e );
2240 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2242 final PhylogenyWriter writer = new PhylogenyWriter();
2243 writer.toPhyloXML( file, t, 0 );
2245 catch ( final Exception e ) {
2247 exceptionOccuredDuringSaveAs( e );
2252 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2253 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2254 _mainpanel.getCurrentTreePanel().getHeight(),
2256 String file_written_to = "";
2257 boolean error = false;
2259 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2260 _mainpanel.getCurrentTreePanel().getWidth(),
2261 _mainpanel.getCurrentTreePanel().getHeight(),
2262 _mainpanel.getCurrentTreePanel(),
2263 _mainpanel.getControlPanel(),
2267 catch ( final IOException e ) {
2269 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2272 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2273 JOptionPane.showMessageDialog( this,
2274 "Wrote image to: " + file_written_to,
2276 JOptionPane.INFORMATION_MESSAGE );
2279 JOptionPane.showMessageDialog( this,
2280 "There was an unknown problem when attempting to write to an image file: \""
2283 JOptionPane.ERROR_MESSAGE );
2286 _contentpane.repaint();
2289 private void writeToFile( final Phylogeny t ) {
2293 String initial_filename = null;
2294 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2296 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2298 catch ( final IOException e ) {
2299 initial_filename = null;
2302 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2303 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2306 _save_filechooser.setSelectedFile( new File( "" ) );
2308 final File my_dir = getCurrentDir();
2309 if ( my_dir != null ) {
2310 _save_filechooser.setCurrentDirectory( my_dir );
2312 final int result = _save_filechooser.showSaveDialog( _contentpane );
2313 final File file = _save_filechooser.getSelectedFile();
2314 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2315 boolean exception = false;
2316 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2317 if ( file.exists() ) {
2318 final int i = JOptionPane.showConfirmDialog( this,
2319 file + " already exists.\nOverwrite?",
2321 JOptionPane.OK_CANCEL_OPTION,
2322 JOptionPane.QUESTION_MESSAGE );
2323 if ( i != JOptionPane.OK_OPTION ) {
2327 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2329 ForesterUtil.copyFile( file, to );
2331 catch ( final Exception e ) {
2332 JOptionPane.showMessageDialog( this,
2333 "Failed to create backup copy " + to,
2334 "Failed to Create Backup Copy",
2335 JOptionPane.WARNING_MESSAGE );
2340 catch ( final Exception e ) {
2341 JOptionPane.showMessageDialog( this,
2342 "Failed to delete: " + file,
2344 JOptionPane.WARNING_MESSAGE );
2348 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2349 exception = writeAsNewHampshire( t, exception, file );
2351 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2352 exception = writeAsNHX( t, exception, file );
2354 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2355 exception = writeAsPhyloXml( t, exception, file );
2357 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2358 exception = writeAsNexus( t, exception, file );
2362 final String file_name = file.getName().trim().toLowerCase();
2363 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2364 || file_name.endsWith( ".tree" ) ) {
2365 exception = writeAsNewHampshire( t, exception, file );
2367 else if ( file_name.endsWith( ".nhx" ) ) {
2368 exception = writeAsNHX( t, exception, file );
2370 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2371 exception = writeAsNexus( t, exception, file );
2375 exception = writeAsPhyloXml( t, exception, file );
2379 getMainPanel().setTitleOfSelectedTab( file.getName() );
2380 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2381 getMainPanel().getCurrentTreePanel().setEdited( false );
2386 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2387 if ( ( t == null ) || t.isEmpty() ) {
2390 String initial_filename = "";
2391 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2392 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2394 if ( initial_filename.indexOf( '.' ) > 0 ) {
2395 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2397 initial_filename = initial_filename + "." + type;
2398 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2399 final File my_dir = getCurrentDir();
2400 if ( my_dir != null ) {
2401 _writetographics_filechooser.setCurrentDirectory( my_dir );
2403 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2404 File file = _writetographics_filechooser.getSelectedFile();
2405 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2406 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2407 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2408 file = new File( file.toString() + "." + type );
2410 if ( file.exists() ) {
2411 final int i = JOptionPane.showConfirmDialog( this,
2412 file + " already exists. Overwrite?",
2414 JOptionPane.OK_CANCEL_OPTION,
2415 JOptionPane.WARNING_MESSAGE );
2416 if ( i != JOptionPane.OK_OPTION ) {
2423 catch ( final Exception e ) {
2424 JOptionPane.showMessageDialog( this,
2425 "Failed to delete: " + file,
2427 JOptionPane.WARNING_MESSAGE );
2431 writePhylogenyToGraphicsFile( file.toString(), type );
2435 private void writeToPdf( final Phylogeny t ) {
2436 if ( ( t == null ) || t.isEmpty() ) {
2439 String initial_filename = "";
2440 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2441 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2443 if ( initial_filename.indexOf( '.' ) > 0 ) {
2444 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2446 initial_filename = initial_filename + ".pdf";
2447 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2448 final File my_dir = getCurrentDir();
2449 if ( my_dir != null ) {
2450 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2452 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2453 File file = _writetopdf_filechooser.getSelectedFile();
2454 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2455 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2456 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2457 file = new File( file.toString() + ".pdf" );
2459 if ( file.exists() ) {
2460 final int i = JOptionPane.showConfirmDialog( this,
2461 file + " already exists. Overwrite?",
2463 JOptionPane.OK_CANCEL_OPTION,
2464 JOptionPane.WARNING_MESSAGE );
2465 if ( i != JOptionPane.OK_OPTION ) {
2469 printPhylogenyToPdf( file.toString() );
2473 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2474 return new MainFrameApplication( phys, config, title );
2477 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2478 return new MainFrameApplication( phys, config_file_name, title );
2481 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2482 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2483 + o.getPrintSizeY() + ")" );
2486 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2487 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2490 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2491 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2493 .showMessageDialog( null,
2495 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2498 JOptionPane.WARNING_MESSAGE );
2502 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2503 _phylogenetic_inference_options = phylogenetic_inference_options;
2506 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2507 if ( _phylogenetic_inference_options == null ) {
2508 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2510 return _phylogenetic_inference_options;
2513 public Msa getMsa() {
2517 void setMsa( final Msa msa ) {
2521 void setMsaFile( final File msa_file ) {
2522 _msa_file = msa_file;
2525 public File getMsaFile() {
2529 public List<Sequence> getSeqs() {
2533 void setSeqs( final List<Sequence> seqs ) {
2537 void setSeqsFile( final File seqs_file ) {
2538 _seqs_file = seqs_file;
2541 public File getSeqsFile() {
2544 } // MainFrameApplication.
2546 class NexusFilter extends FileFilter {
2549 public boolean accept( final File f ) {
2550 final String file_name = f.getName().trim().toLowerCase();
2551 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2552 || file_name.endsWith( ".tre" ) || f.isDirectory();
2556 public String getDescription() {
2557 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2561 class NHFilter extends FileFilter {
2564 public boolean accept( final File f ) {
2565 final String file_name = f.getName().trim().toLowerCase();
2566 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2567 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2568 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2573 public String getDescription() {
2574 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2578 class NHXFilter extends FileFilter {
2581 public boolean accept( final File f ) {
2582 final String file_name = f.getName().trim().toLowerCase();
2583 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2587 public String getDescription() {
2588 return "NHX files (*.nhx)";
2592 class PdfFilter extends FileFilter {
2595 public boolean accept( final File f ) {
2596 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2600 public String getDescription() {
2601 return "PDF files (*.pdf)";
2605 class TolFilter extends FileFilter {
2608 public boolean accept( final File f ) {
2609 final String file_name = f.getName().trim().toLowerCase();
2610 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2611 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2615 public String getDescription() {
2616 return "Tree of Life files (*.tol, *.tolxml)";
2620 class XMLFilter extends FileFilter {
2623 public boolean accept( final File f ) {
2624 final String file_name = f.getName().trim().toLowerCase();
2625 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2626 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2630 public String getDescription() {
2631 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";