2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
27 package org.forester.archaeopteryx;
29 import java.awt.BorderLayout;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.net.MalformedURLException;
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.List;
46 import javax.swing.ButtonGroup;
47 import javax.swing.Icon;
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;
62 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
63 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
64 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
65 import org.forester.archaeopteryx.Util.GraphicsExportType;
66 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
67 import org.forester.archaeopteryx.tools.GoAnnotation;
68 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
69 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
70 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
71 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
72 import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
73 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
74 import org.forester.archaeopteryx.webservices.WebservicesManager;
75 import org.forester.io.parsers.FastaParser;
76 import org.forester.io.parsers.GeneralMsaParser;
77 import org.forester.io.parsers.PhylogenyParser;
78 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
79 import org.forester.io.parsers.nhx.NHXParser;
80 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
81 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
82 import org.forester.io.parsers.tol.TolParser;
83 import org.forester.io.writers.PhylogenyWriter;
84 import org.forester.io.writers.SequenceWriter;
85 import org.forester.msa.Msa;
86 import org.forester.msa.MsaFormatException;
87 import org.forester.phylogeny.Phylogeny;
88 import org.forester.phylogeny.PhylogenyMethods;
89 import org.forester.phylogeny.PhylogenyNode;
90 import org.forester.phylogeny.data.Confidence;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.sdi.GSDI;
96 import org.forester.sdi.SDI;
97 import org.forester.sdi.SDIR;
98 import org.forester.sdi.SDIse;
99 import org.forester.sequence.Sequence;
100 import org.forester.util.BasicDescriptiveStatistics;
101 import org.forester.util.BasicTable;
102 import org.forester.util.BasicTableParser;
103 import org.forester.util.DescriptiveStatistics;
104 import org.forester.util.ForesterUtil;
105 import org.forester.util.ForesterUtil.PhylogenyNodeField;
106 import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
107 import org.forester.util.WindowsUtils;
109 class DefaultFilter extends FileFilter {
112 public boolean accept( final File f ) {
113 final String file_name = f.getName().trim().toLowerCase();
114 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
115 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
116 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
117 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
118 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
119 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
120 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
121 || file_name.endsWith( ".con" ) || f.isDirectory();
125 public String getDescription() {
126 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
130 class GraphicsFileFilter extends FileFilter {
133 public boolean accept( final File f ) {
134 final String file_name = f.getName().trim().toLowerCase();
135 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
136 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
140 public String getDescription() {
141 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
145 class MsaFileFilter extends FileFilter {
148 public boolean accept( final File f ) {
149 final String file_name = f.getName().trim().toLowerCase();
150 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
151 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
155 public String getDescription() {
156 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
160 class SequencesFileFilter extends FileFilter {
163 public boolean accept( final File f ) {
164 final String file_name = f.getName().trim().toLowerCase();
165 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
166 || file_name.endsWith( ".seqs" ) || f.isDirectory();
170 public String getDescription() {
171 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
175 public final class MainFrameApplication extends MainFrame {
177 private final static int FRAME_X_SIZE = 800;
178 private final static int FRAME_Y_SIZE = 800;
179 // Filters for the file-open dialog (classes defined in this file)
180 private final static NHFilter nhfilter = new NHFilter();
181 private final static NHXFilter nhxfilter = new NHXFilter();
182 private final static XMLFilter xmlfilter = new XMLFilter();
183 private final static TolFilter tolfilter = new TolFilter();
184 private final static NexusFilter nexusfilter = new NexusFilter();
185 private final static PdfFilter pdffilter = new PdfFilter();
186 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
187 private final static MsaFileFilter msafilter = new MsaFileFilter();
188 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
189 private final static DefaultFilter defaultfilter = new DefaultFilter();
190 private static final long serialVersionUID = -799735726778865234L;
192 private final JFileChooser _values_filechooser;
193 private final JFileChooser _open_filechooser;
194 private final JFileChooser _msa_filechooser;
195 private final JFileChooser _seqs_filechooser;
196 private final JFileChooser _open_filechooser_for_species_tree;
197 private final JFileChooser _save_filechooser;
198 private final JFileChooser _writetopdf_filechooser;
199 private final JFileChooser _writetographics_filechooser;
201 private JMenu _analysis_menu;
202 private JMenuItem _load_species_tree_item;
203 private JMenuItem _sdi_item;
204 private JMenuItem _gsdi_item;
205 private JMenuItem _root_min_dups_item;
206 private JMenuItem _root_min_cost_l_item;
207 private JMenuItem _lineage_inference;
208 private JMenuItem _function_analysis;
209 // Application-only print menu items
210 private JMenuItem _print_item;
211 private JMenuItem _write_to_pdf_item;
212 private JMenuItem _write_to_jpg_item;
213 private JMenuItem _write_to_gif_item;
214 private JMenuItem _write_to_tif_item;
215 private JMenuItem _write_to_png_item;
216 private JMenuItem _write_to_bmp_item;
217 private Phylogeny _species_tree;
218 private File _current_dir;
219 private ButtonGroup _radio_group_1;
221 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
222 // Phylogeny Inference menu
223 private JMenu _inference_menu;
224 private JMenuItem _inference_from_msa_item;
225 private JMenuItem _inference_from_seqs_item;
226 // Phylogeny Inference
227 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
228 private Msa _msa = null;
229 private File _msa_file = null;
230 private List<Sequence> _seqs = null;
231 private File _seqs_file = null;
232 // expression values menu:
233 JMenuItem _read_values_jmi;
235 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
236 _configuration = config;
237 if ( _configuration == null ) {
238 throw new IllegalArgumentException( "configuration is null" );
241 if ( _configuration.isUseNativeUI() ) {
242 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
245 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
247 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
249 catch ( final UnsupportedLookAndFeelException e ) {
250 Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
252 catch ( final ClassNotFoundException e ) {
253 Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
255 catch ( final InstantiationException e ) {
256 Util.dieWithSystemError( "InstantiationException: " + e.toString() );
258 catch ( final IllegalAccessException e ) {
259 Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
261 catch ( final Exception e ) {
262 Util.dieWithSystemError( e.toString() );
264 // hide until everything is ready
266 setOptions( Options.createInstance( _configuration ) );
267 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
269 _species_tree = null;
271 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
272 _mainpanel = new MainPanel( _configuration, this );
274 _open_filechooser = new JFileChooser();
275 _open_filechooser.setCurrentDirectory( new File( "." ) );
276 _open_filechooser.setMultiSelectionEnabled( false );
277 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
278 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
279 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
280 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
281 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
282 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
283 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
284 _open_filechooser_for_species_tree = new JFileChooser();
285 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
286 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
287 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
288 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
289 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
290 _save_filechooser = new JFileChooser();
291 _save_filechooser.setCurrentDirectory( new File( "." ) );
292 _save_filechooser.setMultiSelectionEnabled( false );
293 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
294 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
295 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
296 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
297 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
298 _writetopdf_filechooser = new JFileChooser();
299 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
300 _writetographics_filechooser = new JFileChooser();
301 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
303 _msa_filechooser = new JFileChooser();
304 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
305 _msa_filechooser.setCurrentDirectory( new File( "." ) );
306 _msa_filechooser.setMultiSelectionEnabled( false );
307 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
308 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
310 _seqs_filechooser = new JFileChooser();
311 _seqs_filechooser.setName( "Read Sequences File" );
312 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
313 _seqs_filechooser.setMultiSelectionEnabled( false );
314 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
315 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
317 _values_filechooser = new JFileChooser();
318 _values_filechooser.setCurrentDirectory( new File( "." ) );
319 _values_filechooser.setMultiSelectionEnabled( false );
320 // build the menu bar
321 _jmenubar = new JMenuBar();
322 if ( !_configuration.isUseNativeUI() ) {
323 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
326 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
327 buildPhylogeneticInferenceMenu();
336 setJMenuBar( _jmenubar );
337 _jmenubar.add( _help_jmenu );
338 _contentpane = getContentPane();
339 _contentpane.setLayout( new BorderLayout() );
340 _contentpane.add( _mainpanel, BorderLayout.CENTER );
342 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
343 // addWindowFocusListener( new WindowAdapter() {
346 // public void windowGainedFocus( WindowEvent e ) {
347 // requestFocusInWindow();
350 // The window listener
351 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
352 addWindowListener( new WindowAdapter() {
355 public void windowClosing( final WindowEvent e ) {
356 if ( isUnsavedDataPresent() ) {
357 final int r = JOptionPane.showConfirmDialog( null,
358 "Exit despite potentially unsaved changes?",
360 JOptionPane.YES_NO_OPTION );
361 if ( r != JOptionPane.YES_OPTION ) {
366 final int r = JOptionPane.showConfirmDialog( null,
367 "Exit Archaeopteryx?",
369 JOptionPane.YES_NO_OPTION );
370 if ( r != JOptionPane.YES_OPTION ) {
377 // The component listener
378 addComponentListener( new ComponentAdapter() {
381 public void componentResized( final ComponentEvent e ) {
382 if ( _mainpanel.getCurrentTreePanel() != null ) {
383 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
385 _mainpanel.getCurrentTreePanel()
391 requestFocusInWindow();
392 // addKeyListener( this );
394 if ( ( phys != null ) && ( phys.length > 0 ) ) {
395 Util.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
397 getMainPanel().getControlPanel().showWholeAll();
398 getMainPanel().getControlPanel().showWhole();
400 activateSaveAllIfNeeded();
401 // ...and its children
402 _contentpane.repaint();
406 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
407 // Reads the config file (false, false => not url, not applet):
408 this( phys, new Configuration( config_file, false, false ), title );
412 public void actionPerformed( final ActionEvent e ) {
414 super.actionPerformed( e );
415 final Object o = e.getSource();
416 // Handle app-specific actions here:
417 if ( o == _open_item ) {
418 readPhylogeniesFromFile();
420 else if ( o == _save_item ) {
421 writeToFile( _mainpanel.getCurrentPhylogeny() );
422 // If subtree currently displayed, save it, instead of complete
425 else if ( o == _new_item ) {
428 else if ( o == _save_all_item ) {
431 else if ( o == _close_item ) {
434 else if ( o == _write_to_pdf_item ) {
435 writeToPdf( _mainpanel.getCurrentPhylogeny() );
437 else if ( o == _write_to_jpg_item ) {
438 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
440 else if ( o == _write_to_png_item ) {
441 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
443 else if ( o == _write_to_gif_item ) {
444 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
446 else if ( o == _write_to_tif_item ) {
447 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
449 else if ( o == _write_to_bmp_item ) {
450 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
452 else if ( o == _print_item ) {
455 else if ( o == _load_species_tree_item ) {
456 readSpeciesTreeFromFile();
458 else if ( o == _sdi_item ) {
459 if ( isSubtreeDisplayed() ) {
464 else if ( o == _lineage_inference ) {
465 if ( isSubtreeDisplayed() ) {
466 JOptionPane.showMessageDialog( this,
468 "Cannot infer ancestral taxonomies",
469 JOptionPane.ERROR_MESSAGE );
472 executeLineageInference();
474 else if ( o == _function_analysis ) {
475 executeFunctionAnalysis();
477 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
478 if ( isSubtreeDisplayed() ) {
481 obtainDetailedTaxonomicInformation();
483 else if ( o == _obtain_uniprot_seq_information_jmi ) {
484 obtainUniProtSequenceInformation();
486 else if ( o == _read_values_jmi ) {
487 if ( isSubtreeDisplayed() ) {
490 addExpressionValuesFromFile();
492 else if ( o == _move_node_names_to_tax_sn_jmi ) {
493 moveNodeNamesToTaxSn();
495 else if ( o == _move_node_names_to_seq_names_jmi ) {
496 moveNodeNamesToSeqNames();
498 else if ( o == _extract_tax_code_from_node_names_jmi ) {
499 extractTaxCodeFromNodeNames();
501 else if ( o == _gsdi_item ) {
502 if ( isSubtreeDisplayed() ) {
507 else if ( o == _root_min_dups_item ) {
508 if ( isSubtreeDisplayed() ) {
511 executeSDIR( false );
513 else if ( o == _root_min_cost_l_item ) {
514 if ( isSubtreeDisplayed() ) {
519 else if ( o == _graphics_export_visible_only_cbmi ) {
520 updateOptions( getOptions() );
522 else if ( o == _antialias_print_cbmi ) {
523 updateOptions( getOptions() );
525 else if ( o == _print_black_and_white_cbmi ) {
526 updateOptions( getOptions() );
528 else if ( o == _print_using_actual_size_cbmi ) {
529 updateOptions( getOptions() );
531 else if ( o == _graphics_export_using_actual_size_cbmi ) {
532 updateOptions( getOptions() );
534 else if ( o == _print_size_mi ) {
537 else if ( o == _choose_pdf_width_mi ) {
540 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
541 updateOptions( getOptions() );
543 else if ( o == _replace_underscores_cbmi ) {
544 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
545 _extract_pfam_style_tax_codes_cbmi.setSelected( false );
547 updateOptions( getOptions() );
549 else if ( o == _collapse_below_threshold ) {
550 if ( isSubtreeDisplayed() ) {
553 collapseBelowThreshold();
555 else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
556 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
557 _replace_underscores_cbmi.setSelected( false );
559 updateOptions( getOptions() );
561 else if ( o == _inference_from_msa_item ) {
562 executePhyleneticInference( false );
564 else if ( o == _inference_from_seqs_item ) {
565 executePhyleneticInference( true );
567 _contentpane.repaint();
569 catch ( final Exception ex ) {
570 Util.unexpectedException( ex );
572 catch ( final Error err ) {
573 Util.unexpectedError( err );
577 void buildAnalysisMenu() {
578 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
579 _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
580 if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
581 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
583 _analysis_menu.addSeparator();
584 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
585 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
586 _analysis_menu.addSeparator();
587 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
588 customizeJMenuItem( _sdi_item );
589 customizeJMenuItem( _gsdi_item );
590 customizeJMenuItem( _root_min_dups_item );
591 customizeJMenuItem( _root_min_cost_l_item );
592 customizeJMenuItem( _load_species_tree_item );
593 _analysis_menu.addSeparator();
594 _analysis_menu.add( _lineage_inference = new JMenuItem( "Infer Ancestor Taxonomies" ) );
595 customizeJMenuItem( _lineage_inference );
596 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
597 _jmenubar.add( _analysis_menu );
600 void buildPhylogeneticInferenceMenu() {
601 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
603 .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
604 customizeJMenuItem( _inference_from_msa_item );
605 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
607 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
608 customizeJMenuItem( _inference_from_seqs_item );
609 _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
610 _jmenubar.add( _inference_menu );
614 void buildFileMenu() {
615 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
616 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
617 _file_jmenu.addSeparator();
618 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
619 _file_jmenu.addSeparator();
620 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
621 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
622 .getAvailablePhylogeniesWebserviceClients().size() ];
623 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
624 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
625 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
626 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
628 if ( getConfiguration().isEditable() ) {
629 _file_jmenu.addSeparator();
630 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
631 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
633 _file_jmenu.addSeparator();
634 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
635 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
636 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
637 _save_all_item.setEnabled( false );
638 _file_jmenu.addSeparator();
639 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
640 if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
641 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
643 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
644 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
645 if ( Util.canWriteFormat( "gif" ) ) {
646 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
648 if ( Util.canWriteFormat( "bmp" ) ) {
649 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
651 _file_jmenu.addSeparator();
652 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
653 _file_jmenu.addSeparator();
654 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
655 _close_item.setToolTipText( "To close the current pane." );
656 _close_item.setEnabled( true );
657 _file_jmenu.addSeparator();
658 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
659 // For print in color option item
660 customizeJMenuItem( _open_item );
662 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
663 customizeJMenuItem( _open_url_item );
664 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
665 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
667 customizeJMenuItem( _save_item );
668 if ( getConfiguration().isEditable() ) {
669 customizeJMenuItem( _new_item );
671 customizeJMenuItem( _close_item );
672 customizeJMenuItem( _save_all_item );
673 customizeJMenuItem( _write_to_pdf_item );
674 customizeJMenuItem( _write_to_png_item );
675 customizeJMenuItem( _write_to_jpg_item );
676 customizeJMenuItem( _write_to_gif_item );
677 customizeJMenuItem( _write_to_tif_item );
678 customizeJMenuItem( _write_to_bmp_item );
679 customizeJMenuItem( _print_item );
680 customizeJMenuItem( _exit_item );
681 _jmenubar.add( _file_jmenu );
684 void buildOptionsMenu() {
685 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
686 _options_jmenu.addChangeListener( new ChangeListener() {
689 public void stateChanged( final ChangeEvent e ) {
690 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() );
691 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
693 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
694 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
695 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
696 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
697 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
698 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
700 _show_branch_length_values_cbmi,
701 _non_lined_up_cladograms_rbmi,
702 _uniform_cladograms_rbmi,
703 _ext_node_dependent_cladogram_rbmi,
704 _label_direction_cbmi );
707 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
709 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
710 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
711 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
712 _radio_group_1 = new ButtonGroup();
713 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
714 _radio_group_1.add( _uniform_cladograms_rbmi );
715 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
718 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
721 _options_jmenu.add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL) );
722 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL));
723 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ));
724 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ));
727 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
729 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
730 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
731 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
732 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
733 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
734 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
735 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
736 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
737 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
738 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
739 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
741 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
742 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
743 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
744 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
745 _options_jmenu.addSeparator();
746 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
747 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
748 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
749 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
750 _options_jmenu.addSeparator();
751 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
752 getConfiguration() ) );
753 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
754 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
756 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
758 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
760 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
761 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
762 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
763 _options_jmenu.addSeparator();
765 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
767 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
768 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
770 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
771 customizeJMenuItem( _choose_font_mi );
772 customizeJMenuItem( _choose_minimal_confidence_mi );
773 customizeJMenuItem( _switch_colors_mi );
774 customizeJMenuItem( _print_size_mi );
775 customizeJMenuItem( _choose_pdf_width_mi );
776 customizeJMenuItem( _overview_placment_mi );
778 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
779 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
780 customizeJMenuItem( _cycle_node_shape_mi );
781 customizeJMenuItem( _cycle_node_fill_mi );
782 customizeJMenuItem( _choose_node_size_mi );
784 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
785 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
786 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
787 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
788 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
789 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
790 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
791 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
792 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
793 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
794 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
795 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
796 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
797 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
798 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
799 customizeCheckBoxMenuItem( _label_direction_cbmi,
800 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
801 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
802 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
803 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
804 .isInternalNumberAreConfidenceForNhParsing() );
805 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
806 .isExtractPfamTaxonomyCodesInNhParsing() );
807 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
808 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
809 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
810 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
811 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
812 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
813 .isGraphicsExportUsingActualSize() );
814 _jmenubar.add( _options_jmenu );
817 void buildToolsMenu() {
818 _tools_menu = createMenu( "Tools", getConfiguration() );
819 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
820 customizeJMenuItem( _confcolor_item );
821 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
822 customizeJMenuItem( _taxcolor_item );
823 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
824 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
825 customizeJMenuItem( _remove_branch_color_item );
826 _tools_menu.addSeparator();
827 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
828 customizeJMenuItem( _midpoint_root_item );
829 _tools_menu.addSeparator();
830 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
831 customizeJMenuItem( _collapse_species_specific_subtrees );
833 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
834 customizeJMenuItem( _collapse_below_threshold );
835 _collapse_below_threshold
836 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
837 _tools_menu.addSeparator();
839 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
840 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
841 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
842 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
843 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
844 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
846 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
847 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
848 _extract_tax_code_from_node_names_jmi
849 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
850 _tools_menu.addSeparator();
852 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
853 customizeJMenuItem( _infer_common_sn_names_item );
854 _tools_menu.addSeparator();
856 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information" ) );
857 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
858 _obtain_detailed_taxonomic_information_jmi
859 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
861 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
862 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
863 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
864 _tools_menu.addSeparator();
865 if ( !Constants.__RELEASE ) {
866 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
867 customizeJMenuItem( _function_analysis );
869 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
870 _tools_menu.addSeparator();
872 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
873 customizeJMenuItem( _read_values_jmi );
874 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
875 _jmenubar.add( _tools_menu );
878 private void choosePdfWidth() {
879 final String s = ( String ) JOptionPane.showInputDialog( this,
880 "Please enter the default line width for PDF export.\n"
882 + getOptions().getPrintLineWidth() + "]\n",
883 "Line Width for PDF Export",
884 JOptionPane.QUESTION_MESSAGE,
887 getOptions().getPrintLineWidth() );
888 if ( !ForesterUtil.isEmpty( s ) ) {
889 boolean success = true;
891 final String m_str = s.trim();
892 if ( !ForesterUtil.isEmpty( m_str ) ) {
894 f = Float.parseFloat( m_str );
896 catch ( final Exception ex ) {
903 if ( success && ( f > 0.0 ) ) {
904 getOptions().setPrintLineWidth( f );
909 private void choosePrintSize() {
910 final String s = ( String ) JOptionPane.showInputDialog( this,
911 "Please enter values for width and height,\nseparated by a comma.\n"
912 + "[current values: "
913 + getOptions().getPrintSizeX() + ", "
914 + getOptions().getPrintSizeY() + "]\n"
915 + "[A4: " + Constants.A4_SIZE_X + ", "
916 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
917 + Constants.US_LETTER_SIZE_X + ", "
918 + Constants.US_LETTER_SIZE_Y + "]",
919 "Default Size for Graphics Export",
920 JOptionPane.QUESTION_MESSAGE,
923 getOptions().getPrintSizeX() + ", "
924 + getOptions().getPrintSizeY() );
925 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
926 boolean success = true;
929 final String[] str_ary = s.split( "," );
930 if ( str_ary.length == 2 ) {
931 final String x_str = str_ary[ 0 ].trim();
932 final String y_str = str_ary[ 1 ].trim();
933 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
935 x = Integer.parseInt( x_str );
936 y = Integer.parseInt( y_str );
938 catch ( final Exception ex ) {
949 if ( success && ( x > 1 ) && ( y > 1 ) ) {
950 getOptions().setPrintSizeX( x );
951 getOptions().setPrintSizeY( y );
958 if ( isUnsavedDataPresent() ) {
959 final int r = JOptionPane.showConfirmDialog( this,
960 "Exit despite potentially unsaved changes?",
962 JOptionPane.YES_NO_OPTION );
963 if ( r != JOptionPane.YES_OPTION ) {
970 private void closeCurrentPane() {
971 if ( getMainPanel().getCurrentTreePanel() != null ) {
972 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
973 final int r = JOptionPane.showConfirmDialog( this,
974 "Close tab despite potentially unsaved changes?",
976 JOptionPane.YES_NO_OPTION );
977 if ( r != JOptionPane.YES_OPTION ) {
981 getMainPanel().closeCurrentPane();
982 activateSaveAllIfNeeded();
986 private void collapse( final Phylogeny phy, final double m ) {
987 final PhylogenyNodeIterator it = phy.iteratorPostorder();
988 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
989 double min_support = Double.MAX_VALUE;
990 boolean conf_present = false;
991 while ( it.hasNext() ) {
992 final PhylogenyNode n = it.next();
993 if ( !n.isExternal() && !n.isRoot() ) {
994 final List<Confidence> c = n.getBranchData().getConfidences();
995 if ( ( c != null ) && ( c.size() > 0 ) ) {
998 for( final Confidence confidence : c ) {
999 if ( confidence.getValue() > max ) {
1000 max = confidence.getValue();
1003 if ( max < getMinNotCollapseConfidenceValue() ) {
1004 to_be_removed.add( n );
1006 if ( max < min_support ) {
1012 if ( conf_present ) {
1013 for( final PhylogenyNode node : to_be_removed ) {
1014 PhylogenyMethods.removeNode( node, phy );
1016 if ( to_be_removed.size() > 0 ) {
1017 phy.externalNodesHaveChanged();
1019 phy.recalculateNumberOfExternalDescendants( true );
1020 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1021 getCurrentTreePanel().setEdited( true );
1022 getCurrentTreePanel().repaint();
1024 if ( to_be_removed.size() > 0 ) {
1025 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1026 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1027 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1030 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1031 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1035 JOptionPane.showMessageDialog( this,
1036 "No branch collapsed because no confidence values present",
1037 "No confidence values present",
1038 JOptionPane.INFORMATION_MESSAGE );
1042 private void collapseBelowThreshold() {
1043 if ( getCurrentTreePanel() != null ) {
1044 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1045 if ( ( phy != null ) && !phy.isEmpty() ) {
1046 final String s = ( String ) JOptionPane.showInputDialog( this,
1047 "Please enter the minimum confidence value\n",
1048 "Minimal Confidence Value",
1049 JOptionPane.QUESTION_MESSAGE,
1052 getMinNotCollapseConfidenceValue() );
1053 if ( !ForesterUtil.isEmpty( s ) ) {
1054 boolean success = true;
1056 final String m_str = s.trim();
1057 if ( !ForesterUtil.isEmpty( m_str ) ) {
1059 m = Double.parseDouble( m_str );
1061 catch ( final Exception ex ) {
1068 if ( success && ( m >= 0.0 ) ) {
1069 setMinNotCollapseConfidenceValue( m );
1077 private PhyloXmlParser createPhyloXmlParser() {
1078 PhyloXmlParser xml_parser = null;
1079 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1081 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1083 catch ( final Exception e ) {
1084 JOptionPane.showMessageDialog( this,
1085 e.getLocalizedMessage(),
1086 "failed to create validating XML parser",
1087 JOptionPane.WARNING_MESSAGE );
1090 if ( xml_parser == null ) {
1091 xml_parser = new PhyloXmlParser();
1096 void executeGSDI() {
1097 if ( !isOKforSDI( false, true ) ) {
1100 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1101 JOptionPane.showMessageDialog( this,
1102 "Gene tree is not rooted.",
1103 "Cannot execute GSDI",
1104 JOptionPane.ERROR_MESSAGE );
1107 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1108 gene_tree.setAllNodesToNotCollapse();
1109 gene_tree.recalculateNumberOfExternalDescendants( false );
1111 int duplications = -1;
1113 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1114 duplications = gsdi.getDuplicationsSum();
1116 catch ( final Exception e ) {
1117 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1119 gene_tree.setRerootable( false );
1120 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1121 getControlPanel().setShowEvents( true );
1123 _mainpanel.getCurrentTreePanel().setEdited( true );
1124 JOptionPane.showMessageDialog( this,
1125 "Number of duplications: " + duplications,
1126 "GSDI successfully completed",
1127 JOptionPane.INFORMATION_MESSAGE );
1130 void executeFunctionAnalysis() {
1131 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1134 final GoAnnotation a = new GoAnnotation( this,
1135 _mainpanel.getCurrentTreePanel(),
1136 _mainpanel.getCurrentPhylogeny() );
1137 new Thread( a ).start();
1140 void executeLineageInference() {
1141 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1144 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1145 JOptionPane.showMessageDialog( this,
1146 "Phylogeny is not rooted.",
1147 "Cannot infer ancestral taxonomies",
1148 JOptionPane.ERROR_MESSAGE );
1151 final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
1152 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1153 _mainpanel.getCurrentTreePanel(),
1155 new Thread( inferrer ).start();
1158 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1159 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1160 getPhylogeneticInferenceOptions(),
1161 from_unaligned_seqs );
1163 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1164 if ( !from_unaligned_seqs ) {
1165 if ( getMsa() != null ) {
1166 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1167 getPhylogeneticInferenceOptions()
1169 new Thread( inferrer ).start();
1172 JOptionPane.showMessageDialog( this,
1173 "No multiple sequence alignment selected",
1174 "Phylogenetic Inference Not Launched",
1175 JOptionPane.WARNING_MESSAGE );
1179 if ( getSeqs() != null ) {
1180 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1181 getPhylogeneticInferenceOptions()
1183 new Thread( inferrer ).start();
1186 JOptionPane.showMessageDialog( this,
1187 "No input sequences selected",
1188 "Phylogenetic Inference Not Launched",
1189 JOptionPane.WARNING_MESSAGE );
1196 if ( !isOKforSDI( true, true ) ) {
1199 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1200 JOptionPane.showMessageDialog( this,
1201 "Gene tree is not rooted",
1202 "Cannot execute SDI",
1203 JOptionPane.ERROR_MESSAGE );
1206 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1207 gene_tree.setAllNodesToNotCollapse();
1208 gene_tree.recalculateNumberOfExternalDescendants( false );
1210 int duplications = -1;
1212 sdi = new SDIse( gene_tree, _species_tree.copy() );
1213 duplications = sdi.getDuplicationsSum();
1215 catch ( final Exception e ) {
1216 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1218 gene_tree.setRerootable( false );
1219 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1220 getControlPanel().setShowEvents( true );
1222 _mainpanel.getCurrentTreePanel().setEdited( true );
1223 JOptionPane.showMessageDialog( this,
1224 "Number of duplications: " + duplications,
1225 "SDI successfully completed",
1226 JOptionPane.INFORMATION_MESSAGE );
1229 void executeSDIR( final boolean minimize_cost ) {
1230 if ( !isOKforSDI( true, true ) ) {
1233 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1234 final SDIR sdiunrooted = new SDIR();
1235 gene_tree.setAllNodesToNotCollapse();
1236 gene_tree.recalculateNumberOfExternalDescendants( false );
1238 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1239 !minimize_cost, // minimize sum of dups
1240 true, // minimize height
1241 true, // return tree(s)
1242 1 )[ 0 ]; // # of trees to return
1244 catch ( final Exception e ) {
1245 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1248 final int duplications = sdiunrooted.getMinimalDuplications();
1249 gene_tree.setRerootable( false );
1250 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1251 getControlPanel().setShowEvents( true );
1253 _mainpanel.getCurrentTreePanel().setEdited( true );
1254 JOptionPane.showMessageDialog( this,
1255 "Number of duplications: " + duplications,
1256 "SDIR successfully completed",
1257 JOptionPane.INFORMATION_MESSAGE );
1262 _mainpanel.terminate();
1263 _contentpane.removeAll();
1264 setVisible( false );
1269 private void extractTaxCodeFromNodeNames() {
1270 if ( getCurrentTreePanel() != null ) {
1271 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1272 if ( ( phy != null ) && !phy.isEmpty() ) {
1273 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1274 while ( it.hasNext() ) {
1275 final PhylogenyNode n = it.next();
1276 final String name = n.getName().trim();
1277 if ( !ForesterUtil.isEmpty( name ) ) {
1278 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1280 TAXONOMY_EXTRACTION.YES );
1281 if ( !ForesterUtil.isEmpty( code ) ) {
1282 PhylogenyMethods.setTaxonomyCode( n, code );
1290 private ControlPanel getControlPanel() {
1291 return getMainPanel().getControlPanel();
1294 private File getCurrentDir() {
1295 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1296 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1298 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1300 catch ( final Exception e ) {
1301 _current_dir = null;
1305 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1306 if ( System.getProperty( "user.home" ) != null ) {
1307 _current_dir = new File( System.getProperty( "user.home" ) );
1309 else if ( System.getProperty( "user.dir" ) != null ) {
1310 _current_dir = new File( System.getProperty( "user.dir" ) );
1313 return _current_dir;
1317 public MainPanel getMainPanel() {
1321 private double getMinNotCollapseConfidenceValue() {
1322 return _min_not_collapse;
1325 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1326 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1329 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1330 JOptionPane.showMessageDialog( this,
1331 "No species tree loaded",
1332 "Cannot execute SDI",
1333 JOptionPane.ERROR_MESSAGE );
1336 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1337 JOptionPane.showMessageDialog( this,
1338 "Species tree is not completely binary",
1339 "Cannot execute SDI",
1340 JOptionPane.ERROR_MESSAGE );
1343 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1344 JOptionPane.showMessageDialog( this,
1345 "Gene tree is not completely binary",
1346 "Cannot execute SDI",
1347 JOptionPane.ERROR_MESSAGE );
1355 private boolean isUnsavedDataPresent() {
1356 final List<TreePanel> tps = getMainPanel().getTreePanels();
1357 for( final TreePanel tp : tps ) {
1358 if ( tp.isEdited() ) {
1365 private void moveNodeNamesToSeqNames() {
1366 if ( getCurrentTreePanel() != null ) {
1367 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1368 if ( ( phy != null ) && !phy.isEmpty() ) {
1369 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1374 private void moveNodeNamesToTaxSn() {
1375 if ( getCurrentTreePanel() != null ) {
1376 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1377 if ( ( phy != null ) && !phy.isEmpty() ) {
1378 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1383 private void newTree() {
1384 final Phylogeny[] phys = new Phylogeny[ 1 ];
1385 final Phylogeny phy = new Phylogeny();
1386 final PhylogenyNode node = new PhylogenyNode();
1387 phy.setRoot( node );
1388 phy.setRooted( true );
1390 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1391 _mainpanel.getControlPanel().showWhole();
1392 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1393 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1394 if ( getMainPanel().getMainFrame() == null ) {
1395 // Must be "E" applet version.
1396 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1397 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1400 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1402 activateSaveAllIfNeeded();
1406 private void obtainDetailedTaxonomicInformation() {
1407 if ( getCurrentTreePanel() != null ) {
1408 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1409 if ( ( phy != null ) && !phy.isEmpty() ) {
1410 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1411 _mainpanel.getCurrentTreePanel(),
1413 new Thread( t ).start();
1418 private void obtainUniProtSequenceInformation() {
1419 if ( getCurrentTreePanel() != null ) {
1420 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1421 if ( ( phy != null ) && !phy.isEmpty() ) {
1422 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1423 _mainpanel.getCurrentTreePanel(),
1425 new Thread( u ).start();
1430 private void print() {
1431 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1432 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1435 if ( !getOptions().isPrintUsingActualSize() ) {
1436 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1437 getOptions().getPrintSizeY() - 140,
1439 getCurrentTreePanel().resetPreferredSize();
1440 getCurrentTreePanel().repaint();
1442 final String job_name = Constants.PRG_NAME;
1443 boolean error = false;
1444 String printer_name = null;
1446 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1448 catch ( final Exception e ) {
1450 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1452 if ( !error && ( printer_name != null ) ) {
1453 String msg = "Printing data sent to printer";
1454 if ( printer_name.length() > 1 ) {
1455 msg += " [" + printer_name + "]";
1457 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1459 if ( !getOptions().isPrintUsingActualSize() ) {
1460 getControlPanel().showWhole();
1464 private void printPhylogenyToPdf( final String file_name ) {
1465 if ( !getOptions().isPrintUsingActualSize() ) {
1466 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1467 getOptions().getPrintSizeY(),
1469 getCurrentTreePanel().resetPreferredSize();
1470 getCurrentTreePanel().repaint();
1472 String pdf_written_to = "";
1473 boolean error = false;
1475 if ( getOptions().isPrintUsingActualSize() ) {
1476 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1477 getCurrentTreePanel(),
1478 getCurrentTreePanel().getWidth(),
1479 getCurrentTreePanel().getHeight() );
1482 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1483 .getPrintSizeX(), getOptions().getPrintSizeY() );
1486 catch ( final IOException e ) {
1488 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1491 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1492 JOptionPane.showMessageDialog( this,
1493 "Wrote PDF to: " + pdf_written_to,
1495 JOptionPane.INFORMATION_MESSAGE );
1498 JOptionPane.showMessageDialog( this,
1499 "There was an unknown problem when attempting to write to PDF file: \""
1502 JOptionPane.ERROR_MESSAGE );
1505 if ( !getOptions().isPrintUsingActualSize() ) {
1506 getControlPanel().showWhole();
1510 private void addExpressionValuesFromFile() {
1511 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1512 JOptionPane.showMessageDialog( this,
1513 "Need to load evolutionary tree first",
1514 "Can Not Read Expression Values",
1515 JOptionPane.WARNING_MESSAGE );
1518 final File my_dir = getCurrentDir();
1519 if ( my_dir != null ) {
1520 _values_filechooser.setCurrentDirectory( my_dir );
1522 final int result = _values_filechooser.showOpenDialog( _contentpane );
1523 final File file = _values_filechooser.getSelectedFile();
1524 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1525 BasicTable<String> t = null;
1527 t = BasicTableParser.parse( file, "\t" );
1528 if ( t.getNumberOfColumns() < 2 ) {
1529 t = BasicTableParser.parse( file, "," );
1531 if ( t.getNumberOfColumns() < 2 ) {
1532 t = BasicTableParser.parse( file, " " );
1535 catch ( final IOException e ) {
1536 JOptionPane.showMessageDialog( this,
1538 "Could Not Read Expression Value Table",
1539 JOptionPane.ERROR_MESSAGE );
1542 if ( t.getNumberOfColumns() < 2 ) {
1543 JOptionPane.showMessageDialog( this,
1544 "Table contains " + t.getNumberOfColumns() + " column(s)",
1545 "Problem with Expression Value Table",
1546 JOptionPane.ERROR_MESSAGE );
1549 if ( t.getNumberOfRows() < 1 ) {
1550 JOptionPane.showMessageDialog( this,
1551 "Table contains zero rows",
1552 "Problem with Expression Value Table",
1553 JOptionPane.ERROR_MESSAGE );
1556 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1557 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1558 JOptionPane.showMessageDialog( this,
1559 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1560 + phy.getNumberOfExternalNodes() + " external nodes",
1562 JOptionPane.WARNING_MESSAGE );
1564 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1566 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1567 final PhylogenyNode node = iter.next();
1568 final String node_name = node.getName();
1569 if ( !ForesterUtil.isEmpty( node_name ) ) {
1572 row = t.findRow( node_name );
1574 catch ( final IllegalArgumentException e ) {
1576 .showMessageDialog( this,
1578 "Error Mapping Node Identifiers to Expression Value Identifiers",
1579 JOptionPane.ERROR_MESSAGE );
1583 if ( node.isExternal() ) {
1588 final List<Double> l = new ArrayList<Double>();
1589 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1592 d = Double.parseDouble( t.getValueAsString( col, row ) );
1594 catch ( final NumberFormatException e ) {
1595 JOptionPane.showMessageDialog( this,
1596 "Could not parse \"" + t.getValueAsString( col, row )
1597 + "\" into a decimal value",
1598 "Issue with Expression Value Table",
1599 JOptionPane.ERROR_MESSAGE );
1602 stats.addValue( d );
1605 if ( !l.isEmpty() ) {
1606 if ( node.getNodeData().getProperties() != null ) {
1607 node.getNodeData().getProperties()
1608 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1610 node.getNodeData().setVector( l );
1614 if ( not_found > 0 ) {
1615 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1616 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1618 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1622 private void readPhylogeniesFromFile() {
1623 boolean exception = false;
1624 Phylogeny[] phys = null;
1625 // Set an initial directory if none set yet
1626 final File my_dir = getCurrentDir();
1627 _open_filechooser.setMultiSelectionEnabled( true );
1628 // Open file-open dialog and set current directory
1629 if ( my_dir != null ) {
1630 _open_filechooser.setCurrentDirectory( my_dir );
1632 final int result = _open_filechooser.showOpenDialog( _contentpane );
1633 // All done: get the file
1634 final File[] files = _open_filechooser.getSelectedFiles();
1635 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1636 boolean nhx_or_nexus = false;
1637 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1638 for( final File file : files ) {
1639 if ( ( file != null ) && !file.isDirectory() ) {
1640 if ( _mainpanel.getCurrentTreePanel() != null ) {
1641 _mainpanel.getCurrentTreePanel().setWaitCursor();
1644 _mainpanel.setWaitCursor();
1646 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1647 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1649 final NHXParser nhx = new NHXParser();
1650 setSpecialOptionsForNhxParser( nhx );
1651 phys = ForesterUtil.readPhylogenies( nhx, file );
1652 nhx_or_nexus = true;
1654 catch ( final Exception e ) {
1656 exceptionOccuredDuringOpenFile( e );
1659 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1660 warnIfNotPhyloXmlValidation( getConfiguration() );
1662 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1663 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1665 catch ( final Exception e ) {
1667 exceptionOccuredDuringOpenFile( e );
1670 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1672 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1674 catch ( final Exception e ) {
1676 exceptionOccuredDuringOpenFile( e );
1679 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1681 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1682 setSpecialOptionsForNexParser( nex );
1683 phys = ForesterUtil.readPhylogenies( nex, file );
1684 nhx_or_nexus = true;
1686 catch ( final Exception e ) {
1688 exceptionOccuredDuringOpenFile( e );
1694 final PhylogenyParser parser = ForesterUtil
1695 .createParserDependingOnFileType( file, getConfiguration()
1696 .isValidatePhyloXmlAgainstSchema() );
1697 if ( parser instanceof NexusPhylogeniesParser ) {
1698 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1699 setSpecialOptionsForNexParser( nex );
1700 nhx_or_nexus = true;
1702 else if ( parser instanceof NHXParser ) {
1703 final NHXParser nhx = ( NHXParser ) parser;
1704 setSpecialOptionsForNhxParser( nhx );
1705 nhx_or_nexus = true;
1707 else if ( parser instanceof PhyloXmlParser ) {
1708 warnIfNotPhyloXmlValidation( getConfiguration() );
1710 phys = ForesterUtil.readPhylogenies( parser, file );
1712 catch ( final Exception e ) {
1714 exceptionOccuredDuringOpenFile( e );
1717 if ( _mainpanel.getCurrentTreePanel() != null ) {
1718 _mainpanel.getCurrentTreePanel().setArrowCursor();
1721 _mainpanel.setArrowCursor();
1723 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1724 boolean one_desc = false;
1725 if ( nhx_or_nexus ) {
1726 for( final Phylogeny phy : phys ) {
1727 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1728 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1730 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1736 Util.addPhylogeniesToTabs( phys,
1738 file.getAbsolutePath(),
1741 _mainpanel.getControlPanel().showWhole();
1742 if ( nhx_or_nexus && one_desc ) {
1744 .showMessageDialog( this,
1745 "One or more trees contain (a) node(s) with one descendant, "
1746 + ForesterUtil.LINE_SEPARATOR
1747 + "possibly indicating illegal parentheses within node names.",
1748 "Warning: Possible Error in New Hampshire Formatted Data",
1749 JOptionPane.WARNING_MESSAGE );
1755 activateSaveAllIfNeeded();
1759 public void readSeqsFromFile() {
1760 // Set an initial directory if none set yet
1761 final File my_dir = getCurrentDir();
1762 _seqs_filechooser.setMultiSelectionEnabled( false );
1763 // Open file-open dialog and set current directory
1764 if ( my_dir != null ) {
1765 _seqs_filechooser.setCurrentDirectory( my_dir );
1767 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1768 // All done: get the seqs
1769 final File file = _seqs_filechooser.getSelectedFile();
1770 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1771 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1772 setSeqsFile( null );
1774 List<Sequence> seqs = null;
1776 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1777 seqs = FastaParser.parse( new FileInputStream( file ) );
1778 for( final Sequence seq : seqs ) {
1779 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1786 catch ( final MsaFormatException e ) {
1788 _mainpanel.getCurrentTreePanel().setArrowCursor();
1790 catch ( final Exception ex ) {
1793 JOptionPane.showMessageDialog( this,
1794 e.getLocalizedMessage(),
1795 "Multiple sequence file format error",
1796 JOptionPane.ERROR_MESSAGE );
1799 catch ( final IOException e ) {
1801 _mainpanel.getCurrentTreePanel().setArrowCursor();
1803 catch ( final Exception ex ) {
1806 JOptionPane.showMessageDialog( this,
1807 e.getLocalizedMessage(),
1808 "Failed to read multiple sequence file",
1809 JOptionPane.ERROR_MESSAGE );
1812 catch ( final IllegalArgumentException e ) {
1814 _mainpanel.getCurrentTreePanel().setArrowCursor();
1816 catch ( final Exception ex ) {
1819 JOptionPane.showMessageDialog( this,
1820 e.getLocalizedMessage(),
1821 "Unexpected error during reading of multiple sequence file",
1822 JOptionPane.ERROR_MESSAGE );
1825 catch ( final Exception e ) {
1827 _mainpanel.getCurrentTreePanel().setArrowCursor();
1829 catch ( final Exception ex ) {
1832 e.printStackTrace();
1833 JOptionPane.showMessageDialog( this,
1834 e.getLocalizedMessage(),
1835 "Unexpected error during reading of multiple sequence file",
1836 JOptionPane.ERROR_MESSAGE );
1839 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1840 JOptionPane.showMessageDialog( this,
1841 "Multiple sequence file is empty",
1842 "Illegal multiple sequence file",
1843 JOptionPane.ERROR_MESSAGE );
1846 if ( seqs.size() < 4 ) {
1847 JOptionPane.showMessageDialog( this,
1848 "Multiple sequence file needs to contain at least 3 sequences",
1849 "Illegal multiple sequence file",
1850 JOptionPane.ERROR_MESSAGE );
1853 // if ( msa.getLength() < 2 ) {
1854 // JOptionPane.showMessageDialog( this,
1855 // "Multiple sequence alignment needs to contain at least 2 residues",
1856 // "Illegal multiple sequence file",
1857 // JOptionPane.ERROR_MESSAGE );
1861 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1866 public void readMsaFromFile() {
1867 // Set an initial directory if none set yet
1868 final File my_dir = getCurrentDir();
1869 _msa_filechooser.setMultiSelectionEnabled( false );
1870 // Open file-open dialog and set current directory
1871 if ( my_dir != null ) {
1872 _msa_filechooser.setCurrentDirectory( my_dir );
1874 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1875 // All done: get the msa
1876 final File file = _msa_filechooser.getSelectedFile();
1877 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1878 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1883 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1884 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1885 System.out.println( msa.toString() );
1888 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1891 catch ( final MsaFormatException e ) {
1893 _mainpanel.getCurrentTreePanel().setArrowCursor();
1895 catch ( final Exception ex ) {
1898 JOptionPane.showMessageDialog( this,
1899 e.getLocalizedMessage(),
1900 "Multiple sequence alignment format error",
1901 JOptionPane.ERROR_MESSAGE );
1904 catch ( final IOException e ) {
1906 _mainpanel.getCurrentTreePanel().setArrowCursor();
1908 catch ( final Exception ex ) {
1911 JOptionPane.showMessageDialog( this,
1912 e.getLocalizedMessage(),
1913 "Failed to read multiple sequence alignment",
1914 JOptionPane.ERROR_MESSAGE );
1917 catch ( final IllegalArgumentException e ) {
1919 _mainpanel.getCurrentTreePanel().setArrowCursor();
1921 catch ( final Exception ex ) {
1924 JOptionPane.showMessageDialog( this,
1925 e.getLocalizedMessage(),
1926 "Unexpected error during reading of multiple sequence alignment",
1927 JOptionPane.ERROR_MESSAGE );
1930 catch ( final Exception e ) {
1932 _mainpanel.getCurrentTreePanel().setArrowCursor();
1934 catch ( final Exception ex ) {
1937 e.printStackTrace();
1938 JOptionPane.showMessageDialog( this,
1939 e.getLocalizedMessage(),
1940 "Unexpected error during reading of multiple sequence alignment",
1941 JOptionPane.ERROR_MESSAGE );
1944 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1945 JOptionPane.showMessageDialog( this,
1946 "Multiple sequence alignment is empty",
1947 "Illegal Multiple Sequence Alignment",
1948 JOptionPane.ERROR_MESSAGE );
1951 if ( msa.getNumberOfSequences() < 4 ) {
1952 JOptionPane.showMessageDialog( this,
1953 "Multiple sequence alignment needs to contain at least 3 sequences",
1954 "Illegal multiple sequence alignment",
1955 JOptionPane.ERROR_MESSAGE );
1958 if ( msa.getLength() < 2 ) {
1959 JOptionPane.showMessageDialog( this,
1960 "Multiple sequence alignment needs to contain at least 2 residues",
1961 "Illegal multiple sequence alignment",
1962 JOptionPane.ERROR_MESSAGE );
1966 setMsaFile( _msa_filechooser.getSelectedFile() );
1972 void readPhylogeniesFromURL() {
1974 Phylogeny[] phys = null;
1975 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1976 final String url_string = JOptionPane.showInputDialog( this,
1978 "Use URL/webservice to obtain a phylogeny",
1979 JOptionPane.QUESTION_MESSAGE );
1980 boolean nhx_or_nexus = false;
1981 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1983 url = new URL( url_string );
1984 PhylogenyParser parser = null;
1985 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1986 parser = new TolParser();
1989 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
1990 .isValidatePhyloXmlAgainstSchema() );
1992 if ( parser instanceof NexusPhylogeniesParser ) {
1993 nhx_or_nexus = true;
1995 else if ( parser instanceof NHXParser ) {
1996 nhx_or_nexus = true;
1998 if ( _mainpanel.getCurrentTreePanel() != null ) {
1999 _mainpanel.getCurrentTreePanel().setWaitCursor();
2002 _mainpanel.setWaitCursor();
2004 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2005 phys = factory.create( url.openStream(), parser );
2007 catch ( final MalformedURLException e ) {
2008 JOptionPane.showMessageDialog( this,
2009 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2011 JOptionPane.ERROR_MESSAGE );
2013 catch ( final IOException e ) {
2014 JOptionPane.showMessageDialog( this,
2015 "Could not read from " + url + "\n"
2016 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2017 "Failed to read URL",
2018 JOptionPane.ERROR_MESSAGE );
2020 catch ( final Exception e ) {
2021 JOptionPane.showMessageDialog( this,
2022 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2023 "Unexpected Exception",
2024 JOptionPane.ERROR_MESSAGE );
2027 if ( _mainpanel.getCurrentTreePanel() != null ) {
2028 _mainpanel.getCurrentTreePanel().setArrowCursor();
2031 _mainpanel.setArrowCursor();
2034 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2035 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2036 for( final Phylogeny phy : phys ) {
2037 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2040 Util.addPhylogeniesToTabs( phys,
2041 new File( url.getFile() ).getName(),
2042 new File( url.getFile() ).toString(),
2045 _mainpanel.getControlPanel().showWhole();
2048 activateSaveAllIfNeeded();
2052 private void readSpeciesTreeFromFile() {
2054 boolean exception = false;
2055 final File my_dir = getCurrentDir();
2056 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2057 if ( my_dir != null ) {
2058 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2060 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2061 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2062 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2063 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2065 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2068 catch ( final Exception e ) {
2070 exceptionOccuredDuringOpenFile( e );
2073 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2075 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2078 catch ( final Exception e ) {
2080 exceptionOccuredDuringOpenFile( e );
2086 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2089 catch ( final Exception e ) {
2091 exceptionOccuredDuringOpenFile( e );
2094 if ( !exception && ( t != null ) && !t.isRooted() ) {
2097 JOptionPane.showMessageDialog( this,
2098 "Species tree is not rooted",
2099 "Species tree not loaded",
2100 JOptionPane.ERROR_MESSAGE );
2102 if ( !exception && ( t != null ) ) {
2103 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2104 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2105 final PhylogenyNode node = it.next();
2106 if ( !node.getNodeData().isHasTaxonomy() ) {
2110 .showMessageDialog( this,
2111 "Species tree contains external node(s) without taxonomy information",
2112 "Species tree not loaded",
2113 JOptionPane.ERROR_MESSAGE );
2117 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2120 JOptionPane.showMessageDialog( this,
2122 + node.getNodeData().getTaxonomy().asSimpleText()
2123 + "] is not unique in species tree",
2124 "Species tree not loaded",
2125 JOptionPane.ERROR_MESSAGE );
2129 tax_set.add( node.getNodeData().getTaxonomy() );
2134 if ( !exception && ( t != null ) ) {
2136 JOptionPane.showMessageDialog( this,
2137 "Species tree successfully loaded",
2138 "Species tree loaded",
2139 JOptionPane.INFORMATION_MESSAGE );
2141 _contentpane.repaint();
2146 private void setCurrentDir( final File current_dir ) {
2147 _current_dir = current_dir;
2150 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2151 _min_not_collapse = min_not_collapse;
2154 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2155 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2158 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2159 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2160 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2161 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2162 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2164 nhx.setTaxonomyExtraction( te );
2167 private void writeAllToFile() {
2168 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2171 final File my_dir = getCurrentDir();
2172 if ( my_dir != null ) {
2173 _save_filechooser.setCurrentDirectory( my_dir );
2175 _save_filechooser.setSelectedFile( new File( "" ) );
2176 final int result = _save_filechooser.showSaveDialog( _contentpane );
2177 final File file = _save_filechooser.getSelectedFile();
2178 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2179 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2180 if ( file.exists() ) {
2181 final int i = JOptionPane.showConfirmDialog( this,
2182 file + " already exists. Overwrite?",
2184 JOptionPane.OK_CANCEL_OPTION,
2185 JOptionPane.WARNING_MESSAGE );
2186 if ( i != JOptionPane.OK_OPTION ) {
2193 catch ( final Exception e ) {
2194 JOptionPane.showMessageDialog( this,
2195 "Failed to delete: " + file,
2197 JOptionPane.WARNING_MESSAGE );
2201 final int count = getMainPanel().getTabbedPane().getTabCount();
2202 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2203 for( int i = 0; i < count; ++i ) {
2204 trees.add( getMainPanel().getPhylogeny( i ) );
2205 getMainPanel().getTreePanels().get( i ).setEdited( false );
2207 final PhylogenyWriter writer = new PhylogenyWriter();
2209 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2211 catch ( final IOException e ) {
2212 JOptionPane.showMessageDialog( this,
2213 "Failed to write to: " + file,
2215 JOptionPane.WARNING_MESSAGE );
2220 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2222 final PhylogenyWriter writer = new PhylogenyWriter();
2223 writer.toNewHampshire( t, false, true, file );
2225 catch ( final Exception e ) {
2227 exceptionOccuredDuringSaveAs( e );
2232 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2234 final PhylogenyWriter writer = new PhylogenyWriter();
2235 writer.toNexus( file, t );
2237 catch ( final Exception e ) {
2239 exceptionOccuredDuringSaveAs( e );
2244 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2246 final PhylogenyWriter writer = new PhylogenyWriter();
2247 writer.toNewHampshireX( t, file );
2249 catch ( final Exception e ) {
2251 exceptionOccuredDuringSaveAs( e );
2256 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2258 final PhylogenyWriter writer = new PhylogenyWriter();
2259 writer.toPhyloXML( file, t, 0 );
2261 catch ( final Exception e ) {
2263 exceptionOccuredDuringSaveAs( e );
2268 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2269 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2270 _mainpanel.getCurrentTreePanel().getHeight(),
2272 String file_written_to = "";
2273 boolean error = false;
2275 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2276 _mainpanel.getCurrentTreePanel().getWidth(),
2277 _mainpanel.getCurrentTreePanel().getHeight(),
2278 _mainpanel.getCurrentTreePanel(),
2279 _mainpanel.getControlPanel(),
2283 catch ( final IOException e ) {
2285 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2288 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2289 JOptionPane.showMessageDialog( this,
2290 "Wrote image to: " + file_written_to,
2292 JOptionPane.INFORMATION_MESSAGE );
2295 JOptionPane.showMessageDialog( this,
2296 "There was an unknown problem when attempting to write to an image file: \""
2299 JOptionPane.ERROR_MESSAGE );
2302 _contentpane.repaint();
2305 private void writeToFile( final Phylogeny t ) {
2309 String initial_filename = null;
2310 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2312 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2314 catch ( final IOException e ) {
2315 initial_filename = null;
2318 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2319 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2322 _save_filechooser.setSelectedFile( new File( "" ) );
2324 final File my_dir = getCurrentDir();
2325 if ( my_dir != null ) {
2326 _save_filechooser.setCurrentDirectory( my_dir );
2328 final int result = _save_filechooser.showSaveDialog( _contentpane );
2329 final File file = _save_filechooser.getSelectedFile();
2330 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2331 boolean exception = false;
2332 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2333 if ( file.exists() ) {
2334 final int i = JOptionPane.showConfirmDialog( this,
2335 file + " already exists.\nOverwrite?",
2337 JOptionPane.OK_CANCEL_OPTION,
2338 JOptionPane.QUESTION_MESSAGE );
2339 if ( i != JOptionPane.OK_OPTION ) {
2343 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2345 ForesterUtil.copyFile( file, to );
2347 catch ( final Exception e ) {
2348 JOptionPane.showMessageDialog( this,
2349 "Failed to create backup copy " + to,
2350 "Failed to Create Backup Copy",
2351 JOptionPane.WARNING_MESSAGE );
2356 catch ( final Exception e ) {
2357 JOptionPane.showMessageDialog( this,
2358 "Failed to delete: " + file,
2360 JOptionPane.WARNING_MESSAGE );
2364 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2365 exception = writeAsNewHampshire( t, exception, file );
2367 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2368 exception = writeAsNHX( t, exception, file );
2370 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2371 exception = writeAsPhyloXml( t, exception, file );
2373 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2374 exception = writeAsNexus( t, exception, file );
2378 final String file_name = file.getName().trim().toLowerCase();
2379 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2380 || file_name.endsWith( ".tree" ) ) {
2381 exception = writeAsNewHampshire( t, exception, file );
2383 else if ( file_name.endsWith( ".nhx" ) ) {
2384 exception = writeAsNHX( t, exception, file );
2386 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2387 exception = writeAsNexus( t, exception, file );
2391 exception = writeAsPhyloXml( t, exception, file );
2395 getMainPanel().setTitleOfSelectedTab( file.getName() );
2396 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2397 getMainPanel().getCurrentTreePanel().setEdited( false );
2402 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2403 if ( ( t == null ) || t.isEmpty() ) {
2406 String initial_filename = "";
2407 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2408 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2410 if ( initial_filename.indexOf( '.' ) > 0 ) {
2411 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2413 initial_filename = initial_filename + "." + type;
2414 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2415 final File my_dir = getCurrentDir();
2416 if ( my_dir != null ) {
2417 _writetographics_filechooser.setCurrentDirectory( my_dir );
2419 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2420 File file = _writetographics_filechooser.getSelectedFile();
2421 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2422 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2423 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2424 file = new File( file.toString() + "." + type );
2426 if ( file.exists() ) {
2427 final int i = JOptionPane.showConfirmDialog( this,
2428 file + " already exists. Overwrite?",
2430 JOptionPane.OK_CANCEL_OPTION,
2431 JOptionPane.WARNING_MESSAGE );
2432 if ( i != JOptionPane.OK_OPTION ) {
2439 catch ( final Exception e ) {
2440 JOptionPane.showMessageDialog( this,
2441 "Failed to delete: " + file,
2443 JOptionPane.WARNING_MESSAGE );
2447 writePhylogenyToGraphicsFile( file.toString(), type );
2451 private void writeToPdf( final Phylogeny t ) {
2452 if ( ( t == null ) || t.isEmpty() ) {
2455 String initial_filename = "";
2456 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2457 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2459 if ( initial_filename.indexOf( '.' ) > 0 ) {
2460 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2462 initial_filename = initial_filename + ".pdf";
2463 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2464 final File my_dir = getCurrentDir();
2465 if ( my_dir != null ) {
2466 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2468 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2469 File file = _writetopdf_filechooser.getSelectedFile();
2470 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2471 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2472 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2473 file = new File( file.toString() + ".pdf" );
2475 if ( file.exists() ) {
2476 final int i = JOptionPane.showConfirmDialog( this,
2477 file + " already exists. Overwrite?",
2479 JOptionPane.OK_CANCEL_OPTION,
2480 JOptionPane.WARNING_MESSAGE );
2481 if ( i != JOptionPane.OK_OPTION ) {
2485 printPhylogenyToPdf( file.toString() );
2489 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2490 return new MainFrameApplication( phys, config, title );
2493 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2494 return new MainFrameApplication( phys, config_file_name, title );
2497 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2498 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2499 + o.getPrintSizeY() + ")" );
2502 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2503 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2506 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2507 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2509 .showMessageDialog( null,
2511 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2514 JOptionPane.WARNING_MESSAGE );
2518 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2519 _phylogenetic_inference_options = phylogenetic_inference_options;
2522 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2523 if ( _phylogenetic_inference_options == null ) {
2524 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2526 return _phylogenetic_inference_options;
2529 public Msa getMsa() {
2533 void setMsa( final Msa msa ) {
2537 void setMsaFile( final File msa_file ) {
2538 _msa_file = msa_file;
2541 public File getMsaFile() {
2545 public List<Sequence> getSeqs() {
2549 void setSeqs( final List<Sequence> seqs ) {
2553 void setSeqsFile( final File seqs_file ) {
2554 _seqs_file = seqs_file;
2557 public File getSeqsFile() {
2560 } // MainFrameApplication.
2562 class NexusFilter extends FileFilter {
2565 public boolean accept( final File f ) {
2566 final String file_name = f.getName().trim().toLowerCase();
2567 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2568 || file_name.endsWith( ".tre" ) || f.isDirectory();
2572 public String getDescription() {
2573 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2577 class NHFilter extends FileFilter {
2580 public boolean accept( final File f ) {
2581 final String file_name = f.getName().trim().toLowerCase();
2582 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2583 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2584 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2589 public String getDescription() {
2590 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2594 class NHXFilter extends FileFilter {
2597 public boolean accept( final File f ) {
2598 final String file_name = f.getName().trim().toLowerCase();
2599 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2603 public String getDescription() {
2604 return "NHX files (*.nhx)";
2608 class PdfFilter extends FileFilter {
2611 public boolean accept( final File f ) {
2612 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2616 public String getDescription() {
2617 return "PDF files (*.pdf)";
2621 class TolFilter extends FileFilter {
2624 public boolean accept( final File f ) {
2625 final String file_name = f.getName().trim().toLowerCase();
2626 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2627 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2631 public String getDescription() {
2632 return "Tree of Life files (*.tol, *.tolxml)";
2636 class XMLFilter extends FileFilter {
2639 public boolean accept( final File f ) {
2640 final String file_name = f.getName().trim().toLowerCase();
2641 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2642 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2646 public String getDescription() {
2647 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";