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 );
765 customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().isShowNodeBoxes() );
766 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
767 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
768 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
769 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
770 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
771 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
772 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
773 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
774 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
775 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
776 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
777 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
778 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
779 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
780 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
781 customizeCheckBoxMenuItem( _label_direction_cbmi,
782 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
783 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
784 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
785 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
786 .isInternalNumberAreConfidenceForNhParsing() );
787 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
788 .isExtractPfamTaxonomyCodesInNhParsing() );
789 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
790 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
791 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
792 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
793 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
794 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
795 .isGraphicsExportUsingActualSize() );
796 _jmenubar.add( _options_jmenu );
799 void buildToolsMenu() {
800 _tools_menu = createMenu( "Tools", getConfiguration() );
801 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
802 customizeJMenuItem( _confcolor_item );
803 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
804 customizeJMenuItem( _taxcolor_item );
805 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
806 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
807 customizeJMenuItem( _remove_branch_color_item );
808 _tools_menu.addSeparator();
809 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
810 customizeJMenuItem( _midpoint_root_item );
811 _tools_menu.addSeparator();
812 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
813 customizeJMenuItem( _collapse_species_specific_subtrees );
815 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
816 customizeJMenuItem( _collapse_below_threshold );
817 _collapse_below_threshold
818 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
819 _tools_menu.addSeparator();
821 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
822 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
823 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
824 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
825 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
826 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
828 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
829 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
830 _extract_tax_code_from_node_names_jmi
831 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
832 _tools_menu.addSeparator();
834 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
835 customizeJMenuItem( _infer_common_sn_names_item );
836 _tools_menu.addSeparator();
838 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
839 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
840 _obtain_detailed_taxonomic_information_jmi
841 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
843 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
844 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
845 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
846 _tools_menu.addSeparator();
847 if ( !Constants.__RELEASE ) {
848 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
849 customizeJMenuItem( _function_analysis );
851 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
852 _tools_menu.addSeparator();
854 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
855 customizeJMenuItem( _read_values_jmi );
856 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
857 _jmenubar.add( _tools_menu );
860 private void choosePdfWidth() {
861 final String s = ( String ) JOptionPane.showInputDialog( this,
862 "Please enter the default line width for PDF export.\n"
864 + getOptions().getPrintLineWidth() + "]\n",
865 "Line Width for PDF Export",
866 JOptionPane.QUESTION_MESSAGE,
869 getOptions().getPrintLineWidth() );
870 if ( !ForesterUtil.isEmpty( s ) ) {
871 boolean success = true;
873 final String m_str = s.trim();
874 if ( !ForesterUtil.isEmpty( m_str ) ) {
876 f = Float.parseFloat( m_str );
878 catch ( final Exception ex ) {
885 if ( success && ( f > 0.0 ) ) {
886 getOptions().setPrintLineWidth( f );
891 private void choosePrintSize() {
892 final String s = ( String ) JOptionPane.showInputDialog( this,
893 "Please enter values for width and height,\nseparated by a comma.\n"
894 + "[current values: "
895 + getOptions().getPrintSizeX() + ", "
896 + getOptions().getPrintSizeY() + "]\n"
897 + "[A4: " + Constants.A4_SIZE_X + ", "
898 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
899 + Constants.US_LETTER_SIZE_X + ", "
900 + Constants.US_LETTER_SIZE_Y + "]",
901 "Default Size for Graphics Export",
902 JOptionPane.QUESTION_MESSAGE,
905 getOptions().getPrintSizeX() + ", "
906 + getOptions().getPrintSizeY() );
907 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
908 boolean success = true;
911 final String[] str_ary = s.split( "," );
912 if ( str_ary.length == 2 ) {
913 final String x_str = str_ary[ 0 ].trim();
914 final String y_str = str_ary[ 1 ].trim();
915 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
917 x = Integer.parseInt( x_str );
918 y = Integer.parseInt( y_str );
920 catch ( final Exception ex ) {
931 if ( success && ( x > 1 ) && ( y > 1 ) ) {
932 getOptions().setPrintSizeX( x );
933 getOptions().setPrintSizeY( y );
940 if ( isUnsavedDataPresent() ) {
941 final int r = JOptionPane.showConfirmDialog( this,
942 "Exit despite potentially unsaved changes?",
944 JOptionPane.YES_NO_OPTION );
945 if ( r != JOptionPane.YES_OPTION ) {
952 private void closeCurrentPane() {
953 if ( getMainPanel().getCurrentTreePanel() != null ) {
954 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
955 final int r = JOptionPane.showConfirmDialog( this,
956 "Close tab despite potentially unsaved changes?",
958 JOptionPane.YES_NO_OPTION );
959 if ( r != JOptionPane.YES_OPTION ) {
963 getMainPanel().closeCurrentPane();
964 activateSaveAllIfNeeded();
968 private void collapse( final Phylogeny phy, final double m ) {
969 final PhylogenyNodeIterator it = phy.iteratorPostorder();
970 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
971 double min_support = Double.MAX_VALUE;
972 boolean conf_present = false;
973 while ( it.hasNext() ) {
974 final PhylogenyNode n = it.next();
975 if ( !n.isExternal() && !n.isRoot() ) {
976 final List<Confidence> c = n.getBranchData().getConfidences();
977 if ( ( c != null ) && ( c.size() > 0 ) ) {
980 for( final Confidence confidence : c ) {
981 if ( confidence.getValue() > max ) {
982 max = confidence.getValue();
985 if ( max < getMinNotCollapseConfidenceValue() ) {
986 to_be_removed.add( n );
988 if ( max < min_support ) {
994 if ( conf_present ) {
995 for( final PhylogenyNode node : to_be_removed ) {
996 PhylogenyMethods.removeNode( node, phy );
998 if ( to_be_removed.size() > 0 ) {
999 phy.externalNodesHaveChanged();
1001 phy.recalculateNumberOfExternalDescendants( true );
1002 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1003 getCurrentTreePanel().setEdited( true );
1004 getCurrentTreePanel().repaint();
1006 if ( to_be_removed.size() > 0 ) {
1007 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1008 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1009 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1012 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1013 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1017 JOptionPane.showMessageDialog( this,
1018 "No branch collapsed because no confidence values present",
1019 "No confidence values present",
1020 JOptionPane.INFORMATION_MESSAGE );
1024 private void collapseBelowThreshold() {
1025 if ( getCurrentTreePanel() != null ) {
1026 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1027 if ( ( phy != null ) && !phy.isEmpty() ) {
1028 final String s = ( String ) JOptionPane.showInputDialog( this,
1029 "Please enter the minimum confidence value\n",
1030 "Minimal Confidence Value",
1031 JOptionPane.QUESTION_MESSAGE,
1034 getMinNotCollapseConfidenceValue() );
1035 if ( !ForesterUtil.isEmpty( s ) ) {
1036 boolean success = true;
1038 final String m_str = s.trim();
1039 if ( !ForesterUtil.isEmpty( m_str ) ) {
1041 m = Double.parseDouble( m_str );
1043 catch ( final Exception ex ) {
1050 if ( success && ( m >= 0.0 ) ) {
1051 setMinNotCollapseConfidenceValue( m );
1059 private PhyloXmlParser createPhyloXmlParser() {
1060 PhyloXmlParser xml_parser = null;
1061 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1063 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1065 catch ( final Exception e ) {
1066 JOptionPane.showMessageDialog( this,
1067 e.getLocalizedMessage(),
1068 "failed to create validating XML parser",
1069 JOptionPane.WARNING_MESSAGE );
1072 if ( xml_parser == null ) {
1073 xml_parser = new PhyloXmlParser();
1078 void executeGSDI() {
1079 if ( !isOKforSDI( false, true ) ) {
1082 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1083 JOptionPane.showMessageDialog( this,
1084 "Gene tree is not rooted.",
1085 "Cannot execute GSDI",
1086 JOptionPane.ERROR_MESSAGE );
1089 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1090 gene_tree.setAllNodesToNotCollapse();
1091 gene_tree.recalculateNumberOfExternalDescendants( false );
1093 int duplications = -1;
1095 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1096 duplications = gsdi.getDuplicationsSum();
1098 catch ( final Exception e ) {
1099 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1101 gene_tree.setRerootable( false );
1102 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1103 getControlPanel().setShowEvents( true );
1105 _mainpanel.getCurrentTreePanel().setEdited( true );
1106 JOptionPane.showMessageDialog( this,
1107 "Number of duplications: " + duplications,
1108 "GSDI successfully completed",
1109 JOptionPane.INFORMATION_MESSAGE );
1112 void executeFunctionAnalysis() {
1113 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1116 final GoAnnotation a = new GoAnnotation( this,
1117 _mainpanel.getCurrentTreePanel(),
1118 _mainpanel.getCurrentPhylogeny() );
1119 new Thread( a ).start();
1122 void executeLineageInference() {
1123 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1126 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1127 JOptionPane.showMessageDialog( this,
1128 "Phylogeny is not rooted.",
1129 "Cannot infer ancestral taxonomies",
1130 JOptionPane.ERROR_MESSAGE );
1133 final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1134 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1135 _mainpanel.getCurrentTreePanel(),
1137 new Thread( inferrer ).start();
1140 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1141 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1142 getPhylogeneticInferenceOptions(),
1143 from_unaligned_seqs );
1145 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1146 if ( !from_unaligned_seqs ) {
1147 if ( getMsa() != null ) {
1148 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1149 getPhylogeneticInferenceOptions()
1151 new Thread( inferrer ).start();
1154 JOptionPane.showMessageDialog( this,
1155 "No multiple sequence alignment selected",
1156 "Phylogenetic Inference Not Launched",
1157 JOptionPane.WARNING_MESSAGE );
1161 if ( getSeqs() != null ) {
1162 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1163 getPhylogeneticInferenceOptions()
1165 new Thread( inferrer ).start();
1168 JOptionPane.showMessageDialog( this,
1169 "No input sequences selected",
1170 "Phylogenetic Inference Not Launched",
1171 JOptionPane.WARNING_MESSAGE );
1178 if ( !isOKforSDI( true, true ) ) {
1181 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1182 JOptionPane.showMessageDialog( this,
1183 "Gene tree is not rooted",
1184 "Cannot execute SDI",
1185 JOptionPane.ERROR_MESSAGE );
1188 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1189 gene_tree.setAllNodesToNotCollapse();
1190 gene_tree.recalculateNumberOfExternalDescendants( false );
1192 int duplications = -1;
1194 sdi = new SDIse( gene_tree, _species_tree.copy() );
1195 duplications = sdi.getDuplicationsSum();
1197 catch ( final Exception e ) {
1198 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1200 gene_tree.setRerootable( false );
1201 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1202 getControlPanel().setShowEvents( true );
1204 _mainpanel.getCurrentTreePanel().setEdited( true );
1205 JOptionPane.showMessageDialog( this,
1206 "Number of duplications: " + duplications,
1207 "SDI successfully completed",
1208 JOptionPane.INFORMATION_MESSAGE );
1211 void executeSDIR( final boolean minimize_cost ) {
1212 if ( !isOKforSDI( true, true ) ) {
1215 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1216 final SDIR sdiunrooted = new SDIR();
1217 gene_tree.setAllNodesToNotCollapse();
1218 gene_tree.recalculateNumberOfExternalDescendants( false );
1220 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1221 !minimize_cost, // minimize sum of dups
1222 true, // minimize height
1223 true, // return tree(s)
1224 1 )[ 0 ]; // # of trees to return
1226 catch ( final Exception e ) {
1227 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1230 final int duplications = sdiunrooted.getMinimalDuplications();
1231 gene_tree.setRerootable( false );
1232 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1233 getControlPanel().setShowEvents( true );
1235 _mainpanel.getCurrentTreePanel().setEdited( true );
1236 JOptionPane.showMessageDialog( this,
1237 "Number of duplications: " + duplications,
1238 "SDIR successfully completed",
1239 JOptionPane.INFORMATION_MESSAGE );
1244 _mainpanel.terminate();
1245 _contentpane.removeAll();
1246 setVisible( false );
1251 private void extractTaxCodeFromNodeNames() {
1252 if ( getCurrentTreePanel() != null ) {
1253 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1254 if ( ( phy != null ) && !phy.isEmpty() ) {
1255 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1256 while ( it.hasNext() ) {
1257 final PhylogenyNode n = it.next();
1258 final String name = n.getName().trim();
1259 if ( !ForesterUtil.isEmpty( name ) ) {
1260 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1262 TAXONOMY_EXTRACTION.YES );
1263 if ( !ForesterUtil.isEmpty( code ) ) {
1264 PhylogenyMethods.setTaxonomyCode( n, code );
1272 private ControlPanel getControlPanel() {
1273 return getMainPanel().getControlPanel();
1276 private File getCurrentDir() {
1277 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1278 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1280 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1282 catch ( final Exception e ) {
1283 _current_dir = null;
1287 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1288 if ( System.getProperty( "user.home" ) != null ) {
1289 _current_dir = new File( System.getProperty( "user.home" ) );
1291 else if ( System.getProperty( "user.dir" ) != null ) {
1292 _current_dir = new File( System.getProperty( "user.dir" ) );
1295 return _current_dir;
1299 public MainPanel getMainPanel() {
1303 private double getMinNotCollapseConfidenceValue() {
1304 return _min_not_collapse;
1307 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1308 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1311 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1312 JOptionPane.showMessageDialog( this,
1313 "No species tree loaded",
1314 "Cannot execute SDI",
1315 JOptionPane.ERROR_MESSAGE );
1318 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1319 JOptionPane.showMessageDialog( this,
1320 "Species tree is not completely binary",
1321 "Cannot execute SDI",
1322 JOptionPane.ERROR_MESSAGE );
1325 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1326 JOptionPane.showMessageDialog( this,
1327 "Gene tree is not completely binary",
1328 "Cannot execute SDI",
1329 JOptionPane.ERROR_MESSAGE );
1337 private boolean isUnsavedDataPresent() {
1338 final List<TreePanel> tps = getMainPanel().getTreePanels();
1339 for( final TreePanel tp : tps ) {
1340 if ( tp.isEdited() ) {
1347 private void moveNodeNamesToSeqNames() {
1348 if ( getCurrentTreePanel() != null ) {
1349 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1350 if ( ( phy != null ) && !phy.isEmpty() ) {
1351 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1356 private void moveNodeNamesToTaxSn() {
1357 if ( getCurrentTreePanel() != null ) {
1358 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1359 if ( ( phy != null ) && !phy.isEmpty() ) {
1360 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1365 private void newTree() {
1366 final Phylogeny[] phys = new Phylogeny[ 1 ];
1367 final Phylogeny phy = new Phylogeny();
1368 final PhylogenyNode node = new PhylogenyNode();
1369 phy.setRoot( node );
1370 phy.setRooted( true );
1372 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1373 _mainpanel.getControlPanel().showWhole();
1374 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1375 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1376 if ( getMainPanel().getMainFrame() == null ) {
1377 // Must be "E" applet version.
1378 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1379 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1382 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1384 activateSaveAllIfNeeded();
1388 private void obtainDetailedTaxonomicInformation() {
1389 if ( getCurrentTreePanel() != null ) {
1390 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1391 if ( ( phy != null ) && !phy.isEmpty() ) {
1392 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1393 _mainpanel.getCurrentTreePanel(),
1395 new Thread( t ).start();
1400 private void obtainUniProtSequenceInformation() {
1401 if ( getCurrentTreePanel() != null ) {
1402 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1403 if ( ( phy != null ) && !phy.isEmpty() ) {
1404 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1405 _mainpanel.getCurrentTreePanel(),
1407 new Thread( u ).start();
1412 private void print() {
1413 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1414 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1417 if ( !getOptions().isPrintUsingActualSize() ) {
1418 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1419 getOptions().getPrintSizeY() - 140,
1421 getCurrentTreePanel().resetPreferredSize();
1422 getCurrentTreePanel().repaint();
1424 final String job_name = Constants.PRG_NAME;
1425 boolean error = false;
1426 String printer_name = null;
1428 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1430 catch ( final Exception e ) {
1432 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1434 if ( !error && ( printer_name != null ) ) {
1435 String msg = "Printing data sent to printer";
1436 if ( printer_name.length() > 1 ) {
1437 msg += " [" + printer_name + "]";
1439 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1441 if ( !getOptions().isPrintUsingActualSize() ) {
1442 getControlPanel().showWhole();
1446 private void printPhylogenyToPdf( final String file_name ) {
1447 if ( !getOptions().isPrintUsingActualSize() ) {
1448 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1449 getOptions().getPrintSizeY(),
1451 getCurrentTreePanel().resetPreferredSize();
1452 getCurrentTreePanel().repaint();
1454 String pdf_written_to = "";
1455 boolean error = false;
1457 if ( getOptions().isPrintUsingActualSize() ) {
1458 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1459 getCurrentTreePanel(),
1460 getCurrentTreePanel().getWidth(),
1461 getCurrentTreePanel().getHeight() );
1464 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1465 .getPrintSizeX(), getOptions().getPrintSizeY() );
1468 catch ( final IOException e ) {
1470 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1473 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1474 JOptionPane.showMessageDialog( this,
1475 "Wrote PDF to: " + pdf_written_to,
1477 JOptionPane.INFORMATION_MESSAGE );
1480 JOptionPane.showMessageDialog( this,
1481 "There was an unknown problem when attempting to write to PDF file: \""
1484 JOptionPane.ERROR_MESSAGE );
1487 if ( !getOptions().isPrintUsingActualSize() ) {
1488 getControlPanel().showWhole();
1492 private void addExpressionValuesFromFile() {
1493 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1494 JOptionPane.showMessageDialog( this,
1495 "Need to load evolutionary tree first",
1496 "Can Not Read Expression Values",
1497 JOptionPane.WARNING_MESSAGE );
1500 final File my_dir = getCurrentDir();
1501 if ( my_dir != null ) {
1502 _values_filechooser.setCurrentDirectory( my_dir );
1504 final int result = _values_filechooser.showOpenDialog( _contentpane );
1505 final File file = _values_filechooser.getSelectedFile();
1506 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1507 BasicTable<String> t = null;
1509 t = BasicTableParser.parse( file, "\t" );
1510 if ( t.getNumberOfColumns() < 2 ) {
1511 t = BasicTableParser.parse( file, "," );
1513 if ( t.getNumberOfColumns() < 2 ) {
1514 t = BasicTableParser.parse( file, " " );
1517 catch ( final IOException e ) {
1518 JOptionPane.showMessageDialog( this,
1520 "Could Not Read Expression Value Table",
1521 JOptionPane.ERROR_MESSAGE );
1524 if ( t.getNumberOfColumns() < 2 ) {
1525 JOptionPane.showMessageDialog( this,
1526 "Table contains " + t.getNumberOfColumns() + " column(s)",
1527 "Problem with Expression Value Table",
1528 JOptionPane.ERROR_MESSAGE );
1531 if ( t.getNumberOfRows() < 1 ) {
1532 JOptionPane.showMessageDialog( this,
1533 "Table contains zero rows",
1534 "Problem with Expression Value Table",
1535 JOptionPane.ERROR_MESSAGE );
1538 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1539 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1540 JOptionPane.showMessageDialog( this,
1541 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1542 + phy.getNumberOfExternalNodes() + " external nodes",
1544 JOptionPane.WARNING_MESSAGE );
1546 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1548 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1549 final PhylogenyNode node = iter.next();
1550 final String node_name = node.getName();
1551 if ( !ForesterUtil.isEmpty( node_name ) ) {
1554 row = t.findRow( node_name );
1556 catch ( final IllegalArgumentException e ) {
1558 .showMessageDialog( this,
1560 "Error Mapping Node Identifiers to Expression Value Identifiers",
1561 JOptionPane.ERROR_MESSAGE );
1565 if ( node.isExternal() ) {
1570 final List<Double> l = new ArrayList<Double>();
1571 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1574 d = Double.parseDouble( t.getValueAsString( col, row ) );
1576 catch ( final NumberFormatException e ) {
1577 JOptionPane.showMessageDialog( this,
1578 "Could not parse \"" + t.getValueAsString( col, row )
1579 + "\" into a decimal value",
1580 "Issue with Expression Value Table",
1581 JOptionPane.ERROR_MESSAGE );
1584 stats.addValue( d );
1587 if ( !l.isEmpty() ) {
1588 if ( node.getNodeData().getProperties() != null ) {
1589 node.getNodeData().getProperties()
1590 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1592 node.getNodeData().setVector( l );
1596 if ( not_found > 0 ) {
1597 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1598 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1600 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1604 private void readPhylogeniesFromFile() {
1605 boolean exception = false;
1606 Phylogeny[] phys = null;
1607 // Set an initial directory if none set yet
1608 final File my_dir = getCurrentDir();
1609 _open_filechooser.setMultiSelectionEnabled( true );
1610 // Open file-open dialog and set current directory
1611 if ( my_dir != null ) {
1612 _open_filechooser.setCurrentDirectory( my_dir );
1614 final int result = _open_filechooser.showOpenDialog( _contentpane );
1615 // All done: get the file
1616 final File[] files = _open_filechooser.getSelectedFiles();
1617 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1618 boolean nhx_or_nexus = false;
1619 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1620 for( final File file : files ) {
1621 if ( ( file != null ) && !file.isDirectory() ) {
1622 if ( _mainpanel.getCurrentTreePanel() != null ) {
1623 _mainpanel.getCurrentTreePanel().setWaitCursor();
1626 _mainpanel.setWaitCursor();
1628 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1629 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1631 final NHXParser nhx = new NHXParser();
1632 setSpecialOptionsForNhxParser( nhx );
1633 phys = ForesterUtil.readPhylogenies( nhx, file );
1634 nhx_or_nexus = true;
1636 catch ( final Exception e ) {
1638 exceptionOccuredDuringOpenFile( e );
1641 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1642 warnIfNotPhyloXmlValidation( getConfiguration() );
1644 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1645 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1647 catch ( final Exception e ) {
1649 exceptionOccuredDuringOpenFile( e );
1652 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1654 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1656 catch ( final Exception e ) {
1658 exceptionOccuredDuringOpenFile( e );
1661 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1663 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1664 setSpecialOptionsForNexParser( nex );
1665 phys = ForesterUtil.readPhylogenies( nex, file );
1666 nhx_or_nexus = true;
1668 catch ( final Exception e ) {
1670 exceptionOccuredDuringOpenFile( e );
1676 final PhylogenyParser parser = ForesterUtil
1677 .createParserDependingOnFileType( file, getConfiguration()
1678 .isValidatePhyloXmlAgainstSchema() );
1679 if ( parser instanceof NexusPhylogeniesParser ) {
1680 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1681 setSpecialOptionsForNexParser( nex );
1682 nhx_or_nexus = true;
1684 else if ( parser instanceof NHXParser ) {
1685 final NHXParser nhx = ( NHXParser ) parser;
1686 setSpecialOptionsForNhxParser( nhx );
1687 nhx_or_nexus = true;
1689 else if ( parser instanceof PhyloXmlParser ) {
1690 warnIfNotPhyloXmlValidation( getConfiguration() );
1692 phys = ForesterUtil.readPhylogenies( parser, file );
1694 catch ( final Exception e ) {
1696 exceptionOccuredDuringOpenFile( e );
1699 if ( _mainpanel.getCurrentTreePanel() != null ) {
1700 _mainpanel.getCurrentTreePanel().setArrowCursor();
1703 _mainpanel.setArrowCursor();
1705 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1706 boolean one_desc = false;
1707 if ( nhx_or_nexus ) {
1708 for( final Phylogeny phy : phys ) {
1709 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1710 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1712 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1718 Util.addPhylogeniesToTabs( phys,
1720 file.getAbsolutePath(),
1723 _mainpanel.getControlPanel().showWhole();
1724 if ( nhx_or_nexus && one_desc ) {
1726 .showMessageDialog( this,
1727 "One or more trees contain (a) node(s) with one descendant, "
1728 + ForesterUtil.LINE_SEPARATOR
1729 + "possibly indicating illegal parentheses within node names.",
1730 "Warning: Possible Error in New Hampshire Formatted Data",
1731 JOptionPane.WARNING_MESSAGE );
1737 activateSaveAllIfNeeded();
1741 public void readSeqsFromFile() {
1742 // Set an initial directory if none set yet
1743 final File my_dir = getCurrentDir();
1744 _seqs_filechooser.setMultiSelectionEnabled( false );
1745 // Open file-open dialog and set current directory
1746 if ( my_dir != null ) {
1747 _seqs_filechooser.setCurrentDirectory( my_dir );
1749 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1750 // All done: get the seqs
1751 final File file = _seqs_filechooser.getSelectedFile();
1752 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1753 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1754 setSeqsFile( null );
1756 List<Sequence> seqs = null;
1758 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1759 seqs = FastaParser.parse( new FileInputStream( file ) );
1760 for( final Sequence seq : seqs ) {
1761 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1768 catch ( final MsaFormatException e ) {
1770 _mainpanel.getCurrentTreePanel().setArrowCursor();
1772 catch ( final Exception ex ) {
1775 JOptionPane.showMessageDialog( this,
1776 e.getLocalizedMessage(),
1777 "Multiple sequence file format error",
1778 JOptionPane.ERROR_MESSAGE );
1781 catch ( final IOException e ) {
1783 _mainpanel.getCurrentTreePanel().setArrowCursor();
1785 catch ( final Exception ex ) {
1788 JOptionPane.showMessageDialog( this,
1789 e.getLocalizedMessage(),
1790 "Failed to read multiple sequence file",
1791 JOptionPane.ERROR_MESSAGE );
1794 catch ( final IllegalArgumentException e ) {
1796 _mainpanel.getCurrentTreePanel().setArrowCursor();
1798 catch ( final Exception ex ) {
1801 JOptionPane.showMessageDialog( this,
1802 e.getLocalizedMessage(),
1803 "Unexpected error during reading of multiple sequence file",
1804 JOptionPane.ERROR_MESSAGE );
1807 catch ( final Exception e ) {
1809 _mainpanel.getCurrentTreePanel().setArrowCursor();
1811 catch ( final Exception ex ) {
1814 e.printStackTrace();
1815 JOptionPane.showMessageDialog( this,
1816 e.getLocalizedMessage(),
1817 "Unexpected error during reading of multiple sequence file",
1818 JOptionPane.ERROR_MESSAGE );
1821 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1822 JOptionPane.showMessageDialog( this,
1823 "Multiple sequence file is empty",
1824 "Illegal multiple sequence file",
1825 JOptionPane.ERROR_MESSAGE );
1828 if ( seqs.size() < 4 ) {
1829 JOptionPane.showMessageDialog( this,
1830 "Multiple sequence file needs to contain at least 3 sequences",
1831 "Illegal multiple sequence file",
1832 JOptionPane.ERROR_MESSAGE );
1835 // if ( msa.getLength() < 2 ) {
1836 // JOptionPane.showMessageDialog( this,
1837 // "Multiple sequence alignment needs to contain at least 2 residues",
1838 // "Illegal multiple sequence file",
1839 // JOptionPane.ERROR_MESSAGE );
1843 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1848 public void readMsaFromFile() {
1849 // Set an initial directory if none set yet
1850 final File my_dir = getCurrentDir();
1851 _msa_filechooser.setMultiSelectionEnabled( false );
1852 // Open file-open dialog and set current directory
1853 if ( my_dir != null ) {
1854 _msa_filechooser.setCurrentDirectory( my_dir );
1856 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1857 // All done: get the msa
1858 final File file = _msa_filechooser.getSelectedFile();
1859 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1860 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1865 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1866 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1867 System.out.println( msa.toString() );
1870 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1873 catch ( final MsaFormatException e ) {
1875 _mainpanel.getCurrentTreePanel().setArrowCursor();
1877 catch ( final Exception ex ) {
1880 JOptionPane.showMessageDialog( this,
1881 e.getLocalizedMessage(),
1882 "Multiple sequence alignment format error",
1883 JOptionPane.ERROR_MESSAGE );
1886 catch ( final IOException e ) {
1888 _mainpanel.getCurrentTreePanel().setArrowCursor();
1890 catch ( final Exception ex ) {
1893 JOptionPane.showMessageDialog( this,
1894 e.getLocalizedMessage(),
1895 "Failed to read multiple sequence alignment",
1896 JOptionPane.ERROR_MESSAGE );
1899 catch ( final IllegalArgumentException e ) {
1901 _mainpanel.getCurrentTreePanel().setArrowCursor();
1903 catch ( final Exception ex ) {
1906 JOptionPane.showMessageDialog( this,
1907 e.getLocalizedMessage(),
1908 "Unexpected error during reading of multiple sequence alignment",
1909 JOptionPane.ERROR_MESSAGE );
1912 catch ( final Exception e ) {
1914 _mainpanel.getCurrentTreePanel().setArrowCursor();
1916 catch ( final Exception ex ) {
1919 e.printStackTrace();
1920 JOptionPane.showMessageDialog( this,
1921 e.getLocalizedMessage(),
1922 "Unexpected error during reading of multiple sequence alignment",
1923 JOptionPane.ERROR_MESSAGE );
1926 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1927 JOptionPane.showMessageDialog( this,
1928 "Multiple sequence alignment is empty",
1929 "Illegal Multiple Sequence Alignment",
1930 JOptionPane.ERROR_MESSAGE );
1933 if ( msa.getNumberOfSequences() < 4 ) {
1934 JOptionPane.showMessageDialog( this,
1935 "Multiple sequence alignment needs to contain at least 3 sequences",
1936 "Illegal multiple sequence alignment",
1937 JOptionPane.ERROR_MESSAGE );
1940 if ( msa.getLength() < 2 ) {
1941 JOptionPane.showMessageDialog( this,
1942 "Multiple sequence alignment needs to contain at least 2 residues",
1943 "Illegal multiple sequence alignment",
1944 JOptionPane.ERROR_MESSAGE );
1948 setMsaFile( _msa_filechooser.getSelectedFile() );
1954 void readPhylogeniesFromURL() {
1956 Phylogeny[] phys = null;
1957 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1958 final String url_string = JOptionPane.showInputDialog( this,
1960 "Use URL/webservice to obtain a phylogeny",
1961 JOptionPane.QUESTION_MESSAGE );
1962 boolean nhx_or_nexus = false;
1963 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1965 url = new URL( url_string );
1966 PhylogenyParser parser = null;
1967 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1968 parser = new TolParser();
1971 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
1972 .isValidatePhyloXmlAgainstSchema() );
1974 if ( parser instanceof NexusPhylogeniesParser ) {
1975 nhx_or_nexus = true;
1977 else if ( parser instanceof NHXParser ) {
1978 nhx_or_nexus = true;
1980 if ( _mainpanel.getCurrentTreePanel() != null ) {
1981 _mainpanel.getCurrentTreePanel().setWaitCursor();
1984 _mainpanel.setWaitCursor();
1986 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1987 phys = factory.create( url.openStream(), parser );
1989 catch ( final MalformedURLException e ) {
1990 JOptionPane.showMessageDialog( this,
1991 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1993 JOptionPane.ERROR_MESSAGE );
1995 catch ( final IOException e ) {
1996 JOptionPane.showMessageDialog( this,
1997 "Could not read from " + url + "\n"
1998 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1999 "Failed to read URL",
2000 JOptionPane.ERROR_MESSAGE );
2002 catch ( final Exception e ) {
2003 JOptionPane.showMessageDialog( this,
2004 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2005 "Unexpected Exception",
2006 JOptionPane.ERROR_MESSAGE );
2009 if ( _mainpanel.getCurrentTreePanel() != null ) {
2010 _mainpanel.getCurrentTreePanel().setArrowCursor();
2013 _mainpanel.setArrowCursor();
2016 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2017 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2018 for( final Phylogeny phy : phys ) {
2019 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2022 Util.addPhylogeniesToTabs( phys,
2023 new File( url.getFile() ).getName(),
2024 new File( url.getFile() ).toString(),
2027 _mainpanel.getControlPanel().showWhole();
2030 activateSaveAllIfNeeded();
2034 private void readSpeciesTreeFromFile() {
2036 boolean exception = false;
2037 final File my_dir = getCurrentDir();
2038 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2039 if ( my_dir != null ) {
2040 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2042 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2043 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2044 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2045 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2047 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2050 catch ( final Exception e ) {
2052 exceptionOccuredDuringOpenFile( e );
2055 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2057 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2060 catch ( final Exception e ) {
2062 exceptionOccuredDuringOpenFile( e );
2068 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2071 catch ( final Exception e ) {
2073 exceptionOccuredDuringOpenFile( e );
2076 if ( !exception && ( t != null ) && !t.isRooted() ) {
2079 JOptionPane.showMessageDialog( this,
2080 "Species tree is not rooted",
2081 "Species tree not loaded",
2082 JOptionPane.ERROR_MESSAGE );
2084 if ( !exception && ( t != null ) ) {
2085 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2086 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2087 final PhylogenyNode node = it.next();
2088 if ( !node.getNodeData().isHasTaxonomy() ) {
2092 .showMessageDialog( this,
2093 "Species tree contains external node(s) without taxonomy information",
2094 "Species tree not loaded",
2095 JOptionPane.ERROR_MESSAGE );
2099 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2102 JOptionPane.showMessageDialog( this,
2104 + node.getNodeData().getTaxonomy().asSimpleText()
2105 + "] is not unique in species tree",
2106 "Species tree not loaded",
2107 JOptionPane.ERROR_MESSAGE );
2111 tax_set.add( node.getNodeData().getTaxonomy() );
2116 if ( !exception && ( t != null ) ) {
2118 JOptionPane.showMessageDialog( this,
2119 "Species tree successfully loaded",
2120 "Species tree loaded",
2121 JOptionPane.INFORMATION_MESSAGE );
2123 _contentpane.repaint();
2128 private void setCurrentDir( final File current_dir ) {
2129 _current_dir = current_dir;
2132 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2133 _min_not_collapse = min_not_collapse;
2136 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2137 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2140 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2141 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2142 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2143 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2144 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2146 nhx.setTaxonomyExtraction( te );
2149 private void writeAllToFile() {
2150 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2153 final File my_dir = getCurrentDir();
2154 if ( my_dir != null ) {
2155 _save_filechooser.setCurrentDirectory( my_dir );
2157 _save_filechooser.setSelectedFile( new File( "" ) );
2158 final int result = _save_filechooser.showSaveDialog( _contentpane );
2159 final File file = _save_filechooser.getSelectedFile();
2160 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2161 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2162 if ( file.exists() ) {
2163 final int i = JOptionPane.showConfirmDialog( this,
2164 file + " already exists. Overwrite?",
2166 JOptionPane.OK_CANCEL_OPTION,
2167 JOptionPane.WARNING_MESSAGE );
2168 if ( i != JOptionPane.OK_OPTION ) {
2175 catch ( final Exception e ) {
2176 JOptionPane.showMessageDialog( this,
2177 "Failed to delete: " + file,
2179 JOptionPane.WARNING_MESSAGE );
2183 final int count = getMainPanel().getTabbedPane().getTabCount();
2184 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2185 for( int i = 0; i < count; ++i ) {
2186 trees.add( getMainPanel().getPhylogeny( i ) );
2187 getMainPanel().getTreePanels().get( i ).setEdited( false );
2189 final PhylogenyWriter writer = new PhylogenyWriter();
2191 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2193 catch ( final IOException e ) {
2194 JOptionPane.showMessageDialog( this,
2195 "Failed to write to: " + file,
2197 JOptionPane.WARNING_MESSAGE );
2202 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2204 final PhylogenyWriter writer = new PhylogenyWriter();
2205 writer.toNewHampshire( t, false, true, file );
2207 catch ( final Exception e ) {
2209 exceptionOccuredDuringSaveAs( e );
2214 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2216 final PhylogenyWriter writer = new PhylogenyWriter();
2217 writer.toNexus( file, t );
2219 catch ( final Exception e ) {
2221 exceptionOccuredDuringSaveAs( e );
2226 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2228 final PhylogenyWriter writer = new PhylogenyWriter();
2229 writer.toNewHampshireX( t, file );
2231 catch ( final Exception e ) {
2233 exceptionOccuredDuringSaveAs( e );
2238 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2240 final PhylogenyWriter writer = new PhylogenyWriter();
2241 writer.toPhyloXML( file, t, 0 );
2243 catch ( final Exception e ) {
2245 exceptionOccuredDuringSaveAs( e );
2250 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2251 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2252 _mainpanel.getCurrentTreePanel().getHeight(),
2254 String file_written_to = "";
2255 boolean error = false;
2257 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2258 _mainpanel.getCurrentTreePanel().getWidth(),
2259 _mainpanel.getCurrentTreePanel().getHeight(),
2260 _mainpanel.getCurrentTreePanel(),
2261 _mainpanel.getControlPanel(),
2265 catch ( final IOException e ) {
2267 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2270 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2271 JOptionPane.showMessageDialog( this,
2272 "Wrote image to: " + file_written_to,
2274 JOptionPane.INFORMATION_MESSAGE );
2277 JOptionPane.showMessageDialog( this,
2278 "There was an unknown problem when attempting to write to an image file: \""
2281 JOptionPane.ERROR_MESSAGE );
2284 _contentpane.repaint();
2287 private void writeToFile( final Phylogeny t ) {
2291 String initial_filename = null;
2292 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2294 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2296 catch ( final IOException e ) {
2297 initial_filename = null;
2300 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2301 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2304 _save_filechooser.setSelectedFile( new File( "" ) );
2306 final File my_dir = getCurrentDir();
2307 if ( my_dir != null ) {
2308 _save_filechooser.setCurrentDirectory( my_dir );
2310 final int result = _save_filechooser.showSaveDialog( _contentpane );
2311 final File file = _save_filechooser.getSelectedFile();
2312 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2313 boolean exception = false;
2314 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2315 if ( file.exists() ) {
2316 final int i = JOptionPane.showConfirmDialog( this,
2317 file + " already exists.\nOverwrite?",
2319 JOptionPane.OK_CANCEL_OPTION,
2320 JOptionPane.QUESTION_MESSAGE );
2321 if ( i != JOptionPane.OK_OPTION ) {
2325 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2327 ForesterUtil.copyFile( file, to );
2329 catch ( final Exception e ) {
2330 JOptionPane.showMessageDialog( this,
2331 "Failed to create backup copy " + to,
2332 "Failed to Create Backup Copy",
2333 JOptionPane.WARNING_MESSAGE );
2338 catch ( final Exception e ) {
2339 JOptionPane.showMessageDialog( this,
2340 "Failed to delete: " + file,
2342 JOptionPane.WARNING_MESSAGE );
2346 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2347 exception = writeAsNewHampshire( t, exception, file );
2349 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2350 exception = writeAsNHX( t, exception, file );
2352 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2353 exception = writeAsPhyloXml( t, exception, file );
2355 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2356 exception = writeAsNexus( t, exception, file );
2360 final String file_name = file.getName().trim().toLowerCase();
2361 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2362 || file_name.endsWith( ".tree" ) ) {
2363 exception = writeAsNewHampshire( t, exception, file );
2365 else if ( file_name.endsWith( ".nhx" ) ) {
2366 exception = writeAsNHX( t, exception, file );
2368 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2369 exception = writeAsNexus( t, exception, file );
2373 exception = writeAsPhyloXml( t, exception, file );
2377 getMainPanel().setTitleOfSelectedTab( file.getName() );
2378 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2379 getMainPanel().getCurrentTreePanel().setEdited( false );
2384 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2385 if ( ( t == null ) || t.isEmpty() ) {
2388 String initial_filename = "";
2389 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2390 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2392 if ( initial_filename.indexOf( '.' ) > 0 ) {
2393 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2395 initial_filename = initial_filename + "." + type;
2396 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2397 final File my_dir = getCurrentDir();
2398 if ( my_dir != null ) {
2399 _writetographics_filechooser.setCurrentDirectory( my_dir );
2401 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2402 File file = _writetographics_filechooser.getSelectedFile();
2403 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2404 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2405 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2406 file = new File( file.toString() + "." + type );
2408 if ( file.exists() ) {
2409 final int i = JOptionPane.showConfirmDialog( this,
2410 file + " already exists. Overwrite?",
2412 JOptionPane.OK_CANCEL_OPTION,
2413 JOptionPane.WARNING_MESSAGE );
2414 if ( i != JOptionPane.OK_OPTION ) {
2421 catch ( final Exception e ) {
2422 JOptionPane.showMessageDialog( this,
2423 "Failed to delete: " + file,
2425 JOptionPane.WARNING_MESSAGE );
2429 writePhylogenyToGraphicsFile( file.toString(), type );
2433 private void writeToPdf( final Phylogeny t ) {
2434 if ( ( t == null ) || t.isEmpty() ) {
2437 String initial_filename = "";
2438 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2439 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2441 if ( initial_filename.indexOf( '.' ) > 0 ) {
2442 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2444 initial_filename = initial_filename + ".pdf";
2445 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2446 final File my_dir = getCurrentDir();
2447 if ( my_dir != null ) {
2448 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2450 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2451 File file = _writetopdf_filechooser.getSelectedFile();
2452 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2453 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2454 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2455 file = new File( file.toString() + ".pdf" );
2457 if ( file.exists() ) {
2458 final int i = JOptionPane.showConfirmDialog( this,
2459 file + " already exists. Overwrite?",
2461 JOptionPane.OK_CANCEL_OPTION,
2462 JOptionPane.WARNING_MESSAGE );
2463 if ( i != JOptionPane.OK_OPTION ) {
2467 printPhylogenyToPdf( file.toString() );
2471 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2472 return new MainFrameApplication( phys, config, title );
2475 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2476 return new MainFrameApplication( phys, config_file_name, title );
2479 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2480 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2481 + o.getPrintSizeY() + ")" );
2484 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2485 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2488 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2489 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2491 .showMessageDialog( null,
2493 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2496 JOptionPane.WARNING_MESSAGE );
2500 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2501 _phylogenetic_inference_options = phylogenetic_inference_options;
2504 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2505 if ( _phylogenetic_inference_options == null ) {
2506 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2508 return _phylogenetic_inference_options;
2511 public Msa getMsa() {
2515 void setMsa( final Msa msa ) {
2519 void setMsaFile( final File msa_file ) {
2520 _msa_file = msa_file;
2523 public File getMsaFile() {
2527 public List<Sequence> getSeqs() {
2531 void setSeqs( final List<Sequence> seqs ) {
2535 void setSeqsFile( final File seqs_file ) {
2536 _seqs_file = seqs_file;
2539 public File getSeqsFile() {
2542 } // MainFrameApplication.
2544 class NexusFilter extends FileFilter {
2547 public boolean accept( final File f ) {
2548 final String file_name = f.getName().trim().toLowerCase();
2549 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2550 || file_name.endsWith( ".tre" ) || f.isDirectory();
2554 public String getDescription() {
2555 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2559 class NHFilter extends FileFilter {
2562 public boolean accept( final File f ) {
2563 final String file_name = f.getName().trim().toLowerCase();
2564 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2565 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2566 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2571 public String getDescription() {
2572 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2576 class NHXFilter extends FileFilter {
2579 public boolean accept( final File f ) {
2580 final String file_name = f.getName().trim().toLowerCase();
2581 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2585 public String getDescription() {
2586 return "NHX files (*.nhx)";
2590 class PdfFilter extends FileFilter {
2593 public boolean accept( final File f ) {
2594 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2598 public String getDescription() {
2599 return "PDF files (*.pdf)";
2603 class TolFilter extends FileFilter {
2606 public boolean accept( final File f ) {
2607 final String file_name = f.getName().trim().toLowerCase();
2608 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2609 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2613 public String getDescription() {
2614 return "Tree of Life files (*.tol, *.tolxml)";
2618 class XMLFilter extends FileFilter {
2621 public boolean accept( final File f ) {
2622 final String file_name = f.getName().trim().toLowerCase();
2623 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2624 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2628 public String getDescription() {
2629 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";