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 ( 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_uniprot_seq_information_jmi ) {
500 obtainUniProtSequenceInformation();
502 else if ( o == _read_values_jmi ) {
503 if ( isSubtreeDisplayed() ) {
506 addExpressionValuesFromFile();
508 else if ( o == _move_node_names_to_tax_sn_jmi ) {
509 moveNodeNamesToTaxSn();
511 else if ( o == _move_node_names_to_seq_names_jmi ) {
512 moveNodeNamesToSeqNames();
514 else if ( o == _extract_tax_code_from_node_names_jmi ) {
515 extractTaxCodeFromNodeNames();
517 else if ( o == _gsdi_item ) {
518 if ( isSubtreeDisplayed() ) {
523 else if ( o == _root_min_dups_item ) {
524 if ( isSubtreeDisplayed() ) {
527 executeSDIR( false );
529 else if ( o == _root_min_cost_l_item ) {
530 if ( isSubtreeDisplayed() ) {
535 else if ( o == _graphics_export_visible_only_cbmi ) {
536 updateOptions( getOptions() );
538 else if ( o == _antialias_print_cbmi ) {
539 updateOptions( getOptions() );
541 else if ( o == _print_black_and_white_cbmi ) {
542 updateOptions( getOptions() );
544 else if ( o == _print_using_actual_size_cbmi ) {
545 updateOptions( getOptions() );
547 else if ( o == _graphics_export_using_actual_size_cbmi ) {
548 updateOptions( getOptions() );
550 else if ( o == _print_size_mi ) {
553 else if ( o == _choose_pdf_width_mi ) {
556 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
557 updateOptions( getOptions() );
559 else if ( o == _replace_underscores_cbmi ) {
560 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
561 _extract_pfam_style_tax_codes_cbmi.setSelected( false );
563 updateOptions( getOptions() );
565 else if ( o == _collapse_below_threshold ) {
566 if ( isSubtreeDisplayed() ) {
569 collapseBelowThreshold();
571 else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
572 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
573 _replace_underscores_cbmi.setSelected( false );
575 updateOptions( getOptions() );
577 else if ( o == _inference_from_msa_item ) {
578 executePhyleneticInference( false );
580 else if ( o == _inference_from_seqs_item ) {
581 executePhyleneticInference( true );
583 _contentpane.repaint();
585 catch ( final Exception ex ) {
586 Util.unexpectedException( ex );
588 catch ( final Error err ) {
589 Util.unexpectedError( err );
593 void buildAnalysisMenu() {
594 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
595 _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
596 if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
597 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
599 _analysis_menu.addSeparator();
600 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
601 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
602 _analysis_menu.addSeparator();
603 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
604 customizeJMenuItem( _sdi_item );
605 customizeJMenuItem( _gsdi_item );
606 customizeJMenuItem( _root_min_dups_item );
607 customizeJMenuItem( _root_min_cost_l_item );
608 customizeJMenuItem( _load_species_tree_item );
609 _analysis_menu.addSeparator();
610 _analysis_menu.add( _lineage_inference = new JMenuItem( "Infer Ancestor Taxonomies" ) );
611 customizeJMenuItem( _lineage_inference );
612 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
613 _jmenubar.add( _analysis_menu );
616 void buildPhylogeneticInferenceMenu() {
617 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
619 .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
620 customizeJMenuItem( _inference_from_msa_item );
621 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
623 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
624 customizeJMenuItem( _inference_from_seqs_item );
625 _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
626 _jmenubar.add( _inference_menu );
630 void buildFileMenu() {
631 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
632 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
633 _file_jmenu.addSeparator();
634 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
635 _file_jmenu.addSeparator();
636 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
637 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
638 .getAvailablePhylogeniesWebserviceClients().size() ];
639 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
640 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
641 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
642 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
644 if ( getConfiguration().isEditable() ) {
645 _file_jmenu.addSeparator();
646 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
647 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
649 _file_jmenu.addSeparator();
650 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
651 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
652 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
653 _save_all_item.setEnabled( false );
654 _file_jmenu.addSeparator();
655 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
656 if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
657 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
659 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
660 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
661 if ( Util.canWriteFormat( "gif" ) ) {
662 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
664 if ( Util.canWriteFormat( "bmp" ) ) {
665 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
667 _file_jmenu.addSeparator();
668 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
669 _file_jmenu.addSeparator();
670 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
671 _close_item.setToolTipText( "To close the current pane." );
672 _close_item.setEnabled( true );
673 _file_jmenu.addSeparator();
674 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
675 // For print in color option item
676 customizeJMenuItem( _open_item );
678 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
679 customizeJMenuItem( _open_url_item );
680 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
681 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
683 customizeJMenuItem( _save_item );
684 if ( getConfiguration().isEditable() ) {
685 customizeJMenuItem( _new_item );
687 customizeJMenuItem( _close_item );
688 customizeJMenuItem( _save_all_item );
689 customizeJMenuItem( _write_to_pdf_item );
690 customizeJMenuItem( _write_to_png_item );
691 customizeJMenuItem( _write_to_jpg_item );
692 customizeJMenuItem( _write_to_gif_item );
693 customizeJMenuItem( _write_to_tif_item );
694 customizeJMenuItem( _write_to_bmp_item );
695 customizeJMenuItem( _print_item );
696 customizeJMenuItem( _exit_item );
697 _jmenubar.add( _file_jmenu );
700 void buildOptionsMenu() {
701 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
702 _options_jmenu.addChangeListener( new ChangeListener() {
705 public void stateChanged( final ChangeEvent e ) {
706 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
707 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
709 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
710 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
711 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
712 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
713 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
714 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
716 _show_branch_length_values_cbmi,
717 _non_lined_up_cladograms_rbmi,
718 _uniform_cladograms_rbmi,
719 _ext_node_dependent_cladogram_rbmi,
720 _label_direction_cbmi );
721 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
722 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
723 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
726 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
728 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
729 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
730 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
731 _radio_group_1 = new ButtonGroup();
732 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
733 _radio_group_1.add( _uniform_cladograms_rbmi );
734 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
735 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
737 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
738 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
739 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
740 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
741 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
743 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
744 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
745 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
746 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
747 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
748 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
749 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
750 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
751 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
752 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
753 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
755 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
756 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
757 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
758 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
759 _options_jmenu.addSeparator();
760 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
761 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
762 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
763 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
764 _options_jmenu.addSeparator();
765 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
766 getConfiguration() ) );
767 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
768 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
770 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
772 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
774 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
775 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
776 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
777 _options_jmenu.addSeparator();
779 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
781 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
782 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
784 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
785 customizeJMenuItem( _choose_font_mi );
786 customizeJMenuItem( _choose_minimal_confidence_mi );
787 customizeJMenuItem( _switch_colors_mi );
788 customizeJMenuItem( _print_size_mi );
789 customizeJMenuItem( _choose_pdf_width_mi );
790 customizeJMenuItem( _overview_placment_mi );
791 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
792 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
793 customizeJMenuItem( _cycle_node_shape_mi );
794 customizeJMenuItem( _cycle_node_fill_mi );
795 customizeJMenuItem( _choose_node_size_mi );
796 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
797 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
798 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
799 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
800 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
801 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
802 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
803 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
804 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
805 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
806 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
807 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
808 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
809 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
810 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
811 customizeCheckBoxMenuItem( _label_direction_cbmi,
812 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
813 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
814 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
815 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
816 .isInternalNumberAreConfidenceForNhParsing() );
817 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
818 .isExtractPfamTaxonomyCodesInNhParsing() );
819 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
820 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
821 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
822 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
823 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
824 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
825 .isGraphicsExportUsingActualSize() );
826 _jmenubar.add( _options_jmenu );
829 void buildToolsMenu() {
830 _tools_menu = createMenu( "Tools", getConfiguration() );
831 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
832 customizeJMenuItem( _confcolor_item );
833 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
834 customizeJMenuItem( _taxcolor_item );
835 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
836 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
837 customizeJMenuItem( _remove_branch_color_item );
838 _tools_menu.addSeparator();
839 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
840 customizeJMenuItem( _midpoint_root_item );
841 _tools_menu.addSeparator();
842 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
843 customizeJMenuItem( _collapse_species_specific_subtrees );
845 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
846 customizeJMenuItem( _collapse_below_threshold );
847 _collapse_below_threshold
848 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
849 _tools_menu.addSeparator();
851 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
852 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
853 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
854 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
855 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
856 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
858 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
859 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
860 _extract_tax_code_from_node_names_jmi
861 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
862 _tools_menu.addSeparator();
864 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
865 customizeJMenuItem( _infer_common_sn_names_item );
866 _tools_menu.addSeparator();
868 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
869 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
870 _obtain_detailed_taxonomic_information_jmi
871 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
873 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
874 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
875 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
876 _tools_menu.addSeparator();
877 if ( !Constants.__RELEASE ) {
878 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
879 customizeJMenuItem( _function_analysis );
881 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
882 _tools_menu.addSeparator();
884 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
885 customizeJMenuItem( _read_values_jmi );
886 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
887 _jmenubar.add( _tools_menu );
890 private void choosePdfWidth() {
891 final String s = ( String ) JOptionPane.showInputDialog( this,
892 "Please enter the default line width for PDF export.\n"
894 + getOptions().getPrintLineWidth() + "]\n",
895 "Line Width for PDF Export",
896 JOptionPane.QUESTION_MESSAGE,
899 getOptions().getPrintLineWidth() );
900 if ( !ForesterUtil.isEmpty( s ) ) {
901 boolean success = true;
903 final String m_str = s.trim();
904 if ( !ForesterUtil.isEmpty( m_str ) ) {
906 f = Float.parseFloat( m_str );
908 catch ( final Exception ex ) {
915 if ( success && ( f > 0.0 ) ) {
916 getOptions().setPrintLineWidth( f );
921 private void choosePrintSize() {
922 final String s = ( String ) JOptionPane.showInputDialog( this,
923 "Please enter values for width and height,\nseparated by a comma.\n"
924 + "[current values: "
925 + getOptions().getPrintSizeX() + ", "
926 + getOptions().getPrintSizeY() + "]\n"
927 + "[A4: " + Constants.A4_SIZE_X + ", "
928 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
929 + Constants.US_LETTER_SIZE_X + ", "
930 + Constants.US_LETTER_SIZE_Y + "]",
931 "Default Size for Graphics Export",
932 JOptionPane.QUESTION_MESSAGE,
935 getOptions().getPrintSizeX() + ", "
936 + getOptions().getPrintSizeY() );
937 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
938 boolean success = true;
941 final String[] str_ary = s.split( "," );
942 if ( str_ary.length == 2 ) {
943 final String x_str = str_ary[ 0 ].trim();
944 final String y_str = str_ary[ 1 ].trim();
945 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
947 x = Integer.parseInt( x_str );
948 y = Integer.parseInt( y_str );
950 catch ( final Exception ex ) {
961 if ( success && ( x > 1 ) && ( y > 1 ) ) {
962 getOptions().setPrintSizeX( x );
963 getOptions().setPrintSizeY( y );
970 if ( isUnsavedDataPresent() ) {
971 final int r = JOptionPane.showConfirmDialog( this,
972 "Exit despite potentially unsaved changes?",
974 JOptionPane.YES_NO_OPTION );
975 if ( r != JOptionPane.YES_OPTION ) {
982 private void closeCurrentPane() {
983 if ( getMainPanel().getCurrentTreePanel() != null ) {
984 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
985 final int r = JOptionPane.showConfirmDialog( this,
986 "Close tab despite potentially unsaved changes?",
988 JOptionPane.YES_NO_OPTION );
989 if ( r != JOptionPane.YES_OPTION ) {
993 getMainPanel().closeCurrentPane();
994 activateSaveAllIfNeeded();
998 private void collapse( final Phylogeny phy, final double m ) {
999 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1000 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1001 double min_support = Double.MAX_VALUE;
1002 boolean conf_present = false;
1003 while ( it.hasNext() ) {
1004 final PhylogenyNode n = it.next();
1005 if ( !n.isExternal() && !n.isRoot() ) {
1006 final List<Confidence> c = n.getBranchData().getConfidences();
1007 if ( ( c != null ) && ( c.size() > 0 ) ) {
1008 conf_present = true;
1010 for( final Confidence confidence : c ) {
1011 if ( confidence.getValue() > max ) {
1012 max = confidence.getValue();
1015 if ( max < getMinNotCollapseConfidenceValue() ) {
1016 to_be_removed.add( n );
1018 if ( max < min_support ) {
1024 if ( conf_present ) {
1025 for( final PhylogenyNode node : to_be_removed ) {
1026 PhylogenyMethods.removeNode( node, phy );
1028 if ( to_be_removed.size() > 0 ) {
1029 phy.externalNodesHaveChanged();
1031 phy.recalculateNumberOfExternalDescendants( true );
1032 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1033 getCurrentTreePanel().setEdited( true );
1034 getCurrentTreePanel().repaint();
1036 if ( to_be_removed.size() > 0 ) {
1037 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1038 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1039 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1042 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1043 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1047 JOptionPane.showMessageDialog( this,
1048 "No branch collapsed because no confidence values present",
1049 "No confidence values present",
1050 JOptionPane.INFORMATION_MESSAGE );
1054 private void collapseBelowThreshold() {
1055 if ( getCurrentTreePanel() != null ) {
1056 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1057 if ( ( phy != null ) && !phy.isEmpty() ) {
1058 final String s = ( String ) JOptionPane.showInputDialog( this,
1059 "Please enter the minimum confidence value\n",
1060 "Minimal Confidence Value",
1061 JOptionPane.QUESTION_MESSAGE,
1064 getMinNotCollapseConfidenceValue() );
1065 if ( !ForesterUtil.isEmpty( s ) ) {
1066 boolean success = true;
1068 final String m_str = s.trim();
1069 if ( !ForesterUtil.isEmpty( m_str ) ) {
1071 m = Double.parseDouble( m_str );
1073 catch ( final Exception ex ) {
1080 if ( success && ( m >= 0.0 ) ) {
1081 setMinNotCollapseConfidenceValue( m );
1089 private PhyloXmlParser createPhyloXmlParser() {
1090 PhyloXmlParser xml_parser = null;
1091 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1093 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1095 catch ( final Exception e ) {
1096 JOptionPane.showMessageDialog( this,
1097 e.getLocalizedMessage(),
1098 "failed to create validating XML parser",
1099 JOptionPane.WARNING_MESSAGE );
1102 if ( xml_parser == null ) {
1103 xml_parser = new PhyloXmlParser();
1108 void executeGSDI() {
1109 if ( !isOKforSDI( false, true ) ) {
1112 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1113 JOptionPane.showMessageDialog( this,
1114 "Gene tree is not rooted.",
1115 "Cannot execute GSDI",
1116 JOptionPane.ERROR_MESSAGE );
1119 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1120 gene_tree.setAllNodesToNotCollapse();
1121 gene_tree.recalculateNumberOfExternalDescendants( false );
1123 int duplications = -1;
1125 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1126 duplications = gsdi.getDuplicationsSum();
1128 catch ( final Exception e ) {
1129 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1131 gene_tree.setRerootable( false );
1132 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1133 getControlPanel().setShowEvents( true );
1135 _mainpanel.getCurrentTreePanel().setEdited( true );
1136 JOptionPane.showMessageDialog( this,
1137 "Number of duplications: " + duplications,
1138 "GSDI successfully completed",
1139 JOptionPane.INFORMATION_MESSAGE );
1142 void executeFunctionAnalysis() {
1143 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1146 final GoAnnotation a = new GoAnnotation( this,
1147 _mainpanel.getCurrentTreePanel(),
1148 _mainpanel.getCurrentPhylogeny() );
1149 new Thread( a ).start();
1152 void executeLineageInference() {
1153 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1156 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1157 JOptionPane.showMessageDialog( this,
1158 "Phylogeny is not rooted.",
1159 "Cannot infer ancestral taxonomies",
1160 JOptionPane.ERROR_MESSAGE );
1163 final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1164 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1165 _mainpanel.getCurrentTreePanel(),
1167 new Thread( inferrer ).start();
1170 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1171 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1172 getPhylogeneticInferenceOptions(),
1173 from_unaligned_seqs );
1175 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1176 if ( !from_unaligned_seqs ) {
1177 if ( getMsa() != null ) {
1178 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1179 getPhylogeneticInferenceOptions()
1181 new Thread( inferrer ).start();
1184 JOptionPane.showMessageDialog( this,
1185 "No multiple sequence alignment selected",
1186 "Phylogenetic Inference Not Launched",
1187 JOptionPane.WARNING_MESSAGE );
1191 if ( getSeqs() != null ) {
1192 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1193 getPhylogeneticInferenceOptions()
1195 new Thread( inferrer ).start();
1198 JOptionPane.showMessageDialog( this,
1199 "No input sequences selected",
1200 "Phylogenetic Inference Not Launched",
1201 JOptionPane.WARNING_MESSAGE );
1208 if ( !isOKforSDI( true, true ) ) {
1211 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1212 JOptionPane.showMessageDialog( this,
1213 "Gene tree is not rooted",
1214 "Cannot execute SDI",
1215 JOptionPane.ERROR_MESSAGE );
1218 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1219 gene_tree.setAllNodesToNotCollapse();
1220 gene_tree.recalculateNumberOfExternalDescendants( false );
1222 int duplications = -1;
1224 sdi = new SDIse( gene_tree, _species_tree.copy() );
1225 duplications = sdi.getDuplicationsSum();
1227 catch ( final Exception e ) {
1228 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1230 gene_tree.setRerootable( false );
1231 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1232 getControlPanel().setShowEvents( true );
1234 _mainpanel.getCurrentTreePanel().setEdited( true );
1235 JOptionPane.showMessageDialog( this,
1236 "Number of duplications: " + duplications,
1237 "SDI successfully completed",
1238 JOptionPane.INFORMATION_MESSAGE );
1241 void executeSDIR( final boolean minimize_cost ) {
1242 if ( !isOKforSDI( true, true ) ) {
1245 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1246 final SDIR sdiunrooted = new SDIR();
1247 gene_tree.setAllNodesToNotCollapse();
1248 gene_tree.recalculateNumberOfExternalDescendants( false );
1250 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1251 !minimize_cost, // minimize sum of dups
1252 true, // minimize height
1253 true, // return tree(s)
1254 1 )[ 0 ]; // # of trees to return
1256 catch ( final Exception e ) {
1257 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1260 final int duplications = sdiunrooted.getMinimalDuplications();
1261 gene_tree.setRerootable( false );
1262 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1263 getControlPanel().setShowEvents( true );
1265 _mainpanel.getCurrentTreePanel().setEdited( true );
1266 JOptionPane.showMessageDialog( this,
1267 "Number of duplications: " + duplications,
1268 "SDIR successfully completed",
1269 JOptionPane.INFORMATION_MESSAGE );
1274 _mainpanel.terminate();
1275 _contentpane.removeAll();
1276 setVisible( false );
1281 private void extractTaxCodeFromNodeNames() {
1282 if ( getCurrentTreePanel() != null ) {
1283 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1284 if ( ( phy != null ) && !phy.isEmpty() ) {
1285 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1286 while ( it.hasNext() ) {
1287 final PhylogenyNode n = it.next();
1288 final String name = n.getName().trim();
1289 if ( !ForesterUtil.isEmpty( name ) ) {
1290 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1292 TAXONOMY_EXTRACTION.YES );
1293 if ( !ForesterUtil.isEmpty( code ) ) {
1294 PhylogenyMethods.setTaxonomyCode( n, code );
1302 private ControlPanel getControlPanel() {
1303 return getMainPanel().getControlPanel();
1306 private File getCurrentDir() {
1307 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1308 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1310 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1312 catch ( final Exception e ) {
1313 _current_dir = null;
1317 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1318 if ( System.getProperty( "user.home" ) != null ) {
1319 _current_dir = new File( System.getProperty( "user.home" ) );
1321 else if ( System.getProperty( "user.dir" ) != null ) {
1322 _current_dir = new File( System.getProperty( "user.dir" ) );
1325 return _current_dir;
1329 public MainPanel getMainPanel() {
1333 private double getMinNotCollapseConfidenceValue() {
1334 return _min_not_collapse;
1337 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1338 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1341 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1342 JOptionPane.showMessageDialog( this,
1343 "No species tree loaded",
1344 "Cannot execute SDI",
1345 JOptionPane.ERROR_MESSAGE );
1348 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1349 JOptionPane.showMessageDialog( this,
1350 "Species tree is not completely binary",
1351 "Cannot execute SDI",
1352 JOptionPane.ERROR_MESSAGE );
1355 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1356 JOptionPane.showMessageDialog( this,
1357 "Gene tree is not completely binary",
1358 "Cannot execute SDI",
1359 JOptionPane.ERROR_MESSAGE );
1367 private boolean isUnsavedDataPresent() {
1368 final List<TreePanel> tps = getMainPanel().getTreePanels();
1369 for( final TreePanel tp : tps ) {
1370 if ( tp.isEdited() ) {
1377 private void moveNodeNamesToSeqNames() {
1378 if ( getCurrentTreePanel() != null ) {
1379 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1380 if ( ( phy != null ) && !phy.isEmpty() ) {
1381 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1386 private void moveNodeNamesToTaxSn() {
1387 if ( getCurrentTreePanel() != null ) {
1388 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1389 if ( ( phy != null ) && !phy.isEmpty() ) {
1390 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1395 private void newTree() {
1396 final Phylogeny[] phys = new Phylogeny[ 1 ];
1397 final Phylogeny phy = new Phylogeny();
1398 final PhylogenyNode node = new PhylogenyNode();
1399 phy.setRoot( node );
1400 phy.setRooted( true );
1402 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1403 _mainpanel.getControlPanel().showWhole();
1404 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1405 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1406 if ( getMainPanel().getMainFrame() == null ) {
1407 // Must be "E" applet version.
1408 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1409 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1412 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1414 activateSaveAllIfNeeded();
1418 private void obtainDetailedTaxonomicInformation() {
1419 if ( getCurrentTreePanel() != null ) {
1420 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1421 if ( ( phy != null ) && !phy.isEmpty() ) {
1422 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1423 _mainpanel.getCurrentTreePanel(),
1425 new Thread( t ).start();
1430 private void obtainUniProtSequenceInformation() {
1431 if ( getCurrentTreePanel() != null ) {
1432 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1433 if ( ( phy != null ) && !phy.isEmpty() ) {
1434 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1435 _mainpanel.getCurrentTreePanel(),
1437 new Thread( u ).start();
1442 private void print() {
1443 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1444 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1447 if ( !getOptions().isPrintUsingActualSize() ) {
1448 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1449 getOptions().getPrintSizeY() - 140,
1451 getCurrentTreePanel().resetPreferredSize();
1452 getCurrentTreePanel().repaint();
1454 final String job_name = Constants.PRG_NAME;
1455 boolean error = false;
1456 String printer_name = null;
1458 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1460 catch ( final Exception e ) {
1462 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1464 if ( !error && ( printer_name != null ) ) {
1465 String msg = "Printing data sent to printer";
1466 if ( printer_name.length() > 1 ) {
1467 msg += " [" + printer_name + "]";
1469 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1471 if ( !getOptions().isPrintUsingActualSize() ) {
1472 getControlPanel().showWhole();
1476 private void printPhylogenyToPdf( final String file_name ) {
1477 if ( !getOptions().isPrintUsingActualSize() ) {
1478 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1479 getOptions().getPrintSizeY(),
1481 getCurrentTreePanel().resetPreferredSize();
1482 getCurrentTreePanel().repaint();
1484 String pdf_written_to = "";
1485 boolean error = false;
1487 if ( getOptions().isPrintUsingActualSize() ) {
1488 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1489 getCurrentTreePanel(),
1490 getCurrentTreePanel().getWidth(),
1491 getCurrentTreePanel().getHeight() );
1494 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1495 .getPrintSizeX(), getOptions().getPrintSizeY() );
1498 catch ( final IOException e ) {
1500 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1503 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1504 JOptionPane.showMessageDialog( this,
1505 "Wrote PDF to: " + pdf_written_to,
1507 JOptionPane.INFORMATION_MESSAGE );
1510 JOptionPane.showMessageDialog( this,
1511 "There was an unknown problem when attempting to write to PDF file: \""
1514 JOptionPane.ERROR_MESSAGE );
1517 if ( !getOptions().isPrintUsingActualSize() ) {
1518 getControlPanel().showWhole();
1522 private void addExpressionValuesFromFile() {
1523 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1524 JOptionPane.showMessageDialog( this,
1525 "Need to load evolutionary tree first",
1526 "Can Not Read Expression Values",
1527 JOptionPane.WARNING_MESSAGE );
1530 final File my_dir = getCurrentDir();
1531 if ( my_dir != null ) {
1532 _values_filechooser.setCurrentDirectory( my_dir );
1534 final int result = _values_filechooser.showOpenDialog( _contentpane );
1535 final File file = _values_filechooser.getSelectedFile();
1536 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1537 BasicTable<String> t = null;
1539 t = BasicTableParser.parse( file, "\t" );
1540 if ( t.getNumberOfColumns() < 2 ) {
1541 t = BasicTableParser.parse( file, "," );
1543 if ( t.getNumberOfColumns() < 2 ) {
1544 t = BasicTableParser.parse( file, " " );
1547 catch ( final IOException e ) {
1548 JOptionPane.showMessageDialog( this,
1550 "Could Not Read Expression Value Table",
1551 JOptionPane.ERROR_MESSAGE );
1554 if ( t.getNumberOfColumns() < 2 ) {
1555 JOptionPane.showMessageDialog( this,
1556 "Table contains " + t.getNumberOfColumns() + " column(s)",
1557 "Problem with Expression Value Table",
1558 JOptionPane.ERROR_MESSAGE );
1561 if ( t.getNumberOfRows() < 1 ) {
1562 JOptionPane.showMessageDialog( this,
1563 "Table contains zero rows",
1564 "Problem with Expression Value Table",
1565 JOptionPane.ERROR_MESSAGE );
1568 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1569 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1570 JOptionPane.showMessageDialog( this,
1571 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1572 + phy.getNumberOfExternalNodes() + " external nodes",
1574 JOptionPane.WARNING_MESSAGE );
1576 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1578 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1579 final PhylogenyNode node = iter.next();
1580 final String node_name = node.getName();
1581 if ( !ForesterUtil.isEmpty( node_name ) ) {
1584 row = t.findRow( node_name );
1586 catch ( final IllegalArgumentException e ) {
1588 .showMessageDialog( this,
1590 "Error Mapping Node Identifiers to Expression Value Identifiers",
1591 JOptionPane.ERROR_MESSAGE );
1595 if ( node.isExternal() ) {
1600 final List<Double> l = new ArrayList<Double>();
1601 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1604 d = Double.parseDouble( t.getValueAsString( col, row ) );
1606 catch ( final NumberFormatException e ) {
1607 JOptionPane.showMessageDialog( this,
1608 "Could not parse \"" + t.getValueAsString( col, row )
1609 + "\" into a decimal value",
1610 "Issue with Expression Value Table",
1611 JOptionPane.ERROR_MESSAGE );
1614 stats.addValue( d );
1617 if ( !l.isEmpty() ) {
1618 if ( node.getNodeData().getProperties() != null ) {
1619 node.getNodeData().getProperties()
1620 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1622 node.getNodeData().setVector( l );
1626 if ( not_found > 0 ) {
1627 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1628 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1630 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1634 private void readPhylogeniesFromFile() {
1635 boolean exception = false;
1636 Phylogeny[] phys = null;
1637 // Set an initial directory if none set yet
1638 final File my_dir = getCurrentDir();
1639 _open_filechooser.setMultiSelectionEnabled( true );
1640 // Open file-open dialog and set current directory
1641 if ( my_dir != null ) {
1642 _open_filechooser.setCurrentDirectory( my_dir );
1644 final int result = _open_filechooser.showOpenDialog( _contentpane );
1645 // All done: get the file
1646 final File[] files = _open_filechooser.getSelectedFiles();
1647 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1648 boolean nhx_or_nexus = false;
1649 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1650 for( final File file : files ) {
1651 if ( ( file != null ) && !file.isDirectory() ) {
1652 if ( _mainpanel.getCurrentTreePanel() != null ) {
1653 _mainpanel.getCurrentTreePanel().setWaitCursor();
1656 _mainpanel.setWaitCursor();
1658 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1659 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1661 final NHXParser nhx = new NHXParser();
1662 setSpecialOptionsForNhxParser( nhx );
1663 phys = ForesterUtil.readPhylogenies( nhx, file );
1664 nhx_or_nexus = true;
1666 catch ( final Exception e ) {
1668 exceptionOccuredDuringOpenFile( e );
1671 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1672 warnIfNotPhyloXmlValidation( getConfiguration() );
1674 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1675 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1677 catch ( final Exception e ) {
1679 exceptionOccuredDuringOpenFile( e );
1682 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1684 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1686 catch ( final Exception e ) {
1688 exceptionOccuredDuringOpenFile( e );
1691 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1693 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1694 setSpecialOptionsForNexParser( nex );
1695 phys = ForesterUtil.readPhylogenies( nex, file );
1696 nhx_or_nexus = true;
1698 catch ( final Exception e ) {
1700 exceptionOccuredDuringOpenFile( e );
1706 final PhylogenyParser parser = ForesterUtil
1707 .createParserDependingOnFileType( file, getConfiguration()
1708 .isValidatePhyloXmlAgainstSchema() );
1709 if ( parser instanceof NexusPhylogeniesParser ) {
1710 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1711 setSpecialOptionsForNexParser( nex );
1712 nhx_or_nexus = true;
1714 else if ( parser instanceof NHXParser ) {
1715 final NHXParser nhx = ( NHXParser ) parser;
1716 setSpecialOptionsForNhxParser( nhx );
1717 nhx_or_nexus = true;
1719 else if ( parser instanceof PhyloXmlParser ) {
1720 warnIfNotPhyloXmlValidation( getConfiguration() );
1722 phys = ForesterUtil.readPhylogenies( parser, file );
1724 catch ( final Exception e ) {
1726 exceptionOccuredDuringOpenFile( e );
1729 if ( _mainpanel.getCurrentTreePanel() != null ) {
1730 _mainpanel.getCurrentTreePanel().setArrowCursor();
1733 _mainpanel.setArrowCursor();
1735 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1736 boolean one_desc = false;
1737 if ( nhx_or_nexus ) {
1738 for( final Phylogeny phy : phys ) {
1739 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1740 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1742 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1748 Util.addPhylogeniesToTabs( phys,
1750 file.getAbsolutePath(),
1753 _mainpanel.getControlPanel().showWhole();
1754 if ( nhx_or_nexus && one_desc ) {
1756 .showMessageDialog( this,
1757 "One or more trees contain (a) node(s) with one descendant, "
1758 + ForesterUtil.LINE_SEPARATOR
1759 + "possibly indicating illegal parentheses within node names.",
1760 "Warning: Possible Error in New Hampshire Formatted Data",
1761 JOptionPane.WARNING_MESSAGE );
1767 activateSaveAllIfNeeded();
1771 public void readSeqsFromFile() {
1772 // Set an initial directory if none set yet
1773 final File my_dir = getCurrentDir();
1774 _seqs_filechooser.setMultiSelectionEnabled( false );
1775 // Open file-open dialog and set current directory
1776 if ( my_dir != null ) {
1777 _seqs_filechooser.setCurrentDirectory( my_dir );
1779 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1780 // All done: get the seqs
1781 final File file = _seqs_filechooser.getSelectedFile();
1782 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1783 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1784 setSeqsFile( null );
1786 List<Sequence> seqs = null;
1788 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1789 seqs = FastaParser.parse( new FileInputStream( file ) );
1790 for( final Sequence seq : seqs ) {
1791 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1798 catch ( final MsaFormatException e ) {
1800 _mainpanel.getCurrentTreePanel().setArrowCursor();
1802 catch ( final Exception ex ) {
1805 JOptionPane.showMessageDialog( this,
1806 e.getLocalizedMessage(),
1807 "Multiple sequence file format error",
1808 JOptionPane.ERROR_MESSAGE );
1811 catch ( final IOException e ) {
1813 _mainpanel.getCurrentTreePanel().setArrowCursor();
1815 catch ( final Exception ex ) {
1818 JOptionPane.showMessageDialog( this,
1819 e.getLocalizedMessage(),
1820 "Failed to read multiple sequence file",
1821 JOptionPane.ERROR_MESSAGE );
1824 catch ( final IllegalArgumentException e ) {
1826 _mainpanel.getCurrentTreePanel().setArrowCursor();
1828 catch ( final Exception ex ) {
1831 JOptionPane.showMessageDialog( this,
1832 e.getLocalizedMessage(),
1833 "Unexpected error during reading of multiple sequence file",
1834 JOptionPane.ERROR_MESSAGE );
1837 catch ( final Exception e ) {
1839 _mainpanel.getCurrentTreePanel().setArrowCursor();
1841 catch ( final Exception ex ) {
1844 e.printStackTrace();
1845 JOptionPane.showMessageDialog( this,
1846 e.getLocalizedMessage(),
1847 "Unexpected error during reading of multiple sequence file",
1848 JOptionPane.ERROR_MESSAGE );
1851 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1852 JOptionPane.showMessageDialog( this,
1853 "Multiple sequence file is empty",
1854 "Illegal multiple sequence file",
1855 JOptionPane.ERROR_MESSAGE );
1858 if ( seqs.size() < 4 ) {
1859 JOptionPane.showMessageDialog( this,
1860 "Multiple sequence file needs to contain at least 3 sequences",
1861 "Illegal multiple sequence file",
1862 JOptionPane.ERROR_MESSAGE );
1865 // if ( msa.getLength() < 2 ) {
1866 // JOptionPane.showMessageDialog( this,
1867 // "Multiple sequence alignment needs to contain at least 2 residues",
1868 // "Illegal multiple sequence file",
1869 // JOptionPane.ERROR_MESSAGE );
1873 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1878 public void readMsaFromFile() {
1879 // Set an initial directory if none set yet
1880 final File my_dir = getCurrentDir();
1881 _msa_filechooser.setMultiSelectionEnabled( false );
1882 // Open file-open dialog and set current directory
1883 if ( my_dir != null ) {
1884 _msa_filechooser.setCurrentDirectory( my_dir );
1886 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1887 // All done: get the msa
1888 final File file = _msa_filechooser.getSelectedFile();
1889 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1890 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1895 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1896 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1897 System.out.println( msa.toString() );
1900 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1903 catch ( final MsaFormatException e ) {
1905 _mainpanel.getCurrentTreePanel().setArrowCursor();
1907 catch ( final Exception ex ) {
1910 JOptionPane.showMessageDialog( this,
1911 e.getLocalizedMessage(),
1912 "Multiple sequence alignment format error",
1913 JOptionPane.ERROR_MESSAGE );
1916 catch ( final IOException e ) {
1918 _mainpanel.getCurrentTreePanel().setArrowCursor();
1920 catch ( final Exception ex ) {
1923 JOptionPane.showMessageDialog( this,
1924 e.getLocalizedMessage(),
1925 "Failed to read multiple sequence alignment",
1926 JOptionPane.ERROR_MESSAGE );
1929 catch ( final IllegalArgumentException e ) {
1931 _mainpanel.getCurrentTreePanel().setArrowCursor();
1933 catch ( final Exception ex ) {
1936 JOptionPane.showMessageDialog( this,
1937 e.getLocalizedMessage(),
1938 "Unexpected error during reading of multiple sequence alignment",
1939 JOptionPane.ERROR_MESSAGE );
1942 catch ( final Exception e ) {
1944 _mainpanel.getCurrentTreePanel().setArrowCursor();
1946 catch ( final Exception ex ) {
1949 e.printStackTrace();
1950 JOptionPane.showMessageDialog( this,
1951 e.getLocalizedMessage(),
1952 "Unexpected error during reading of multiple sequence alignment",
1953 JOptionPane.ERROR_MESSAGE );
1956 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1957 JOptionPane.showMessageDialog( this,
1958 "Multiple sequence alignment is empty",
1959 "Illegal Multiple Sequence Alignment",
1960 JOptionPane.ERROR_MESSAGE );
1963 if ( msa.getNumberOfSequences() < 4 ) {
1964 JOptionPane.showMessageDialog( this,
1965 "Multiple sequence alignment needs to contain at least 3 sequences",
1966 "Illegal multiple sequence alignment",
1967 JOptionPane.ERROR_MESSAGE );
1970 if ( msa.getLength() < 2 ) {
1971 JOptionPane.showMessageDialog( this,
1972 "Multiple sequence alignment needs to contain at least 2 residues",
1973 "Illegal multiple sequence alignment",
1974 JOptionPane.ERROR_MESSAGE );
1978 setMsaFile( _msa_filechooser.getSelectedFile() );
1984 void readPhylogeniesFromURL() {
1986 Phylogeny[] phys = null;
1987 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1988 final String url_string = JOptionPane.showInputDialog( this,
1990 "Use URL/webservice to obtain a phylogeny",
1991 JOptionPane.QUESTION_MESSAGE );
1992 boolean nhx_or_nexus = false;
1993 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1995 url = new URL( url_string );
1996 PhylogenyParser parser = null;
1997 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1998 parser = new TolParser();
2001 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
2002 .isValidatePhyloXmlAgainstSchema() );
2004 if ( parser instanceof NexusPhylogeniesParser ) {
2005 nhx_or_nexus = true;
2007 else if ( parser instanceof NHXParser ) {
2008 nhx_or_nexus = true;
2010 if ( _mainpanel.getCurrentTreePanel() != null ) {
2011 _mainpanel.getCurrentTreePanel().setWaitCursor();
2014 _mainpanel.setWaitCursor();
2016 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2017 phys = factory.create( url.openStream(), parser );
2019 catch ( final MalformedURLException e ) {
2020 JOptionPane.showMessageDialog( this,
2021 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2023 JOptionPane.ERROR_MESSAGE );
2025 catch ( final IOException e ) {
2026 JOptionPane.showMessageDialog( this,
2027 "Could not read from " + url + "\n"
2028 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2029 "Failed to read URL",
2030 JOptionPane.ERROR_MESSAGE );
2032 catch ( final Exception e ) {
2033 JOptionPane.showMessageDialog( this,
2034 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2035 "Unexpected Exception",
2036 JOptionPane.ERROR_MESSAGE );
2039 if ( _mainpanel.getCurrentTreePanel() != null ) {
2040 _mainpanel.getCurrentTreePanel().setArrowCursor();
2043 _mainpanel.setArrowCursor();
2046 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2047 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2048 for( final Phylogeny phy : phys ) {
2049 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2052 Util.addPhylogeniesToTabs( phys,
2053 new File( url.getFile() ).getName(),
2054 new File( url.getFile() ).toString(),
2057 _mainpanel.getControlPanel().showWhole();
2060 activateSaveAllIfNeeded();
2064 private void readSpeciesTreeFromFile() {
2066 boolean exception = false;
2067 final File my_dir = getCurrentDir();
2068 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2069 if ( my_dir != null ) {
2070 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2072 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2073 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2074 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2075 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2077 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2080 catch ( final Exception e ) {
2082 exceptionOccuredDuringOpenFile( e );
2085 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2087 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2090 catch ( final Exception e ) {
2092 exceptionOccuredDuringOpenFile( e );
2098 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2101 catch ( final Exception e ) {
2103 exceptionOccuredDuringOpenFile( e );
2106 if ( !exception && ( t != null ) && !t.isRooted() ) {
2109 JOptionPane.showMessageDialog( this,
2110 "Species tree is not rooted",
2111 "Species tree not loaded",
2112 JOptionPane.ERROR_MESSAGE );
2114 if ( !exception && ( t != null ) ) {
2115 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2116 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2117 final PhylogenyNode node = it.next();
2118 if ( !node.getNodeData().isHasTaxonomy() ) {
2122 .showMessageDialog( this,
2123 "Species tree contains external node(s) without taxonomy information",
2124 "Species tree not loaded",
2125 JOptionPane.ERROR_MESSAGE );
2129 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2132 JOptionPane.showMessageDialog( this,
2134 + node.getNodeData().getTaxonomy().asSimpleText()
2135 + "] is not unique in species tree",
2136 "Species tree not loaded",
2137 JOptionPane.ERROR_MESSAGE );
2141 tax_set.add( node.getNodeData().getTaxonomy() );
2146 if ( !exception && ( t != null ) ) {
2148 JOptionPane.showMessageDialog( this,
2149 "Species tree successfully loaded",
2150 "Species tree loaded",
2151 JOptionPane.INFORMATION_MESSAGE );
2153 _contentpane.repaint();
2158 private void setCurrentDir( final File current_dir ) {
2159 _current_dir = current_dir;
2162 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2163 _min_not_collapse = min_not_collapse;
2166 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2167 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2170 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2171 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2172 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2173 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2174 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2176 nhx.setTaxonomyExtraction( te );
2179 private void writeAllToFile() {
2180 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2183 final File my_dir = getCurrentDir();
2184 if ( my_dir != null ) {
2185 _save_filechooser.setCurrentDirectory( my_dir );
2187 _save_filechooser.setSelectedFile( new File( "" ) );
2188 final int result = _save_filechooser.showSaveDialog( _contentpane );
2189 final File file = _save_filechooser.getSelectedFile();
2190 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2191 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2192 if ( file.exists() ) {
2193 final int i = JOptionPane.showConfirmDialog( this,
2194 file + " already exists. Overwrite?",
2196 JOptionPane.OK_CANCEL_OPTION,
2197 JOptionPane.WARNING_MESSAGE );
2198 if ( i != JOptionPane.OK_OPTION ) {
2205 catch ( final Exception e ) {
2206 JOptionPane.showMessageDialog( this,
2207 "Failed to delete: " + file,
2209 JOptionPane.WARNING_MESSAGE );
2213 final int count = getMainPanel().getTabbedPane().getTabCount();
2214 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2215 for( int i = 0; i < count; ++i ) {
2216 trees.add( getMainPanel().getPhylogeny( i ) );
2217 getMainPanel().getTreePanels().get( i ).setEdited( false );
2219 final PhylogenyWriter writer = new PhylogenyWriter();
2221 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2223 catch ( final IOException e ) {
2224 JOptionPane.showMessageDialog( this,
2225 "Failed to write to: " + file,
2227 JOptionPane.WARNING_MESSAGE );
2232 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2234 final PhylogenyWriter writer = new PhylogenyWriter();
2235 writer.toNewHampshire( t, false, true, file );
2237 catch ( final Exception e ) {
2239 exceptionOccuredDuringSaveAs( e );
2244 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2246 final PhylogenyWriter writer = new PhylogenyWriter();
2247 writer.toNexus( file, t );
2249 catch ( final Exception e ) {
2251 exceptionOccuredDuringSaveAs( e );
2256 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2258 final PhylogenyWriter writer = new PhylogenyWriter();
2259 writer.toNewHampshireX( t, file );
2261 catch ( final Exception e ) {
2263 exceptionOccuredDuringSaveAs( e );
2268 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2270 final PhylogenyWriter writer = new PhylogenyWriter();
2271 writer.toPhyloXML( file, t, 0 );
2273 catch ( final Exception e ) {
2275 exceptionOccuredDuringSaveAs( e );
2280 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2281 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2282 _mainpanel.getCurrentTreePanel().getHeight(),
2284 String file_written_to = "";
2285 boolean error = false;
2287 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2288 _mainpanel.getCurrentTreePanel().getWidth(),
2289 _mainpanel.getCurrentTreePanel().getHeight(),
2290 _mainpanel.getCurrentTreePanel(),
2291 _mainpanel.getControlPanel(),
2295 catch ( final IOException e ) {
2297 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2300 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2301 JOptionPane.showMessageDialog( this,
2302 "Wrote image to: " + file_written_to,
2304 JOptionPane.INFORMATION_MESSAGE );
2307 JOptionPane.showMessageDialog( this,
2308 "There was an unknown problem when attempting to write to an image file: \""
2311 JOptionPane.ERROR_MESSAGE );
2314 _contentpane.repaint();
2317 private void writeToFile( final Phylogeny t ) {
2321 String initial_filename = null;
2322 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2324 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2326 catch ( final IOException e ) {
2327 initial_filename = null;
2330 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2331 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2334 _save_filechooser.setSelectedFile( new File( "" ) );
2336 final File my_dir = getCurrentDir();
2337 if ( my_dir != null ) {
2338 _save_filechooser.setCurrentDirectory( my_dir );
2340 final int result = _save_filechooser.showSaveDialog( _contentpane );
2341 final File file = _save_filechooser.getSelectedFile();
2342 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2343 boolean exception = false;
2344 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2345 if ( file.exists() ) {
2346 final int i = JOptionPane.showConfirmDialog( this,
2347 file + " already exists.\nOverwrite?",
2349 JOptionPane.OK_CANCEL_OPTION,
2350 JOptionPane.QUESTION_MESSAGE );
2351 if ( i != JOptionPane.OK_OPTION ) {
2355 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2357 ForesterUtil.copyFile( file, to );
2359 catch ( final Exception e ) {
2360 JOptionPane.showMessageDialog( this,
2361 "Failed to create backup copy " + to,
2362 "Failed to Create Backup Copy",
2363 JOptionPane.WARNING_MESSAGE );
2368 catch ( final Exception e ) {
2369 JOptionPane.showMessageDialog( this,
2370 "Failed to delete: " + file,
2372 JOptionPane.WARNING_MESSAGE );
2376 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2377 exception = writeAsNewHampshire( t, exception, file );
2379 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2380 exception = writeAsNHX( t, exception, file );
2382 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2383 exception = writeAsPhyloXml( t, exception, file );
2385 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2386 exception = writeAsNexus( t, exception, file );
2390 final String file_name = file.getName().trim().toLowerCase();
2391 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2392 || file_name.endsWith( ".tree" ) ) {
2393 exception = writeAsNewHampshire( t, exception, file );
2395 else if ( file_name.endsWith( ".nhx" ) ) {
2396 exception = writeAsNHX( t, exception, file );
2398 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2399 exception = writeAsNexus( t, exception, file );
2403 exception = writeAsPhyloXml( t, exception, file );
2407 getMainPanel().setTitleOfSelectedTab( file.getName() );
2408 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2409 getMainPanel().getCurrentTreePanel().setEdited( false );
2414 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2415 if ( ( t == null ) || t.isEmpty() ) {
2418 String initial_filename = "";
2419 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2420 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2422 if ( initial_filename.indexOf( '.' ) > 0 ) {
2423 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2425 initial_filename = initial_filename + "." + type;
2426 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2427 final File my_dir = getCurrentDir();
2428 if ( my_dir != null ) {
2429 _writetographics_filechooser.setCurrentDirectory( my_dir );
2431 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2432 File file = _writetographics_filechooser.getSelectedFile();
2433 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2434 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2435 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2436 file = new File( file.toString() + "." + type );
2438 if ( file.exists() ) {
2439 final int i = JOptionPane.showConfirmDialog( this,
2440 file + " already exists. Overwrite?",
2442 JOptionPane.OK_CANCEL_OPTION,
2443 JOptionPane.WARNING_MESSAGE );
2444 if ( i != JOptionPane.OK_OPTION ) {
2451 catch ( final Exception e ) {
2452 JOptionPane.showMessageDialog( this,
2453 "Failed to delete: " + file,
2455 JOptionPane.WARNING_MESSAGE );
2459 writePhylogenyToGraphicsFile( file.toString(), type );
2463 private void writeToPdf( final Phylogeny t ) {
2464 if ( ( t == null ) || t.isEmpty() ) {
2467 String initial_filename = "";
2468 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2469 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2471 if ( initial_filename.indexOf( '.' ) > 0 ) {
2472 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2474 initial_filename = initial_filename + ".pdf";
2475 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2476 final File my_dir = getCurrentDir();
2477 if ( my_dir != null ) {
2478 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2480 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2481 File file = _writetopdf_filechooser.getSelectedFile();
2482 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2483 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2484 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2485 file = new File( file.toString() + ".pdf" );
2487 if ( file.exists() ) {
2488 final int i = JOptionPane.showConfirmDialog( this,
2489 file + " already exists. Overwrite?",
2491 JOptionPane.OK_CANCEL_OPTION,
2492 JOptionPane.WARNING_MESSAGE );
2493 if ( i != JOptionPane.OK_OPTION ) {
2497 printPhylogenyToPdf( file.toString() );
2501 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2502 return new MainFrameApplication( phys, config, title );
2505 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2506 return new MainFrameApplication( phys, config_file_name, title );
2509 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2510 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2511 + o.getPrintSizeY() + ")" );
2514 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2515 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2518 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2519 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2521 .showMessageDialog( null,
2523 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2526 JOptionPane.WARNING_MESSAGE );
2530 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2531 _phylogenetic_inference_options = phylogenetic_inference_options;
2534 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2535 if ( _phylogenetic_inference_options == null ) {
2536 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2538 return _phylogenetic_inference_options;
2541 public Msa getMsa() {
2545 void setMsa( final Msa msa ) {
2549 void setMsaFile( final File msa_file ) {
2550 _msa_file = msa_file;
2553 public File getMsaFile() {
2557 public List<Sequence> getSeqs() {
2561 void setSeqs( final List<Sequence> seqs ) {
2565 void setSeqsFile( final File seqs_file ) {
2566 _seqs_file = seqs_file;
2569 public File getSeqsFile() {
2572 } // MainFrameApplication.
2574 class NexusFilter extends FileFilter {
2577 public boolean accept( final File f ) {
2578 final String file_name = f.getName().trim().toLowerCase();
2579 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2580 || file_name.endsWith( ".tre" ) || f.isDirectory();
2584 public String getDescription() {
2585 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2589 class NHFilter extends FileFilter {
2592 public boolean accept( final File f ) {
2593 final String file_name = f.getName().trim().toLowerCase();
2594 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2595 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2596 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2601 public String getDescription() {
2602 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2606 class NHXFilter extends FileFilter {
2609 public boolean accept( final File f ) {
2610 final String file_name = f.getName().trim().toLowerCase();
2611 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2615 public String getDescription() {
2616 return "NHX files (*.nhx)";
2620 class PdfFilter extends FileFilter {
2623 public boolean accept( final File f ) {
2624 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2628 public String getDescription() {
2629 return "PDF files (*.pdf)";
2633 class TolFilter extends FileFilter {
2636 public boolean accept( final File f ) {
2637 final String file_name = f.getName().trim().toLowerCase();
2638 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2639 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2643 public String getDescription() {
2644 return "Tree of Life files (*.tol, *.tolxml)";
2648 class XMLFilter extends FileFilter {
2651 public boolean accept( final File f ) {
2652 final String file_name = f.getName().trim().toLowerCase();
2653 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2654 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2658 public String getDescription() {
2659 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";