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;
60 import javax.swing.plaf.synth.SynthLookAndFeel;
62 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
63 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
64 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
65 import org.forester.archaeopteryx.Util.GraphicsExportType;
66 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
67 import org.forester.archaeopteryx.tools.GoAnnotation;
68 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
69 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
70 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
71 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
72 import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
73 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
74 import org.forester.archaeopteryx.webservices.WebservicesManager;
75 import org.forester.io.parsers.FastaParser;
76 import org.forester.io.parsers.GeneralMsaParser;
77 import org.forester.io.parsers.PhylogenyParser;
78 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
79 import org.forester.io.parsers.nhx.NHXParser;
80 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
81 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
82 import org.forester.io.parsers.tol.TolParser;
83 import org.forester.io.writers.PhylogenyWriter;
84 import org.forester.io.writers.SequenceWriter;
85 import org.forester.msa.Msa;
86 import org.forester.msa.MsaFormatException;
87 import org.forester.phylogeny.Phylogeny;
88 import org.forester.phylogeny.PhylogenyMethods;
89 import org.forester.phylogeny.PhylogenyNode;
90 import org.forester.phylogeny.data.Confidence;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.sdi.GSDI;
96 import org.forester.sdi.SDI;
97 import org.forester.sdi.SDIR;
98 import org.forester.sdi.SDIse;
99 import org.forester.sequence.Sequence;
100 import org.forester.util.BasicDescriptiveStatistics;
101 import org.forester.util.BasicTable;
102 import org.forester.util.BasicTableParser;
103 import org.forester.util.DescriptiveStatistics;
104 import org.forester.util.ForesterUtil;
105 import org.forester.util.ForesterUtil.PhylogenyNodeField;
106 import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
107 import org.forester.util.WindowsUtils;
109 class DefaultFilter extends FileFilter {
112 public boolean accept( final File f ) {
113 final String file_name = f.getName().trim().toLowerCase();
114 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
115 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
116 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
117 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
118 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
119 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
120 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
121 || file_name.endsWith( ".con" ) || f.isDirectory();
125 public String getDescription() {
126 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
130 class GraphicsFileFilter extends FileFilter {
133 public boolean accept( final File f ) {
134 final String file_name = f.getName().trim().toLowerCase();
135 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
136 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
140 public String getDescription() {
141 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
145 class MsaFileFilter extends FileFilter {
148 public boolean accept( final File f ) {
149 final String file_name = f.getName().trim().toLowerCase();
150 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
151 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
155 public String getDescription() {
156 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
160 class SequencesFileFilter extends FileFilter {
163 public boolean accept( final File f ) {
164 final String file_name = f.getName().trim().toLowerCase();
165 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
166 || file_name.endsWith( ".seqs" ) || f.isDirectory();
170 public String getDescription() {
171 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
175 public final class MainFrameApplication extends MainFrame {
177 private final static int FRAME_X_SIZE = 800;
178 private final static int FRAME_Y_SIZE = 800;
179 // Filters for the file-open dialog (classes defined in this file)
180 private final static NHFilter nhfilter = new NHFilter();
181 private final static NHXFilter nhxfilter = new NHXFilter();
182 private final static XMLFilter xmlfilter = new XMLFilter();
183 private final static TolFilter tolfilter = new TolFilter();
184 private final static NexusFilter nexusfilter = new NexusFilter();
185 private final static PdfFilter pdffilter = new PdfFilter();
186 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
187 private final static MsaFileFilter msafilter = new MsaFileFilter();
188 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
189 private final static DefaultFilter defaultfilter = new DefaultFilter();
190 private static final long serialVersionUID = -799735726778865234L;
191 private final JFileChooser _values_filechooser;
192 private final JFileChooser _open_filechooser;
193 private final JFileChooser _msa_filechooser;
194 private final JFileChooser _seqs_filechooser;
195 private final JFileChooser _open_filechooser_for_species_tree;
196 private final JFileChooser _save_filechooser;
197 private final JFileChooser _writetopdf_filechooser;
198 private final JFileChooser _writetographics_filechooser;
200 private JMenu _analysis_menu;
201 private JMenuItem _load_species_tree_item;
202 private JMenuItem _sdi_item;
203 private JMenuItem _gsdi_item;
204 private JMenuItem _root_min_dups_item;
205 private JMenuItem _root_min_cost_l_item;
206 private JMenuItem _lineage_inference;
207 private JMenuItem _function_analysis;
208 // Application-only print menu items
209 private JMenuItem _print_item;
210 private JMenuItem _write_to_pdf_item;
211 private JMenuItem _write_to_jpg_item;
212 private JMenuItem _write_to_gif_item;
213 private JMenuItem _write_to_tif_item;
214 private JMenuItem _write_to_png_item;
215 private JMenuItem _write_to_bmp_item;
216 private Phylogeny _species_tree;
217 private File _current_dir;
218 private ButtonGroup _radio_group_1;
220 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
221 // Phylogeny Inference menu
222 private JMenu _inference_menu;
223 private JMenuItem _inference_from_msa_item;
224 private JMenuItem _inference_from_seqs_item;
225 // Phylogeny Inference
226 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
227 private Msa _msa = null;
228 private File _msa_file = null;
229 private List<Sequence> _seqs = null;
230 private File _seqs_file = null;
231 // expression values menu:
232 JMenuItem _read_values_jmi;
234 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
235 _configuration = config;
236 if ( _configuration == null ) {
237 throw new IllegalArgumentException( "configuration is null" );
240 boolean synth_exception = false;
241 if ( Constants.__SYNTH_LF ) {
243 final SynthLookAndFeel synth = new SynthLookAndFeel();
244 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
245 MainFrameApplication.class );
246 UIManager.setLookAndFeel( synth );
248 catch ( final Exception ex ) {
249 synth_exception = true;
250 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
251 "could not create synth look and feel: "
252 + ex.getLocalizedMessage() );
255 if ( !Constants.__SYNTH_LF || synth_exception ) {
256 if ( _configuration.isUseNativeUI() ) {
257 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
260 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
263 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
265 catch ( final UnsupportedLookAndFeelException e ) {
266 Util.dieWithSystemError( "unsupported look and feel: " + e.toString() );
268 catch ( final ClassNotFoundException e ) {
269 Util.dieWithSystemError( "class not found exception: " + e.toString() );
271 catch ( final InstantiationException e ) {
272 Util.dieWithSystemError( "instantiation exception: " + e.toString() );
274 catch ( final IllegalAccessException e ) {
275 Util.dieWithSystemError( "illegal access exception: " + e.toString() );
277 catch ( final Exception e ) {
278 Util.dieWithSystemError( e.toString() );
280 // hide until everything is ready
282 setOptions( Options.createInstance( _configuration ) );
283 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
285 _species_tree = null;
287 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
288 _mainpanel = new MainPanel( _configuration, this );
290 _open_filechooser = new JFileChooser();
291 _open_filechooser.setCurrentDirectory( new File( "." ) );
292 _open_filechooser.setMultiSelectionEnabled( false );
293 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
294 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
295 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
296 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
297 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
298 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
299 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
300 _open_filechooser_for_species_tree = new JFileChooser();
301 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
302 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
303 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
304 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
305 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
306 _save_filechooser = new JFileChooser();
307 _save_filechooser.setCurrentDirectory( new File( "." ) );
308 _save_filechooser.setMultiSelectionEnabled( false );
309 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
310 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
311 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
312 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
313 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
314 _writetopdf_filechooser = new JFileChooser();
315 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
316 _writetographics_filechooser = new JFileChooser();
317 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
319 _msa_filechooser = new JFileChooser();
320 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
321 _msa_filechooser.setCurrentDirectory( new File( "." ) );
322 _msa_filechooser.setMultiSelectionEnabled( false );
323 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
324 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
326 _seqs_filechooser = new JFileChooser();
327 _seqs_filechooser.setName( "Read Sequences File" );
328 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
329 _seqs_filechooser.setMultiSelectionEnabled( false );
330 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
331 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
333 _values_filechooser = new JFileChooser();
334 _values_filechooser.setCurrentDirectory( new File( "." ) );
335 _values_filechooser.setMultiSelectionEnabled( false );
336 // build the menu bar
337 _jmenubar = new JMenuBar();
338 if ( !_configuration.isUseNativeUI() ) {
339 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
342 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
343 buildPhylogeneticInferenceMenu();
352 setJMenuBar( _jmenubar );
353 _jmenubar.add( _help_jmenu );
354 _contentpane = getContentPane();
355 _contentpane.setLayout( new BorderLayout() );
356 _contentpane.add( _mainpanel, BorderLayout.CENTER );
358 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
359 // addWindowFocusListener( new WindowAdapter() {
362 // public void windowGainedFocus( WindowEvent e ) {
363 // requestFocusInWindow();
366 // The window listener
367 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
368 addWindowListener( new WindowAdapter() {
371 public void windowClosing( final WindowEvent e ) {
372 if ( isUnsavedDataPresent() ) {
373 final int r = JOptionPane.showConfirmDialog( null,
374 "Exit despite potentially unsaved changes?",
376 JOptionPane.YES_NO_OPTION );
377 if ( r != JOptionPane.YES_OPTION ) {
382 final int r = JOptionPane.showConfirmDialog( null,
383 "Exit Archaeopteryx?",
385 JOptionPane.YES_NO_OPTION );
386 if ( r != JOptionPane.YES_OPTION ) {
393 // The component listener
394 addComponentListener( new ComponentAdapter() {
397 public void componentResized( final ComponentEvent e ) {
398 if ( _mainpanel.getCurrentTreePanel() != null ) {
399 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
401 _mainpanel.getCurrentTreePanel()
407 requestFocusInWindow();
408 // addKeyListener( this );
410 if ( ( phys != null ) && ( phys.length > 0 ) ) {
411 Util.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
413 getMainPanel().getControlPanel().showWholeAll();
414 getMainPanel().getControlPanel().showWhole();
416 activateSaveAllIfNeeded();
417 // ...and its children
418 _contentpane.repaint();
422 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
423 // Reads the config file (false, false => not url, not applet):
424 this( phys, new Configuration( config_file, false, false ), title );
428 public void actionPerformed( final ActionEvent e ) {
430 super.actionPerformed( e );
431 final Object o = e.getSource();
432 // Handle app-specific actions here:
433 if ( o == _open_item ) {
434 readPhylogeniesFromFile();
436 else if ( o == _save_item ) {
437 writeToFile( _mainpanel.getCurrentPhylogeny() );
438 // If subtree currently displayed, save it, instead of complete
441 else if ( o == _new_item ) {
444 else if ( o == _save_all_item ) {
447 else if ( o == _close_item ) {
450 else if ( o == _write_to_pdf_item ) {
451 writeToPdf( _mainpanel.getCurrentPhylogeny() );
453 else if ( o == _write_to_jpg_item ) {
454 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
456 else if ( o == _write_to_png_item ) {
457 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
459 else if ( o == _write_to_gif_item ) {
460 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
462 else if ( o == _write_to_tif_item ) {
463 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
465 else if ( o == _write_to_bmp_item ) {
466 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
468 else if ( o == _print_item ) {
471 else if ( o == _load_species_tree_item ) {
472 readSpeciesTreeFromFile();
474 else if ( o == _sdi_item ) {
475 if ( isSubtreeDisplayed() ) {
480 else if ( o == _lineage_inference ) {
481 if ( isSubtreeDisplayed() ) {
482 JOptionPane.showMessageDialog( this,
484 "Cannot infer ancestral taxonomies",
485 JOptionPane.ERROR_MESSAGE );
488 executeLineageInference();
490 else if ( o == _function_analysis ) {
491 executeFunctionAnalysis();
493 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
494 if ( isSubtreeDisplayed() ) {
497 obtainDetailedTaxonomicInformation();
499 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
500 if ( isSubtreeDisplayed() ) {
503 obtainDetailedTaxonomicInformationDelete();
505 else if ( o == _obtain_uniprot_seq_information_jmi ) {
506 obtainUniProtSequenceInformation();
508 else if ( o == _read_values_jmi ) {
509 if ( isSubtreeDisplayed() ) {
512 addExpressionValuesFromFile();
514 else if ( o == _move_node_names_to_tax_sn_jmi ) {
515 moveNodeNamesToTaxSn();
517 else if ( o == _move_node_names_to_seq_names_jmi ) {
518 moveNodeNamesToSeqNames();
520 else if ( o == _extract_tax_code_from_node_names_jmi ) {
521 extractTaxCodeFromNodeNames();
523 else if ( o == _gsdi_item ) {
524 if ( isSubtreeDisplayed() ) {
529 else if ( o == _root_min_dups_item ) {
530 if ( isSubtreeDisplayed() ) {
533 executeSDIR( false );
535 else if ( o == _root_min_cost_l_item ) {
536 if ( isSubtreeDisplayed() ) {
541 else if ( o == _graphics_export_visible_only_cbmi ) {
542 updateOptions( getOptions() );
544 else if ( o == _antialias_print_cbmi ) {
545 updateOptions( getOptions() );
547 else if ( o == _print_black_and_white_cbmi ) {
548 updateOptions( getOptions() );
550 else if ( o == _print_using_actual_size_cbmi ) {
551 updateOptions( getOptions() );
553 else if ( o == _graphics_export_using_actual_size_cbmi ) {
554 updateOptions( getOptions() );
556 else if ( o == _print_size_mi ) {
559 else if ( o == _choose_pdf_width_mi ) {
562 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
563 updateOptions( getOptions() );
565 else if ( o == _replace_underscores_cbmi ) {
566 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
567 _extract_pfam_style_tax_codes_cbmi.setSelected( false );
569 updateOptions( getOptions() );
571 else if ( o == _collapse_below_threshold ) {
572 if ( isSubtreeDisplayed() ) {
575 collapseBelowThreshold();
577 else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
578 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
579 _replace_underscores_cbmi.setSelected( false );
581 updateOptions( getOptions() );
583 else if ( o == _inference_from_msa_item ) {
584 executePhyleneticInference( false );
586 else if ( o == _inference_from_seqs_item ) {
587 executePhyleneticInference( true );
589 _contentpane.repaint();
591 catch ( final Exception ex ) {
592 Util.unexpectedException( ex );
594 catch ( final Error err ) {
595 Util.unexpectedError( err );
599 void buildAnalysisMenu() {
600 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
601 _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
602 if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
603 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
605 _analysis_menu.addSeparator();
606 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
607 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
608 _analysis_menu.addSeparator();
609 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
610 customizeJMenuItem( _sdi_item );
611 customizeJMenuItem( _gsdi_item );
612 customizeJMenuItem( _root_min_dups_item );
613 customizeJMenuItem( _root_min_cost_l_item );
614 customizeJMenuItem( _load_species_tree_item );
615 _analysis_menu.addSeparator();
616 _analysis_menu.add( _lineage_inference = new JMenuItem( "Infer Ancestor Taxonomies" ) );
617 customizeJMenuItem( _lineage_inference );
618 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
619 _jmenubar.add( _analysis_menu );
622 void buildPhylogeneticInferenceMenu() {
623 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
625 .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
626 customizeJMenuItem( _inference_from_msa_item );
627 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
629 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
630 customizeJMenuItem( _inference_from_seqs_item );
631 _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
632 _jmenubar.add( _inference_menu );
636 void buildFileMenu() {
637 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
638 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
639 _file_jmenu.addSeparator();
640 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
641 _file_jmenu.addSeparator();
642 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
643 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
644 .getAvailablePhylogeniesWebserviceClients().size() ];
645 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
646 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
647 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
648 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
650 if ( getConfiguration().isEditable() ) {
651 _file_jmenu.addSeparator();
652 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
653 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
655 _file_jmenu.addSeparator();
656 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
657 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
658 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
659 _save_all_item.setEnabled( false );
660 _file_jmenu.addSeparator();
661 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
662 if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
663 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
665 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
666 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
667 if ( Util.canWriteFormat( "gif" ) ) {
668 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
670 if ( Util.canWriteFormat( "bmp" ) ) {
671 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
673 _file_jmenu.addSeparator();
674 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
675 _file_jmenu.addSeparator();
676 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
677 _close_item.setToolTipText( "To close the current pane." );
678 _close_item.setEnabled( true );
679 _file_jmenu.addSeparator();
680 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
681 // For print in color option item
682 customizeJMenuItem( _open_item );
684 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
685 customizeJMenuItem( _open_url_item );
686 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
687 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
689 customizeJMenuItem( _save_item );
690 if ( getConfiguration().isEditable() ) {
691 customizeJMenuItem( _new_item );
693 customizeJMenuItem( _close_item );
694 customizeJMenuItem( _save_all_item );
695 customizeJMenuItem( _write_to_pdf_item );
696 customizeJMenuItem( _write_to_png_item );
697 customizeJMenuItem( _write_to_jpg_item );
698 customizeJMenuItem( _write_to_gif_item );
699 customizeJMenuItem( _write_to_tif_item );
700 customizeJMenuItem( _write_to_bmp_item );
701 customizeJMenuItem( _print_item );
702 customizeJMenuItem( _exit_item );
703 _jmenubar.add( _file_jmenu );
706 void buildOptionsMenu() {
707 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
708 _options_jmenu.addChangeListener( new ChangeListener() {
711 public void stateChanged( final ChangeEvent e ) {
712 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
713 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
715 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
716 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
717 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
718 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
719 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
720 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
722 _show_branch_length_values_cbmi,
723 _non_lined_up_cladograms_rbmi,
724 _uniform_cladograms_rbmi,
725 _ext_node_dependent_cladogram_rbmi,
726 _label_direction_cbmi );
727 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
728 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
729 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
732 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
734 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
735 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
736 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
737 _radio_group_1 = new ButtonGroup();
738 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
739 _radio_group_1.add( _uniform_cladograms_rbmi );
740 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
741 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
743 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
744 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
745 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
746 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
747 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
749 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
750 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
751 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
752 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
753 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
754 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
755 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
756 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
757 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
758 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
759 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
761 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
762 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
763 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
764 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
765 _options_jmenu.addSeparator();
766 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
767 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
768 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
769 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
770 _options_jmenu.addSeparator();
771 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
772 getConfiguration() ) );
773 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
774 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
776 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
778 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
780 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
781 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
782 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
783 _options_jmenu.addSeparator();
785 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
787 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
788 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
790 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
791 customizeJMenuItem( _choose_font_mi );
792 customizeJMenuItem( _choose_minimal_confidence_mi );
793 customizeJMenuItem( _switch_colors_mi );
794 customizeJMenuItem( _print_size_mi );
795 customizeJMenuItem( _choose_pdf_width_mi );
796 customizeJMenuItem( _overview_placment_mi );
797 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
798 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
799 customizeJMenuItem( _cycle_node_shape_mi );
800 customizeJMenuItem( _cycle_node_fill_mi );
801 customizeJMenuItem( _choose_node_size_mi );
802 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
803 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
804 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
805 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
806 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
807 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
808 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
809 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
810 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
811 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
812 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
813 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
814 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
815 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
816 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
817 customizeCheckBoxMenuItem( _label_direction_cbmi,
818 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
819 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
820 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
821 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
822 .isInternalNumberAreConfidenceForNhParsing() );
823 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
824 .isExtractPfamTaxonomyCodesInNhParsing() );
825 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
826 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
827 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
828 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
829 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
830 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
831 .isGraphicsExportUsingActualSize() );
832 _jmenubar.add( _options_jmenu );
835 void buildToolsMenu() {
836 _tools_menu = createMenu( "Tools", getConfiguration() );
837 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
838 customizeJMenuItem( _confcolor_item );
839 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
840 customizeJMenuItem( _taxcolor_item );
841 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
842 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
843 customizeJMenuItem( _remove_branch_color_item );
844 _tools_menu.addSeparator();
845 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
846 customizeJMenuItem( _midpoint_root_item );
847 _tools_menu.addSeparator();
848 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
849 customizeJMenuItem( _collapse_species_specific_subtrees );
851 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
852 customizeJMenuItem( _collapse_below_threshold );
853 _collapse_below_threshold
854 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
855 _tools_menu.addSeparator();
857 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
858 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
859 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
860 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
861 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
862 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
864 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
865 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
866 _extract_tax_code_from_node_names_jmi
867 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
868 _tools_menu.addSeparator();
870 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
871 customizeJMenuItem( _infer_common_sn_names_item );
872 _tools_menu.addSeparator();
874 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
875 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
876 _obtain_detailed_taxonomic_information_jmi
877 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
879 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
880 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
881 _obtain_detailed_taxonomic_information_deleting_jmi
882 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
884 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
885 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
886 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
887 _tools_menu.addSeparator();
888 if ( !Constants.__RELEASE ) {
889 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
890 customizeJMenuItem( _function_analysis );
892 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
893 _tools_menu.addSeparator();
895 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
896 customizeJMenuItem( _read_values_jmi );
897 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
898 _jmenubar.add( _tools_menu );
901 private void choosePdfWidth() {
902 final String s = ( String ) JOptionPane.showInputDialog( this,
903 "Please enter the default line width for PDF export.\n"
905 + getOptions().getPrintLineWidth() + "]\n",
906 "Line Width for PDF Export",
907 JOptionPane.QUESTION_MESSAGE,
910 getOptions().getPrintLineWidth() );
911 if ( !ForesterUtil.isEmpty( s ) ) {
912 boolean success = true;
914 final String m_str = s.trim();
915 if ( !ForesterUtil.isEmpty( m_str ) ) {
917 f = Float.parseFloat( m_str );
919 catch ( final Exception ex ) {
926 if ( success && ( f > 0.0 ) ) {
927 getOptions().setPrintLineWidth( f );
932 private void choosePrintSize() {
933 final String s = ( String ) JOptionPane.showInputDialog( this,
934 "Please enter values for width and height,\nseparated by a comma.\n"
935 + "[current values: "
936 + getOptions().getPrintSizeX() + ", "
937 + getOptions().getPrintSizeY() + "]\n"
938 + "[A4: " + Constants.A4_SIZE_X + ", "
939 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
940 + Constants.US_LETTER_SIZE_X + ", "
941 + Constants.US_LETTER_SIZE_Y + "]",
942 "Default Size for Graphics Export",
943 JOptionPane.QUESTION_MESSAGE,
946 getOptions().getPrintSizeX() + ", "
947 + getOptions().getPrintSizeY() );
948 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
949 boolean success = true;
952 final String[] str_ary = s.split( "," );
953 if ( str_ary.length == 2 ) {
954 final String x_str = str_ary[ 0 ].trim();
955 final String y_str = str_ary[ 1 ].trim();
956 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
958 x = Integer.parseInt( x_str );
959 y = Integer.parseInt( y_str );
961 catch ( final Exception ex ) {
972 if ( success && ( x > 1 ) && ( y > 1 ) ) {
973 getOptions().setPrintSizeX( x );
974 getOptions().setPrintSizeY( y );
981 if ( isUnsavedDataPresent() ) {
982 final int r = JOptionPane.showConfirmDialog( this,
983 "Exit despite potentially unsaved changes?",
985 JOptionPane.YES_NO_OPTION );
986 if ( r != JOptionPane.YES_OPTION ) {
993 private void closeCurrentPane() {
994 if ( getMainPanel().getCurrentTreePanel() != null ) {
995 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
996 final int r = JOptionPane.showConfirmDialog( this,
997 "Close tab despite potentially unsaved changes?",
999 JOptionPane.YES_NO_OPTION );
1000 if ( r != JOptionPane.YES_OPTION ) {
1004 getMainPanel().closeCurrentPane();
1005 activateSaveAllIfNeeded();
1009 private void collapse( final Phylogeny phy, final double m ) {
1010 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1011 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1012 double min_support = Double.MAX_VALUE;
1013 boolean conf_present = false;
1014 while ( it.hasNext() ) {
1015 final PhylogenyNode n = it.next();
1016 if ( !n.isExternal() && !n.isRoot() ) {
1017 final List<Confidence> c = n.getBranchData().getConfidences();
1018 if ( ( c != null ) && ( c.size() > 0 ) ) {
1019 conf_present = true;
1021 for( final Confidence confidence : c ) {
1022 if ( confidence.getValue() > max ) {
1023 max = confidence.getValue();
1026 if ( max < getMinNotCollapseConfidenceValue() ) {
1027 to_be_removed.add( n );
1029 if ( max < min_support ) {
1035 if ( conf_present ) {
1036 for( final PhylogenyNode node : to_be_removed ) {
1037 PhylogenyMethods.removeNode( node, phy );
1039 if ( to_be_removed.size() > 0 ) {
1040 phy.externalNodesHaveChanged();
1042 phy.recalculateNumberOfExternalDescendants( true );
1043 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1044 getCurrentTreePanel().setEdited( true );
1045 getCurrentTreePanel().repaint();
1047 if ( to_be_removed.size() > 0 ) {
1048 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1049 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1050 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1053 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1054 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1058 JOptionPane.showMessageDialog( this,
1059 "No branch collapsed because no confidence values present",
1060 "No confidence values present",
1061 JOptionPane.INFORMATION_MESSAGE );
1065 private void collapseBelowThreshold() {
1066 if ( getCurrentTreePanel() != null ) {
1067 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1068 if ( ( phy != null ) && !phy.isEmpty() ) {
1069 final String s = ( String ) JOptionPane.showInputDialog( this,
1070 "Please enter the minimum confidence value\n",
1071 "Minimal Confidence Value",
1072 JOptionPane.QUESTION_MESSAGE,
1075 getMinNotCollapseConfidenceValue() );
1076 if ( !ForesterUtil.isEmpty( s ) ) {
1077 boolean success = true;
1079 final String m_str = s.trim();
1080 if ( !ForesterUtil.isEmpty( m_str ) ) {
1082 m = Double.parseDouble( m_str );
1084 catch ( final Exception ex ) {
1091 if ( success && ( m >= 0.0 ) ) {
1092 setMinNotCollapseConfidenceValue( m );
1100 private PhyloXmlParser createPhyloXmlParser() {
1101 PhyloXmlParser xml_parser = null;
1102 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1104 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1106 catch ( final Exception e ) {
1107 JOptionPane.showMessageDialog( this,
1108 e.getLocalizedMessage(),
1109 "failed to create validating XML parser",
1110 JOptionPane.WARNING_MESSAGE );
1113 if ( xml_parser == null ) {
1114 xml_parser = new PhyloXmlParser();
1119 void executeGSDI() {
1120 if ( !isOKforSDI( false, true ) ) {
1123 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1124 JOptionPane.showMessageDialog( this,
1125 "Gene tree is not rooted.",
1126 "Cannot execute GSDI",
1127 JOptionPane.ERROR_MESSAGE );
1130 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1131 gene_tree.setAllNodesToNotCollapse();
1132 gene_tree.recalculateNumberOfExternalDescendants( false );
1134 int duplications = -1;
1136 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1137 duplications = gsdi.getDuplicationsSum();
1139 catch ( final Exception e ) {
1140 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1142 gene_tree.setRerootable( false );
1143 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1144 getControlPanel().setShowEvents( true );
1146 _mainpanel.getCurrentTreePanel().setEdited( true );
1147 JOptionPane.showMessageDialog( this,
1148 "Number of duplications: " + duplications,
1149 "GSDI successfully completed",
1150 JOptionPane.INFORMATION_MESSAGE );
1153 void executeFunctionAnalysis() {
1154 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1157 final GoAnnotation a = new GoAnnotation( this,
1158 _mainpanel.getCurrentTreePanel(),
1159 _mainpanel.getCurrentPhylogeny() );
1160 new Thread( a ).start();
1163 void executeLineageInference() {
1164 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1167 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1168 JOptionPane.showMessageDialog( this,
1169 "Phylogeny is not rooted.",
1170 "Cannot infer ancestral taxonomies",
1171 JOptionPane.ERROR_MESSAGE );
1174 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1175 _mainpanel.getCurrentTreePanel(),
1176 _mainpanel.getCurrentPhylogeny()
1178 new Thread( inferrer ).start();
1181 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1182 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1183 getPhylogeneticInferenceOptions(),
1184 from_unaligned_seqs );
1186 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1187 if ( !from_unaligned_seqs ) {
1188 if ( getMsa() != null ) {
1189 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1190 getPhylogeneticInferenceOptions()
1192 new Thread( inferrer ).start();
1195 JOptionPane.showMessageDialog( this,
1196 "No multiple sequence alignment selected",
1197 "Phylogenetic Inference Not Launched",
1198 JOptionPane.WARNING_MESSAGE );
1202 if ( getSeqs() != null ) {
1203 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1204 getPhylogeneticInferenceOptions()
1206 new Thread( inferrer ).start();
1209 JOptionPane.showMessageDialog( this,
1210 "No input sequences selected",
1211 "Phylogenetic Inference Not Launched",
1212 JOptionPane.WARNING_MESSAGE );
1219 if ( !isOKforSDI( true, true ) ) {
1222 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1223 JOptionPane.showMessageDialog( this,
1224 "Gene tree is not rooted",
1225 "Cannot execute SDI",
1226 JOptionPane.ERROR_MESSAGE );
1229 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1230 gene_tree.setAllNodesToNotCollapse();
1231 gene_tree.recalculateNumberOfExternalDescendants( false );
1233 int duplications = -1;
1235 sdi = new SDIse( gene_tree, _species_tree.copy() );
1236 duplications = sdi.getDuplicationsSum();
1238 catch ( final Exception e ) {
1239 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1241 gene_tree.setRerootable( false );
1242 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1243 getControlPanel().setShowEvents( true );
1245 _mainpanel.getCurrentTreePanel().setEdited( true );
1246 JOptionPane.showMessageDialog( this,
1247 "Number of duplications: " + duplications,
1248 "SDI successfully completed",
1249 JOptionPane.INFORMATION_MESSAGE );
1252 void executeSDIR( final boolean minimize_cost ) {
1253 if ( !isOKforSDI( true, true ) ) {
1256 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1257 final SDIR sdiunrooted = new SDIR();
1258 gene_tree.setAllNodesToNotCollapse();
1259 gene_tree.recalculateNumberOfExternalDescendants( false );
1261 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1262 !minimize_cost, // minimize sum of dups
1263 true, // minimize height
1264 true, // return tree(s)
1265 1 )[ 0 ]; // # of trees to return
1267 catch ( final Exception e ) {
1268 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1271 final int duplications = sdiunrooted.getMinimalDuplications();
1272 gene_tree.setRerootable( false );
1273 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1274 getControlPanel().setShowEvents( true );
1276 _mainpanel.getCurrentTreePanel().setEdited( true );
1277 JOptionPane.showMessageDialog( this,
1278 "Number of duplications: " + duplications,
1279 "SDIR successfully completed",
1280 JOptionPane.INFORMATION_MESSAGE );
1285 _mainpanel.terminate();
1286 _contentpane.removeAll();
1287 setVisible( false );
1292 private void extractTaxCodeFromNodeNames() {
1293 if ( getCurrentTreePanel() != null ) {
1294 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1295 if ( ( phy != null ) && !phy.isEmpty() ) {
1296 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1297 while ( it.hasNext() ) {
1298 final PhylogenyNode n = it.next();
1299 final String name = n.getName().trim();
1300 if ( !ForesterUtil.isEmpty( name ) ) {
1301 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1303 TAXONOMY_EXTRACTION.YES );
1304 if ( !ForesterUtil.isEmpty( code ) ) {
1305 PhylogenyMethods.setTaxonomyCode( n, code );
1313 private ControlPanel getControlPanel() {
1314 return getMainPanel().getControlPanel();
1317 private File getCurrentDir() {
1318 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1319 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1321 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1323 catch ( final Exception e ) {
1324 _current_dir = null;
1328 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1329 if ( System.getProperty( "user.home" ) != null ) {
1330 _current_dir = new File( System.getProperty( "user.home" ) );
1332 else if ( System.getProperty( "user.dir" ) != null ) {
1333 _current_dir = new File( System.getProperty( "user.dir" ) );
1336 return _current_dir;
1340 public MainPanel getMainPanel() {
1344 private double getMinNotCollapseConfidenceValue() {
1345 return _min_not_collapse;
1348 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1349 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1352 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1353 JOptionPane.showMessageDialog( this,
1354 "No species tree loaded",
1355 "Cannot execute SDI",
1356 JOptionPane.ERROR_MESSAGE );
1359 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1360 JOptionPane.showMessageDialog( this,
1361 "Species tree is not completely binary",
1362 "Cannot execute SDI",
1363 JOptionPane.ERROR_MESSAGE );
1366 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1367 JOptionPane.showMessageDialog( this,
1368 "Gene tree is not completely binary",
1369 "Cannot execute SDI",
1370 JOptionPane.ERROR_MESSAGE );
1378 private boolean isUnsavedDataPresent() {
1379 final List<TreePanel> tps = getMainPanel().getTreePanels();
1380 for( final TreePanel tp : tps ) {
1381 if ( tp.isEdited() ) {
1388 private void moveNodeNamesToSeqNames() {
1389 if ( getCurrentTreePanel() != null ) {
1390 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1391 if ( ( phy != null ) && !phy.isEmpty() ) {
1392 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1397 private void moveNodeNamesToTaxSn() {
1398 if ( getCurrentTreePanel() != null ) {
1399 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1400 if ( ( phy != null ) && !phy.isEmpty() ) {
1401 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1406 private void newTree() {
1407 final Phylogeny[] phys = new Phylogeny[ 1 ];
1408 final Phylogeny phy = new Phylogeny();
1409 final PhylogenyNode node = new PhylogenyNode();
1410 phy.setRoot( node );
1411 phy.setRooted( true );
1413 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1414 _mainpanel.getControlPanel().showWhole();
1415 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1416 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1417 if ( getMainPanel().getMainFrame() == null ) {
1418 // Must be "E" applet version.
1419 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1420 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1423 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1425 activateSaveAllIfNeeded();
1429 private void obtainDetailedTaxonomicInformation() {
1430 if ( getCurrentTreePanel() != null ) {
1431 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1432 if ( ( phy != null ) && !phy.isEmpty() ) {
1433 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1434 _mainpanel.getCurrentTreePanel(),
1436 new Thread( t ).start();
1441 private void obtainDetailedTaxonomicInformationDelete() {
1442 if ( getCurrentTreePanel() != null ) {
1443 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1444 if ( ( phy != null ) && !phy.isEmpty() ) {
1445 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1446 _mainpanel.getCurrentTreePanel(),
1449 new Thread( t ).start();
1454 private void obtainUniProtSequenceInformation() {
1455 if ( getCurrentTreePanel() != null ) {
1456 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1457 if ( ( phy != null ) && !phy.isEmpty() ) {
1458 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1459 _mainpanel.getCurrentTreePanel(),
1461 new Thread( u ).start();
1466 private void print() {
1467 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1468 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1471 if ( !getOptions().isPrintUsingActualSize() ) {
1472 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1473 getOptions().getPrintSizeY() - 140,
1475 getCurrentTreePanel().resetPreferredSize();
1476 getCurrentTreePanel().repaint();
1478 final String job_name = Constants.PRG_NAME;
1479 boolean error = false;
1480 String printer_name = null;
1482 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1484 catch ( final Exception e ) {
1486 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1488 if ( !error && ( printer_name != null ) ) {
1489 String msg = "Printing data sent to printer";
1490 if ( printer_name.length() > 1 ) {
1491 msg += " [" + printer_name + "]";
1493 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1495 if ( !getOptions().isPrintUsingActualSize() ) {
1496 getControlPanel().showWhole();
1500 private void printPhylogenyToPdf( final String file_name ) {
1501 if ( !getOptions().isPrintUsingActualSize() ) {
1502 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1503 getOptions().getPrintSizeY(),
1505 getCurrentTreePanel().resetPreferredSize();
1506 getCurrentTreePanel().repaint();
1508 String pdf_written_to = "";
1509 boolean error = false;
1511 if ( getOptions().isPrintUsingActualSize() ) {
1512 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1513 getCurrentTreePanel(),
1514 getCurrentTreePanel().getWidth(),
1515 getCurrentTreePanel().getHeight() );
1518 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1519 .getPrintSizeX(), getOptions().getPrintSizeY() );
1522 catch ( final IOException e ) {
1524 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1527 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1528 JOptionPane.showMessageDialog( this,
1529 "Wrote PDF to: " + pdf_written_to,
1531 JOptionPane.INFORMATION_MESSAGE );
1534 JOptionPane.showMessageDialog( this,
1535 "There was an unknown problem when attempting to write to PDF file: \""
1538 JOptionPane.ERROR_MESSAGE );
1541 if ( !getOptions().isPrintUsingActualSize() ) {
1542 getControlPanel().showWhole();
1546 private void addExpressionValuesFromFile() {
1547 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1548 JOptionPane.showMessageDialog( this,
1549 "Need to load evolutionary tree first",
1550 "Can Not Read Expression Values",
1551 JOptionPane.WARNING_MESSAGE );
1554 final File my_dir = getCurrentDir();
1555 if ( my_dir != null ) {
1556 _values_filechooser.setCurrentDirectory( my_dir );
1558 final int result = _values_filechooser.showOpenDialog( _contentpane );
1559 final File file = _values_filechooser.getSelectedFile();
1560 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1561 BasicTable<String> t = null;
1563 t = BasicTableParser.parse( file, "\t" );
1564 if ( t.getNumberOfColumns() < 2 ) {
1565 t = BasicTableParser.parse( file, "," );
1567 if ( t.getNumberOfColumns() < 2 ) {
1568 t = BasicTableParser.parse( file, " " );
1571 catch ( final IOException e ) {
1572 JOptionPane.showMessageDialog( this,
1574 "Could Not Read Expression Value Table",
1575 JOptionPane.ERROR_MESSAGE );
1578 if ( t.getNumberOfColumns() < 2 ) {
1579 JOptionPane.showMessageDialog( this,
1580 "Table contains " + t.getNumberOfColumns() + " column(s)",
1581 "Problem with Expression Value Table",
1582 JOptionPane.ERROR_MESSAGE );
1585 if ( t.getNumberOfRows() < 1 ) {
1586 JOptionPane.showMessageDialog( this,
1587 "Table contains zero rows",
1588 "Problem with Expression Value Table",
1589 JOptionPane.ERROR_MESSAGE );
1592 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1593 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1594 JOptionPane.showMessageDialog( this,
1595 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1596 + phy.getNumberOfExternalNodes() + " external nodes",
1598 JOptionPane.WARNING_MESSAGE );
1600 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1602 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1603 final PhylogenyNode node = iter.next();
1604 final String node_name = node.getName();
1605 if ( !ForesterUtil.isEmpty( node_name ) ) {
1608 row = t.findRow( node_name );
1610 catch ( final IllegalArgumentException e ) {
1612 .showMessageDialog( this,
1614 "Error Mapping Node Identifiers to Expression Value Identifiers",
1615 JOptionPane.ERROR_MESSAGE );
1619 if ( node.isExternal() ) {
1624 final List<Double> l = new ArrayList<Double>();
1625 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1628 d = Double.parseDouble( t.getValueAsString( col, row ) );
1630 catch ( final NumberFormatException e ) {
1631 JOptionPane.showMessageDialog( this,
1632 "Could not parse \"" + t.getValueAsString( col, row )
1633 + "\" into a decimal value",
1634 "Issue with Expression Value Table",
1635 JOptionPane.ERROR_MESSAGE );
1638 stats.addValue( d );
1641 if ( !l.isEmpty() ) {
1642 if ( node.getNodeData().getProperties() != null ) {
1643 node.getNodeData().getProperties()
1644 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1646 node.getNodeData().setVector( l );
1650 if ( not_found > 0 ) {
1651 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1652 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1654 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1658 private void readPhylogeniesFromFile() {
1659 boolean exception = false;
1660 Phylogeny[] phys = null;
1661 // Set an initial directory if none set yet
1662 final File my_dir = getCurrentDir();
1663 _open_filechooser.setMultiSelectionEnabled( true );
1664 // Open file-open dialog and set current directory
1665 if ( my_dir != null ) {
1666 _open_filechooser.setCurrentDirectory( my_dir );
1668 final int result = _open_filechooser.showOpenDialog( _contentpane );
1669 // All done: get the file
1670 final File[] files = _open_filechooser.getSelectedFiles();
1671 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1672 boolean nhx_or_nexus = false;
1673 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1674 for( final File file : files ) {
1675 if ( ( file != null ) && !file.isDirectory() ) {
1676 if ( _mainpanel.getCurrentTreePanel() != null ) {
1677 _mainpanel.getCurrentTreePanel().setWaitCursor();
1680 _mainpanel.setWaitCursor();
1682 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1683 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1685 final NHXParser nhx = new NHXParser();
1686 setSpecialOptionsForNhxParser( nhx );
1687 phys = ForesterUtil.readPhylogenies( nhx, file );
1688 nhx_or_nexus = true;
1690 catch ( final Exception e ) {
1692 exceptionOccuredDuringOpenFile( e );
1695 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1696 warnIfNotPhyloXmlValidation( getConfiguration() );
1698 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1699 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1701 catch ( final Exception e ) {
1703 exceptionOccuredDuringOpenFile( e );
1706 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1708 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1710 catch ( final Exception e ) {
1712 exceptionOccuredDuringOpenFile( e );
1715 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1717 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1718 setSpecialOptionsForNexParser( nex );
1719 phys = ForesterUtil.readPhylogenies( nex, file );
1720 nhx_or_nexus = true;
1722 catch ( final Exception e ) {
1724 exceptionOccuredDuringOpenFile( e );
1730 final PhylogenyParser parser = ForesterUtil
1731 .createParserDependingOnFileType( file, getConfiguration()
1732 .isValidatePhyloXmlAgainstSchema() );
1733 if ( parser instanceof NexusPhylogeniesParser ) {
1734 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1735 setSpecialOptionsForNexParser( nex );
1736 nhx_or_nexus = true;
1738 else if ( parser instanceof NHXParser ) {
1739 final NHXParser nhx = ( NHXParser ) parser;
1740 setSpecialOptionsForNhxParser( nhx );
1741 nhx_or_nexus = true;
1743 else if ( parser instanceof PhyloXmlParser ) {
1744 warnIfNotPhyloXmlValidation( getConfiguration() );
1746 phys = ForesterUtil.readPhylogenies( parser, file );
1748 catch ( final Exception e ) {
1750 exceptionOccuredDuringOpenFile( e );
1753 if ( _mainpanel.getCurrentTreePanel() != null ) {
1754 _mainpanel.getCurrentTreePanel().setArrowCursor();
1757 _mainpanel.setArrowCursor();
1759 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1760 boolean one_desc = false;
1761 if ( nhx_or_nexus ) {
1762 for( final Phylogeny phy : phys ) {
1763 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1764 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1766 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1772 Util.addPhylogeniesToTabs( phys,
1774 file.getAbsolutePath(),
1777 _mainpanel.getControlPanel().showWhole();
1778 if ( nhx_or_nexus && one_desc ) {
1780 .showMessageDialog( this,
1781 "One or more trees contain (a) node(s) with one descendant, "
1782 + ForesterUtil.LINE_SEPARATOR
1783 + "possibly indicating illegal parentheses within node names.",
1784 "Warning: Possible Error in New Hampshire Formatted Data",
1785 JOptionPane.WARNING_MESSAGE );
1791 activateSaveAllIfNeeded();
1795 public void readSeqsFromFile() {
1796 // Set an initial directory if none set yet
1797 final File my_dir = getCurrentDir();
1798 _seqs_filechooser.setMultiSelectionEnabled( false );
1799 // Open file-open dialog and set current directory
1800 if ( my_dir != null ) {
1801 _seqs_filechooser.setCurrentDirectory( my_dir );
1803 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1804 // All done: get the seqs
1805 final File file = _seqs_filechooser.getSelectedFile();
1806 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1807 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1808 setSeqsFile( null );
1810 List<Sequence> seqs = null;
1812 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1813 seqs = FastaParser.parse( new FileInputStream( file ) );
1814 for( final Sequence seq : seqs ) {
1815 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1822 catch ( final MsaFormatException e ) {
1824 _mainpanel.getCurrentTreePanel().setArrowCursor();
1826 catch ( final Exception ex ) {
1829 JOptionPane.showMessageDialog( this,
1830 e.getLocalizedMessage(),
1831 "Multiple sequence file format error",
1832 JOptionPane.ERROR_MESSAGE );
1835 catch ( final IOException e ) {
1837 _mainpanel.getCurrentTreePanel().setArrowCursor();
1839 catch ( final Exception ex ) {
1842 JOptionPane.showMessageDialog( this,
1843 e.getLocalizedMessage(),
1844 "Failed to read multiple sequence file",
1845 JOptionPane.ERROR_MESSAGE );
1848 catch ( final IllegalArgumentException e ) {
1850 _mainpanel.getCurrentTreePanel().setArrowCursor();
1852 catch ( final Exception ex ) {
1855 JOptionPane.showMessageDialog( this,
1856 e.getLocalizedMessage(),
1857 "Unexpected error during reading of multiple sequence file",
1858 JOptionPane.ERROR_MESSAGE );
1861 catch ( final Exception e ) {
1863 _mainpanel.getCurrentTreePanel().setArrowCursor();
1865 catch ( final Exception ex ) {
1868 e.printStackTrace();
1869 JOptionPane.showMessageDialog( this,
1870 e.getLocalizedMessage(),
1871 "Unexpected error during reading of multiple sequence file",
1872 JOptionPane.ERROR_MESSAGE );
1875 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1876 JOptionPane.showMessageDialog( this,
1877 "Multiple sequence file is empty",
1878 "Illegal multiple sequence file",
1879 JOptionPane.ERROR_MESSAGE );
1882 if ( seqs.size() < 4 ) {
1883 JOptionPane.showMessageDialog( this,
1884 "Multiple sequence file needs to contain at least 3 sequences",
1885 "Illegal multiple sequence file",
1886 JOptionPane.ERROR_MESSAGE );
1889 // if ( msa.getLength() < 2 ) {
1890 // JOptionPane.showMessageDialog( this,
1891 // "Multiple sequence alignment needs to contain at least 2 residues",
1892 // "Illegal multiple sequence file",
1893 // JOptionPane.ERROR_MESSAGE );
1897 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1902 public void readMsaFromFile() {
1903 // Set an initial directory if none set yet
1904 final File my_dir = getCurrentDir();
1905 _msa_filechooser.setMultiSelectionEnabled( false );
1906 // Open file-open dialog and set current directory
1907 if ( my_dir != null ) {
1908 _msa_filechooser.setCurrentDirectory( my_dir );
1910 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1911 // All done: get the msa
1912 final File file = _msa_filechooser.getSelectedFile();
1913 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1914 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1919 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1920 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1921 System.out.println( msa.toString() );
1924 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1927 catch ( final MsaFormatException e ) {
1929 _mainpanel.getCurrentTreePanel().setArrowCursor();
1931 catch ( final Exception ex ) {
1934 JOptionPane.showMessageDialog( this,
1935 e.getLocalizedMessage(),
1936 "Multiple sequence alignment format error",
1937 JOptionPane.ERROR_MESSAGE );
1940 catch ( final IOException e ) {
1942 _mainpanel.getCurrentTreePanel().setArrowCursor();
1944 catch ( final Exception ex ) {
1947 JOptionPane.showMessageDialog( this,
1948 e.getLocalizedMessage(),
1949 "Failed to read multiple sequence alignment",
1950 JOptionPane.ERROR_MESSAGE );
1953 catch ( final IllegalArgumentException e ) {
1955 _mainpanel.getCurrentTreePanel().setArrowCursor();
1957 catch ( final Exception ex ) {
1960 JOptionPane.showMessageDialog( this,
1961 e.getLocalizedMessage(),
1962 "Unexpected error during reading of multiple sequence alignment",
1963 JOptionPane.ERROR_MESSAGE );
1966 catch ( final Exception e ) {
1968 _mainpanel.getCurrentTreePanel().setArrowCursor();
1970 catch ( final Exception ex ) {
1973 e.printStackTrace();
1974 JOptionPane.showMessageDialog( this,
1975 e.getLocalizedMessage(),
1976 "Unexpected error during reading of multiple sequence alignment",
1977 JOptionPane.ERROR_MESSAGE );
1980 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1981 JOptionPane.showMessageDialog( this,
1982 "Multiple sequence alignment is empty",
1983 "Illegal Multiple Sequence Alignment",
1984 JOptionPane.ERROR_MESSAGE );
1987 if ( msa.getNumberOfSequences() < 4 ) {
1988 JOptionPane.showMessageDialog( this,
1989 "Multiple sequence alignment needs to contain at least 3 sequences",
1990 "Illegal multiple sequence alignment",
1991 JOptionPane.ERROR_MESSAGE );
1994 if ( msa.getLength() < 2 ) {
1995 JOptionPane.showMessageDialog( this,
1996 "Multiple sequence alignment needs to contain at least 2 residues",
1997 "Illegal multiple sequence alignment",
1998 JOptionPane.ERROR_MESSAGE );
2002 setMsaFile( _msa_filechooser.getSelectedFile() );
2008 void readPhylogeniesFromURL() {
2010 Phylogeny[] phys = null;
2011 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
2012 final String url_string = JOptionPane.showInputDialog( this,
2014 "Use URL/webservice to obtain a phylogeny",
2015 JOptionPane.QUESTION_MESSAGE );
2016 boolean nhx_or_nexus = false;
2017 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
2019 url = new URL( url_string );
2020 PhylogenyParser parser = null;
2021 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
2022 parser = new TolParser();
2025 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
2026 .isValidatePhyloXmlAgainstSchema() );
2028 if ( parser instanceof NexusPhylogeniesParser ) {
2029 nhx_or_nexus = true;
2031 else if ( parser instanceof NHXParser ) {
2032 nhx_or_nexus = true;
2034 if ( _mainpanel.getCurrentTreePanel() != null ) {
2035 _mainpanel.getCurrentTreePanel().setWaitCursor();
2038 _mainpanel.setWaitCursor();
2040 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2041 phys = factory.create( url.openStream(), parser );
2043 catch ( final MalformedURLException e ) {
2044 JOptionPane.showMessageDialog( this,
2045 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2047 JOptionPane.ERROR_MESSAGE );
2049 catch ( final IOException e ) {
2050 JOptionPane.showMessageDialog( this,
2051 "Could not read from " + url + "\n"
2052 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2053 "Failed to read URL",
2054 JOptionPane.ERROR_MESSAGE );
2056 catch ( final Exception e ) {
2057 JOptionPane.showMessageDialog( this,
2058 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2059 "Unexpected Exception",
2060 JOptionPane.ERROR_MESSAGE );
2063 if ( _mainpanel.getCurrentTreePanel() != null ) {
2064 _mainpanel.getCurrentTreePanel().setArrowCursor();
2067 _mainpanel.setArrowCursor();
2070 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2071 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2072 for( final Phylogeny phy : phys ) {
2073 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2076 Util.addPhylogeniesToTabs( phys,
2077 new File( url.getFile() ).getName(),
2078 new File( url.getFile() ).toString(),
2081 _mainpanel.getControlPanel().showWhole();
2084 activateSaveAllIfNeeded();
2088 private void readSpeciesTreeFromFile() {
2090 boolean exception = false;
2091 final File my_dir = getCurrentDir();
2092 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2093 if ( my_dir != null ) {
2094 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2096 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2097 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2098 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2099 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2101 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2104 catch ( final Exception e ) {
2106 exceptionOccuredDuringOpenFile( e );
2109 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2111 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2114 catch ( final Exception e ) {
2116 exceptionOccuredDuringOpenFile( e );
2122 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2125 catch ( final Exception e ) {
2127 exceptionOccuredDuringOpenFile( e );
2130 if ( !exception && ( t != null ) && !t.isRooted() ) {
2133 JOptionPane.showMessageDialog( this,
2134 "Species tree is not rooted",
2135 "Species tree not loaded",
2136 JOptionPane.ERROR_MESSAGE );
2138 if ( !exception && ( t != null ) ) {
2139 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2140 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2141 final PhylogenyNode node = it.next();
2142 if ( !node.getNodeData().isHasTaxonomy() ) {
2146 .showMessageDialog( this,
2147 "Species tree contains external node(s) without taxonomy information",
2148 "Species tree not loaded",
2149 JOptionPane.ERROR_MESSAGE );
2153 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2156 JOptionPane.showMessageDialog( this,
2158 + node.getNodeData().getTaxonomy().asSimpleText()
2159 + "] is not unique in species tree",
2160 "Species tree not loaded",
2161 JOptionPane.ERROR_MESSAGE );
2165 tax_set.add( node.getNodeData().getTaxonomy() );
2170 if ( !exception && ( t != null ) ) {
2172 JOptionPane.showMessageDialog( this,
2173 "Species tree successfully loaded",
2174 "Species tree loaded",
2175 JOptionPane.INFORMATION_MESSAGE );
2177 _contentpane.repaint();
2182 private void setCurrentDir( final File current_dir ) {
2183 _current_dir = current_dir;
2186 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2187 _min_not_collapse = min_not_collapse;
2190 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2191 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2194 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2195 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2196 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2197 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2198 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2200 nhx.setTaxonomyExtraction( te );
2203 private void writeAllToFile() {
2204 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2207 final File my_dir = getCurrentDir();
2208 if ( my_dir != null ) {
2209 _save_filechooser.setCurrentDirectory( my_dir );
2211 _save_filechooser.setSelectedFile( new File( "" ) );
2212 final int result = _save_filechooser.showSaveDialog( _contentpane );
2213 final File file = _save_filechooser.getSelectedFile();
2214 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2215 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2216 if ( file.exists() ) {
2217 final int i = JOptionPane.showConfirmDialog( this,
2218 file + " already exists. Overwrite?",
2220 JOptionPane.OK_CANCEL_OPTION,
2221 JOptionPane.WARNING_MESSAGE );
2222 if ( i != JOptionPane.OK_OPTION ) {
2229 catch ( final Exception e ) {
2230 JOptionPane.showMessageDialog( this,
2231 "Failed to delete: " + file,
2233 JOptionPane.WARNING_MESSAGE );
2237 final int count = getMainPanel().getTabbedPane().getTabCount();
2238 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2239 for( int i = 0; i < count; ++i ) {
2240 trees.add( getMainPanel().getPhylogeny( i ) );
2241 getMainPanel().getTreePanels().get( i ).setEdited( false );
2243 final PhylogenyWriter writer = new PhylogenyWriter();
2245 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2247 catch ( final IOException e ) {
2248 JOptionPane.showMessageDialog( this,
2249 "Failed to write to: " + file,
2251 JOptionPane.WARNING_MESSAGE );
2256 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2258 final PhylogenyWriter writer = new PhylogenyWriter();
2259 writer.toNewHampshire( t, false, true, file );
2261 catch ( final Exception e ) {
2263 exceptionOccuredDuringSaveAs( e );
2268 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2270 final PhylogenyWriter writer = new PhylogenyWriter();
2271 writer.toNexus( file, t );
2273 catch ( final Exception e ) {
2275 exceptionOccuredDuringSaveAs( e );
2280 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2282 final PhylogenyWriter writer = new PhylogenyWriter();
2283 writer.toNewHampshireX( t, file );
2285 catch ( final Exception e ) {
2287 exceptionOccuredDuringSaveAs( e );
2292 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2294 final PhylogenyWriter writer = new PhylogenyWriter();
2295 writer.toPhyloXML( file, t, 0 );
2297 catch ( final Exception e ) {
2299 exceptionOccuredDuringSaveAs( e );
2304 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2305 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2306 _mainpanel.getCurrentTreePanel().getHeight(),
2308 String file_written_to = "";
2309 boolean error = false;
2311 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2312 _mainpanel.getCurrentTreePanel().getWidth(),
2313 _mainpanel.getCurrentTreePanel().getHeight(),
2314 _mainpanel.getCurrentTreePanel(),
2315 _mainpanel.getControlPanel(),
2319 catch ( final IOException e ) {
2321 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2324 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2325 JOptionPane.showMessageDialog( this,
2326 "Wrote image to: " + file_written_to,
2328 JOptionPane.INFORMATION_MESSAGE );
2331 JOptionPane.showMessageDialog( this,
2332 "There was an unknown problem when attempting to write to an image file: \""
2335 JOptionPane.ERROR_MESSAGE );
2338 _contentpane.repaint();
2341 private void writeToFile( final Phylogeny t ) {
2345 String initial_filename = null;
2346 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2348 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2350 catch ( final IOException e ) {
2351 initial_filename = null;
2354 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2355 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2358 _save_filechooser.setSelectedFile( new File( "" ) );
2360 final File my_dir = getCurrentDir();
2361 if ( my_dir != null ) {
2362 _save_filechooser.setCurrentDirectory( my_dir );
2364 final int result = _save_filechooser.showSaveDialog( _contentpane );
2365 final File file = _save_filechooser.getSelectedFile();
2366 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2367 boolean exception = false;
2368 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2369 if ( file.exists() ) {
2370 final int i = JOptionPane.showConfirmDialog( this,
2371 file + " already exists.\nOverwrite?",
2373 JOptionPane.OK_CANCEL_OPTION,
2374 JOptionPane.QUESTION_MESSAGE );
2375 if ( i != JOptionPane.OK_OPTION ) {
2379 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2381 ForesterUtil.copyFile( file, to );
2383 catch ( final Exception e ) {
2384 JOptionPane.showMessageDialog( this,
2385 "Failed to create backup copy " + to,
2386 "Failed to Create Backup Copy",
2387 JOptionPane.WARNING_MESSAGE );
2392 catch ( final Exception e ) {
2393 JOptionPane.showMessageDialog( this,
2394 "Failed to delete: " + file,
2396 JOptionPane.WARNING_MESSAGE );
2400 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2401 exception = writeAsNewHampshire( t, exception, file );
2403 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2404 exception = writeAsNHX( t, exception, file );
2406 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2407 exception = writeAsPhyloXml( t, exception, file );
2409 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2410 exception = writeAsNexus( t, exception, file );
2414 final String file_name = file.getName().trim().toLowerCase();
2415 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2416 || file_name.endsWith( ".tree" ) ) {
2417 exception = writeAsNewHampshire( t, exception, file );
2419 else if ( file_name.endsWith( ".nhx" ) ) {
2420 exception = writeAsNHX( t, exception, file );
2422 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2423 exception = writeAsNexus( t, exception, file );
2427 exception = writeAsPhyloXml( t, exception, file );
2431 getMainPanel().setTitleOfSelectedTab( file.getName() );
2432 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2433 getMainPanel().getCurrentTreePanel().setEdited( false );
2438 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2439 if ( ( t == null ) || t.isEmpty() ) {
2442 String initial_filename = "";
2443 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2444 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2446 if ( initial_filename.indexOf( '.' ) > 0 ) {
2447 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2449 initial_filename = initial_filename + "." + type;
2450 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2451 final File my_dir = getCurrentDir();
2452 if ( my_dir != null ) {
2453 _writetographics_filechooser.setCurrentDirectory( my_dir );
2455 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2456 File file = _writetographics_filechooser.getSelectedFile();
2457 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2458 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2459 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2460 file = new File( file.toString() + "." + type );
2462 if ( file.exists() ) {
2463 final int i = JOptionPane.showConfirmDialog( this,
2464 file + " already exists. Overwrite?",
2466 JOptionPane.OK_CANCEL_OPTION,
2467 JOptionPane.WARNING_MESSAGE );
2468 if ( i != JOptionPane.OK_OPTION ) {
2475 catch ( final Exception e ) {
2476 JOptionPane.showMessageDialog( this,
2477 "Failed to delete: " + file,
2479 JOptionPane.WARNING_MESSAGE );
2483 writePhylogenyToGraphicsFile( file.toString(), type );
2487 private void writeToPdf( final Phylogeny t ) {
2488 if ( ( t == null ) || t.isEmpty() ) {
2491 String initial_filename = "";
2492 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2493 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2495 if ( initial_filename.indexOf( '.' ) > 0 ) {
2496 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2498 initial_filename = initial_filename + ".pdf";
2499 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2500 final File my_dir = getCurrentDir();
2501 if ( my_dir != null ) {
2502 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2504 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2505 File file = _writetopdf_filechooser.getSelectedFile();
2506 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2507 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2508 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2509 file = new File( file.toString() + ".pdf" );
2511 if ( file.exists() ) {
2512 final int i = JOptionPane.showConfirmDialog( this,
2513 file + " already exists. Overwrite?",
2515 JOptionPane.OK_CANCEL_OPTION,
2516 JOptionPane.WARNING_MESSAGE );
2517 if ( i != JOptionPane.OK_OPTION ) {
2521 printPhylogenyToPdf( file.toString() );
2525 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2526 return new MainFrameApplication( phys, config, title );
2529 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2530 return new MainFrameApplication( phys, config_file_name, title );
2533 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2534 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2535 + o.getPrintSizeY() + ")" );
2538 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2539 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2542 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2543 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2545 .showMessageDialog( null,
2547 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2550 JOptionPane.WARNING_MESSAGE );
2554 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2555 _phylogenetic_inference_options = phylogenetic_inference_options;
2558 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2559 if ( _phylogenetic_inference_options == null ) {
2560 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2562 return _phylogenetic_inference_options;
2565 public Msa getMsa() {
2569 void setMsa( final Msa msa ) {
2573 void setMsaFile( final File msa_file ) {
2574 _msa_file = msa_file;
2577 public File getMsaFile() {
2581 public List<Sequence> getSeqs() {
2585 void setSeqs( final List<Sequence> seqs ) {
2589 void setSeqsFile( final File seqs_file ) {
2590 _seqs_file = seqs_file;
2593 public File getSeqsFile() {
2596 } // MainFrameApplication.
2598 class NexusFilter extends FileFilter {
2601 public boolean accept( final File f ) {
2602 final String file_name = f.getName().trim().toLowerCase();
2603 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2604 || file_name.endsWith( ".tre" ) || f.isDirectory();
2608 public String getDescription() {
2609 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2613 class NHFilter extends FileFilter {
2616 public boolean accept( final File f ) {
2617 final String file_name = f.getName().trim().toLowerCase();
2618 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2619 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2620 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2625 public String getDescription() {
2626 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2630 class NHXFilter extends FileFilter {
2633 public boolean accept( final File f ) {
2634 final String file_name = f.getName().trim().toLowerCase();
2635 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2639 public String getDescription() {
2640 return "NHX files (*.nhx)";
2644 class PdfFilter extends FileFilter {
2647 public boolean accept( final File f ) {
2648 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2652 public String getDescription() {
2653 return "PDF files (*.pdf)";
2657 class TolFilter extends FileFilter {
2660 public boolean accept( final File f ) {
2661 final String file_name = f.getName().trim().toLowerCase();
2662 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2663 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2667 public String getDescription() {
2668 return "Tree of Life files (*.tol, *.tolxml)";
2672 class XMLFilter extends FileFilter {
2675 public boolean accept( final File f ) {
2676 final String file_name = f.getName().trim().toLowerCase();
2677 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2678 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2682 public String getDescription() {
2683 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";