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 );
715 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
717 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
718 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
719 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
720 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
722 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
724 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
725 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
726 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
727 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
728 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
729 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
730 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
731 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
732 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
733 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
734 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
736 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
737 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
738 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
739 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
740 _options_jmenu.addSeparator();
741 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
742 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
743 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
744 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
745 _options_jmenu.addSeparator();
746 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
747 getConfiguration() ) );
748 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
749 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
751 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
753 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
755 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
756 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
757 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
758 _options_jmenu.addSeparator();
760 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
762 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
763 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
765 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
766 customizeJMenuItem( _choose_font_mi );
767 customizeJMenuItem( _choose_minimal_confidence_mi );
768 customizeJMenuItem( _switch_colors_mi );
769 customizeJMenuItem( _print_size_mi );
770 customizeJMenuItem( _choose_pdf_width_mi );
771 customizeJMenuItem( _overview_placment_mi );
773 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
774 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
775 customizeJMenuItem( _cycle_node_shape_mi );
776 customizeJMenuItem( _cycle_node_fill_mi );
777 customizeJMenuItem( _choose_node_size_mi );
779 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
780 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
781 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
782 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
783 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
784 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
785 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
786 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
787 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
788 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
789 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
790 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
791 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
792 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
793 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
794 customizeCheckBoxMenuItem( _label_direction_cbmi,
795 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
796 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
797 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
798 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
799 .isInternalNumberAreConfidenceForNhParsing() );
800 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
801 .isExtractPfamTaxonomyCodesInNhParsing() );
802 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
803 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
804 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
805 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
806 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
807 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
808 .isGraphicsExportUsingActualSize() );
809 _jmenubar.add( _options_jmenu );
812 void buildToolsMenu() {
813 _tools_menu = createMenu( "Tools", getConfiguration() );
814 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
815 customizeJMenuItem( _confcolor_item );
816 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
817 customizeJMenuItem( _taxcolor_item );
818 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
819 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
820 customizeJMenuItem( _remove_branch_color_item );
821 _tools_menu.addSeparator();
822 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
823 customizeJMenuItem( _midpoint_root_item );
824 _tools_menu.addSeparator();
825 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
826 customizeJMenuItem( _collapse_species_specific_subtrees );
828 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
829 customizeJMenuItem( _collapse_below_threshold );
830 _collapse_below_threshold
831 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
832 _tools_menu.addSeparator();
834 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
835 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
836 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
837 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
838 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
839 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
841 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
842 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
843 _extract_tax_code_from_node_names_jmi
844 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
845 _tools_menu.addSeparator();
847 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
848 customizeJMenuItem( _infer_common_sn_names_item );
849 _tools_menu.addSeparator();
851 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
852 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
853 _obtain_detailed_taxonomic_information_jmi
854 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
856 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
857 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
858 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
859 _tools_menu.addSeparator();
860 if ( !Constants.__RELEASE ) {
861 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
862 customizeJMenuItem( _function_analysis );
864 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
865 _tools_menu.addSeparator();
867 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
868 customizeJMenuItem( _read_values_jmi );
869 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
870 _jmenubar.add( _tools_menu );
873 private void choosePdfWidth() {
874 final String s = ( String ) JOptionPane.showInputDialog( this,
875 "Please enter the default line width for PDF export.\n"
877 + getOptions().getPrintLineWidth() + "]\n",
878 "Line Width for PDF Export",
879 JOptionPane.QUESTION_MESSAGE,
882 getOptions().getPrintLineWidth() );
883 if ( !ForesterUtil.isEmpty( s ) ) {
884 boolean success = true;
886 final String m_str = s.trim();
887 if ( !ForesterUtil.isEmpty( m_str ) ) {
889 f = Float.parseFloat( m_str );
891 catch ( final Exception ex ) {
898 if ( success && ( f > 0.0 ) ) {
899 getOptions().setPrintLineWidth( f );
904 private void choosePrintSize() {
905 final String s = ( String ) JOptionPane.showInputDialog( this,
906 "Please enter values for width and height,\nseparated by a comma.\n"
907 + "[current values: "
908 + getOptions().getPrintSizeX() + ", "
909 + getOptions().getPrintSizeY() + "]\n"
910 + "[A4: " + Constants.A4_SIZE_X + ", "
911 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
912 + Constants.US_LETTER_SIZE_X + ", "
913 + Constants.US_LETTER_SIZE_Y + "]",
914 "Default Size for Graphics Export",
915 JOptionPane.QUESTION_MESSAGE,
918 getOptions().getPrintSizeX() + ", "
919 + getOptions().getPrintSizeY() );
920 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
921 boolean success = true;
924 final String[] str_ary = s.split( "," );
925 if ( str_ary.length == 2 ) {
926 final String x_str = str_ary[ 0 ].trim();
927 final String y_str = str_ary[ 1 ].trim();
928 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
930 x = Integer.parseInt( x_str );
931 y = Integer.parseInt( y_str );
933 catch ( final Exception ex ) {
944 if ( success && ( x > 1 ) && ( y > 1 ) ) {
945 getOptions().setPrintSizeX( x );
946 getOptions().setPrintSizeY( y );
953 if ( isUnsavedDataPresent() ) {
954 final int r = JOptionPane.showConfirmDialog( this,
955 "Exit despite potentially unsaved changes?",
957 JOptionPane.YES_NO_OPTION );
958 if ( r != JOptionPane.YES_OPTION ) {
965 private void closeCurrentPane() {
966 if ( getMainPanel().getCurrentTreePanel() != null ) {
967 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
968 final int r = JOptionPane.showConfirmDialog( this,
969 "Close tab despite potentially unsaved changes?",
971 JOptionPane.YES_NO_OPTION );
972 if ( r != JOptionPane.YES_OPTION ) {
976 getMainPanel().closeCurrentPane();
977 activateSaveAllIfNeeded();
981 private void collapse( final Phylogeny phy, final double m ) {
982 final PhylogenyNodeIterator it = phy.iteratorPostorder();
983 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
984 double min_support = Double.MAX_VALUE;
985 boolean conf_present = false;
986 while ( it.hasNext() ) {
987 final PhylogenyNode n = it.next();
988 if ( !n.isExternal() && !n.isRoot() ) {
989 final List<Confidence> c = n.getBranchData().getConfidences();
990 if ( ( c != null ) && ( c.size() > 0 ) ) {
993 for( final Confidence confidence : c ) {
994 if ( confidence.getValue() > max ) {
995 max = confidence.getValue();
998 if ( max < getMinNotCollapseConfidenceValue() ) {
999 to_be_removed.add( n );
1001 if ( max < min_support ) {
1007 if ( conf_present ) {
1008 for( final PhylogenyNode node : to_be_removed ) {
1009 PhylogenyMethods.removeNode( node, phy );
1011 if ( to_be_removed.size() > 0 ) {
1012 phy.externalNodesHaveChanged();
1014 phy.recalculateNumberOfExternalDescendants( true );
1015 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1016 getCurrentTreePanel().setEdited( true );
1017 getCurrentTreePanel().repaint();
1019 if ( to_be_removed.size() > 0 ) {
1020 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1021 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1022 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1025 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1026 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1030 JOptionPane.showMessageDialog( this,
1031 "No branch collapsed because no confidence values present",
1032 "No confidence values present",
1033 JOptionPane.INFORMATION_MESSAGE );
1037 private void collapseBelowThreshold() {
1038 if ( getCurrentTreePanel() != null ) {
1039 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1040 if ( ( phy != null ) && !phy.isEmpty() ) {
1041 final String s = ( String ) JOptionPane.showInputDialog( this,
1042 "Please enter the minimum confidence value\n",
1043 "Minimal Confidence Value",
1044 JOptionPane.QUESTION_MESSAGE,
1047 getMinNotCollapseConfidenceValue() );
1048 if ( !ForesterUtil.isEmpty( s ) ) {
1049 boolean success = true;
1051 final String m_str = s.trim();
1052 if ( !ForesterUtil.isEmpty( m_str ) ) {
1054 m = Double.parseDouble( m_str );
1056 catch ( final Exception ex ) {
1063 if ( success && ( m >= 0.0 ) ) {
1064 setMinNotCollapseConfidenceValue( m );
1072 private PhyloXmlParser createPhyloXmlParser() {
1073 PhyloXmlParser xml_parser = null;
1074 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1076 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1078 catch ( final Exception e ) {
1079 JOptionPane.showMessageDialog( this,
1080 e.getLocalizedMessage(),
1081 "failed to create validating XML parser",
1082 JOptionPane.WARNING_MESSAGE );
1085 if ( xml_parser == null ) {
1086 xml_parser = new PhyloXmlParser();
1091 void executeGSDI() {
1092 if ( !isOKforSDI( false, true ) ) {
1095 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1096 JOptionPane.showMessageDialog( this,
1097 "Gene tree is not rooted.",
1098 "Cannot execute GSDI",
1099 JOptionPane.ERROR_MESSAGE );
1102 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1103 gene_tree.setAllNodesToNotCollapse();
1104 gene_tree.recalculateNumberOfExternalDescendants( false );
1106 int duplications = -1;
1108 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1109 duplications = gsdi.getDuplicationsSum();
1111 catch ( final Exception e ) {
1112 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1114 gene_tree.setRerootable( false );
1115 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1116 getControlPanel().setShowEvents( true );
1118 _mainpanel.getCurrentTreePanel().setEdited( true );
1119 JOptionPane.showMessageDialog( this,
1120 "Number of duplications: " + duplications,
1121 "GSDI successfully completed",
1122 JOptionPane.INFORMATION_MESSAGE );
1125 void executeFunctionAnalysis() {
1126 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1129 final GoAnnotation a = new GoAnnotation( this,
1130 _mainpanel.getCurrentTreePanel(),
1131 _mainpanel.getCurrentPhylogeny() );
1132 new Thread( a ).start();
1135 void executeLineageInference() {
1136 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1139 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1140 JOptionPane.showMessageDialog( this,
1141 "Phylogeny is not rooted.",
1142 "Cannot infer ancestral taxonomies",
1143 JOptionPane.ERROR_MESSAGE );
1146 final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1147 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1148 _mainpanel.getCurrentTreePanel(),
1150 new Thread( inferrer ).start();
1153 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1154 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1155 getPhylogeneticInferenceOptions(),
1156 from_unaligned_seqs );
1158 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1159 if ( !from_unaligned_seqs ) {
1160 if ( getMsa() != null ) {
1161 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1162 getPhylogeneticInferenceOptions()
1164 new Thread( inferrer ).start();
1167 JOptionPane.showMessageDialog( this,
1168 "No multiple sequence alignment selected",
1169 "Phylogenetic Inference Not Launched",
1170 JOptionPane.WARNING_MESSAGE );
1174 if ( getSeqs() != null ) {
1175 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1176 getPhylogeneticInferenceOptions()
1178 new Thread( inferrer ).start();
1181 JOptionPane.showMessageDialog( this,
1182 "No input sequences selected",
1183 "Phylogenetic Inference Not Launched",
1184 JOptionPane.WARNING_MESSAGE );
1191 if ( !isOKforSDI( true, true ) ) {
1194 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1195 JOptionPane.showMessageDialog( this,
1196 "Gene tree is not rooted",
1197 "Cannot execute SDI",
1198 JOptionPane.ERROR_MESSAGE );
1201 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1202 gene_tree.setAllNodesToNotCollapse();
1203 gene_tree.recalculateNumberOfExternalDescendants( false );
1205 int duplications = -1;
1207 sdi = new SDIse( gene_tree, _species_tree.copy() );
1208 duplications = sdi.getDuplicationsSum();
1210 catch ( final Exception e ) {
1211 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1213 gene_tree.setRerootable( false );
1214 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1215 getControlPanel().setShowEvents( true );
1217 _mainpanel.getCurrentTreePanel().setEdited( true );
1218 JOptionPane.showMessageDialog( this,
1219 "Number of duplications: " + duplications,
1220 "SDI successfully completed",
1221 JOptionPane.INFORMATION_MESSAGE );
1224 void executeSDIR( final boolean minimize_cost ) {
1225 if ( !isOKforSDI( true, true ) ) {
1228 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1229 final SDIR sdiunrooted = new SDIR();
1230 gene_tree.setAllNodesToNotCollapse();
1231 gene_tree.recalculateNumberOfExternalDescendants( false );
1233 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1234 !minimize_cost, // minimize sum of dups
1235 true, // minimize height
1236 true, // return tree(s)
1237 1 )[ 0 ]; // # of trees to return
1239 catch ( final Exception e ) {
1240 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1243 final int duplications = sdiunrooted.getMinimalDuplications();
1244 gene_tree.setRerootable( false );
1245 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1246 getControlPanel().setShowEvents( true );
1248 _mainpanel.getCurrentTreePanel().setEdited( true );
1249 JOptionPane.showMessageDialog( this,
1250 "Number of duplications: " + duplications,
1251 "SDIR successfully completed",
1252 JOptionPane.INFORMATION_MESSAGE );
1257 _mainpanel.terminate();
1258 _contentpane.removeAll();
1259 setVisible( false );
1264 private void extractTaxCodeFromNodeNames() {
1265 if ( getCurrentTreePanel() != null ) {
1266 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1267 if ( ( phy != null ) && !phy.isEmpty() ) {
1268 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1269 while ( it.hasNext() ) {
1270 final PhylogenyNode n = it.next();
1271 final String name = n.getName().trim();
1272 if ( !ForesterUtil.isEmpty( name ) ) {
1273 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1275 TAXONOMY_EXTRACTION.YES );
1276 if ( !ForesterUtil.isEmpty( code ) ) {
1277 PhylogenyMethods.setTaxonomyCode( n, code );
1285 private ControlPanel getControlPanel() {
1286 return getMainPanel().getControlPanel();
1289 private File getCurrentDir() {
1290 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1291 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1293 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1295 catch ( final Exception e ) {
1296 _current_dir = null;
1300 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1301 if ( System.getProperty( "user.home" ) != null ) {
1302 _current_dir = new File( System.getProperty( "user.home" ) );
1304 else if ( System.getProperty( "user.dir" ) != null ) {
1305 _current_dir = new File( System.getProperty( "user.dir" ) );
1308 return _current_dir;
1312 public MainPanel getMainPanel() {
1316 private double getMinNotCollapseConfidenceValue() {
1317 return _min_not_collapse;
1320 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1321 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1324 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1325 JOptionPane.showMessageDialog( this,
1326 "No species tree loaded",
1327 "Cannot execute SDI",
1328 JOptionPane.ERROR_MESSAGE );
1331 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1332 JOptionPane.showMessageDialog( this,
1333 "Species tree is not completely binary",
1334 "Cannot execute SDI",
1335 JOptionPane.ERROR_MESSAGE );
1338 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1339 JOptionPane.showMessageDialog( this,
1340 "Gene tree is not completely binary",
1341 "Cannot execute SDI",
1342 JOptionPane.ERROR_MESSAGE );
1350 private boolean isUnsavedDataPresent() {
1351 final List<TreePanel> tps = getMainPanel().getTreePanels();
1352 for( final TreePanel tp : tps ) {
1353 if ( tp.isEdited() ) {
1360 private void moveNodeNamesToSeqNames() {
1361 if ( getCurrentTreePanel() != null ) {
1362 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1363 if ( ( phy != null ) && !phy.isEmpty() ) {
1364 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1369 private void moveNodeNamesToTaxSn() {
1370 if ( getCurrentTreePanel() != null ) {
1371 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1372 if ( ( phy != null ) && !phy.isEmpty() ) {
1373 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1378 private void newTree() {
1379 final Phylogeny[] phys = new Phylogeny[ 1 ];
1380 final Phylogeny phy = new Phylogeny();
1381 final PhylogenyNode node = new PhylogenyNode();
1382 phy.setRoot( node );
1383 phy.setRooted( true );
1385 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1386 _mainpanel.getControlPanel().showWhole();
1387 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1388 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1389 if ( getMainPanel().getMainFrame() == null ) {
1390 // Must be "E" applet version.
1391 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1392 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1395 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1397 activateSaveAllIfNeeded();
1401 private void obtainDetailedTaxonomicInformation() {
1402 if ( getCurrentTreePanel() != null ) {
1403 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1404 if ( ( phy != null ) && !phy.isEmpty() ) {
1405 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1406 _mainpanel.getCurrentTreePanel(),
1408 new Thread( t ).start();
1413 private void obtainUniProtSequenceInformation() {
1414 if ( getCurrentTreePanel() != null ) {
1415 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1416 if ( ( phy != null ) && !phy.isEmpty() ) {
1417 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1418 _mainpanel.getCurrentTreePanel(),
1420 new Thread( u ).start();
1425 private void print() {
1426 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1427 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1430 if ( !getOptions().isPrintUsingActualSize() ) {
1431 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1432 getOptions().getPrintSizeY() - 140,
1434 getCurrentTreePanel().resetPreferredSize();
1435 getCurrentTreePanel().repaint();
1437 final String job_name = Constants.PRG_NAME;
1438 boolean error = false;
1439 String printer_name = null;
1441 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1443 catch ( final Exception e ) {
1445 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1447 if ( !error && ( printer_name != null ) ) {
1448 String msg = "Printing data sent to printer";
1449 if ( printer_name.length() > 1 ) {
1450 msg += " [" + printer_name + "]";
1452 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1454 if ( !getOptions().isPrintUsingActualSize() ) {
1455 getControlPanel().showWhole();
1459 private void printPhylogenyToPdf( final String file_name ) {
1460 if ( !getOptions().isPrintUsingActualSize() ) {
1461 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1462 getOptions().getPrintSizeY(),
1464 getCurrentTreePanel().resetPreferredSize();
1465 getCurrentTreePanel().repaint();
1467 String pdf_written_to = "";
1468 boolean error = false;
1470 if ( getOptions().isPrintUsingActualSize() ) {
1471 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1472 getCurrentTreePanel(),
1473 getCurrentTreePanel().getWidth(),
1474 getCurrentTreePanel().getHeight() );
1477 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1478 .getPrintSizeX(), getOptions().getPrintSizeY() );
1481 catch ( final IOException e ) {
1483 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1486 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1487 JOptionPane.showMessageDialog( this,
1488 "Wrote PDF to: " + pdf_written_to,
1490 JOptionPane.INFORMATION_MESSAGE );
1493 JOptionPane.showMessageDialog( this,
1494 "There was an unknown problem when attempting to write to PDF file: \""
1497 JOptionPane.ERROR_MESSAGE );
1500 if ( !getOptions().isPrintUsingActualSize() ) {
1501 getControlPanel().showWhole();
1505 private void addExpressionValuesFromFile() {
1506 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1507 JOptionPane.showMessageDialog( this,
1508 "Need to load evolutionary tree first",
1509 "Can Not Read Expression Values",
1510 JOptionPane.WARNING_MESSAGE );
1513 final File my_dir = getCurrentDir();
1514 if ( my_dir != null ) {
1515 _values_filechooser.setCurrentDirectory( my_dir );
1517 final int result = _values_filechooser.showOpenDialog( _contentpane );
1518 final File file = _values_filechooser.getSelectedFile();
1519 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1520 BasicTable<String> t = null;
1522 t = BasicTableParser.parse( file, "\t" );
1523 if ( t.getNumberOfColumns() < 2 ) {
1524 t = BasicTableParser.parse( file, "," );
1526 if ( t.getNumberOfColumns() < 2 ) {
1527 t = BasicTableParser.parse( file, " " );
1530 catch ( final IOException e ) {
1531 JOptionPane.showMessageDialog( this,
1533 "Could Not Read Expression Value Table",
1534 JOptionPane.ERROR_MESSAGE );
1537 if ( t.getNumberOfColumns() < 2 ) {
1538 JOptionPane.showMessageDialog( this,
1539 "Table contains " + t.getNumberOfColumns() + " column(s)",
1540 "Problem with Expression Value Table",
1541 JOptionPane.ERROR_MESSAGE );
1544 if ( t.getNumberOfRows() < 1 ) {
1545 JOptionPane.showMessageDialog( this,
1546 "Table contains zero rows",
1547 "Problem with Expression Value Table",
1548 JOptionPane.ERROR_MESSAGE );
1551 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1552 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1553 JOptionPane.showMessageDialog( this,
1554 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1555 + phy.getNumberOfExternalNodes() + " external nodes",
1557 JOptionPane.WARNING_MESSAGE );
1559 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1561 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1562 final PhylogenyNode node = iter.next();
1563 final String node_name = node.getName();
1564 if ( !ForesterUtil.isEmpty( node_name ) ) {
1567 row = t.findRow( node_name );
1569 catch ( final IllegalArgumentException e ) {
1571 .showMessageDialog( this,
1573 "Error Mapping Node Identifiers to Expression Value Identifiers",
1574 JOptionPane.ERROR_MESSAGE );
1578 if ( node.isExternal() ) {
1583 final List<Double> l = new ArrayList<Double>();
1584 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1587 d = Double.parseDouble( t.getValueAsString( col, row ) );
1589 catch ( final NumberFormatException e ) {
1590 JOptionPane.showMessageDialog( this,
1591 "Could not parse \"" + t.getValueAsString( col, row )
1592 + "\" into a decimal value",
1593 "Issue with Expression Value Table",
1594 JOptionPane.ERROR_MESSAGE );
1597 stats.addValue( d );
1600 if ( !l.isEmpty() ) {
1601 if ( node.getNodeData().getProperties() != null ) {
1602 node.getNodeData().getProperties()
1603 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1605 node.getNodeData().setVector( l );
1609 if ( not_found > 0 ) {
1610 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1611 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1613 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1617 private void readPhylogeniesFromFile() {
1618 boolean exception = false;
1619 Phylogeny[] phys = null;
1620 // Set an initial directory if none set yet
1621 final File my_dir = getCurrentDir();
1622 _open_filechooser.setMultiSelectionEnabled( true );
1623 // Open file-open dialog and set current directory
1624 if ( my_dir != null ) {
1625 _open_filechooser.setCurrentDirectory( my_dir );
1627 final int result = _open_filechooser.showOpenDialog( _contentpane );
1628 // All done: get the file
1629 final File[] files = _open_filechooser.getSelectedFiles();
1630 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1631 boolean nhx_or_nexus = false;
1632 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1633 for( final File file : files ) {
1634 if ( ( file != null ) && !file.isDirectory() ) {
1635 if ( _mainpanel.getCurrentTreePanel() != null ) {
1636 _mainpanel.getCurrentTreePanel().setWaitCursor();
1639 _mainpanel.setWaitCursor();
1641 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1642 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1644 final NHXParser nhx = new NHXParser();
1645 setSpecialOptionsForNhxParser( nhx );
1646 phys = ForesterUtil.readPhylogenies( nhx, file );
1647 nhx_or_nexus = true;
1649 catch ( final Exception e ) {
1651 exceptionOccuredDuringOpenFile( e );
1654 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1655 warnIfNotPhyloXmlValidation( getConfiguration() );
1657 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1658 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1660 catch ( final Exception e ) {
1662 exceptionOccuredDuringOpenFile( e );
1665 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1667 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1669 catch ( final Exception e ) {
1671 exceptionOccuredDuringOpenFile( e );
1674 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1676 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1677 setSpecialOptionsForNexParser( nex );
1678 phys = ForesterUtil.readPhylogenies( nex, file );
1679 nhx_or_nexus = true;
1681 catch ( final Exception e ) {
1683 exceptionOccuredDuringOpenFile( e );
1689 final PhylogenyParser parser = ForesterUtil
1690 .createParserDependingOnFileType( file, getConfiguration()
1691 .isValidatePhyloXmlAgainstSchema() );
1692 if ( parser instanceof NexusPhylogeniesParser ) {
1693 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1694 setSpecialOptionsForNexParser( nex );
1695 nhx_or_nexus = true;
1697 else if ( parser instanceof NHXParser ) {
1698 final NHXParser nhx = ( NHXParser ) parser;
1699 setSpecialOptionsForNhxParser( nhx );
1700 nhx_or_nexus = true;
1702 else if ( parser instanceof PhyloXmlParser ) {
1703 warnIfNotPhyloXmlValidation( getConfiguration() );
1705 phys = ForesterUtil.readPhylogenies( parser, file );
1707 catch ( final Exception e ) {
1709 exceptionOccuredDuringOpenFile( e );
1712 if ( _mainpanel.getCurrentTreePanel() != null ) {
1713 _mainpanel.getCurrentTreePanel().setArrowCursor();
1716 _mainpanel.setArrowCursor();
1718 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1719 boolean one_desc = false;
1720 if ( nhx_or_nexus ) {
1721 for( final Phylogeny phy : phys ) {
1722 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1723 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1725 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1731 Util.addPhylogeniesToTabs( phys,
1733 file.getAbsolutePath(),
1736 _mainpanel.getControlPanel().showWhole();
1737 if ( nhx_or_nexus && one_desc ) {
1739 .showMessageDialog( this,
1740 "One or more trees contain (a) node(s) with one descendant, "
1741 + ForesterUtil.LINE_SEPARATOR
1742 + "possibly indicating illegal parentheses within node names.",
1743 "Warning: Possible Error in New Hampshire Formatted Data",
1744 JOptionPane.WARNING_MESSAGE );
1750 activateSaveAllIfNeeded();
1754 public void readSeqsFromFile() {
1755 // Set an initial directory if none set yet
1756 final File my_dir = getCurrentDir();
1757 _seqs_filechooser.setMultiSelectionEnabled( false );
1758 // Open file-open dialog and set current directory
1759 if ( my_dir != null ) {
1760 _seqs_filechooser.setCurrentDirectory( my_dir );
1762 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1763 // All done: get the seqs
1764 final File file = _seqs_filechooser.getSelectedFile();
1765 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1766 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1767 setSeqsFile( null );
1769 List<Sequence> seqs = null;
1771 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1772 seqs = FastaParser.parse( new FileInputStream( file ) );
1773 for( final Sequence seq : seqs ) {
1774 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1781 catch ( final MsaFormatException e ) {
1783 _mainpanel.getCurrentTreePanel().setArrowCursor();
1785 catch ( final Exception ex ) {
1788 JOptionPane.showMessageDialog( this,
1789 e.getLocalizedMessage(),
1790 "Multiple sequence file format error",
1791 JOptionPane.ERROR_MESSAGE );
1794 catch ( final IOException e ) {
1796 _mainpanel.getCurrentTreePanel().setArrowCursor();
1798 catch ( final Exception ex ) {
1801 JOptionPane.showMessageDialog( this,
1802 e.getLocalizedMessage(),
1803 "Failed to read multiple sequence file",
1804 JOptionPane.ERROR_MESSAGE );
1807 catch ( final IllegalArgumentException e ) {
1809 _mainpanel.getCurrentTreePanel().setArrowCursor();
1811 catch ( final Exception ex ) {
1814 JOptionPane.showMessageDialog( this,
1815 e.getLocalizedMessage(),
1816 "Unexpected error during reading of multiple sequence file",
1817 JOptionPane.ERROR_MESSAGE );
1820 catch ( final Exception e ) {
1822 _mainpanel.getCurrentTreePanel().setArrowCursor();
1824 catch ( final Exception ex ) {
1827 e.printStackTrace();
1828 JOptionPane.showMessageDialog( this,
1829 e.getLocalizedMessage(),
1830 "Unexpected error during reading of multiple sequence file",
1831 JOptionPane.ERROR_MESSAGE );
1834 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1835 JOptionPane.showMessageDialog( this,
1836 "Multiple sequence file is empty",
1837 "Illegal multiple sequence file",
1838 JOptionPane.ERROR_MESSAGE );
1841 if ( seqs.size() < 4 ) {
1842 JOptionPane.showMessageDialog( this,
1843 "Multiple sequence file needs to contain at least 3 sequences",
1844 "Illegal multiple sequence file",
1845 JOptionPane.ERROR_MESSAGE );
1848 // if ( msa.getLength() < 2 ) {
1849 // JOptionPane.showMessageDialog( this,
1850 // "Multiple sequence alignment needs to contain at least 2 residues",
1851 // "Illegal multiple sequence file",
1852 // JOptionPane.ERROR_MESSAGE );
1856 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1861 public void readMsaFromFile() {
1862 // Set an initial directory if none set yet
1863 final File my_dir = getCurrentDir();
1864 _msa_filechooser.setMultiSelectionEnabled( false );
1865 // Open file-open dialog and set current directory
1866 if ( my_dir != null ) {
1867 _msa_filechooser.setCurrentDirectory( my_dir );
1869 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1870 // All done: get the msa
1871 final File file = _msa_filechooser.getSelectedFile();
1872 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1873 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1878 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1879 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1880 System.out.println( msa.toString() );
1883 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1886 catch ( final MsaFormatException e ) {
1888 _mainpanel.getCurrentTreePanel().setArrowCursor();
1890 catch ( final Exception ex ) {
1893 JOptionPane.showMessageDialog( this,
1894 e.getLocalizedMessage(),
1895 "Multiple sequence alignment format error",
1896 JOptionPane.ERROR_MESSAGE );
1899 catch ( final IOException e ) {
1901 _mainpanel.getCurrentTreePanel().setArrowCursor();
1903 catch ( final Exception ex ) {
1906 JOptionPane.showMessageDialog( this,
1907 e.getLocalizedMessage(),
1908 "Failed to read multiple sequence alignment",
1909 JOptionPane.ERROR_MESSAGE );
1912 catch ( final IllegalArgumentException e ) {
1914 _mainpanel.getCurrentTreePanel().setArrowCursor();
1916 catch ( final Exception ex ) {
1919 JOptionPane.showMessageDialog( this,
1920 e.getLocalizedMessage(),
1921 "Unexpected error during reading of multiple sequence alignment",
1922 JOptionPane.ERROR_MESSAGE );
1925 catch ( final Exception e ) {
1927 _mainpanel.getCurrentTreePanel().setArrowCursor();
1929 catch ( final Exception ex ) {
1932 e.printStackTrace();
1933 JOptionPane.showMessageDialog( this,
1934 e.getLocalizedMessage(),
1935 "Unexpected error during reading of multiple sequence alignment",
1936 JOptionPane.ERROR_MESSAGE );
1939 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1940 JOptionPane.showMessageDialog( this,
1941 "Multiple sequence alignment is empty",
1942 "Illegal Multiple Sequence Alignment",
1943 JOptionPane.ERROR_MESSAGE );
1946 if ( msa.getNumberOfSequences() < 4 ) {
1947 JOptionPane.showMessageDialog( this,
1948 "Multiple sequence alignment needs to contain at least 3 sequences",
1949 "Illegal multiple sequence alignment",
1950 JOptionPane.ERROR_MESSAGE );
1953 if ( msa.getLength() < 2 ) {
1954 JOptionPane.showMessageDialog( this,
1955 "Multiple sequence alignment needs to contain at least 2 residues",
1956 "Illegal multiple sequence alignment",
1957 JOptionPane.ERROR_MESSAGE );
1961 setMsaFile( _msa_filechooser.getSelectedFile() );
1967 void readPhylogeniesFromURL() {
1969 Phylogeny[] phys = null;
1970 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1971 final String url_string = JOptionPane.showInputDialog( this,
1973 "Use URL/webservice to obtain a phylogeny",
1974 JOptionPane.QUESTION_MESSAGE );
1975 boolean nhx_or_nexus = false;
1976 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1978 url = new URL( url_string );
1979 PhylogenyParser parser = null;
1980 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1981 parser = new TolParser();
1984 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
1985 .isValidatePhyloXmlAgainstSchema() );
1987 if ( parser instanceof NexusPhylogeniesParser ) {
1988 nhx_or_nexus = true;
1990 else if ( parser instanceof NHXParser ) {
1991 nhx_or_nexus = true;
1993 if ( _mainpanel.getCurrentTreePanel() != null ) {
1994 _mainpanel.getCurrentTreePanel().setWaitCursor();
1997 _mainpanel.setWaitCursor();
1999 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2000 phys = factory.create( url.openStream(), parser );
2002 catch ( final MalformedURLException e ) {
2003 JOptionPane.showMessageDialog( this,
2004 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2006 JOptionPane.ERROR_MESSAGE );
2008 catch ( final IOException e ) {
2009 JOptionPane.showMessageDialog( this,
2010 "Could not read from " + url + "\n"
2011 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2012 "Failed to read URL",
2013 JOptionPane.ERROR_MESSAGE );
2015 catch ( final Exception e ) {
2016 JOptionPane.showMessageDialog( this,
2017 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2018 "Unexpected Exception",
2019 JOptionPane.ERROR_MESSAGE );
2022 if ( _mainpanel.getCurrentTreePanel() != null ) {
2023 _mainpanel.getCurrentTreePanel().setArrowCursor();
2026 _mainpanel.setArrowCursor();
2029 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2030 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2031 for( final Phylogeny phy : phys ) {
2032 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2035 Util.addPhylogeniesToTabs( phys,
2036 new File( url.getFile() ).getName(),
2037 new File( url.getFile() ).toString(),
2040 _mainpanel.getControlPanel().showWhole();
2043 activateSaveAllIfNeeded();
2047 private void readSpeciesTreeFromFile() {
2049 boolean exception = false;
2050 final File my_dir = getCurrentDir();
2051 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2052 if ( my_dir != null ) {
2053 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2055 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2056 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2057 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2058 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2060 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2063 catch ( final Exception e ) {
2065 exceptionOccuredDuringOpenFile( e );
2068 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2070 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2073 catch ( final Exception e ) {
2075 exceptionOccuredDuringOpenFile( e );
2081 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2084 catch ( final Exception e ) {
2086 exceptionOccuredDuringOpenFile( e );
2089 if ( !exception && ( t != null ) && !t.isRooted() ) {
2092 JOptionPane.showMessageDialog( this,
2093 "Species tree is not rooted",
2094 "Species tree not loaded",
2095 JOptionPane.ERROR_MESSAGE );
2097 if ( !exception && ( t != null ) ) {
2098 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2099 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2100 final PhylogenyNode node = it.next();
2101 if ( !node.getNodeData().isHasTaxonomy() ) {
2105 .showMessageDialog( this,
2106 "Species tree contains external node(s) without taxonomy information",
2107 "Species tree not loaded",
2108 JOptionPane.ERROR_MESSAGE );
2112 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2115 JOptionPane.showMessageDialog( this,
2117 + node.getNodeData().getTaxonomy().asSimpleText()
2118 + "] is not unique in species tree",
2119 "Species tree not loaded",
2120 JOptionPane.ERROR_MESSAGE );
2124 tax_set.add( node.getNodeData().getTaxonomy() );
2129 if ( !exception && ( t != null ) ) {
2131 JOptionPane.showMessageDialog( this,
2132 "Species tree successfully loaded",
2133 "Species tree loaded",
2134 JOptionPane.INFORMATION_MESSAGE );
2136 _contentpane.repaint();
2141 private void setCurrentDir( final File current_dir ) {
2142 _current_dir = current_dir;
2145 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2146 _min_not_collapse = min_not_collapse;
2149 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2150 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2153 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2154 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2155 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2156 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2157 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2159 nhx.setTaxonomyExtraction( te );
2162 private void writeAllToFile() {
2163 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2166 final File my_dir = getCurrentDir();
2167 if ( my_dir != null ) {
2168 _save_filechooser.setCurrentDirectory( my_dir );
2170 _save_filechooser.setSelectedFile( new File( "" ) );
2171 final int result = _save_filechooser.showSaveDialog( _contentpane );
2172 final File file = _save_filechooser.getSelectedFile();
2173 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2174 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2175 if ( file.exists() ) {
2176 final int i = JOptionPane.showConfirmDialog( this,
2177 file + " already exists. Overwrite?",
2179 JOptionPane.OK_CANCEL_OPTION,
2180 JOptionPane.WARNING_MESSAGE );
2181 if ( i != JOptionPane.OK_OPTION ) {
2188 catch ( final Exception e ) {
2189 JOptionPane.showMessageDialog( this,
2190 "Failed to delete: " + file,
2192 JOptionPane.WARNING_MESSAGE );
2196 final int count = getMainPanel().getTabbedPane().getTabCount();
2197 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2198 for( int i = 0; i < count; ++i ) {
2199 trees.add( getMainPanel().getPhylogeny( i ) );
2200 getMainPanel().getTreePanels().get( i ).setEdited( false );
2202 final PhylogenyWriter writer = new PhylogenyWriter();
2204 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2206 catch ( final IOException e ) {
2207 JOptionPane.showMessageDialog( this,
2208 "Failed to write to: " + file,
2210 JOptionPane.WARNING_MESSAGE );
2215 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2217 final PhylogenyWriter writer = new PhylogenyWriter();
2218 writer.toNewHampshire( t, false, true, file );
2220 catch ( final Exception e ) {
2222 exceptionOccuredDuringSaveAs( e );
2227 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2229 final PhylogenyWriter writer = new PhylogenyWriter();
2230 writer.toNexus( file, t );
2232 catch ( final Exception e ) {
2234 exceptionOccuredDuringSaveAs( e );
2239 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2241 final PhylogenyWriter writer = new PhylogenyWriter();
2242 writer.toNewHampshireX( t, file );
2244 catch ( final Exception e ) {
2246 exceptionOccuredDuringSaveAs( e );
2251 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2253 final PhylogenyWriter writer = new PhylogenyWriter();
2254 writer.toPhyloXML( file, t, 0 );
2256 catch ( final Exception e ) {
2258 exceptionOccuredDuringSaveAs( e );
2263 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2264 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2265 _mainpanel.getCurrentTreePanel().getHeight(),
2267 String file_written_to = "";
2268 boolean error = false;
2270 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2271 _mainpanel.getCurrentTreePanel().getWidth(),
2272 _mainpanel.getCurrentTreePanel().getHeight(),
2273 _mainpanel.getCurrentTreePanel(),
2274 _mainpanel.getControlPanel(),
2278 catch ( final IOException e ) {
2280 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2283 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2284 JOptionPane.showMessageDialog( this,
2285 "Wrote image to: " + file_written_to,
2287 JOptionPane.INFORMATION_MESSAGE );
2290 JOptionPane.showMessageDialog( this,
2291 "There was an unknown problem when attempting to write to an image file: \""
2294 JOptionPane.ERROR_MESSAGE );
2297 _contentpane.repaint();
2300 private void writeToFile( final Phylogeny t ) {
2304 String initial_filename = null;
2305 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2307 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2309 catch ( final IOException e ) {
2310 initial_filename = null;
2313 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2314 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2317 _save_filechooser.setSelectedFile( new File( "" ) );
2319 final File my_dir = getCurrentDir();
2320 if ( my_dir != null ) {
2321 _save_filechooser.setCurrentDirectory( my_dir );
2323 final int result = _save_filechooser.showSaveDialog( _contentpane );
2324 final File file = _save_filechooser.getSelectedFile();
2325 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2326 boolean exception = false;
2327 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2328 if ( file.exists() ) {
2329 final int i = JOptionPane.showConfirmDialog( this,
2330 file + " already exists.\nOverwrite?",
2332 JOptionPane.OK_CANCEL_OPTION,
2333 JOptionPane.QUESTION_MESSAGE );
2334 if ( i != JOptionPane.OK_OPTION ) {
2338 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2340 ForesterUtil.copyFile( file, to );
2342 catch ( final Exception e ) {
2343 JOptionPane.showMessageDialog( this,
2344 "Failed to create backup copy " + to,
2345 "Failed to Create Backup Copy",
2346 JOptionPane.WARNING_MESSAGE );
2351 catch ( final Exception e ) {
2352 JOptionPane.showMessageDialog( this,
2353 "Failed to delete: " + file,
2355 JOptionPane.WARNING_MESSAGE );
2359 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2360 exception = writeAsNewHampshire( t, exception, file );
2362 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2363 exception = writeAsNHX( t, exception, file );
2365 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2366 exception = writeAsPhyloXml( t, exception, file );
2368 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2369 exception = writeAsNexus( t, exception, file );
2373 final String file_name = file.getName().trim().toLowerCase();
2374 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2375 || file_name.endsWith( ".tree" ) ) {
2376 exception = writeAsNewHampshire( t, exception, file );
2378 else if ( file_name.endsWith( ".nhx" ) ) {
2379 exception = writeAsNHX( t, exception, file );
2381 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2382 exception = writeAsNexus( t, exception, file );
2386 exception = writeAsPhyloXml( t, exception, file );
2390 getMainPanel().setTitleOfSelectedTab( file.getName() );
2391 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2392 getMainPanel().getCurrentTreePanel().setEdited( false );
2397 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2398 if ( ( t == null ) || t.isEmpty() ) {
2401 String initial_filename = "";
2402 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2403 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2405 if ( initial_filename.indexOf( '.' ) > 0 ) {
2406 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2408 initial_filename = initial_filename + "." + type;
2409 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2410 final File my_dir = getCurrentDir();
2411 if ( my_dir != null ) {
2412 _writetographics_filechooser.setCurrentDirectory( my_dir );
2414 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2415 File file = _writetographics_filechooser.getSelectedFile();
2416 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2417 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2418 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2419 file = new File( file.toString() + "." + type );
2421 if ( file.exists() ) {
2422 final int i = JOptionPane.showConfirmDialog( this,
2423 file + " already exists. Overwrite?",
2425 JOptionPane.OK_CANCEL_OPTION,
2426 JOptionPane.WARNING_MESSAGE );
2427 if ( i != JOptionPane.OK_OPTION ) {
2434 catch ( final Exception e ) {
2435 JOptionPane.showMessageDialog( this,
2436 "Failed to delete: " + file,
2438 JOptionPane.WARNING_MESSAGE );
2442 writePhylogenyToGraphicsFile( file.toString(), type );
2446 private void writeToPdf( final Phylogeny t ) {
2447 if ( ( t == null ) || t.isEmpty() ) {
2450 String initial_filename = "";
2451 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2452 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2454 if ( initial_filename.indexOf( '.' ) > 0 ) {
2455 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2457 initial_filename = initial_filename + ".pdf";
2458 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2459 final File my_dir = getCurrentDir();
2460 if ( my_dir != null ) {
2461 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2463 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2464 File file = _writetopdf_filechooser.getSelectedFile();
2465 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2466 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2467 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2468 file = new File( file.toString() + ".pdf" );
2470 if ( file.exists() ) {
2471 final int i = JOptionPane.showConfirmDialog( this,
2472 file + " already exists. Overwrite?",
2474 JOptionPane.OK_CANCEL_OPTION,
2475 JOptionPane.WARNING_MESSAGE );
2476 if ( i != JOptionPane.OK_OPTION ) {
2480 printPhylogenyToPdf( file.toString() );
2484 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2485 return new MainFrameApplication( phys, config, title );
2488 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2489 return new MainFrameApplication( phys, config_file_name, title );
2492 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2493 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2494 + o.getPrintSizeY() + ")" );
2497 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2498 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2501 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2502 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2504 .showMessageDialog( null,
2506 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2509 JOptionPane.WARNING_MESSAGE );
2513 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2514 _phylogenetic_inference_options = phylogenetic_inference_options;
2517 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2518 if ( _phylogenetic_inference_options == null ) {
2519 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2521 return _phylogenetic_inference_options;
2524 public Msa getMsa() {
2528 void setMsa( final Msa msa ) {
2532 void setMsaFile( final File msa_file ) {
2533 _msa_file = msa_file;
2536 public File getMsaFile() {
2540 public List<Sequence> getSeqs() {
2544 void setSeqs( final List<Sequence> seqs ) {
2548 void setSeqsFile( final File seqs_file ) {
2549 _seqs_file = seqs_file;
2552 public File getSeqsFile() {
2555 } // MainFrameApplication.
2557 class NexusFilter extends FileFilter {
2560 public boolean accept( final File f ) {
2561 final String file_name = f.getName().trim().toLowerCase();
2562 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2563 || file_name.endsWith( ".tre" ) || f.isDirectory();
2567 public String getDescription() {
2568 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2572 class NHFilter extends FileFilter {
2575 public boolean accept( final File f ) {
2576 final String file_name = f.getName().trim().toLowerCase();
2577 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2578 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2579 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2584 public String getDescription() {
2585 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2589 class NHXFilter extends FileFilter {
2592 public boolean accept( final File f ) {
2593 final String file_name = f.getName().trim().toLowerCase();
2594 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2598 public String getDescription() {
2599 return "NHX files (*.nhx)";
2603 class PdfFilter extends FileFilter {
2606 public boolean accept( final File f ) {
2607 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2611 public String getDescription() {
2612 return "PDF files (*.pdf)";
2616 class TolFilter extends FileFilter {
2619 public boolean accept( final File f ) {
2620 final String file_name = f.getName().trim().toLowerCase();
2621 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2622 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2626 public String getDescription() {
2627 return "Tree of Life files (*.tol, *.tolxml)";
2631 class XMLFilter extends FileFilter {
2634 public boolean accept( final File f ) {
2635 final String file_name = f.getName().trim().toLowerCase();
2636 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2637 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2641 public String getDescription() {
2642 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";