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( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
840 customizeJMenuItem( _color_rank_jmi );
841 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
842 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
843 customizeJMenuItem( _taxcolor_item );
844 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
845 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
846 customizeJMenuItem( _remove_branch_color_item );
847 _tools_menu.addSeparator();
848 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
849 customizeJMenuItem( _midpoint_root_item );
850 _tools_menu.addSeparator();
851 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
852 customizeJMenuItem( _collapse_species_specific_subtrees );
854 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
855 customizeJMenuItem( _collapse_below_threshold );
856 _collapse_below_threshold
857 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
858 _tools_menu.addSeparator();
860 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
861 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
862 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
863 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
864 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
865 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
867 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
868 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
869 _extract_tax_code_from_node_names_jmi
870 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
871 _tools_menu.addSeparator();
873 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
874 customizeJMenuItem( _infer_common_sn_names_item );
875 _tools_menu.addSeparator();
877 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
878 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
879 _obtain_detailed_taxonomic_information_jmi
880 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
882 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
883 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
884 _obtain_detailed_taxonomic_information_deleting_jmi
885 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
887 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
888 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
889 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
890 _tools_menu.addSeparator();
891 if ( !Constants.__RELEASE ) {
892 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
893 customizeJMenuItem( _function_analysis );
895 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
896 _tools_menu.addSeparator();
898 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
899 customizeJMenuItem( _read_values_jmi );
900 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
901 _jmenubar.add( _tools_menu );
904 private void choosePdfWidth() {
905 final String s = ( String ) JOptionPane.showInputDialog( this,
906 "Please enter the default line width for PDF export.\n"
908 + getOptions().getPrintLineWidth() + "]\n",
909 "Line Width for PDF Export",
910 JOptionPane.QUESTION_MESSAGE,
913 getOptions().getPrintLineWidth() );
914 if ( !ForesterUtil.isEmpty( s ) ) {
915 boolean success = true;
917 final String m_str = s.trim();
918 if ( !ForesterUtil.isEmpty( m_str ) ) {
920 f = Float.parseFloat( m_str );
922 catch ( final Exception ex ) {
929 if ( success && ( f > 0.0 ) ) {
930 getOptions().setPrintLineWidth( f );
935 private void choosePrintSize() {
936 final String s = ( String ) JOptionPane.showInputDialog( this,
937 "Please enter values for width and height,\nseparated by a comma.\n"
938 + "[current values: "
939 + getOptions().getPrintSizeX() + ", "
940 + getOptions().getPrintSizeY() + "]\n"
941 + "[A4: " + Constants.A4_SIZE_X + ", "
942 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
943 + Constants.US_LETTER_SIZE_X + ", "
944 + Constants.US_LETTER_SIZE_Y + "]",
945 "Default Size for Graphics Export",
946 JOptionPane.QUESTION_MESSAGE,
949 getOptions().getPrintSizeX() + ", "
950 + getOptions().getPrintSizeY() );
951 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
952 boolean success = true;
955 final String[] str_ary = s.split( "," );
956 if ( str_ary.length == 2 ) {
957 final String x_str = str_ary[ 0 ].trim();
958 final String y_str = str_ary[ 1 ].trim();
959 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
961 x = Integer.parseInt( x_str );
962 y = Integer.parseInt( y_str );
964 catch ( final Exception ex ) {
975 if ( success && ( x > 1 ) && ( y > 1 ) ) {
976 getOptions().setPrintSizeX( x );
977 getOptions().setPrintSizeY( y );
984 if ( isUnsavedDataPresent() ) {
985 final int r = JOptionPane.showConfirmDialog( this,
986 "Exit despite potentially unsaved changes?",
988 JOptionPane.YES_NO_OPTION );
989 if ( r != JOptionPane.YES_OPTION ) {
996 private void closeCurrentPane() {
997 if ( getMainPanel().getCurrentTreePanel() != null ) {
998 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
999 final int r = JOptionPane.showConfirmDialog( this,
1000 "Close tab despite potentially unsaved changes?",
1002 JOptionPane.YES_NO_OPTION );
1003 if ( r != JOptionPane.YES_OPTION ) {
1007 getMainPanel().closeCurrentPane();
1008 activateSaveAllIfNeeded();
1012 private void collapse( final Phylogeny phy, final double m ) {
1013 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1014 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1015 double min_support = Double.MAX_VALUE;
1016 boolean conf_present = false;
1017 while ( it.hasNext() ) {
1018 final PhylogenyNode n = it.next();
1019 if ( !n.isExternal() && !n.isRoot() ) {
1020 final List<Confidence> c = n.getBranchData().getConfidences();
1021 if ( ( c != null ) && ( c.size() > 0 ) ) {
1022 conf_present = true;
1024 for( final Confidence confidence : c ) {
1025 if ( confidence.getValue() > max ) {
1026 max = confidence.getValue();
1029 if ( max < getMinNotCollapseConfidenceValue() ) {
1030 to_be_removed.add( n );
1032 if ( max < min_support ) {
1038 if ( conf_present ) {
1039 for( final PhylogenyNode node : to_be_removed ) {
1040 PhylogenyMethods.removeNode( node, phy );
1042 if ( to_be_removed.size() > 0 ) {
1043 phy.externalNodesHaveChanged();
1045 phy.recalculateNumberOfExternalDescendants( true );
1046 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1047 getCurrentTreePanel().setEdited( true );
1048 getCurrentTreePanel().repaint();
1050 if ( to_be_removed.size() > 0 ) {
1051 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1052 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1053 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1056 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1057 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1061 JOptionPane.showMessageDialog( this,
1062 "No branch collapsed because no confidence values present",
1063 "No confidence values present",
1064 JOptionPane.INFORMATION_MESSAGE );
1068 private void collapseBelowThreshold() {
1069 if ( getCurrentTreePanel() != null ) {
1070 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1071 if ( ( phy != null ) && !phy.isEmpty() ) {
1072 final String s = ( String ) JOptionPane.showInputDialog( this,
1073 "Please enter the minimum confidence value\n",
1074 "Minimal Confidence Value",
1075 JOptionPane.QUESTION_MESSAGE,
1078 getMinNotCollapseConfidenceValue() );
1079 if ( !ForesterUtil.isEmpty( s ) ) {
1080 boolean success = true;
1082 final String m_str = s.trim();
1083 if ( !ForesterUtil.isEmpty( m_str ) ) {
1085 m = Double.parseDouble( m_str );
1087 catch ( final Exception ex ) {
1094 if ( success && ( m >= 0.0 ) ) {
1095 setMinNotCollapseConfidenceValue( m );
1103 private PhyloXmlParser createPhyloXmlParser() {
1104 PhyloXmlParser xml_parser = null;
1105 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1107 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1109 catch ( final Exception e ) {
1110 JOptionPane.showMessageDialog( this,
1111 e.getLocalizedMessage(),
1112 "failed to create validating XML parser",
1113 JOptionPane.WARNING_MESSAGE );
1116 if ( xml_parser == null ) {
1117 xml_parser = new PhyloXmlParser();
1122 void executeGSDI() {
1123 if ( !isOKforSDI( false, true ) ) {
1126 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1127 JOptionPane.showMessageDialog( this,
1128 "Gene tree is not rooted.",
1129 "Cannot execute GSDI",
1130 JOptionPane.ERROR_MESSAGE );
1133 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1134 gene_tree.setAllNodesToNotCollapse();
1135 gene_tree.recalculateNumberOfExternalDescendants( false );
1137 int duplications = -1;
1139 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1140 duplications = gsdi.getDuplicationsSum();
1142 catch ( final Exception e ) {
1143 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1145 gene_tree.setRerootable( false );
1146 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1147 getControlPanel().setShowEvents( true );
1149 _mainpanel.getCurrentTreePanel().setEdited( true );
1150 JOptionPane.showMessageDialog( this,
1151 "Number of duplications: " + duplications,
1152 "GSDI successfully completed",
1153 JOptionPane.INFORMATION_MESSAGE );
1156 void executeFunctionAnalysis() {
1157 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1160 final GoAnnotation a = new GoAnnotation( this,
1161 _mainpanel.getCurrentTreePanel(),
1162 _mainpanel.getCurrentPhylogeny() );
1163 new Thread( a ).start();
1166 void executeLineageInference() {
1167 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1170 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1171 JOptionPane.showMessageDialog( this,
1172 "Phylogeny is not rooted.",
1173 "Cannot infer ancestral taxonomies",
1174 JOptionPane.ERROR_MESSAGE );
1177 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1178 _mainpanel.getCurrentTreePanel(),
1179 _mainpanel.getCurrentPhylogeny()
1181 new Thread( inferrer ).start();
1184 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1185 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1186 getPhylogeneticInferenceOptions(),
1187 from_unaligned_seqs );
1189 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1190 if ( !from_unaligned_seqs ) {
1191 if ( getMsa() != null ) {
1192 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1193 getPhylogeneticInferenceOptions()
1195 new Thread( inferrer ).start();
1198 JOptionPane.showMessageDialog( this,
1199 "No multiple sequence alignment selected",
1200 "Phylogenetic Inference Not Launched",
1201 JOptionPane.WARNING_MESSAGE );
1205 if ( getSeqs() != null ) {
1206 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1207 getPhylogeneticInferenceOptions()
1209 new Thread( inferrer ).start();
1212 JOptionPane.showMessageDialog( this,
1213 "No input sequences selected",
1214 "Phylogenetic Inference Not Launched",
1215 JOptionPane.WARNING_MESSAGE );
1222 if ( !isOKforSDI( true, true ) ) {
1225 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1226 JOptionPane.showMessageDialog( this,
1227 "Gene tree is not rooted",
1228 "Cannot execute SDI",
1229 JOptionPane.ERROR_MESSAGE );
1232 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1233 gene_tree.setAllNodesToNotCollapse();
1234 gene_tree.recalculateNumberOfExternalDescendants( false );
1236 int duplications = -1;
1238 sdi = new SDIse( gene_tree, _species_tree.copy() );
1239 duplications = sdi.getDuplicationsSum();
1241 catch ( final Exception e ) {
1242 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
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 "SDI successfully completed",
1252 JOptionPane.INFORMATION_MESSAGE );
1255 void executeSDIR( final boolean minimize_cost ) {
1256 if ( !isOKforSDI( true, true ) ) {
1259 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1260 final SDIR sdiunrooted = new SDIR();
1261 gene_tree.setAllNodesToNotCollapse();
1262 gene_tree.recalculateNumberOfExternalDescendants( false );
1264 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1265 !minimize_cost, // minimize sum of dups
1266 true, // minimize height
1267 true, // return tree(s)
1268 1 )[ 0 ]; // # of trees to return
1270 catch ( final Exception e ) {
1271 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1274 final int duplications = sdiunrooted.getMinimalDuplications();
1275 gene_tree.setRerootable( false );
1276 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1277 getControlPanel().setShowEvents( true );
1279 _mainpanel.getCurrentTreePanel().setEdited( true );
1280 JOptionPane.showMessageDialog( this,
1281 "Number of duplications: " + duplications,
1282 "SDIR successfully completed",
1283 JOptionPane.INFORMATION_MESSAGE );
1288 _mainpanel.terminate();
1289 _contentpane.removeAll();
1290 setVisible( false );
1295 private void extractTaxCodeFromNodeNames() {
1296 if ( getCurrentTreePanel() != null ) {
1297 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1298 if ( ( phy != null ) && !phy.isEmpty() ) {
1299 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1300 while ( it.hasNext() ) {
1301 final PhylogenyNode n = it.next();
1302 final String name = n.getName().trim();
1303 if ( !ForesterUtil.isEmpty( name ) ) {
1304 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1306 TAXONOMY_EXTRACTION.YES );
1307 if ( !ForesterUtil.isEmpty( code ) ) {
1308 PhylogenyMethods.setTaxonomyCode( n, code );
1316 private ControlPanel getControlPanel() {
1317 return getMainPanel().getControlPanel();
1320 private File getCurrentDir() {
1321 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1322 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1324 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1326 catch ( final Exception e ) {
1327 _current_dir = null;
1331 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1332 if ( System.getProperty( "user.home" ) != null ) {
1333 _current_dir = new File( System.getProperty( "user.home" ) );
1335 else if ( System.getProperty( "user.dir" ) != null ) {
1336 _current_dir = new File( System.getProperty( "user.dir" ) );
1339 return _current_dir;
1343 public MainPanel getMainPanel() {
1347 private double getMinNotCollapseConfidenceValue() {
1348 return _min_not_collapse;
1351 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1352 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1355 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1356 JOptionPane.showMessageDialog( this,
1357 "No species tree loaded",
1358 "Cannot execute SDI",
1359 JOptionPane.ERROR_MESSAGE );
1362 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1363 JOptionPane.showMessageDialog( this,
1364 "Species tree is not completely binary",
1365 "Cannot execute SDI",
1366 JOptionPane.ERROR_MESSAGE );
1369 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1370 JOptionPane.showMessageDialog( this,
1371 "Gene tree is not completely binary",
1372 "Cannot execute SDI",
1373 JOptionPane.ERROR_MESSAGE );
1381 private boolean isUnsavedDataPresent() {
1382 final List<TreePanel> tps = getMainPanel().getTreePanels();
1383 for( final TreePanel tp : tps ) {
1384 if ( tp.isEdited() ) {
1391 private void moveNodeNamesToSeqNames() {
1392 if ( getCurrentTreePanel() != null ) {
1393 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1394 if ( ( phy != null ) && !phy.isEmpty() ) {
1395 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1400 private void moveNodeNamesToTaxSn() {
1401 if ( getCurrentTreePanel() != null ) {
1402 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1403 if ( ( phy != null ) && !phy.isEmpty() ) {
1404 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1409 private void newTree() {
1410 final Phylogeny[] phys = new Phylogeny[ 1 ];
1411 final Phylogeny phy = new Phylogeny();
1412 final PhylogenyNode node = new PhylogenyNode();
1413 phy.setRoot( node );
1414 phy.setRooted( true );
1416 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1417 _mainpanel.getControlPanel().showWhole();
1418 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1419 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1420 if ( getMainPanel().getMainFrame() == null ) {
1421 // Must be "E" applet version.
1422 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1423 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1426 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1428 activateSaveAllIfNeeded();
1432 private void obtainDetailedTaxonomicInformation() {
1433 if ( getCurrentTreePanel() != null ) {
1434 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1435 if ( ( phy != null ) && !phy.isEmpty() ) {
1436 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1437 _mainpanel.getCurrentTreePanel(),
1439 new Thread( t ).start();
1444 private void obtainDetailedTaxonomicInformationDelete() {
1445 if ( getCurrentTreePanel() != null ) {
1446 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1447 if ( ( phy != null ) && !phy.isEmpty() ) {
1448 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1449 _mainpanel.getCurrentTreePanel(),
1452 new Thread( t ).start();
1457 private void obtainUniProtSequenceInformation() {
1458 if ( getCurrentTreePanel() != null ) {
1459 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1460 if ( ( phy != null ) && !phy.isEmpty() ) {
1461 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1462 _mainpanel.getCurrentTreePanel(),
1464 new Thread( u ).start();
1469 private void print() {
1470 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1471 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1474 if ( !getOptions().isPrintUsingActualSize() ) {
1475 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1476 getOptions().getPrintSizeY() - 140,
1478 getCurrentTreePanel().resetPreferredSize();
1479 getCurrentTreePanel().repaint();
1481 final String job_name = Constants.PRG_NAME;
1482 boolean error = false;
1483 String printer_name = null;
1485 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1487 catch ( final Exception e ) {
1489 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1491 if ( !error && ( printer_name != null ) ) {
1492 String msg = "Printing data sent to printer";
1493 if ( printer_name.length() > 1 ) {
1494 msg += " [" + printer_name + "]";
1496 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1498 if ( !getOptions().isPrintUsingActualSize() ) {
1499 getControlPanel().showWhole();
1503 private void printPhylogenyToPdf( final String file_name ) {
1504 if ( !getOptions().isPrintUsingActualSize() ) {
1505 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1506 getOptions().getPrintSizeY(),
1508 getCurrentTreePanel().resetPreferredSize();
1509 getCurrentTreePanel().repaint();
1511 String pdf_written_to = "";
1512 boolean error = false;
1514 if ( getOptions().isPrintUsingActualSize() ) {
1515 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1516 getCurrentTreePanel(),
1517 getCurrentTreePanel().getWidth(),
1518 getCurrentTreePanel().getHeight() );
1521 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1522 .getPrintSizeX(), getOptions().getPrintSizeY() );
1525 catch ( final IOException e ) {
1527 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1530 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1531 JOptionPane.showMessageDialog( this,
1532 "Wrote PDF to: " + pdf_written_to,
1534 JOptionPane.INFORMATION_MESSAGE );
1537 JOptionPane.showMessageDialog( this,
1538 "There was an unknown problem when attempting to write to PDF file: \""
1541 JOptionPane.ERROR_MESSAGE );
1544 if ( !getOptions().isPrintUsingActualSize() ) {
1545 getControlPanel().showWhole();
1549 private void addExpressionValuesFromFile() {
1550 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1551 JOptionPane.showMessageDialog( this,
1552 "Need to load evolutionary tree first",
1553 "Can Not Read Expression Values",
1554 JOptionPane.WARNING_MESSAGE );
1557 final File my_dir = getCurrentDir();
1558 if ( my_dir != null ) {
1559 _values_filechooser.setCurrentDirectory( my_dir );
1561 final int result = _values_filechooser.showOpenDialog( _contentpane );
1562 final File file = _values_filechooser.getSelectedFile();
1563 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1564 BasicTable<String> t = null;
1566 t = BasicTableParser.parse( file, "\t" );
1567 if ( t.getNumberOfColumns() < 2 ) {
1568 t = BasicTableParser.parse( file, "," );
1570 if ( t.getNumberOfColumns() < 2 ) {
1571 t = BasicTableParser.parse( file, " " );
1574 catch ( final IOException e ) {
1575 JOptionPane.showMessageDialog( this,
1577 "Could Not Read Expression Value Table",
1578 JOptionPane.ERROR_MESSAGE );
1581 if ( t.getNumberOfColumns() < 2 ) {
1582 JOptionPane.showMessageDialog( this,
1583 "Table contains " + t.getNumberOfColumns() + " column(s)",
1584 "Problem with Expression Value Table",
1585 JOptionPane.ERROR_MESSAGE );
1588 if ( t.getNumberOfRows() < 1 ) {
1589 JOptionPane.showMessageDialog( this,
1590 "Table contains zero rows",
1591 "Problem with Expression Value Table",
1592 JOptionPane.ERROR_MESSAGE );
1595 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1596 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1597 JOptionPane.showMessageDialog( this,
1598 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1599 + phy.getNumberOfExternalNodes() + " external nodes",
1601 JOptionPane.WARNING_MESSAGE );
1603 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1605 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1606 final PhylogenyNode node = iter.next();
1607 final String node_name = node.getName();
1608 if ( !ForesterUtil.isEmpty( node_name ) ) {
1611 row = t.findRow( node_name );
1613 catch ( final IllegalArgumentException e ) {
1615 .showMessageDialog( this,
1617 "Error Mapping Node Identifiers to Expression Value Identifiers",
1618 JOptionPane.ERROR_MESSAGE );
1622 if ( node.isExternal() ) {
1627 final List<Double> l = new ArrayList<Double>();
1628 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1631 d = Double.parseDouble( t.getValueAsString( col, row ) );
1633 catch ( final NumberFormatException e ) {
1634 JOptionPane.showMessageDialog( this,
1635 "Could not parse \"" + t.getValueAsString( col, row )
1636 + "\" into a decimal value",
1637 "Issue with Expression Value Table",
1638 JOptionPane.ERROR_MESSAGE );
1641 stats.addValue( d );
1644 if ( !l.isEmpty() ) {
1645 if ( node.getNodeData().getProperties() != null ) {
1646 node.getNodeData().getProperties()
1647 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1649 node.getNodeData().setVector( l );
1653 if ( not_found > 0 ) {
1654 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1655 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1657 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1661 private void readPhylogeniesFromFile() {
1662 boolean exception = false;
1663 Phylogeny[] phys = null;
1664 // Set an initial directory if none set yet
1665 final File my_dir = getCurrentDir();
1666 _open_filechooser.setMultiSelectionEnabled( true );
1667 // Open file-open dialog and set current directory
1668 if ( my_dir != null ) {
1669 _open_filechooser.setCurrentDirectory( my_dir );
1671 final int result = _open_filechooser.showOpenDialog( _contentpane );
1672 // All done: get the file
1673 final File[] files = _open_filechooser.getSelectedFiles();
1674 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1675 boolean nhx_or_nexus = false;
1676 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1677 for( final File file : files ) {
1678 if ( ( file != null ) && !file.isDirectory() ) {
1679 if ( _mainpanel.getCurrentTreePanel() != null ) {
1680 _mainpanel.getCurrentTreePanel().setWaitCursor();
1683 _mainpanel.setWaitCursor();
1685 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1686 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1688 final NHXParser nhx = new NHXParser();
1689 setSpecialOptionsForNhxParser( nhx );
1690 phys = ForesterUtil.readPhylogenies( nhx, file );
1691 nhx_or_nexus = true;
1693 catch ( final Exception e ) {
1695 exceptionOccuredDuringOpenFile( e );
1698 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1699 warnIfNotPhyloXmlValidation( getConfiguration() );
1701 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1702 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1704 catch ( final Exception e ) {
1706 exceptionOccuredDuringOpenFile( e );
1709 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1711 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1713 catch ( final Exception e ) {
1715 exceptionOccuredDuringOpenFile( e );
1718 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1720 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1721 setSpecialOptionsForNexParser( nex );
1722 phys = ForesterUtil.readPhylogenies( nex, file );
1723 nhx_or_nexus = true;
1725 catch ( final Exception e ) {
1727 exceptionOccuredDuringOpenFile( e );
1733 final PhylogenyParser parser = ForesterUtil
1734 .createParserDependingOnFileType( file, getConfiguration()
1735 .isValidatePhyloXmlAgainstSchema() );
1736 if ( parser instanceof NexusPhylogeniesParser ) {
1737 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1738 setSpecialOptionsForNexParser( nex );
1739 nhx_or_nexus = true;
1741 else if ( parser instanceof NHXParser ) {
1742 final NHXParser nhx = ( NHXParser ) parser;
1743 setSpecialOptionsForNhxParser( nhx );
1744 nhx_or_nexus = true;
1746 else if ( parser instanceof PhyloXmlParser ) {
1747 warnIfNotPhyloXmlValidation( getConfiguration() );
1749 phys = ForesterUtil.readPhylogenies( parser, file );
1751 catch ( final Exception e ) {
1753 exceptionOccuredDuringOpenFile( e );
1756 if ( _mainpanel.getCurrentTreePanel() != null ) {
1757 _mainpanel.getCurrentTreePanel().setArrowCursor();
1760 _mainpanel.setArrowCursor();
1762 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1763 boolean one_desc = false;
1764 if ( nhx_or_nexus ) {
1765 for( final Phylogeny phy : phys ) {
1766 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1767 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1769 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1775 Util.addPhylogeniesToTabs( phys,
1777 file.getAbsolutePath(),
1780 _mainpanel.getControlPanel().showWhole();
1781 if ( nhx_or_nexus && one_desc ) {
1783 .showMessageDialog( this,
1784 "One or more trees contain (a) node(s) with one descendant, "
1785 + ForesterUtil.LINE_SEPARATOR
1786 + "possibly indicating illegal parentheses within node names.",
1787 "Warning: Possible Error in New Hampshire Formatted Data",
1788 JOptionPane.WARNING_MESSAGE );
1794 activateSaveAllIfNeeded();
1798 public void readSeqsFromFile() {
1799 // Set an initial directory if none set yet
1800 final File my_dir = getCurrentDir();
1801 _seqs_filechooser.setMultiSelectionEnabled( false );
1802 // Open file-open dialog and set current directory
1803 if ( my_dir != null ) {
1804 _seqs_filechooser.setCurrentDirectory( my_dir );
1806 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1807 // All done: get the seqs
1808 final File file = _seqs_filechooser.getSelectedFile();
1809 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1810 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1811 setSeqsFile( null );
1813 List<Sequence> seqs = null;
1815 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1816 seqs = FastaParser.parse( new FileInputStream( file ) );
1817 for( final Sequence seq : seqs ) {
1818 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1825 catch ( final MsaFormatException e ) {
1827 _mainpanel.getCurrentTreePanel().setArrowCursor();
1829 catch ( final Exception ex ) {
1832 JOptionPane.showMessageDialog( this,
1833 e.getLocalizedMessage(),
1834 "Multiple sequence file format error",
1835 JOptionPane.ERROR_MESSAGE );
1838 catch ( final IOException e ) {
1840 _mainpanel.getCurrentTreePanel().setArrowCursor();
1842 catch ( final Exception ex ) {
1845 JOptionPane.showMessageDialog( this,
1846 e.getLocalizedMessage(),
1847 "Failed to read multiple sequence file",
1848 JOptionPane.ERROR_MESSAGE );
1851 catch ( final IllegalArgumentException e ) {
1853 _mainpanel.getCurrentTreePanel().setArrowCursor();
1855 catch ( final Exception ex ) {
1858 JOptionPane.showMessageDialog( this,
1859 e.getLocalizedMessage(),
1860 "Unexpected error during reading of multiple sequence file",
1861 JOptionPane.ERROR_MESSAGE );
1864 catch ( final Exception e ) {
1866 _mainpanel.getCurrentTreePanel().setArrowCursor();
1868 catch ( final Exception ex ) {
1871 e.printStackTrace();
1872 JOptionPane.showMessageDialog( this,
1873 e.getLocalizedMessage(),
1874 "Unexpected error during reading of multiple sequence file",
1875 JOptionPane.ERROR_MESSAGE );
1878 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1879 JOptionPane.showMessageDialog( this,
1880 "Multiple sequence file is empty",
1881 "Illegal multiple sequence file",
1882 JOptionPane.ERROR_MESSAGE );
1885 if ( seqs.size() < 4 ) {
1886 JOptionPane.showMessageDialog( this,
1887 "Multiple sequence file needs to contain at least 3 sequences",
1888 "Illegal multiple sequence file",
1889 JOptionPane.ERROR_MESSAGE );
1892 // if ( msa.getLength() < 2 ) {
1893 // JOptionPane.showMessageDialog( this,
1894 // "Multiple sequence alignment needs to contain at least 2 residues",
1895 // "Illegal multiple sequence file",
1896 // JOptionPane.ERROR_MESSAGE );
1900 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1905 public void readMsaFromFile() {
1906 // Set an initial directory if none set yet
1907 final File my_dir = getCurrentDir();
1908 _msa_filechooser.setMultiSelectionEnabled( false );
1909 // Open file-open dialog and set current directory
1910 if ( my_dir != null ) {
1911 _msa_filechooser.setCurrentDirectory( my_dir );
1913 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1914 // All done: get the msa
1915 final File file = _msa_filechooser.getSelectedFile();
1916 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1917 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1922 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1923 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1924 System.out.println( msa.toString() );
1927 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1930 catch ( final MsaFormatException e ) {
1932 _mainpanel.getCurrentTreePanel().setArrowCursor();
1934 catch ( final Exception ex ) {
1937 JOptionPane.showMessageDialog( this,
1938 e.getLocalizedMessage(),
1939 "Multiple sequence alignment format error",
1940 JOptionPane.ERROR_MESSAGE );
1943 catch ( final IOException e ) {
1945 _mainpanel.getCurrentTreePanel().setArrowCursor();
1947 catch ( final Exception ex ) {
1950 JOptionPane.showMessageDialog( this,
1951 e.getLocalizedMessage(),
1952 "Failed to read multiple sequence alignment",
1953 JOptionPane.ERROR_MESSAGE );
1956 catch ( final IllegalArgumentException e ) {
1958 _mainpanel.getCurrentTreePanel().setArrowCursor();
1960 catch ( final Exception ex ) {
1963 JOptionPane.showMessageDialog( this,
1964 e.getLocalizedMessage(),
1965 "Unexpected error during reading of multiple sequence alignment",
1966 JOptionPane.ERROR_MESSAGE );
1969 catch ( final Exception e ) {
1971 _mainpanel.getCurrentTreePanel().setArrowCursor();
1973 catch ( final Exception ex ) {
1976 e.printStackTrace();
1977 JOptionPane.showMessageDialog( this,
1978 e.getLocalizedMessage(),
1979 "Unexpected error during reading of multiple sequence alignment",
1980 JOptionPane.ERROR_MESSAGE );
1983 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1984 JOptionPane.showMessageDialog( this,
1985 "Multiple sequence alignment is empty",
1986 "Illegal Multiple Sequence Alignment",
1987 JOptionPane.ERROR_MESSAGE );
1990 if ( msa.getNumberOfSequences() < 4 ) {
1991 JOptionPane.showMessageDialog( this,
1992 "Multiple sequence alignment needs to contain at least 3 sequences",
1993 "Illegal multiple sequence alignment",
1994 JOptionPane.ERROR_MESSAGE );
1997 if ( msa.getLength() < 2 ) {
1998 JOptionPane.showMessageDialog( this,
1999 "Multiple sequence alignment needs to contain at least 2 residues",
2000 "Illegal multiple sequence alignment",
2001 JOptionPane.ERROR_MESSAGE );
2005 setMsaFile( _msa_filechooser.getSelectedFile() );
2011 void readPhylogeniesFromURL() {
2013 Phylogeny[] phys = null;
2014 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
2015 final String url_string = JOptionPane.showInputDialog( this,
2017 "Use URL/webservice to obtain a phylogeny",
2018 JOptionPane.QUESTION_MESSAGE );
2019 boolean nhx_or_nexus = false;
2020 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
2022 url = new URL( url_string );
2023 PhylogenyParser parser = null;
2024 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
2025 parser = new TolParser();
2028 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
2029 .isValidatePhyloXmlAgainstSchema() );
2031 if ( parser instanceof NexusPhylogeniesParser ) {
2032 nhx_or_nexus = true;
2034 else if ( parser instanceof NHXParser ) {
2035 nhx_or_nexus = true;
2037 if ( _mainpanel.getCurrentTreePanel() != null ) {
2038 _mainpanel.getCurrentTreePanel().setWaitCursor();
2041 _mainpanel.setWaitCursor();
2043 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2044 phys = factory.create( url.openStream(), parser );
2046 catch ( final MalformedURLException e ) {
2047 JOptionPane.showMessageDialog( this,
2048 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2050 JOptionPane.ERROR_MESSAGE );
2052 catch ( final IOException e ) {
2053 JOptionPane.showMessageDialog( this,
2054 "Could not read from " + url + "\n"
2055 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2056 "Failed to read URL",
2057 JOptionPane.ERROR_MESSAGE );
2059 catch ( final Exception e ) {
2060 JOptionPane.showMessageDialog( this,
2061 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2062 "Unexpected Exception",
2063 JOptionPane.ERROR_MESSAGE );
2066 if ( _mainpanel.getCurrentTreePanel() != null ) {
2067 _mainpanel.getCurrentTreePanel().setArrowCursor();
2070 _mainpanel.setArrowCursor();
2073 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2074 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2075 for( final Phylogeny phy : phys ) {
2076 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2079 Util.addPhylogeniesToTabs( phys,
2080 new File( url.getFile() ).getName(),
2081 new File( url.getFile() ).toString(),
2084 _mainpanel.getControlPanel().showWhole();
2087 activateSaveAllIfNeeded();
2091 private void readSpeciesTreeFromFile() {
2093 boolean exception = false;
2094 final File my_dir = getCurrentDir();
2095 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2096 if ( my_dir != null ) {
2097 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2099 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2100 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2101 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2102 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2104 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2107 catch ( final Exception e ) {
2109 exceptionOccuredDuringOpenFile( e );
2112 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2114 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2117 catch ( final Exception e ) {
2119 exceptionOccuredDuringOpenFile( e );
2125 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2128 catch ( final Exception e ) {
2130 exceptionOccuredDuringOpenFile( e );
2133 if ( !exception && ( t != null ) && !t.isRooted() ) {
2136 JOptionPane.showMessageDialog( this,
2137 "Species tree is not rooted",
2138 "Species tree not loaded",
2139 JOptionPane.ERROR_MESSAGE );
2141 if ( !exception && ( t != null ) ) {
2142 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2143 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2144 final PhylogenyNode node = it.next();
2145 if ( !node.getNodeData().isHasTaxonomy() ) {
2149 .showMessageDialog( this,
2150 "Species tree contains external node(s) without taxonomy information",
2151 "Species tree not loaded",
2152 JOptionPane.ERROR_MESSAGE );
2156 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2159 JOptionPane.showMessageDialog( this,
2161 + node.getNodeData().getTaxonomy().asSimpleText()
2162 + "] is not unique in species tree",
2163 "Species tree not loaded",
2164 JOptionPane.ERROR_MESSAGE );
2168 tax_set.add( node.getNodeData().getTaxonomy() );
2173 if ( !exception && ( t != null ) ) {
2175 JOptionPane.showMessageDialog( this,
2176 "Species tree successfully loaded",
2177 "Species tree loaded",
2178 JOptionPane.INFORMATION_MESSAGE );
2180 _contentpane.repaint();
2185 private void setCurrentDir( final File current_dir ) {
2186 _current_dir = current_dir;
2189 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2190 _min_not_collapse = min_not_collapse;
2193 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2194 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2197 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2198 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2199 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2200 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2201 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2203 nhx.setTaxonomyExtraction( te );
2206 private void writeAllToFile() {
2207 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2210 final File my_dir = getCurrentDir();
2211 if ( my_dir != null ) {
2212 _save_filechooser.setCurrentDirectory( my_dir );
2214 _save_filechooser.setSelectedFile( new File( "" ) );
2215 final int result = _save_filechooser.showSaveDialog( _contentpane );
2216 final File file = _save_filechooser.getSelectedFile();
2217 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2218 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2219 if ( file.exists() ) {
2220 final int i = JOptionPane.showConfirmDialog( this,
2221 file + " already exists. Overwrite?",
2223 JOptionPane.OK_CANCEL_OPTION,
2224 JOptionPane.WARNING_MESSAGE );
2225 if ( i != JOptionPane.OK_OPTION ) {
2232 catch ( final Exception e ) {
2233 JOptionPane.showMessageDialog( this,
2234 "Failed to delete: " + file,
2236 JOptionPane.WARNING_MESSAGE );
2240 final int count = getMainPanel().getTabbedPane().getTabCount();
2241 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2242 for( int i = 0; i < count; ++i ) {
2243 trees.add( getMainPanel().getPhylogeny( i ) );
2244 getMainPanel().getTreePanels().get( i ).setEdited( false );
2246 final PhylogenyWriter writer = new PhylogenyWriter();
2248 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2250 catch ( final IOException e ) {
2251 JOptionPane.showMessageDialog( this,
2252 "Failed to write to: " + file,
2254 JOptionPane.WARNING_MESSAGE );
2259 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2261 final PhylogenyWriter writer = new PhylogenyWriter();
2262 writer.toNewHampshire( t, false, true, file );
2264 catch ( final Exception e ) {
2266 exceptionOccuredDuringSaveAs( e );
2271 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2273 final PhylogenyWriter writer = new PhylogenyWriter();
2274 writer.toNexus( file, t );
2276 catch ( final Exception e ) {
2278 exceptionOccuredDuringSaveAs( e );
2283 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2285 final PhylogenyWriter writer = new PhylogenyWriter();
2286 writer.toNewHampshireX( t, file );
2288 catch ( final Exception e ) {
2290 exceptionOccuredDuringSaveAs( e );
2295 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2297 final PhylogenyWriter writer = new PhylogenyWriter();
2298 writer.toPhyloXML( file, t, 0 );
2300 catch ( final Exception e ) {
2302 exceptionOccuredDuringSaveAs( e );
2307 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2308 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2309 _mainpanel.getCurrentTreePanel().getHeight(),
2311 String file_written_to = "";
2312 boolean error = false;
2314 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2315 _mainpanel.getCurrentTreePanel().getWidth(),
2316 _mainpanel.getCurrentTreePanel().getHeight(),
2317 _mainpanel.getCurrentTreePanel(),
2318 _mainpanel.getControlPanel(),
2322 catch ( final IOException e ) {
2324 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2327 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2328 JOptionPane.showMessageDialog( this,
2329 "Wrote image to: " + file_written_to,
2331 JOptionPane.INFORMATION_MESSAGE );
2334 JOptionPane.showMessageDialog( this,
2335 "There was an unknown problem when attempting to write to an image file: \""
2338 JOptionPane.ERROR_MESSAGE );
2341 _contentpane.repaint();
2344 private void writeToFile( final Phylogeny t ) {
2348 String initial_filename = null;
2349 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2351 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2353 catch ( final IOException e ) {
2354 initial_filename = null;
2357 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2358 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2361 _save_filechooser.setSelectedFile( new File( "" ) );
2363 final File my_dir = getCurrentDir();
2364 if ( my_dir != null ) {
2365 _save_filechooser.setCurrentDirectory( my_dir );
2367 final int result = _save_filechooser.showSaveDialog( _contentpane );
2368 final File file = _save_filechooser.getSelectedFile();
2369 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2370 boolean exception = false;
2371 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2372 if ( file.exists() ) {
2373 final int i = JOptionPane.showConfirmDialog( this,
2374 file + " already exists.\nOverwrite?",
2376 JOptionPane.OK_CANCEL_OPTION,
2377 JOptionPane.QUESTION_MESSAGE );
2378 if ( i != JOptionPane.OK_OPTION ) {
2382 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2384 ForesterUtil.copyFile( file, to );
2386 catch ( final Exception e ) {
2387 JOptionPane.showMessageDialog( this,
2388 "Failed to create backup copy " + to,
2389 "Failed to Create Backup Copy",
2390 JOptionPane.WARNING_MESSAGE );
2395 catch ( final Exception e ) {
2396 JOptionPane.showMessageDialog( this,
2397 "Failed to delete: " + file,
2399 JOptionPane.WARNING_MESSAGE );
2403 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2404 exception = writeAsNewHampshire( t, exception, file );
2406 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2407 exception = writeAsNHX( t, exception, file );
2409 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2410 exception = writeAsPhyloXml( t, exception, file );
2412 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2413 exception = writeAsNexus( t, exception, file );
2417 final String file_name = file.getName().trim().toLowerCase();
2418 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2419 || file_name.endsWith( ".tree" ) ) {
2420 exception = writeAsNewHampshire( t, exception, file );
2422 else if ( file_name.endsWith( ".nhx" ) ) {
2423 exception = writeAsNHX( t, exception, file );
2425 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2426 exception = writeAsNexus( t, exception, file );
2430 exception = writeAsPhyloXml( t, exception, file );
2434 getMainPanel().setTitleOfSelectedTab( file.getName() );
2435 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2436 getMainPanel().getCurrentTreePanel().setEdited( false );
2441 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2442 if ( ( t == null ) || t.isEmpty() ) {
2445 String initial_filename = "";
2446 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2447 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2449 if ( initial_filename.indexOf( '.' ) > 0 ) {
2450 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2452 initial_filename = initial_filename + "." + type;
2453 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2454 final File my_dir = getCurrentDir();
2455 if ( my_dir != null ) {
2456 _writetographics_filechooser.setCurrentDirectory( my_dir );
2458 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2459 File file = _writetographics_filechooser.getSelectedFile();
2460 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2461 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2462 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2463 file = new File( file.toString() + "." + type );
2465 if ( file.exists() ) {
2466 final int i = JOptionPane.showConfirmDialog( this,
2467 file + " already exists. Overwrite?",
2469 JOptionPane.OK_CANCEL_OPTION,
2470 JOptionPane.WARNING_MESSAGE );
2471 if ( i != JOptionPane.OK_OPTION ) {
2478 catch ( final Exception e ) {
2479 JOptionPane.showMessageDialog( this,
2480 "Failed to delete: " + file,
2482 JOptionPane.WARNING_MESSAGE );
2486 writePhylogenyToGraphicsFile( file.toString(), type );
2490 private void writeToPdf( final Phylogeny t ) {
2491 if ( ( t == null ) || t.isEmpty() ) {
2494 String initial_filename = "";
2495 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2496 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2498 if ( initial_filename.indexOf( '.' ) > 0 ) {
2499 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2501 initial_filename = initial_filename + ".pdf";
2502 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2503 final File my_dir = getCurrentDir();
2504 if ( my_dir != null ) {
2505 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2507 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2508 File file = _writetopdf_filechooser.getSelectedFile();
2509 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2510 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2511 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2512 file = new File( file.toString() + ".pdf" );
2514 if ( file.exists() ) {
2515 final int i = JOptionPane.showConfirmDialog( this,
2516 file + " already exists. Overwrite?",
2518 JOptionPane.OK_CANCEL_OPTION,
2519 JOptionPane.WARNING_MESSAGE );
2520 if ( i != JOptionPane.OK_OPTION ) {
2524 printPhylogenyToPdf( file.toString() );
2528 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2529 return new MainFrameApplication( phys, config, title );
2532 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2533 return new MainFrameApplication( phys, config_file_name, title );
2536 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2537 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2538 + o.getPrintSizeY() + ")" );
2541 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2542 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2545 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2546 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2548 .showMessageDialog( null,
2550 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2553 JOptionPane.WARNING_MESSAGE );
2557 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2558 _phylogenetic_inference_options = phylogenetic_inference_options;
2561 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2562 if ( _phylogenetic_inference_options == null ) {
2563 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2565 return _phylogenetic_inference_options;
2568 public Msa getMsa() {
2572 void setMsa( final Msa msa ) {
2576 void setMsaFile( final File msa_file ) {
2577 _msa_file = msa_file;
2580 public File getMsaFile() {
2584 public List<Sequence> getSeqs() {
2588 void setSeqs( final List<Sequence> seqs ) {
2592 void setSeqsFile( final File seqs_file ) {
2593 _seqs_file = seqs_file;
2596 public File getSeqsFile() {
2599 } // MainFrameApplication.
2601 class NexusFilter extends FileFilter {
2604 public boolean accept( final File f ) {
2605 final String file_name = f.getName().trim().toLowerCase();
2606 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2607 || file_name.endsWith( ".tre" ) || f.isDirectory();
2611 public String getDescription() {
2612 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2616 class NHFilter extends FileFilter {
2619 public boolean accept( final File f ) {
2620 final String file_name = f.getName().trim().toLowerCase();
2621 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2622 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2623 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2628 public String getDescription() {
2629 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2633 class NHXFilter extends FileFilter {
2636 public boolean accept( final File f ) {
2637 final String file_name = f.getName().trim().toLowerCase();
2638 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2642 public String getDescription() {
2643 return "NHX files (*.nhx)";
2647 class PdfFilter extends FileFilter {
2650 public boolean accept( final File f ) {
2651 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2655 public String getDescription() {
2656 return "PDF files (*.pdf)";
2660 class TolFilter extends FileFilter {
2663 public boolean accept( final File f ) {
2664 final String file_name = f.getName().trim().toLowerCase();
2665 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2666 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2670 public String getDescription() {
2671 return "Tree of Life files (*.tol, *.tolxml)";
2675 class XMLFilter extends FileFilter {
2678 public boolean accept( final File f ) {
2679 final String file_name = f.getName().trim().toLowerCase();
2680 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2681 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2685 public String getDescription() {
2686 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";