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.io.InputStream;
40 import java.net.MalformedURLException;
42 import java.util.ArrayList;
43 import java.util.HashSet;
44 import java.util.List;
47 import javax.swing.ButtonGroup;
48 import javax.swing.JCheckBoxMenuItem;
49 import javax.swing.JFileChooser;
50 import javax.swing.JMenu;
51 import javax.swing.JMenuBar;
52 import javax.swing.JMenuItem;
53 import javax.swing.JOptionPane;
54 import javax.swing.JRadioButtonMenuItem;
55 import javax.swing.UIManager;
56 import javax.swing.UnsupportedLookAndFeelException;
57 import javax.swing.WindowConstants;
58 import javax.swing.event.ChangeEvent;
59 import javax.swing.event.ChangeListener;
60 import javax.swing.filechooser.FileFilter;
61 import javax.swing.plaf.synth.SynthLookAndFeel;
63 import org.forester.analysis.TaxonomyDataManager;
64 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
65 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
66 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
67 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
68 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
69 import org.forester.archaeopteryx.tools.GoAnnotation;
70 import org.forester.archaeopteryx.tools.InferenceManager;
71 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
72 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
73 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
74 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
75 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
76 import org.forester.archaeopteryx.webservices.WebservicesManager;
77 import org.forester.io.parsers.FastaParser;
78 import org.forester.io.parsers.GeneralMsaParser;
79 import org.forester.io.parsers.PhylogenyParser;
80 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
81 import org.forester.io.parsers.nhx.NHXParser;
82 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
83 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
84 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
85 import org.forester.io.parsers.tol.TolParser;
86 import org.forester.io.parsers.util.ParserUtils;
87 import org.forester.io.writers.PhylogenyWriter;
88 import org.forester.io.writers.SequenceWriter;
89 import org.forester.msa.Msa;
90 import org.forester.msa.MsaFormatException;
91 import org.forester.phylogeny.Phylogeny;
92 import org.forester.phylogeny.PhylogenyMethods;
93 import org.forester.phylogeny.PhylogenyNode;
94 import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
95 import org.forester.phylogeny.data.Confidence;
96 import org.forester.phylogeny.data.Taxonomy;
97 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
98 import org.forester.phylogeny.factories.PhylogenyFactory;
99 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
100 import org.forester.sdi.GSDI;
101 import org.forester.sdi.SDIR;
102 import org.forester.sequence.Sequence;
103 import org.forester.util.BasicDescriptiveStatistics;
104 import org.forester.util.BasicTable;
105 import org.forester.util.BasicTableParser;
106 import org.forester.util.DescriptiveStatistics;
107 import org.forester.util.ForesterUtil;
108 import org.forester.util.WindowsUtils;
110 class DefaultFilter extends FileFilter {
113 public boolean accept( final File f ) {
114 final String file_name = f.getName().trim().toLowerCase();
115 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
116 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
117 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
118 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
119 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
120 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
121 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
122 || file_name.endsWith( ".con" ) || f.isDirectory();
126 public String getDescription() {
127 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
131 class GraphicsFileFilter extends FileFilter {
134 public boolean accept( final File f ) {
135 final String file_name = f.getName().trim().toLowerCase();
136 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
137 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
141 public String getDescription() {
142 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
146 class MsaFileFilter extends FileFilter {
149 public boolean accept( final File f ) {
150 final String file_name = f.getName().trim().toLowerCase();
151 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
152 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
156 public String getDescription() {
157 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
161 class SequencesFileFilter extends FileFilter {
164 public boolean accept( final File f ) {
165 final String file_name = f.getName().trim().toLowerCase();
166 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
167 || file_name.endsWith( ".seqs" ) || f.isDirectory();
171 public String getDescription() {
172 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
176 public final class MainFrameApplication extends MainFrame {
178 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
179 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
180 private final static int FRAME_X_SIZE = 800;
181 private final static int FRAME_Y_SIZE = 800;
182 // Filters for the file-open dialog (classes defined in this file)
183 private final static NHFilter nhfilter = new NHFilter();
184 private final static NHXFilter nhxfilter = new NHXFilter();
185 private final static XMLFilter xmlfilter = new XMLFilter();
186 private final static TolFilter tolfilter = new TolFilter();
187 private final static NexusFilter nexusfilter = new NexusFilter();
188 private final static PdfFilter pdffilter = new PdfFilter();
189 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
190 private final static MsaFileFilter msafilter = new MsaFileFilter();
191 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
192 private final static DefaultFilter defaultfilter = new DefaultFilter();
193 private static final long serialVersionUID = -799735726778865234L;
194 private final JFileChooser _values_filechooser;
195 private final JFileChooser _open_filechooser;
196 private final JFileChooser _msa_filechooser;
197 private final JFileChooser _seqs_filechooser;
198 private final JFileChooser _open_filechooser_for_species_tree;
199 private final JFileChooser _save_filechooser;
200 private final JFileChooser _writetopdf_filechooser;
201 private final JFileChooser _writetographics_filechooser;
203 private JMenu _analysis_menu;
204 private JMenuItem _load_species_tree_item;
205 private JMenuItem _gsdi_item;
206 private JMenuItem _root_min_dups_item;
207 private JMenuItem _root_min_cost_l_item;
208 private JMenuItem _lineage_inference;
209 private JMenuItem _function_analysis;
210 // Application-only print menu items
211 private JMenuItem _print_item;
212 private JMenuItem _write_to_pdf_item;
213 private JMenuItem _write_to_jpg_item;
214 private JMenuItem _write_to_gif_item;
215 private JMenuItem _write_to_tif_item;
216 private JMenuItem _write_to_png_item;
217 private JMenuItem _write_to_bmp_item;
218 private Phylogeny _species_tree;
219 private File _current_dir;
220 private ButtonGroup _radio_group_1;
222 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
223 // Phylogeny Inference menu
224 private JMenu _inference_menu;
225 private JMenuItem _inference_from_msa_item;
226 private JMenuItem _inference_from_seqs_item;
227 // Phylogeny Inference
228 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
229 private Msa _msa = null;
230 private File _msa_file = null;
231 private List<Sequence> _seqs = null;
232 private File _seqs_file = null;
233 // expression values menu:
234 JMenuItem _read_values_jmi;
236 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
237 this( phys, config, title, null );
240 private MainFrameApplication( final Phylogeny[] phys,
241 final Configuration config,
243 final File current_dir ) {
245 _configuration = config;
246 if ( _configuration == null ) {
247 throw new IllegalArgumentException( "configuration is null" );
250 boolean synth_exception = false;
251 if ( Constants.__SYNTH_LF ) {
253 final SynthLookAndFeel synth = new SynthLookAndFeel();
254 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
255 MainFrameApplication.class );
256 UIManager.setLookAndFeel( synth );
258 catch ( final Exception ex ) {
259 synth_exception = true;
260 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
261 "could not create synth look and feel: "
262 + ex.getLocalizedMessage() );
265 if ( !Constants.__SYNTH_LF || synth_exception ) {
266 if ( _configuration.isUseNativeUI() ) {
267 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
270 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
273 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
275 catch ( final UnsupportedLookAndFeelException e ) {
276 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
278 catch ( final ClassNotFoundException e ) {
279 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
281 catch ( final InstantiationException e ) {
282 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
284 catch ( final IllegalAccessException e ) {
285 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
287 catch ( final Exception e ) {
288 AptxUtil.dieWithSystemError( e.toString() );
290 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
291 setCurrentDir( current_dir );
293 // hide until everything is ready
295 setOptions( Options.createInstance( _configuration ) );
296 setInferenceManager( InferenceManager.createInstance( _configuration ) );
297 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
298 // _textframe = null; #~~~~
299 _species_tree = null;
301 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
302 _mainpanel = new MainPanel( _configuration, this );
304 _open_filechooser = new JFileChooser();
305 _open_filechooser.setCurrentDirectory( new File( "." ) );
306 _open_filechooser.setMultiSelectionEnabled( false );
307 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
308 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
309 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
310 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
311 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
312 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
313 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
314 _open_filechooser_for_species_tree = new JFileChooser();
315 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
316 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
317 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
318 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
319 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
320 _save_filechooser = new JFileChooser();
321 _save_filechooser.setCurrentDirectory( new File( "." ) );
322 _save_filechooser.setMultiSelectionEnabled( false );
323 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
324 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
325 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
326 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
327 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
328 _writetopdf_filechooser = new JFileChooser();
329 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
330 _writetographics_filechooser = new JFileChooser();
331 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
333 _msa_filechooser = new JFileChooser();
334 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
335 _msa_filechooser.setCurrentDirectory( new File( "." ) );
336 _msa_filechooser.setMultiSelectionEnabled( false );
337 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
338 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
340 _seqs_filechooser = new JFileChooser();
341 _seqs_filechooser.setName( "Read Sequences File" );
342 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
343 _seqs_filechooser.setMultiSelectionEnabled( false );
344 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
345 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
347 _values_filechooser = new JFileChooser();
348 _values_filechooser.setCurrentDirectory( new File( "." ) );
349 _values_filechooser.setMultiSelectionEnabled( false );
350 // build the menu bar
351 _jmenubar = new JMenuBar();
352 if ( !_configuration.isUseNativeUI() ) {
353 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
356 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
357 buildPhylogeneticInferenceMenu();
366 setJMenuBar( _jmenubar );
367 _jmenubar.add( _help_jmenu );
368 _contentpane = getContentPane();
369 _contentpane.setLayout( new BorderLayout() );
370 _contentpane.add( _mainpanel, BorderLayout.CENTER );
372 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
373 // addWindowFocusListener( new WindowAdapter() {
376 // public void windowGainedFocus( WindowEvent e ) {
377 // requestFocusInWindow();
380 // The window listener
381 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
382 addWindowListener( new WindowAdapter() {
385 public void windowClosing( final WindowEvent e ) {
386 if ( isUnsavedDataPresent() ) {
387 final int r = JOptionPane.showConfirmDialog( null,
388 "Exit despite potentially unsaved changes?",
390 JOptionPane.YES_NO_OPTION );
391 if ( r != JOptionPane.YES_OPTION ) {
396 final int r = JOptionPane.showConfirmDialog( null,
397 "Exit Archaeopteryx?",
399 JOptionPane.YES_NO_OPTION );
400 if ( r != JOptionPane.YES_OPTION ) {
407 // The component listener
408 addComponentListener( new ComponentAdapter() {
411 public void componentResized( final ComponentEvent e ) {
412 if ( _mainpanel.getCurrentTreePanel() != null ) {
413 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
415 _mainpanel.getCurrentTreePanel()
421 requestFocusInWindow();
422 // addKeyListener( this );
424 if ( ( phys != null ) && ( phys.length > 0 ) ) {
425 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
427 getMainPanel().getControlPanel().showWholeAll();
428 getMainPanel().getControlPanel().showWhole();
430 activateSaveAllIfNeeded();
431 // ...and its children
432 _contentpane.repaint();
436 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
437 _configuration = config;
438 if ( _configuration == null ) {
439 throw new IllegalArgumentException( "configuration is null" );
442 setOptions( Options.createInstance( _configuration ) );
443 _mainpanel = new MainPanel( _configuration, this );
444 _open_filechooser = null;
445 _open_filechooser_for_species_tree = null;
446 _save_filechooser = null;
447 _writetopdf_filechooser = null;
448 _writetographics_filechooser = null;
449 _msa_filechooser = null;
450 _seqs_filechooser = null;
451 _values_filechooser = null;
452 _jmenubar = new JMenuBar();
455 _contentpane = getContentPane();
456 _contentpane.setLayout( new BorderLayout() );
457 _contentpane.add( _mainpanel, BorderLayout.CENTER );
459 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
460 // The window listener
461 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
462 addWindowListener( new WindowAdapter() {
465 public void windowClosing( final WindowEvent e ) {
469 // setVisible( true );
470 if ( ( phys != null ) && ( phys.length > 0 ) ) {
471 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
473 getMainPanel().getControlPanel().showWholeAll();
474 getMainPanel().getControlPanel().showWhole();
476 //activateSaveAllIfNeeded();
477 // ...and its children
478 _contentpane.repaint();
481 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
482 // Reads the config file (false, false => not url, not applet):
483 this( phys, new Configuration( config_file, false, false, true ), title );
487 public void actionPerformed( final ActionEvent e ) {
489 super.actionPerformed( e );
490 final Object o = e.getSource();
491 // Handle app-specific actions here:
492 if ( o == _open_item ) {
493 readPhylogeniesFromFile();
495 else if ( o == _save_item ) {
496 writeToFile( _mainpanel.getCurrentPhylogeny() );
497 // If subtree currently displayed, save it, instead of complete
500 else if ( o == _new_item ) {
503 else if ( o == _save_all_item ) {
506 else if ( o == _close_item ) {
509 else if ( o == _write_to_pdf_item ) {
510 writeToPdf( _mainpanel.getCurrentPhylogeny() );
512 else if ( o == _write_to_jpg_item ) {
513 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
515 else if ( o == _write_to_png_item ) {
516 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
518 else if ( o == _write_to_gif_item ) {
519 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
521 else if ( o == _write_to_tif_item ) {
522 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
524 else if ( o == _write_to_bmp_item ) {
525 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
527 else if ( o == _print_item ) {
530 else if ( o == _load_species_tree_item ) {
531 readSpeciesTreeFromFile();
533 else if ( o == _lineage_inference ) {
534 if ( isSubtreeDisplayed() ) {
535 JOptionPane.showMessageDialog( this,
537 "Cannot infer ancestral taxonomies",
538 JOptionPane.ERROR_MESSAGE );
541 executeLineageInference();
543 else if ( o == _function_analysis ) {
544 executeFunctionAnalysis();
546 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
547 if ( isSubtreeDisplayed() ) {
550 obtainDetailedTaxonomicInformation();
552 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
553 if ( isSubtreeDisplayed() ) {
556 obtainDetailedTaxonomicInformationDelete();
558 else if ( o == _obtain_uniprot_seq_information_jmi ) {
559 obtainUniProtSequenceInformation();
561 else if ( o == _read_values_jmi ) {
562 if ( isSubtreeDisplayed() ) {
565 addExpressionValuesFromFile();
567 else if ( o == _move_node_names_to_tax_sn_jmi ) {
568 moveNodeNamesToTaxSn();
570 else if ( o == _move_node_names_to_seq_names_jmi ) {
571 moveNodeNamesToSeqNames();
573 else if ( o == _extract_tax_code_from_node_names_jmi ) {
574 extractTaxCodeFromNodeNames();
576 else if ( o == _gsdi_item ) {
577 if ( isSubtreeDisplayed() ) {
582 else if ( o == _root_min_dups_item ) {
583 if ( isSubtreeDisplayed() ) {
586 executeSDIR( false );
588 else if ( o == _root_min_cost_l_item ) {
589 if ( isSubtreeDisplayed() ) {
594 else if ( o == _graphics_export_visible_only_cbmi ) {
595 updateOptions( getOptions() );
597 else if ( o == _antialias_print_cbmi ) {
598 updateOptions( getOptions() );
600 else if ( o == _print_black_and_white_cbmi ) {
601 updateOptions( getOptions() );
603 else if ( o == _print_using_actual_size_cbmi ) {
604 updateOptions( getOptions() );
606 else if ( o == _graphics_export_using_actual_size_cbmi ) {
607 updateOptions( getOptions() );
609 else if ( o == _print_size_mi ) {
612 else if ( o == _choose_pdf_width_mi ) {
615 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
616 updateOptions( getOptions() );
618 else if ( o == _replace_underscores_cbmi ) {
619 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
620 _extract_pfam_style_tax_codes_cbmi.setSelected( false );
622 updateOptions( getOptions() );
624 else if ( o == _collapse_below_threshold ) {
625 if ( isSubtreeDisplayed() ) {
628 collapseBelowThreshold();
630 else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
631 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
632 _replace_underscores_cbmi.setSelected( false );
634 updateOptions( getOptions() );
636 else if ( o == _inference_from_msa_item ) {
637 executePhyleneticInference( false );
639 else if ( o == _inference_from_seqs_item ) {
640 executePhyleneticInference( true );
642 _contentpane.repaint();
644 catch ( final Exception ex ) {
645 AptxUtil.unexpectedException( ex );
647 catch ( final Error err ) {
648 AptxUtil.unexpectedError( err );
652 void buildAnalysisMenu() {
653 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
654 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
655 _analysis_menu.addSeparator();
656 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
657 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
658 _analysis_menu.addSeparator();
659 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
660 customizeJMenuItem( _gsdi_item );
661 customizeJMenuItem( _root_min_dups_item );
662 customizeJMenuItem( _root_min_cost_l_item );
663 customizeJMenuItem( _load_species_tree_item );
664 _analysis_menu.addSeparator();
665 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
666 customizeJMenuItem( _lineage_inference );
667 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
668 _jmenubar.add( _analysis_menu );
671 void buildPhylogeneticInferenceMenu() {
672 final InferenceManager im = getInferenceManager();
673 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
674 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
675 customizeJMenuItem( _inference_from_msa_item );
676 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
677 if ( im.canDoMsa() ) {
678 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
679 customizeJMenuItem( _inference_from_seqs_item );
680 _inference_from_seqs_item
681 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
685 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
686 customizeJMenuItem( _inference_from_seqs_item );
687 _inference_from_seqs_item.setEnabled( false );
689 _jmenubar.add( _inference_menu );
693 void buildFileMenu() {
694 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
695 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
696 _file_jmenu.addSeparator();
697 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
698 _file_jmenu.addSeparator();
699 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
700 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
701 .getAvailablePhylogeniesWebserviceClients().size() ];
702 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
703 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
704 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
705 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
707 if ( getConfiguration().isEditable() ) {
708 _file_jmenu.addSeparator();
709 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
710 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
712 _file_jmenu.addSeparator();
713 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
714 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
715 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
716 _save_all_item.setEnabled( false );
717 _file_jmenu.addSeparator();
718 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
719 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
720 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
722 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
723 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
724 if ( AptxUtil.canWriteFormat( "gif" ) ) {
725 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
727 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
728 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
730 _file_jmenu.addSeparator();
731 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
732 _file_jmenu.addSeparator();
733 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
734 _close_item.setToolTipText( "To close the current pane." );
735 _close_item.setEnabled( true );
736 _file_jmenu.addSeparator();
737 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
738 // For print in color option item
739 customizeJMenuItem( _open_item );
741 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
742 customizeJMenuItem( _open_url_item );
743 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
744 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
746 customizeJMenuItem( _save_item );
747 if ( getConfiguration().isEditable() ) {
748 customizeJMenuItem( _new_item );
750 customizeJMenuItem( _close_item );
751 customizeJMenuItem( _save_all_item );
752 customizeJMenuItem( _write_to_pdf_item );
753 customizeJMenuItem( _write_to_png_item );
754 customizeJMenuItem( _write_to_jpg_item );
755 customizeJMenuItem( _write_to_gif_item );
756 customizeJMenuItem( _write_to_tif_item );
757 customizeJMenuItem( _write_to_bmp_item );
758 customizeJMenuItem( _print_item );
759 customizeJMenuItem( _exit_item );
760 _jmenubar.add( _file_jmenu );
763 void buildOptionsMenu() {
764 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
765 _options_jmenu.addChangeListener( new ChangeListener() {
768 public void stateChanged( final ChangeEvent e ) {
769 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
770 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
772 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
773 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
774 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
775 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
776 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
777 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
779 _show_branch_length_values_cbmi,
780 _non_lined_up_cladograms_rbmi,
781 _uniform_cladograms_rbmi,
782 _ext_node_dependent_cladogram_rbmi,
783 _label_direction_cbmi );
784 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
785 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
786 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
789 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
791 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
792 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
793 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
794 _radio_group_1 = new ButtonGroup();
795 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
796 _radio_group_1.add( _uniform_cladograms_rbmi );
797 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
798 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
799 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
801 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
802 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
803 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
805 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
806 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
807 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
808 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
809 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
810 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
811 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
812 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
813 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
814 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
815 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
816 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
817 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
819 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
820 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
821 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
822 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
823 _options_jmenu.addSeparator();
824 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
825 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
826 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
827 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
828 _options_jmenu.addSeparator();
829 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
830 getConfiguration() ) );
831 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
832 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
834 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
836 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
838 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
839 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
840 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
841 _options_jmenu.addSeparator();
842 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
844 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
845 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
847 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
848 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
850 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
851 _use_brackets_for_conf_in_nh_export_cbmi
852 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
854 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
855 customizeJMenuItem( _choose_font_mi );
856 customizeJMenuItem( _choose_minimal_confidence_mi );
857 customizeJMenuItem( _switch_colors_mi );
858 customizeJMenuItem( _print_size_mi );
859 customizeJMenuItem( _choose_pdf_width_mi );
860 customizeJMenuItem( _overview_placment_mi );
861 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
862 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
863 customizeJMenuItem( _cycle_node_shape_mi );
864 customizeJMenuItem( _cycle_node_fill_mi );
865 customizeJMenuItem( _choose_node_size_mi );
866 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
867 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
868 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
869 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
870 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
871 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
872 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
873 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
874 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
875 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
876 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
877 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
878 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
879 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
880 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
881 customizeCheckBoxMenuItem( _label_direction_cbmi,
882 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
883 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
884 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
885 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
886 .isInternalNumberAreConfidenceForNhParsing() );
887 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
888 .isExtractPfamTaxonomyCodesInNhParsing() );
889 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
890 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
891 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
892 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
893 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
894 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
895 .isGraphicsExportUsingActualSize() );
896 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
897 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
898 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
899 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
900 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
901 _jmenubar.add( _options_jmenu );
904 void buildToolsMenu() {
905 _tools_menu = createMenu( "Tools", getConfiguration() );
906 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
907 customizeJMenuItem( _confcolor_item );
908 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
909 customizeJMenuItem( _color_rank_jmi );
910 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
911 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
912 customizeJMenuItem( _taxcolor_item );
913 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
914 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
915 customizeJMenuItem( _remove_branch_color_item );
916 _tools_menu.addSeparator();
917 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
918 customizeJMenuItem( _annotate_item );
919 _tools_menu.addSeparator();
920 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
921 customizeJMenuItem( _midpoint_root_item );
922 _tools_menu.addSeparator();
923 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
924 customizeJMenuItem( _collapse_species_specific_subtrees );
926 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
927 customizeJMenuItem( _collapse_below_threshold );
928 _collapse_below_threshold
929 .setToolTipText( "To collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );
930 _tools_menu.addSeparator();
932 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
933 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
934 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
935 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
936 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
937 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
939 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
940 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
941 _extract_tax_code_from_node_names_jmi
942 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
943 _tools_menu.addSeparator();
945 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
946 customizeJMenuItem( _infer_common_sn_names_item );
947 _tools_menu.addSeparator();
949 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
950 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
951 _obtain_detailed_taxonomic_information_jmi
952 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
954 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
955 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
956 _obtain_detailed_taxonomic_information_deleting_jmi
957 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
958 _tools_menu.add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
959 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
960 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information" );
961 _tools_menu.addSeparator();
962 if ( !Constants.__RELEASE ) {
963 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
964 customizeJMenuItem( _function_analysis );
966 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
967 _tools_menu.addSeparator();
969 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
970 customizeJMenuItem( _read_values_jmi );
971 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
972 _jmenubar.add( _tools_menu );
975 private void choosePdfWidth() {
976 final String s = ( String ) JOptionPane.showInputDialog( this,
977 "Please enter the default line width for PDF export.\n"
979 + getOptions().getPrintLineWidth() + "]\n",
980 "Line Width for PDF Export",
981 JOptionPane.QUESTION_MESSAGE,
984 getOptions().getPrintLineWidth() );
985 if ( !ForesterUtil.isEmpty( s ) ) {
986 boolean success = true;
988 final String m_str = s.trim();
989 if ( !ForesterUtil.isEmpty( m_str ) ) {
991 f = Float.parseFloat( m_str );
993 catch ( final Exception ex ) {
1000 if ( success && ( f > 0.0 ) ) {
1001 getOptions().setPrintLineWidth( f );
1006 private void choosePrintSize() {
1007 final String s = ( String ) JOptionPane.showInputDialog( this,
1008 "Please enter values for width and height,\nseparated by a comma.\n"
1009 + "[current values: "
1010 + getOptions().getPrintSizeX() + ", "
1011 + getOptions().getPrintSizeY() + "]\n"
1012 + "[A4: " + Constants.A4_SIZE_X + ", "
1013 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
1014 + Constants.US_LETTER_SIZE_X + ", "
1015 + Constants.US_LETTER_SIZE_Y + "]",
1016 "Default Size for Graphics Export",
1017 JOptionPane.QUESTION_MESSAGE,
1020 getOptions().getPrintSizeX() + ", "
1021 + getOptions().getPrintSizeY() );
1022 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
1023 boolean success = true;
1026 final String[] str_ary = s.split( "," );
1027 if ( str_ary.length == 2 ) {
1028 final String x_str = str_ary[ 0 ].trim();
1029 final String y_str = str_ary[ 1 ].trim();
1030 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
1032 x = Integer.parseInt( x_str );
1033 y = Integer.parseInt( y_str );
1035 catch ( final Exception ex ) {
1046 if ( success && ( x > 1 ) && ( y > 1 ) ) {
1047 getOptions().setPrintSizeX( x );
1048 getOptions().setPrintSizeY( y );
1055 if ( isUnsavedDataPresent() ) {
1056 final int r = JOptionPane.showConfirmDialog( this,
1057 "Exit despite potentially unsaved changes?",
1059 JOptionPane.YES_NO_OPTION );
1060 if ( r != JOptionPane.YES_OPTION ) {
1067 private void closeCurrentPane() {
1068 if ( getMainPanel().getCurrentTreePanel() != null ) {
1069 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1070 final int r = JOptionPane.showConfirmDialog( this,
1071 "Close tab despite potentially unsaved changes?",
1073 JOptionPane.YES_NO_OPTION );
1074 if ( r != JOptionPane.YES_OPTION ) {
1078 getMainPanel().closeCurrentPane();
1079 activateSaveAllIfNeeded();
1083 private void collapse( final Phylogeny phy, final double m ) {
1084 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1085 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1086 double min_support = Double.MAX_VALUE;
1087 boolean conf_present = false;
1088 while ( it.hasNext() ) {
1089 final PhylogenyNode n = it.next();
1090 if ( !n.isExternal() && !n.isRoot() ) {
1091 final List<Confidence> c = n.getBranchData().getConfidences();
1092 if ( ( c != null ) && ( c.size() > 0 ) ) {
1093 conf_present = true;
1095 for( final Confidence confidence : c ) {
1096 if ( confidence.getValue() > max ) {
1097 max = confidence.getValue();
1100 if ( max < getMinNotCollapseConfidenceValue() ) {
1101 to_be_removed.add( n );
1103 if ( max < min_support ) {
1109 if ( conf_present ) {
1110 for( final PhylogenyNode node : to_be_removed ) {
1111 PhylogenyMethods.removeNode( node, phy );
1113 if ( to_be_removed.size() > 0 ) {
1114 phy.externalNodesHaveChanged();
1115 phy.clearHashIdToNodeMap();
1116 phy.recalculateNumberOfExternalDescendants( true );
1117 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1118 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1119 getCurrentTreePanel().calculateLongestExtNodeInfo();
1120 getCurrentTreePanel().setNodeInPreorderToNull();
1121 getCurrentTreePanel().recalculateMaxDistanceToRoot();
1122 getCurrentTreePanel().resetPreferredSize();
1123 getCurrentTreePanel().setEdited( true );
1124 getCurrentTreePanel().repaint();
1127 if ( to_be_removed.size() > 0 ) {
1128 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1129 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1130 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1133 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1134 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1138 JOptionPane.showMessageDialog( this,
1139 "No branch collapsed because no confidence values present",
1140 "No confidence values present",
1141 JOptionPane.INFORMATION_MESSAGE );
1145 private void collapseBelowThreshold() {
1146 if ( getCurrentTreePanel() != null ) {
1147 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1148 if ( ( phy != null ) && !phy.isEmpty() ) {
1149 final String s = ( String ) JOptionPane.showInputDialog( this,
1150 "Please enter the minimum confidence value\n",
1151 "Minimal Confidence Value",
1152 JOptionPane.QUESTION_MESSAGE,
1155 getMinNotCollapseConfidenceValue() );
1156 if ( !ForesterUtil.isEmpty( s ) ) {
1157 boolean success = true;
1159 final String m_str = s.trim();
1160 if ( !ForesterUtil.isEmpty( m_str ) ) {
1162 m = Double.parseDouble( m_str );
1164 catch ( final Exception ex ) {
1171 if ( success && ( m >= 0.0 ) ) {
1172 setMinNotCollapseConfidenceValue( m );
1180 private PhyloXmlParser createPhyloXmlParser() {
1181 PhyloXmlParser xml_parser = null;
1182 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1184 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1186 catch ( final Exception e ) {
1187 JOptionPane.showMessageDialog( this,
1188 e.getLocalizedMessage(),
1189 "failed to create validating XML parser",
1190 JOptionPane.WARNING_MESSAGE );
1193 if ( xml_parser == null ) {
1194 xml_parser = new PhyloXmlParser();
1199 void executeGSDI() {
1200 if ( !isOKforSDI( false, true ) ) {
1203 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1204 JOptionPane.showMessageDialog( this,
1205 "Gene tree is not rooted.",
1206 "Cannot execute GSDI",
1207 JOptionPane.ERROR_MESSAGE );
1210 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1211 gene_tree.setAllNodesToNotCollapse();
1212 gene_tree.recalculateNumberOfExternalDescendants( false );
1215 gsdi = new GSDI( gene_tree, _species_tree.copy(), false, true, true );
1217 catch ( final Exception e ) {
1218 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1220 gene_tree.setRerootable( false );
1221 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1222 _mainpanel.getCurrentPhylogeny().clearHashIdToNodeMap();
1223 _mainpanel.getCurrentPhylogeny().recalculateNumberOfExternalDescendants( true );
1224 _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1225 _mainpanel.getCurrentTreePanel().setEdited( true );
1226 getControlPanel().setShowEvents( true );
1228 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1229 _mainpanel.addPhylogenyInNewTab( gsdi.getSpeciesTree(), getConfiguration(), "species tree", null );
1231 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1233 _mainpanel.getCurrentTreePanel().setEdited( true );
1234 JOptionPane.showMessageDialog( this, "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1235 + "Potential duplications: " + gsdi.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
1236 + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
1239 void executeFunctionAnalysis() {
1240 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1243 final GoAnnotation a = new GoAnnotation( this,
1244 _mainpanel.getCurrentTreePanel(),
1245 _mainpanel.getCurrentPhylogeny() );
1246 new Thread( a ).start();
1249 void executeLineageInference() {
1250 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1253 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1254 JOptionPane.showMessageDialog( this,
1255 "Phylogeny is not rooted.",
1256 "Cannot infer ancestral taxonomies",
1257 JOptionPane.ERROR_MESSAGE );
1260 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1261 _mainpanel.getCurrentTreePanel(),
1262 _mainpanel.getCurrentPhylogeny()
1264 new Thread( inferrer ).start();
1267 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1268 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1269 getPhylogeneticInferenceOptions(),
1270 from_unaligned_seqs );
1272 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1273 if ( !from_unaligned_seqs ) {
1274 if ( getMsa() != null ) {
1275 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1276 getPhylogeneticInferenceOptions()
1278 new Thread( inferrer ).start();
1281 JOptionPane.showMessageDialog( this,
1282 "No multiple sequence alignment selected",
1283 "Phylogenetic Inference Not Launched",
1284 JOptionPane.WARNING_MESSAGE );
1288 if ( getSeqs() != null ) {
1289 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1290 getPhylogeneticInferenceOptions()
1292 new Thread( inferrer ).start();
1295 JOptionPane.showMessageDialog( this,
1296 "No input sequences selected",
1297 "Phylogenetic Inference Not Launched",
1298 JOptionPane.WARNING_MESSAGE );
1304 void executeSDIR( final boolean minimize_cost ) {
1305 if ( !isOKforSDI( true, true ) ) {
1308 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1309 final SDIR sdiunrooted = new SDIR();
1310 gene_tree.setAllNodesToNotCollapse();
1311 gene_tree.recalculateNumberOfExternalDescendants( false );
1313 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1314 !minimize_cost, // minimize sum of dups
1315 true, // minimize height
1316 true, // return tree(s)
1317 1 )[ 0 ]; // # of trees to return
1319 catch ( final Exception e ) {
1320 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1323 final int duplications = sdiunrooted.getMinimalDuplications();
1324 gene_tree.setRerootable( false );
1325 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1326 getControlPanel().setShowEvents( true );
1328 _mainpanel.getCurrentTreePanel().setEdited( true );
1329 JOptionPane.showMessageDialog( this,
1330 "Number of duplications: " + duplications,
1331 "SDIR successfully completed",
1332 JOptionPane.INFORMATION_MESSAGE );
1336 removeAllTextFrames();
1337 _mainpanel.terminate();
1338 _contentpane.removeAll();
1339 setVisible( false );
1345 _mainpanel.terminate();
1346 _contentpane.removeAll();
1347 setVisible( false );
1351 private void extractTaxCodeFromNodeNames() throws PhyloXmlDataFormatException {
1352 if ( getCurrentTreePanel() != null ) {
1353 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1354 if ( ( phy != null ) && !phy.isEmpty() ) {
1355 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1356 while ( it.hasNext() ) {
1357 final PhylogenyNode n = it.next();
1358 final String name = n.getName().trim();
1359 if ( !ForesterUtil.isEmpty( name ) ) {
1360 final String code = ParserUtils
1361 .extractTaxonomyCodeFromNodeName( name, PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
1362 if ( !ForesterUtil.isEmpty( code ) ) {
1363 PhylogenyMethods.setTaxonomyCode( n, code );
1371 private ControlPanel getControlPanel() {
1372 return getMainPanel().getControlPanel();
1375 private File getCurrentDir() {
1376 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1377 if ( ForesterUtil.isWindowns() ) {
1379 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1381 catch ( final Exception e ) {
1382 _current_dir = null;
1386 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1387 if ( System.getProperty( "user.home" ) != null ) {
1388 _current_dir = new File( System.getProperty( "user.home" ) );
1390 else if ( System.getProperty( "user.dir" ) != null ) {
1391 _current_dir = new File( System.getProperty( "user.dir" ) );
1394 return _current_dir;
1398 public MainPanel getMainPanel() {
1402 private double getMinNotCollapseConfidenceValue() {
1403 return _min_not_collapse;
1406 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1407 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1410 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1411 JOptionPane.showMessageDialog( this,
1412 "No species tree loaded",
1413 "Cannot execute SDI",
1414 JOptionPane.ERROR_MESSAGE );
1417 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1418 JOptionPane.showMessageDialog( this,
1419 "Species tree is not completely binary",
1420 "Cannot execute SDI",
1421 JOptionPane.ERROR_MESSAGE );
1424 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1425 JOptionPane.showMessageDialog( this,
1426 "Gene tree is not completely binary",
1427 "Cannot execute SDI",
1428 JOptionPane.ERROR_MESSAGE );
1436 private boolean isUnsavedDataPresent() {
1437 final List<TreePanel> tps = getMainPanel().getTreePanels();
1438 for( final TreePanel tp : tps ) {
1439 if ( tp.isEdited() ) {
1446 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
1447 if ( getCurrentTreePanel() != null ) {
1448 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1449 if ( ( phy != null ) && !phy.isEmpty() ) {
1451 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
1456 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
1457 if ( getCurrentTreePanel() != null ) {
1458 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1459 if ( ( phy != null ) && !phy.isEmpty() ) {
1460 PhylogenyMethods.transferNodeNameToField( phy,
1461 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
1467 private void newTree() {
1468 final Phylogeny[] phys = new Phylogeny[ 1 ];
1469 final Phylogeny phy = new Phylogeny();
1470 final PhylogenyNode node = new PhylogenyNode();
1471 phy.setRoot( node );
1472 phy.setRooted( true );
1474 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1475 _mainpanel.getControlPanel().showWhole();
1476 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1477 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1478 if ( getMainPanel().getMainFrame() == null ) {
1479 // Must be "E" applet version.
1480 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1481 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1484 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1486 activateSaveAllIfNeeded();
1490 private void obtainDetailedTaxonomicInformation() {
1491 if ( getCurrentTreePanel() != null ) {
1492 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1493 if ( ( phy != null ) && !phy.isEmpty() ) {
1494 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1495 _mainpanel.getCurrentTreePanel(),
1499 new Thread( t ).start();
1504 private void obtainDetailedTaxonomicInformationDelete() {
1505 if ( getCurrentTreePanel() != null ) {
1506 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1507 if ( ( phy != null ) && !phy.isEmpty() ) {
1508 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1509 _mainpanel.getCurrentTreePanel(),
1513 new Thread( t ).start();
1518 private void obtainUniProtSequenceInformation() {
1519 if ( getCurrentTreePanel() != null ) {
1520 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1521 if ( ( phy != null ) && !phy.isEmpty() ) {
1522 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1523 _mainpanel.getCurrentTreePanel(),
1525 new Thread( u ).start();
1530 private void print() {
1531 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1532 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1535 if ( !getOptions().isPrintUsingActualSize() ) {
1536 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1537 getOptions().getPrintSizeY() - 140,
1539 getCurrentTreePanel().resetPreferredSize();
1540 getCurrentTreePanel().repaint();
1542 final String job_name = Constants.PRG_NAME;
1543 boolean error = false;
1544 String printer_name = null;
1546 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1548 catch ( final Exception e ) {
1550 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1552 if ( !error && ( printer_name != null ) ) {
1553 String msg = "Printing data sent to printer";
1554 if ( printer_name.length() > 1 ) {
1555 msg += " [" + printer_name + "]";
1557 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1559 if ( !getOptions().isPrintUsingActualSize() ) {
1560 getControlPanel().showWhole();
1564 private void printPhylogenyToPdf( final String file_name ) {
1565 if ( !getOptions().isPrintUsingActualSize() ) {
1566 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1567 getOptions().getPrintSizeY(),
1569 getCurrentTreePanel().resetPreferredSize();
1570 getCurrentTreePanel().repaint();
1572 String pdf_written_to = "";
1573 boolean error = false;
1575 if ( getOptions().isPrintUsingActualSize() ) {
1576 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1577 getCurrentTreePanel(),
1578 getCurrentTreePanel().getWidth(),
1579 getCurrentTreePanel().getHeight() );
1582 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1583 .getPrintSizeX(), getOptions().getPrintSizeY() );
1586 catch ( final IOException e ) {
1588 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1591 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1592 JOptionPane.showMessageDialog( this,
1593 "Wrote PDF to: " + pdf_written_to,
1595 JOptionPane.INFORMATION_MESSAGE );
1598 JOptionPane.showMessageDialog( this,
1599 "There was an unknown problem when attempting to write to PDF file: \""
1602 JOptionPane.ERROR_MESSAGE );
1605 if ( !getOptions().isPrintUsingActualSize() ) {
1606 getControlPanel().showWhole();
1610 private void addExpressionValuesFromFile() {
1611 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1612 JOptionPane.showMessageDialog( this,
1613 "Need to load evolutionary tree first",
1614 "Can Not Read Expression Values",
1615 JOptionPane.WARNING_MESSAGE );
1618 final File my_dir = getCurrentDir();
1619 if ( my_dir != null ) {
1620 _values_filechooser.setCurrentDirectory( my_dir );
1622 final int result = _values_filechooser.showOpenDialog( _contentpane );
1623 final File file = _values_filechooser.getSelectedFile();
1624 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1625 BasicTable<String> t = null;
1627 t = BasicTableParser.parse( file, "\t" );
1628 if ( t.getNumberOfColumns() < 2 ) {
1629 t = BasicTableParser.parse( file, "," );
1631 if ( t.getNumberOfColumns() < 2 ) {
1632 t = BasicTableParser.parse( file, " " );
1635 catch ( final IOException e ) {
1636 JOptionPane.showMessageDialog( this,
1638 "Could Not Read Expression Value Table",
1639 JOptionPane.ERROR_MESSAGE );
1642 if ( t.getNumberOfColumns() < 2 ) {
1643 JOptionPane.showMessageDialog( this,
1644 "Table contains " + t.getNumberOfColumns() + " column(s)",
1645 "Problem with Expression Value Table",
1646 JOptionPane.ERROR_MESSAGE );
1649 if ( t.getNumberOfRows() < 1 ) {
1650 JOptionPane.showMessageDialog( this,
1651 "Table contains zero rows",
1652 "Problem with Expression Value Table",
1653 JOptionPane.ERROR_MESSAGE );
1656 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1657 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1658 JOptionPane.showMessageDialog( this,
1659 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1660 + phy.getNumberOfExternalNodes() + " external nodes",
1662 JOptionPane.WARNING_MESSAGE );
1664 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1666 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1667 final PhylogenyNode node = iter.next();
1668 final String node_name = node.getName();
1669 if ( !ForesterUtil.isEmpty( node_name ) ) {
1672 row = t.findRow( node_name );
1674 catch ( final IllegalArgumentException e ) {
1676 .showMessageDialog( this,
1678 "Error Mapping Node Identifiers to Expression Value Identifiers",
1679 JOptionPane.ERROR_MESSAGE );
1683 if ( node.isExternal() ) {
1688 final List<Double> l = new ArrayList<Double>();
1689 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1692 d = Double.parseDouble( t.getValueAsString( col, row ) );
1694 catch ( final NumberFormatException e ) {
1695 JOptionPane.showMessageDialog( this,
1696 "Could not parse \"" + t.getValueAsString( col, row )
1697 + "\" into a decimal value",
1698 "Issue with Expression Value Table",
1699 JOptionPane.ERROR_MESSAGE );
1702 stats.addValue( d );
1705 if ( !l.isEmpty() ) {
1706 if ( node.getNodeData().getProperties() != null ) {
1707 node.getNodeData().getProperties()
1708 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1710 node.getNodeData().setVector( l );
1714 if ( not_found > 0 ) {
1715 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1716 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1718 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1722 private void readPhylogeniesFromFile() {
1723 boolean exception = false;
1724 Phylogeny[] phys = null;
1725 // Set an initial directory if none set yet
1726 final File my_dir = getCurrentDir();
1727 _open_filechooser.setMultiSelectionEnabled( true );
1728 // Open file-open dialog and set current directory
1729 if ( my_dir != null ) {
1730 _open_filechooser.setCurrentDirectory( my_dir );
1732 final int result = _open_filechooser.showOpenDialog( _contentpane );
1733 // All done: get the file
1734 final File[] files = _open_filechooser.getSelectedFiles();
1735 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1736 boolean nhx_or_nexus = false;
1737 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1738 for( final File file : files ) {
1739 if ( ( file != null ) && !file.isDirectory() ) {
1740 if ( _mainpanel.getCurrentTreePanel() != null ) {
1741 _mainpanel.getCurrentTreePanel().setWaitCursor();
1744 _mainpanel.setWaitCursor();
1746 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1747 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1749 final NHXParser nhx = new NHXParser();
1750 setSpecialOptionsForNhxParser( nhx );
1751 phys = PhylogenyMethods.readPhylogenies( nhx, file );
1752 nhx_or_nexus = true;
1754 catch ( final Exception e ) {
1756 exceptionOccuredDuringOpenFile( e );
1759 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1760 warnIfNotPhyloXmlValidation( getConfiguration() );
1762 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1763 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
1765 catch ( final Exception e ) {
1767 exceptionOccuredDuringOpenFile( e );
1770 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1772 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
1774 catch ( final Exception e ) {
1776 exceptionOccuredDuringOpenFile( e );
1779 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1781 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1782 setSpecialOptionsForNexParser( nex );
1783 phys = PhylogenyMethods.readPhylogenies( nex, file );
1784 nhx_or_nexus = true;
1786 catch ( final Exception e ) {
1788 exceptionOccuredDuringOpenFile( e );
1794 final PhylogenyParser parser = ParserUtils
1795 .createParserDependingOnFileType( file, getConfiguration()
1796 .isValidatePhyloXmlAgainstSchema() );
1797 if ( parser instanceof NexusPhylogeniesParser ) {
1798 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1799 setSpecialOptionsForNexParser( nex );
1800 nhx_or_nexus = true;
1802 else if ( parser instanceof NHXParser ) {
1803 final NHXParser nhx = ( NHXParser ) parser;
1804 setSpecialOptionsForNhxParser( nhx );
1805 nhx_or_nexus = true;
1807 else if ( parser instanceof PhyloXmlParser ) {
1808 warnIfNotPhyloXmlValidation( getConfiguration() );
1810 phys = PhylogenyMethods.readPhylogenies( parser, file );
1812 catch ( final Exception e ) {
1814 exceptionOccuredDuringOpenFile( e );
1817 if ( _mainpanel.getCurrentTreePanel() != null ) {
1818 _mainpanel.getCurrentTreePanel().setArrowCursor();
1821 _mainpanel.setArrowCursor();
1823 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1824 boolean one_desc = false;
1825 if ( nhx_or_nexus ) {
1826 for( final Phylogeny phy : phys ) {
1827 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1828 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
1830 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1836 AptxUtil.addPhylogeniesToTabs( phys,
1838 file.getAbsolutePath(),
1841 _mainpanel.getControlPanel().showWhole();
1842 if ( nhx_or_nexus && one_desc ) {
1844 .showMessageDialog( this,
1845 "One or more trees contain (a) node(s) with one descendant, "
1846 + ForesterUtil.LINE_SEPARATOR
1847 + "possibly indicating illegal parentheses within node names.",
1848 "Warning: Possible Error in New Hampshire Formatted Data",
1849 JOptionPane.WARNING_MESSAGE );
1855 activateSaveAllIfNeeded();
1859 public void readSeqsFromFile() {
1860 // Set an initial directory if none set yet
1861 final File my_dir = getCurrentDir();
1862 _seqs_filechooser.setMultiSelectionEnabled( false );
1863 // Open file-open dialog and set current directory
1864 if ( my_dir != null ) {
1865 _seqs_filechooser.setCurrentDirectory( my_dir );
1867 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1868 // All done: get the seqs
1869 final File file = _seqs_filechooser.getSelectedFile();
1870 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1871 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1872 setSeqsFile( null );
1874 List<Sequence> seqs = null;
1876 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1877 seqs = FastaParser.parse( new FileInputStream( file ) );
1878 for( final Sequence seq : seqs ) {
1879 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1886 catch ( final MsaFormatException e ) {
1888 _mainpanel.getCurrentTreePanel().setArrowCursor();
1890 catch ( final Exception ex ) {
1893 JOptionPane.showMessageDialog( this,
1894 e.getLocalizedMessage(),
1895 "Multiple sequence file format error",
1896 JOptionPane.ERROR_MESSAGE );
1899 catch ( final IOException e ) {
1901 _mainpanel.getCurrentTreePanel().setArrowCursor();
1903 catch ( final Exception ex ) {
1906 JOptionPane.showMessageDialog( this,
1907 e.getLocalizedMessage(),
1908 "Failed to read multiple sequence file",
1909 JOptionPane.ERROR_MESSAGE );
1912 catch ( final IllegalArgumentException e ) {
1914 _mainpanel.getCurrentTreePanel().setArrowCursor();
1916 catch ( final Exception ex ) {
1919 JOptionPane.showMessageDialog( this,
1920 e.getLocalizedMessage(),
1921 "Unexpected error during reading of multiple sequence file",
1922 JOptionPane.ERROR_MESSAGE );
1925 catch ( final Exception e ) {
1927 _mainpanel.getCurrentTreePanel().setArrowCursor();
1929 catch ( final Exception ex ) {
1932 e.printStackTrace();
1933 JOptionPane.showMessageDialog( this,
1934 e.getLocalizedMessage(),
1935 "Unexpected error during reading of multiple sequence file",
1936 JOptionPane.ERROR_MESSAGE );
1939 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1940 JOptionPane.showMessageDialog( this,
1941 "Multiple sequence file is empty",
1942 "Illegal multiple sequence file",
1943 JOptionPane.ERROR_MESSAGE );
1946 if ( seqs.size() < 4 ) {
1947 JOptionPane.showMessageDialog( this,
1948 "Multiple sequence file needs to contain at least 3 sequences",
1949 "Illegal multiple sequence file",
1950 JOptionPane.ERROR_MESSAGE );
1953 // if ( msa.getLength() < 2 ) {
1954 // JOptionPane.showMessageDialog( this,
1955 // "Multiple sequence alignment needs to contain at least 2 residues",
1956 // "Illegal multiple sequence file",
1957 // JOptionPane.ERROR_MESSAGE );
1961 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1966 public void readMsaFromFile() {
1967 // Set an initial directory if none set yet
1968 final File my_dir = getCurrentDir();
1969 _msa_filechooser.setMultiSelectionEnabled( false );
1970 // Open file-open dialog and set current directory
1971 if ( my_dir != null ) {
1972 _msa_filechooser.setCurrentDirectory( my_dir );
1974 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1975 // All done: get the msa
1976 final File file = _msa_filechooser.getSelectedFile();
1977 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1978 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1983 final InputStream is = new FileInputStream( file );
1984 if ( FastaParser.isLikelyFasta( file ) ) {
1985 msa = FastaParser.parseMsa( is );
1988 msa = GeneralMsaParser.parse( is );
1991 catch ( final MsaFormatException e ) {
1993 _mainpanel.getCurrentTreePanel().setArrowCursor();
1995 catch ( final Exception ex ) {
1998 JOptionPane.showMessageDialog( this,
1999 e.getLocalizedMessage(),
2000 "Multiple sequence alignment format error",
2001 JOptionPane.ERROR_MESSAGE );
2004 catch ( final IOException e ) {
2006 _mainpanel.getCurrentTreePanel().setArrowCursor();
2008 catch ( final Exception ex ) {
2011 JOptionPane.showMessageDialog( this,
2012 e.getLocalizedMessage(),
2013 "Failed to read multiple sequence alignment",
2014 JOptionPane.ERROR_MESSAGE );
2017 catch ( final IllegalArgumentException e ) {
2019 _mainpanel.getCurrentTreePanel().setArrowCursor();
2021 catch ( final Exception ex ) {
2024 JOptionPane.showMessageDialog( this,
2025 e.getLocalizedMessage(),
2026 "Unexpected error during reading of multiple sequence alignment",
2027 JOptionPane.ERROR_MESSAGE );
2030 catch ( final Exception e ) {
2032 _mainpanel.getCurrentTreePanel().setArrowCursor();
2034 catch ( final Exception ex ) {
2037 e.printStackTrace();
2038 JOptionPane.showMessageDialog( this,
2039 e.getLocalizedMessage(),
2040 "Unexpected error during reading of multiple sequence alignment",
2041 JOptionPane.ERROR_MESSAGE );
2044 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
2045 JOptionPane.showMessageDialog( this,
2046 "Multiple sequence alignment is empty",
2047 "Illegal Multiple Sequence Alignment",
2048 JOptionPane.ERROR_MESSAGE );
2051 if ( msa.getNumberOfSequences() < 4 ) {
2052 JOptionPane.showMessageDialog( this,
2053 "Multiple sequence alignment needs to contain at least 3 sequences",
2054 "Illegal multiple sequence alignment",
2055 JOptionPane.ERROR_MESSAGE );
2058 if ( msa.getLength() < 2 ) {
2059 JOptionPane.showMessageDialog( this,
2060 "Multiple sequence alignment needs to contain at least 2 residues",
2061 "Illegal multiple sequence alignment",
2062 JOptionPane.ERROR_MESSAGE );
2066 setMsaFile( _msa_filechooser.getSelectedFile() );
2072 void readPhylogeniesFromURL() {
2074 Phylogeny[] phys = null;
2075 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
2076 final String url_string = JOptionPane.showInputDialog( this,
2078 "Use URL/webservice to obtain a phylogeny",
2079 JOptionPane.QUESTION_MESSAGE );
2080 boolean nhx_or_nexus = false;
2081 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
2083 url = new URL( url_string );
2084 PhylogenyParser parser = null;
2085 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
2086 parser = new TolParser();
2089 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
2090 .isValidatePhyloXmlAgainstSchema() );
2092 if ( parser instanceof NexusPhylogeniesParser ) {
2093 nhx_or_nexus = true;
2095 else if ( parser instanceof NHXParser ) {
2096 nhx_or_nexus = true;
2098 if ( _mainpanel.getCurrentTreePanel() != null ) {
2099 _mainpanel.getCurrentTreePanel().setWaitCursor();
2102 _mainpanel.setWaitCursor();
2104 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2105 phys = factory.create( url.openStream(), parser );
2107 catch ( final MalformedURLException e ) {
2108 JOptionPane.showMessageDialog( this,
2109 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2111 JOptionPane.ERROR_MESSAGE );
2113 catch ( final IOException e ) {
2114 JOptionPane.showMessageDialog( this,
2115 "Could not read from " + url + "\n"
2116 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2117 "Failed to read URL",
2118 JOptionPane.ERROR_MESSAGE );
2120 catch ( final Exception e ) {
2121 JOptionPane.showMessageDialog( this,
2122 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2123 "Unexpected Exception",
2124 JOptionPane.ERROR_MESSAGE );
2127 if ( _mainpanel.getCurrentTreePanel() != null ) {
2128 _mainpanel.getCurrentTreePanel().setArrowCursor();
2131 _mainpanel.setArrowCursor();
2134 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2135 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2136 for( final Phylogeny phy : phys ) {
2137 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
2140 AptxUtil.addPhylogeniesToTabs( phys,
2141 new File( url.getFile() ).getName(),
2142 new File( url.getFile() ).toString(),
2145 _mainpanel.getControlPanel().showWhole();
2148 activateSaveAllIfNeeded();
2152 private void readSpeciesTreeFromFile() {
2154 boolean exception = false;
2155 final File my_dir = getCurrentDir();
2156 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2157 if ( my_dir != null ) {
2158 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2160 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2161 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2162 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2163 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2165 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2168 catch ( final Exception e ) {
2170 exceptionOccuredDuringOpenFile( e );
2173 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2175 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2178 catch ( final Exception e ) {
2180 exceptionOccuredDuringOpenFile( e );
2186 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2189 catch ( final Exception e ) {
2191 exceptionOccuredDuringOpenFile( e );
2194 if ( !exception && ( t != null ) && !t.isRooted() ) {
2197 JOptionPane.showMessageDialog( this,
2198 "Species tree is not rooted",
2199 "Species tree not loaded",
2200 JOptionPane.ERROR_MESSAGE );
2202 if ( !exception && ( t != null ) ) {
2203 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2204 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2205 final PhylogenyNode node = it.next();
2206 if ( !node.getNodeData().isHasTaxonomy() ) {
2210 .showMessageDialog( this,
2211 "Species tree contains external node(s) without taxonomy information",
2212 "Species tree not loaded",
2213 JOptionPane.ERROR_MESSAGE );
2217 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2220 JOptionPane.showMessageDialog( this,
2222 + node.getNodeData().getTaxonomy().asSimpleText()
2223 + "] is not unique in species tree",
2224 "Species tree not loaded",
2225 JOptionPane.ERROR_MESSAGE );
2229 tax_set.add( node.getNodeData().getTaxonomy() );
2234 if ( !exception && ( t != null ) ) {
2236 JOptionPane.showMessageDialog( this,
2237 "Species tree successfully loaded",
2238 "Species tree loaded",
2239 JOptionPane.INFORMATION_MESSAGE );
2241 _contentpane.repaint();
2246 private void setCurrentDir( final File current_dir ) {
2247 _current_dir = current_dir;
2250 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2251 _min_not_collapse = min_not_collapse;
2254 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2255 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2258 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2259 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2260 PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO;
2261 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2262 te = PhylogenyMethods.TAXONOMY_EXTRACTION.YES;
2264 nhx.setTaxonomyExtraction( te );
2267 private void writeAllToFile() {
2268 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2271 final File my_dir = getCurrentDir();
2272 if ( my_dir != null ) {
2273 _save_filechooser.setCurrentDirectory( my_dir );
2275 _save_filechooser.setSelectedFile( new File( "" ) );
2276 final int result = _save_filechooser.showSaveDialog( _contentpane );
2277 final File file = _save_filechooser.getSelectedFile();
2278 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2279 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2280 if ( file.exists() ) {
2281 final int i = JOptionPane.showConfirmDialog( this,
2282 file + " already exists. Overwrite?",
2284 JOptionPane.OK_CANCEL_OPTION,
2285 JOptionPane.WARNING_MESSAGE );
2286 if ( i != JOptionPane.OK_OPTION ) {
2293 catch ( final Exception e ) {
2294 JOptionPane.showMessageDialog( this,
2295 "Failed to delete: " + file,
2297 JOptionPane.WARNING_MESSAGE );
2301 final int count = getMainPanel().getTabbedPane().getTabCount();
2302 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2303 for( int i = 0; i < count; ++i ) {
2304 trees.add( getMainPanel().getPhylogeny( i ) );
2305 getMainPanel().getTreePanels().get( i ).setEdited( false );
2307 final PhylogenyWriter writer = new PhylogenyWriter();
2309 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2311 catch ( final IOException e ) {
2312 JOptionPane.showMessageDialog( this,
2313 "Failed to write to: " + file,
2315 JOptionPane.WARNING_MESSAGE );
2320 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2322 final PhylogenyWriter writer = new PhylogenyWriter();
2323 writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
2325 catch ( final Exception e ) {
2327 exceptionOccuredDuringSaveAs( e );
2332 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2334 final PhylogenyWriter writer = new PhylogenyWriter();
2335 writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
2337 catch ( final Exception e ) {
2339 exceptionOccuredDuringSaveAs( e );
2344 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2346 final PhylogenyWriter writer = new PhylogenyWriter();
2347 writer.toNewHampshireX( t, file );
2349 catch ( final Exception e ) {
2351 exceptionOccuredDuringSaveAs( e );
2356 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2358 final PhylogenyWriter writer = new PhylogenyWriter();
2359 writer.toPhyloXML( file, t, 0 );
2361 catch ( final Exception e ) {
2363 exceptionOccuredDuringSaveAs( e );
2368 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2369 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2370 _mainpanel.getCurrentTreePanel().getHeight(),
2372 String file_written_to = "";
2373 boolean error = false;
2375 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
2376 _mainpanel.getCurrentTreePanel().getWidth(),
2377 _mainpanel.getCurrentTreePanel().getHeight(),
2378 _mainpanel.getCurrentTreePanel(),
2379 _mainpanel.getControlPanel(),
2383 catch ( final IOException e ) {
2385 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2388 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2389 JOptionPane.showMessageDialog( this,
2390 "Wrote image to: " + file_written_to,
2392 JOptionPane.INFORMATION_MESSAGE );
2395 JOptionPane.showMessageDialog( this,
2396 "There was an unknown problem when attempting to write to an image file: \""
2399 JOptionPane.ERROR_MESSAGE );
2402 _contentpane.repaint();
2405 private void writeToFile( final Phylogeny t ) {
2409 String initial_filename = null;
2410 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2412 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2414 catch ( final IOException e ) {
2415 initial_filename = null;
2418 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2419 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2422 _save_filechooser.setSelectedFile( new File( "" ) );
2424 final File my_dir = getCurrentDir();
2425 if ( my_dir != null ) {
2426 _save_filechooser.setCurrentDirectory( my_dir );
2428 final int result = _save_filechooser.showSaveDialog( _contentpane );
2429 final File file = _save_filechooser.getSelectedFile();
2430 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2431 boolean exception = false;
2432 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2433 if ( file.exists() ) {
2434 final int i = JOptionPane.showConfirmDialog( this,
2435 file + " already exists.\nOverwrite?",
2437 JOptionPane.OK_CANCEL_OPTION,
2438 JOptionPane.QUESTION_MESSAGE );
2439 if ( i != JOptionPane.OK_OPTION ) {
2443 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2445 ForesterUtil.copyFile( file, to );
2447 catch ( final Exception e ) {
2448 JOptionPane.showMessageDialog( this,
2449 "Failed to create backup copy " + to,
2450 "Failed to Create Backup Copy",
2451 JOptionPane.WARNING_MESSAGE );
2456 catch ( final Exception e ) {
2457 JOptionPane.showMessageDialog( this,
2458 "Failed to delete: " + file,
2460 JOptionPane.WARNING_MESSAGE );
2464 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2465 exception = writeAsNewHampshire( t, exception, file );
2467 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2468 exception = writeAsNHX( t, exception, file );
2470 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2471 exception = writeAsPhyloXml( t, exception, file );
2473 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2474 exception = writeAsNexus( t, exception, file );
2478 final String file_name = file.getName().trim().toLowerCase();
2479 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2480 || file_name.endsWith( ".tree" ) ) {
2481 exception = writeAsNewHampshire( t, exception, file );
2483 else if ( file_name.endsWith( ".nhx" ) ) {
2484 exception = writeAsNHX( t, exception, file );
2486 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2487 exception = writeAsNexus( t, exception, file );
2491 exception = writeAsPhyloXml( t, exception, file );
2495 getMainPanel().setTitleOfSelectedTab( file.getName() );
2496 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2497 getMainPanel().getCurrentTreePanel().setEdited( false );
2502 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2503 if ( ( t == null ) || t.isEmpty() ) {
2506 String initial_filename = "";
2507 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2508 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2510 if ( initial_filename.indexOf( '.' ) > 0 ) {
2511 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2513 initial_filename = initial_filename + "." + type;
2514 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2515 final File my_dir = getCurrentDir();
2516 if ( my_dir != null ) {
2517 _writetographics_filechooser.setCurrentDirectory( my_dir );
2519 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2520 File file = _writetographics_filechooser.getSelectedFile();
2521 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2522 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2523 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2524 file = new File( file.toString() + "." + type );
2526 if ( file.exists() ) {
2527 final int i = JOptionPane.showConfirmDialog( this,
2528 file + " already exists. Overwrite?",
2530 JOptionPane.OK_CANCEL_OPTION,
2531 JOptionPane.WARNING_MESSAGE );
2532 if ( i != JOptionPane.OK_OPTION ) {
2539 catch ( final Exception e ) {
2540 JOptionPane.showMessageDialog( this,
2541 "Failed to delete: " + file,
2543 JOptionPane.WARNING_MESSAGE );
2547 writePhylogenyToGraphicsFile( file.toString(), type );
2551 private void writeToPdf( final Phylogeny t ) {
2552 if ( ( t == null ) || t.isEmpty() ) {
2555 String initial_filename = "";
2556 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2557 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2559 if ( initial_filename.indexOf( '.' ) > 0 ) {
2560 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2562 initial_filename = initial_filename + ".pdf";
2563 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2564 final File my_dir = getCurrentDir();
2565 if ( my_dir != null ) {
2566 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2568 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2569 File file = _writetopdf_filechooser.getSelectedFile();
2570 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2571 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2572 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2573 file = new File( file.toString() + ".pdf" );
2575 if ( file.exists() ) {
2576 final int i = JOptionPane.showConfirmDialog( this,
2577 file + " already exists. Overwrite?",
2579 JOptionPane.OK_CANCEL_OPTION,
2580 JOptionPane.WARNING_MESSAGE );
2581 if ( i != JOptionPane.OK_OPTION ) {
2585 printPhylogenyToPdf( file.toString() );
2589 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2590 return new MainFrameApplication( phys, config, title );
2593 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
2594 return new MainFrameApplication( phys, config );
2597 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2598 return new MainFrameApplication( phys, config_file_name, title );
2601 public static MainFrame createInstance( final Phylogeny[] phys,
2602 final Configuration config,
2604 final File current_dir ) {
2605 return new MainFrameApplication( phys, config, title, current_dir );
2608 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2609 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2610 + o.getPrintSizeY() + ")" );
2613 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2614 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2617 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2618 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2620 .showMessageDialog( null,
2622 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2625 JOptionPane.WARNING_MESSAGE );
2629 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2630 _phylogenetic_inference_options = phylogenetic_inference_options;
2633 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2634 if ( _phylogenetic_inference_options == null ) {
2635 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2637 return _phylogenetic_inference_options;
2640 public Msa getMsa() {
2644 void setMsa( final Msa msa ) {
2648 void setMsaFile( final File msa_file ) {
2649 _msa_file = msa_file;
2652 public File getMsaFile() {
2656 public List<Sequence> getSeqs() {
2660 void setSeqs( final List<Sequence> seqs ) {
2664 void setSeqsFile( final File seqs_file ) {
2665 _seqs_file = seqs_file;
2668 public File getSeqsFile() {
2671 } // MainFrameApplication.
2673 class NexusFilter extends FileFilter {
2676 public boolean accept( final File f ) {
2677 final String file_name = f.getName().trim().toLowerCase();
2678 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2679 || file_name.endsWith( ".tre" ) || f.isDirectory();
2683 public String getDescription() {
2684 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2688 class NHFilter extends FileFilter {
2691 public boolean accept( final File f ) {
2692 final String file_name = f.getName().trim().toLowerCase();
2693 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2694 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2695 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2700 public String getDescription() {
2701 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2705 class NHXFilter extends FileFilter {
2708 public boolean accept( final File f ) {
2709 final String file_name = f.getName().trim().toLowerCase();
2710 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2714 public String getDescription() {
2715 return "NHX files (*.nhx)";
2719 class PdfFilter extends FileFilter {
2722 public boolean accept( final File f ) {
2723 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2727 public String getDescription() {
2728 return "PDF files (*.pdf)";
2732 class TolFilter extends FileFilter {
2735 public boolean accept( final File f ) {
2736 final String file_name = f.getName().trim().toLowerCase();
2737 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2738 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2742 public String getDescription() {
2743 return "Tree of Life files (*.tol, *.tolxml)";
2747 class XMLFilter extends FileFilter {
2750 public boolean accept( final File f ) {
2751 final String file_name = f.getName().trim().toLowerCase();
2752 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2753 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2757 public String getDescription() {
2758 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";