2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
27 package org.forester.archaeopteryx;
29 import java.awt.BorderLayout;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.net.MalformedURLException;
41 import java.util.ArrayList;
42 import java.util.HashSet;
43 import java.util.List;
46 import javax.swing.ButtonGroup;
47 import javax.swing.JCheckBoxMenuItem;
48 import javax.swing.JFileChooser;
49 import javax.swing.JMenu;
50 import javax.swing.JMenuBar;
51 import javax.swing.JMenuItem;
52 import javax.swing.JOptionPane;
53 import javax.swing.JRadioButtonMenuItem;
54 import javax.swing.UIManager;
55 import javax.swing.UnsupportedLookAndFeelException;
56 import javax.swing.WindowConstants;
57 import javax.swing.event.ChangeEvent;
58 import javax.swing.event.ChangeListener;
59 import javax.swing.filechooser.FileFilter;
60 import javax.swing.plaf.synth.SynthLookAndFeel;
62 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
63 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
64 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
65 import org.forester.archaeopteryx.Util.GraphicsExportType;
66 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
67 import org.forester.archaeopteryx.tools.GoAnnotation;
68 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
69 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
70 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
71 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
72 import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
73 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
74 import org.forester.archaeopteryx.webservices.WebservicesManager;
75 import org.forester.io.parsers.FastaParser;
76 import org.forester.io.parsers.GeneralMsaParser;
77 import org.forester.io.parsers.PhylogenyParser;
78 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
79 import org.forester.io.parsers.nhx.NHXParser;
80 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
81 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
82 import org.forester.io.parsers.tol.TolParser;
83 import org.forester.io.writers.PhylogenyWriter;
84 import org.forester.io.writers.SequenceWriter;
85 import org.forester.msa.Msa;
86 import org.forester.msa.MsaFormatException;
87 import org.forester.phylogeny.Phylogeny;
88 import org.forester.phylogeny.PhylogenyMethods;
89 import org.forester.phylogeny.PhylogenyNode;
90 import org.forester.phylogeny.data.Confidence;
91 import org.forester.phylogeny.data.Taxonomy;
92 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
93 import org.forester.phylogeny.factories.PhylogenyFactory;
94 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
95 import org.forester.sdi.GSDI;
96 import org.forester.sdi.SDI;
97 import org.forester.sdi.SDIR;
98 import org.forester.sdi.SDIse;
99 import org.forester.sequence.Sequence;
100 import org.forester.util.BasicDescriptiveStatistics;
101 import org.forester.util.BasicTable;
102 import org.forester.util.BasicTableParser;
103 import org.forester.util.DescriptiveStatistics;
104 import org.forester.util.ForesterUtil;
105 import org.forester.util.ForesterUtil.PhylogenyNodeField;
106 import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
107 import org.forester.util.WindowsUtils;
109 class DefaultFilter extends FileFilter {
112 public boolean accept( final File f ) {
113 final String file_name = f.getName().trim().toLowerCase();
114 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
115 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
116 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
117 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
118 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
119 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
120 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
121 || file_name.endsWith( ".con" ) || f.isDirectory();
125 public String getDescription() {
126 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
130 class GraphicsFileFilter extends FileFilter {
133 public boolean accept( final File f ) {
134 final String file_name = f.getName().trim().toLowerCase();
135 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
136 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
140 public String getDescription() {
141 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
145 class MsaFileFilter extends FileFilter {
148 public boolean accept( final File f ) {
149 final String file_name = f.getName().trim().toLowerCase();
150 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
151 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
155 public String getDescription() {
156 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
160 class SequencesFileFilter extends FileFilter {
163 public boolean accept( final File f ) {
164 final String file_name = f.getName().trim().toLowerCase();
165 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
166 || file_name.endsWith( ".seqs" ) || f.isDirectory();
170 public String getDescription() {
171 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
175 public final class MainFrameApplication extends MainFrame {
177 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
178 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
179 private final static int FRAME_X_SIZE = 800;
180 private final static int FRAME_Y_SIZE = 800;
181 // Filters for the file-open dialog (classes defined in this file)
182 private final static NHFilter nhfilter = new NHFilter();
183 private final static NHXFilter nhxfilter = new NHXFilter();
184 private final static XMLFilter xmlfilter = new XMLFilter();
185 private final static TolFilter tolfilter = new TolFilter();
186 private final static NexusFilter nexusfilter = new NexusFilter();
187 private final static PdfFilter pdffilter = new PdfFilter();
188 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
189 private final static MsaFileFilter msafilter = new MsaFileFilter();
190 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
191 private final static DefaultFilter defaultfilter = new DefaultFilter();
192 private static final long serialVersionUID = -799735726778865234L;
193 private final JFileChooser _values_filechooser;
194 private final JFileChooser _open_filechooser;
195 private final JFileChooser _msa_filechooser;
196 private final JFileChooser _seqs_filechooser;
197 private final JFileChooser _open_filechooser_for_species_tree;
198 private final JFileChooser _save_filechooser;
199 private final JFileChooser _writetopdf_filechooser;
200 private final JFileChooser _writetographics_filechooser;
202 private JMenu _analysis_menu;
203 private JMenuItem _load_species_tree_item;
204 private JMenuItem _sdi_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 _configuration = config;
238 if ( _configuration == null ) {
239 throw new IllegalArgumentException( "configuration is null" );
242 boolean synth_exception = false;
243 if ( Constants.__SYNTH_LF ) {
245 final SynthLookAndFeel synth = new SynthLookAndFeel();
246 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
247 MainFrameApplication.class );
248 UIManager.setLookAndFeel( synth );
250 catch ( final Exception ex ) {
251 synth_exception = true;
252 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
253 "could not create synth look and feel: "
254 + ex.getLocalizedMessage() );
257 if ( !Constants.__SYNTH_LF || synth_exception ) {
258 if ( _configuration.isUseNativeUI() ) {
259 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
262 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
265 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
267 catch ( final UnsupportedLookAndFeelException e ) {
268 Util.dieWithSystemError( "unsupported look and feel: " + e.toString() );
270 catch ( final ClassNotFoundException e ) {
271 Util.dieWithSystemError( "class not found exception: " + e.toString() );
273 catch ( final InstantiationException e ) {
274 Util.dieWithSystemError( "instantiation exception: " + e.toString() );
276 catch ( final IllegalAccessException e ) {
277 Util.dieWithSystemError( "illegal access exception: " + e.toString() );
279 catch ( final Exception e ) {
280 Util.dieWithSystemError( e.toString() );
282 // hide until everything is ready
284 setOptions( Options.createInstance( _configuration ) );
285 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
287 _species_tree = null;
289 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
290 _mainpanel = new MainPanel( _configuration, this );
292 _open_filechooser = new JFileChooser();
293 _open_filechooser.setCurrentDirectory( new File( "." ) );
294 _open_filechooser.setMultiSelectionEnabled( false );
295 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
296 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
297 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
298 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
299 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
300 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
301 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
302 _open_filechooser_for_species_tree = new JFileChooser();
303 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
304 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
305 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
306 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
307 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
308 _save_filechooser = new JFileChooser();
309 _save_filechooser.setCurrentDirectory( new File( "." ) );
310 _save_filechooser.setMultiSelectionEnabled( false );
311 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
312 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
313 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
314 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
315 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
316 _writetopdf_filechooser = new JFileChooser();
317 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
318 _writetographics_filechooser = new JFileChooser();
319 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
321 _msa_filechooser = new JFileChooser();
322 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
323 _msa_filechooser.setCurrentDirectory( new File( "." ) );
324 _msa_filechooser.setMultiSelectionEnabled( false );
325 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
326 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
328 _seqs_filechooser = new JFileChooser();
329 _seqs_filechooser.setName( "Read Sequences File" );
330 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
331 _seqs_filechooser.setMultiSelectionEnabled( false );
332 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
333 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
335 _values_filechooser = new JFileChooser();
336 _values_filechooser.setCurrentDirectory( new File( "." ) );
337 _values_filechooser.setMultiSelectionEnabled( false );
338 // build the menu bar
339 _jmenubar = new JMenuBar();
340 if ( !_configuration.isUseNativeUI() ) {
341 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
344 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
345 buildPhylogeneticInferenceMenu();
354 setJMenuBar( _jmenubar );
355 _jmenubar.add( _help_jmenu );
356 _contentpane = getContentPane();
357 _contentpane.setLayout( new BorderLayout() );
358 _contentpane.add( _mainpanel, BorderLayout.CENTER );
360 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
361 // addWindowFocusListener( new WindowAdapter() {
364 // public void windowGainedFocus( WindowEvent e ) {
365 // requestFocusInWindow();
368 // The window listener
369 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
370 addWindowListener( new WindowAdapter() {
373 public void windowClosing( final WindowEvent e ) {
374 if ( isUnsavedDataPresent() ) {
375 final int r = JOptionPane.showConfirmDialog( null,
376 "Exit despite potentially unsaved changes?",
378 JOptionPane.YES_NO_OPTION );
379 if ( r != JOptionPane.YES_OPTION ) {
384 final int r = JOptionPane.showConfirmDialog( null,
385 "Exit Archaeopteryx?",
387 JOptionPane.YES_NO_OPTION );
388 if ( r != JOptionPane.YES_OPTION ) {
395 // The component listener
396 addComponentListener( new ComponentAdapter() {
399 public void componentResized( final ComponentEvent e ) {
400 if ( _mainpanel.getCurrentTreePanel() != null ) {
401 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
403 _mainpanel.getCurrentTreePanel()
409 requestFocusInWindow();
410 // addKeyListener( this );
412 if ( ( phys != null ) && ( phys.length > 0 ) ) {
413 Util.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
415 getMainPanel().getControlPanel().showWholeAll();
416 getMainPanel().getControlPanel().showWhole();
418 activateSaveAllIfNeeded();
419 // ...and its children
420 _contentpane.repaint();
424 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
425 // Reads the config file (false, false => not url, not applet):
426 this( phys, new Configuration( config_file, false, false ), title );
430 public void actionPerformed( final ActionEvent e ) {
432 super.actionPerformed( e );
433 final Object o = e.getSource();
434 // Handle app-specific actions here:
435 if ( o == _open_item ) {
436 readPhylogeniesFromFile();
438 else if ( o == _save_item ) {
439 writeToFile( _mainpanel.getCurrentPhylogeny() );
440 // If subtree currently displayed, save it, instead of complete
443 else if ( o == _new_item ) {
446 else if ( o == _save_all_item ) {
449 else if ( o == _close_item ) {
452 else if ( o == _write_to_pdf_item ) {
453 writeToPdf( _mainpanel.getCurrentPhylogeny() );
455 else if ( o == _write_to_jpg_item ) {
456 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
458 else if ( o == _write_to_png_item ) {
459 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
461 else if ( o == _write_to_gif_item ) {
462 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
464 else if ( o == _write_to_tif_item ) {
465 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
467 else if ( o == _write_to_bmp_item ) {
468 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
470 else if ( o == _print_item ) {
473 else if ( o == _load_species_tree_item ) {
474 readSpeciesTreeFromFile();
476 else if ( o == _sdi_item ) {
477 if ( isSubtreeDisplayed() ) {
482 else if ( o == _lineage_inference ) {
483 if ( isSubtreeDisplayed() ) {
484 JOptionPane.showMessageDialog( this,
486 "Cannot infer ancestral taxonomies",
487 JOptionPane.ERROR_MESSAGE );
490 executeLineageInference();
492 else if ( o == _function_analysis ) {
493 executeFunctionAnalysis();
495 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
496 if ( isSubtreeDisplayed() ) {
499 obtainDetailedTaxonomicInformation();
501 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
502 if ( isSubtreeDisplayed() ) {
505 obtainDetailedTaxonomicInformationDelete();
507 else if ( o == _obtain_uniprot_seq_information_jmi ) {
508 obtainUniProtSequenceInformation();
510 else if ( o == _read_values_jmi ) {
511 if ( isSubtreeDisplayed() ) {
514 addExpressionValuesFromFile();
516 else if ( o == _move_node_names_to_tax_sn_jmi ) {
517 moveNodeNamesToTaxSn();
519 else if ( o == _move_node_names_to_seq_names_jmi ) {
520 moveNodeNamesToSeqNames();
522 else if ( o == _extract_tax_code_from_node_names_jmi ) {
523 extractTaxCodeFromNodeNames();
525 else if ( o == _gsdi_item ) {
526 if ( isSubtreeDisplayed() ) {
531 else if ( o == _root_min_dups_item ) {
532 if ( isSubtreeDisplayed() ) {
535 executeSDIR( false );
537 else if ( o == _root_min_cost_l_item ) {
538 if ( isSubtreeDisplayed() ) {
543 else if ( o == _graphics_export_visible_only_cbmi ) {
544 updateOptions( getOptions() );
546 else if ( o == _antialias_print_cbmi ) {
547 updateOptions( getOptions() );
549 else if ( o == _print_black_and_white_cbmi ) {
550 updateOptions( getOptions() );
552 else if ( o == _print_using_actual_size_cbmi ) {
553 updateOptions( getOptions() );
555 else if ( o == _graphics_export_using_actual_size_cbmi ) {
556 updateOptions( getOptions() );
558 else if ( o == _print_size_mi ) {
561 else if ( o == _choose_pdf_width_mi ) {
564 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
565 updateOptions( getOptions() );
567 else if ( o == _replace_underscores_cbmi ) {
568 if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
569 _extract_pfam_style_tax_codes_cbmi.setSelected( false );
571 updateOptions( getOptions() );
573 else if ( o == _collapse_below_threshold ) {
574 if ( isSubtreeDisplayed() ) {
577 collapseBelowThreshold();
579 else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
580 if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
581 _replace_underscores_cbmi.setSelected( false );
583 updateOptions( getOptions() );
585 else if ( o == _inference_from_msa_item ) {
586 executePhyleneticInference( false );
588 else if ( o == _inference_from_seqs_item ) {
589 executePhyleneticInference( true );
591 _contentpane.repaint();
593 catch ( final Exception ex ) {
594 Util.unexpectedException( ex );
596 catch ( final Error err ) {
597 Util.unexpectedError( err );
601 void buildAnalysisMenu() {
602 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
603 _analysis_menu.add( _sdi_item = new JMenuItem( "SDI (Speciation Duplication Inference)" ) );
604 if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
605 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
607 _analysis_menu.addSeparator();
608 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
609 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
610 _analysis_menu.addSeparator();
611 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
612 customizeJMenuItem( _sdi_item );
613 customizeJMenuItem( _gsdi_item );
614 customizeJMenuItem( _root_min_dups_item );
615 customizeJMenuItem( _root_min_cost_l_item );
616 customizeJMenuItem( _load_species_tree_item );
617 _analysis_menu.addSeparator();
618 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
619 customizeJMenuItem( _lineage_inference );
620 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
621 _jmenubar.add( _analysis_menu );
624 void buildPhylogeneticInferenceMenu() {
625 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
627 .add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment...(EXPERIMENTAL - DO NOT USE!!) " ) );
628 customizeJMenuItem( _inference_from_msa_item );
629 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
631 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences...(EXPERIMENTAL - DO NOT USE!!) " ) );
632 customizeJMenuItem( _inference_from_seqs_item );
633 _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
634 _jmenubar.add( _inference_menu );
638 void buildFileMenu() {
639 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
640 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
641 _file_jmenu.addSeparator();
642 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
643 _file_jmenu.addSeparator();
644 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
645 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
646 .getAvailablePhylogeniesWebserviceClients().size() ];
647 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
648 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
649 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
650 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
652 if ( getConfiguration().isEditable() ) {
653 _file_jmenu.addSeparator();
654 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
655 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
657 _file_jmenu.addSeparator();
658 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
659 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
660 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
661 _save_all_item.setEnabled( false );
662 _file_jmenu.addSeparator();
663 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
664 if ( Util.canWriteFormat( "tif" ) || Util.canWriteFormat( "tiff" ) || Util.canWriteFormat( "TIF" ) ) {
665 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
667 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
668 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
669 if ( Util.canWriteFormat( "gif" ) ) {
670 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
672 if ( Util.canWriteFormat( "bmp" ) ) {
673 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
675 _file_jmenu.addSeparator();
676 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
677 _file_jmenu.addSeparator();
678 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
679 _close_item.setToolTipText( "To close the current pane." );
680 _close_item.setEnabled( true );
681 _file_jmenu.addSeparator();
682 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
683 // For print in color option item
684 customizeJMenuItem( _open_item );
686 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
687 customizeJMenuItem( _open_url_item );
688 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
689 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
691 customizeJMenuItem( _save_item );
692 if ( getConfiguration().isEditable() ) {
693 customizeJMenuItem( _new_item );
695 customizeJMenuItem( _close_item );
696 customizeJMenuItem( _save_all_item );
697 customizeJMenuItem( _write_to_pdf_item );
698 customizeJMenuItem( _write_to_png_item );
699 customizeJMenuItem( _write_to_jpg_item );
700 customizeJMenuItem( _write_to_gif_item );
701 customizeJMenuItem( _write_to_tif_item );
702 customizeJMenuItem( _write_to_bmp_item );
703 customizeJMenuItem( _print_item );
704 customizeJMenuItem( _exit_item );
705 _jmenubar.add( _file_jmenu );
708 void buildOptionsMenu() {
709 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
710 _options_jmenu.addChangeListener( new ChangeListener() {
713 public void stateChanged( final ChangeEvent e ) {
714 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
715 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
717 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
718 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
719 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
720 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
721 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
722 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
724 _show_branch_length_values_cbmi,
725 _non_lined_up_cladograms_rbmi,
726 _uniform_cladograms_rbmi,
727 _ext_node_dependent_cladogram_rbmi,
728 _label_direction_cbmi );
729 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
730 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
731 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
734 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
736 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
737 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
738 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
739 _radio_group_1 = new ButtonGroup();
740 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
741 _radio_group_1.add( _uniform_cladograms_rbmi );
742 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
743 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
745 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
746 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
747 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
748 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
749 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
751 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
752 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
753 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
754 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
755 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
756 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
757 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
758 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
759 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
760 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
761 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
763 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
764 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
765 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
766 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
767 _options_jmenu.addSeparator();
768 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
769 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
770 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
771 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
772 _options_jmenu.addSeparator();
773 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
774 getConfiguration() ) );
775 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
776 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
778 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
780 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
782 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
783 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
784 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
785 _options_jmenu.addSeparator();
787 .add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Parsing:" ), getConfiguration() ) );
789 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Numbers Are Confidence Values" ) );
790 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
792 .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
793 customizeJMenuItem( _choose_font_mi );
794 customizeJMenuItem( _choose_minimal_confidence_mi );
795 customizeJMenuItem( _switch_colors_mi );
796 customizeJMenuItem( _print_size_mi );
797 customizeJMenuItem( _choose_pdf_width_mi );
798 customizeJMenuItem( _overview_placment_mi );
799 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
800 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
801 customizeJMenuItem( _cycle_node_shape_mi );
802 customizeJMenuItem( _cycle_node_fill_mi );
803 customizeJMenuItem( _choose_node_size_mi );
804 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
805 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
806 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
807 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
808 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
809 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
810 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
811 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
812 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
813 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
814 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
815 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
816 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
817 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
818 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
819 customizeCheckBoxMenuItem( _label_direction_cbmi,
820 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
821 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
822 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
823 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
824 .isInternalNumberAreConfidenceForNhParsing() );
825 customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
826 .isExtractPfamTaxonomyCodesInNhParsing() );
827 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
828 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
829 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
830 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
831 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
832 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
833 .isGraphicsExportUsingActualSize() );
834 _jmenubar.add( _options_jmenu );
837 void buildToolsMenu() {
838 _tools_menu = createMenu( "Tools", getConfiguration() );
839 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
840 customizeJMenuItem( _confcolor_item );
841 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
842 customizeJMenuItem( _color_rank_jmi );
843 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
844 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
845 customizeJMenuItem( _taxcolor_item );
846 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
847 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
848 customizeJMenuItem( _remove_branch_color_item );
849 _tools_menu.addSeparator();
850 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
851 customizeJMenuItem( _midpoint_root_item );
852 _tools_menu.addSeparator();
853 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
854 customizeJMenuItem( _collapse_species_specific_subtrees );
856 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold" ) );
857 customizeJMenuItem( _collapse_below_threshold );
858 _collapse_below_threshold
859 .setToolTipText( "To permanently collapse branches without at least one support value above a given threshold" );
860 _tools_menu.addSeparator();
862 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
863 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
864 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
865 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
866 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
867 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
869 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
870 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
871 _extract_tax_code_from_node_names_jmi
872 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
873 _tools_menu.addSeparator();
875 .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
876 customizeJMenuItem( _infer_common_sn_names_item );
877 _tools_menu.addSeparator();
879 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
880 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
881 _obtain_detailed_taxonomic_information_jmi
882 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
884 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
885 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
886 _obtain_detailed_taxonomic_information_deleting_jmi
887 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
889 .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
890 customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
891 _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
892 _tools_menu.addSeparator();
893 if ( !Constants.__RELEASE ) {
894 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
895 customizeJMenuItem( _function_analysis );
897 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
898 _tools_menu.addSeparator();
900 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
901 customizeJMenuItem( _read_values_jmi );
902 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
903 _jmenubar.add( _tools_menu );
906 private void choosePdfWidth() {
907 final String s = ( String ) JOptionPane.showInputDialog( this,
908 "Please enter the default line width for PDF export.\n"
910 + getOptions().getPrintLineWidth() + "]\n",
911 "Line Width for PDF Export",
912 JOptionPane.QUESTION_MESSAGE,
915 getOptions().getPrintLineWidth() );
916 if ( !ForesterUtil.isEmpty( s ) ) {
917 boolean success = true;
919 final String m_str = s.trim();
920 if ( !ForesterUtil.isEmpty( m_str ) ) {
922 f = Float.parseFloat( m_str );
924 catch ( final Exception ex ) {
931 if ( success && ( f > 0.0 ) ) {
932 getOptions().setPrintLineWidth( f );
937 private void choosePrintSize() {
938 final String s = ( String ) JOptionPane.showInputDialog( this,
939 "Please enter values for width and height,\nseparated by a comma.\n"
940 + "[current values: "
941 + getOptions().getPrintSizeX() + ", "
942 + getOptions().getPrintSizeY() + "]\n"
943 + "[A4: " + Constants.A4_SIZE_X + ", "
944 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
945 + Constants.US_LETTER_SIZE_X + ", "
946 + Constants.US_LETTER_SIZE_Y + "]",
947 "Default Size for Graphics Export",
948 JOptionPane.QUESTION_MESSAGE,
951 getOptions().getPrintSizeX() + ", "
952 + getOptions().getPrintSizeY() );
953 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
954 boolean success = true;
957 final String[] str_ary = s.split( "," );
958 if ( str_ary.length == 2 ) {
959 final String x_str = str_ary[ 0 ].trim();
960 final String y_str = str_ary[ 1 ].trim();
961 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
963 x = Integer.parseInt( x_str );
964 y = Integer.parseInt( y_str );
966 catch ( final Exception ex ) {
977 if ( success && ( x > 1 ) && ( y > 1 ) ) {
978 getOptions().setPrintSizeX( x );
979 getOptions().setPrintSizeY( y );
986 if ( isUnsavedDataPresent() ) {
987 final int r = JOptionPane.showConfirmDialog( this,
988 "Exit despite potentially unsaved changes?",
990 JOptionPane.YES_NO_OPTION );
991 if ( r != JOptionPane.YES_OPTION ) {
998 private void closeCurrentPane() {
999 if ( getMainPanel().getCurrentTreePanel() != null ) {
1000 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1001 final int r = JOptionPane.showConfirmDialog( this,
1002 "Close tab despite potentially unsaved changes?",
1004 JOptionPane.YES_NO_OPTION );
1005 if ( r != JOptionPane.YES_OPTION ) {
1009 getMainPanel().closeCurrentPane();
1010 activateSaveAllIfNeeded();
1014 private void collapse( final Phylogeny phy, final double m ) {
1015 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1016 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1017 double min_support = Double.MAX_VALUE;
1018 boolean conf_present = false;
1019 while ( it.hasNext() ) {
1020 final PhylogenyNode n = it.next();
1021 if ( !n.isExternal() && !n.isRoot() ) {
1022 final List<Confidence> c = n.getBranchData().getConfidences();
1023 if ( ( c != null ) && ( c.size() > 0 ) ) {
1024 conf_present = true;
1026 for( final Confidence confidence : c ) {
1027 if ( confidence.getValue() > max ) {
1028 max = confidence.getValue();
1031 if ( max < getMinNotCollapseConfidenceValue() ) {
1032 to_be_removed.add( n );
1034 if ( max < min_support ) {
1040 if ( conf_present ) {
1041 for( final PhylogenyNode node : to_be_removed ) {
1042 PhylogenyMethods.removeNode( node, phy );
1044 if ( to_be_removed.size() > 0 ) {
1045 phy.externalNodesHaveChanged();
1047 phy.recalculateNumberOfExternalDescendants( true );
1048 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1049 getCurrentTreePanel().setEdited( true );
1050 getCurrentTreePanel().repaint();
1052 if ( to_be_removed.size() > 0 ) {
1053 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1054 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1055 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1058 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1059 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1063 JOptionPane.showMessageDialog( this,
1064 "No branch collapsed because no confidence values present",
1065 "No confidence values present",
1066 JOptionPane.INFORMATION_MESSAGE );
1070 private void collapseBelowThreshold() {
1071 if ( getCurrentTreePanel() != null ) {
1072 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1073 if ( ( phy != null ) && !phy.isEmpty() ) {
1074 final String s = ( String ) JOptionPane.showInputDialog( this,
1075 "Please enter the minimum confidence value\n",
1076 "Minimal Confidence Value",
1077 JOptionPane.QUESTION_MESSAGE,
1080 getMinNotCollapseConfidenceValue() );
1081 if ( !ForesterUtil.isEmpty( s ) ) {
1082 boolean success = true;
1084 final String m_str = s.trim();
1085 if ( !ForesterUtil.isEmpty( m_str ) ) {
1087 m = Double.parseDouble( m_str );
1089 catch ( final Exception ex ) {
1096 if ( success && ( m >= 0.0 ) ) {
1097 setMinNotCollapseConfidenceValue( m );
1105 private PhyloXmlParser createPhyloXmlParser() {
1106 PhyloXmlParser xml_parser = null;
1107 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1109 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1111 catch ( final Exception e ) {
1112 JOptionPane.showMessageDialog( this,
1113 e.getLocalizedMessage(),
1114 "failed to create validating XML parser",
1115 JOptionPane.WARNING_MESSAGE );
1118 if ( xml_parser == null ) {
1119 xml_parser = new PhyloXmlParser();
1124 void executeGSDI() {
1125 if ( !isOKforSDI( false, true ) ) {
1128 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1129 JOptionPane.showMessageDialog( this,
1130 "Gene tree is not rooted.",
1131 "Cannot execute GSDI",
1132 JOptionPane.ERROR_MESSAGE );
1135 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1136 gene_tree.setAllNodesToNotCollapse();
1137 gene_tree.recalculateNumberOfExternalDescendants( false );
1139 int duplications = -1;
1141 gsdi = new GSDI( gene_tree, _species_tree.copy(), true );
1142 duplications = gsdi.getDuplicationsSum();
1144 catch ( final Exception e ) {
1145 JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
1147 gene_tree.setRerootable( false );
1148 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1149 getControlPanel().setShowEvents( true );
1151 _mainpanel.getCurrentTreePanel().setEdited( true );
1152 JOptionPane.showMessageDialog( this,
1153 "Number of duplications: " + duplications,
1154 "GSDI successfully completed",
1155 JOptionPane.INFORMATION_MESSAGE );
1158 void executeFunctionAnalysis() {
1159 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1162 final GoAnnotation a = new GoAnnotation( this,
1163 _mainpanel.getCurrentTreePanel(),
1164 _mainpanel.getCurrentPhylogeny() );
1165 new Thread( a ).start();
1168 void executeLineageInference() {
1169 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1172 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1173 JOptionPane.showMessageDialog( this,
1174 "Phylogeny is not rooted.",
1175 "Cannot infer ancestral taxonomies",
1176 JOptionPane.ERROR_MESSAGE );
1179 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1180 _mainpanel.getCurrentTreePanel(),
1181 _mainpanel.getCurrentPhylogeny()
1183 new Thread( inferrer ).start();
1186 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1187 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1188 getPhylogeneticInferenceOptions(),
1189 from_unaligned_seqs );
1191 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1192 if ( !from_unaligned_seqs ) {
1193 if ( getMsa() != null ) {
1194 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1195 getPhylogeneticInferenceOptions()
1197 new Thread( inferrer ).start();
1200 JOptionPane.showMessageDialog( this,
1201 "No multiple sequence alignment selected",
1202 "Phylogenetic Inference Not Launched",
1203 JOptionPane.WARNING_MESSAGE );
1207 if ( getSeqs() != null ) {
1208 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1209 getPhylogeneticInferenceOptions()
1211 new Thread( inferrer ).start();
1214 JOptionPane.showMessageDialog( this,
1215 "No input sequences selected",
1216 "Phylogenetic Inference Not Launched",
1217 JOptionPane.WARNING_MESSAGE );
1224 if ( !isOKforSDI( true, true ) ) {
1227 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1228 JOptionPane.showMessageDialog( this,
1229 "Gene tree is not rooted",
1230 "Cannot execute SDI",
1231 JOptionPane.ERROR_MESSAGE );
1234 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1235 gene_tree.setAllNodesToNotCollapse();
1236 gene_tree.recalculateNumberOfExternalDescendants( false );
1238 int duplications = -1;
1240 sdi = new SDIse( gene_tree, _species_tree.copy() );
1241 duplications = sdi.getDuplicationsSum();
1243 catch ( final Exception e ) {
1244 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDI", JOptionPane.ERROR_MESSAGE );
1246 gene_tree.setRerootable( false );
1247 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1248 getControlPanel().setShowEvents( true );
1250 _mainpanel.getCurrentTreePanel().setEdited( true );
1251 JOptionPane.showMessageDialog( this,
1252 "Number of duplications: " + duplications,
1253 "SDI successfully completed",
1254 JOptionPane.INFORMATION_MESSAGE );
1257 void executeSDIR( final boolean minimize_cost ) {
1258 if ( !isOKforSDI( true, true ) ) {
1261 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1262 final SDIR sdiunrooted = new SDIR();
1263 gene_tree.setAllNodesToNotCollapse();
1264 gene_tree.recalculateNumberOfExternalDescendants( false );
1266 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1267 !minimize_cost, // minimize sum of dups
1268 true, // minimize height
1269 true, // return tree(s)
1270 1 )[ 0 ]; // # of trees to return
1272 catch ( final Exception e ) {
1273 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1276 final int duplications = sdiunrooted.getMinimalDuplications();
1277 gene_tree.setRerootable( false );
1278 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1279 getControlPanel().setShowEvents( true );
1281 _mainpanel.getCurrentTreePanel().setEdited( true );
1282 JOptionPane.showMessageDialog( this,
1283 "Number of duplications: " + duplications,
1284 "SDIR successfully completed",
1285 JOptionPane.INFORMATION_MESSAGE );
1290 _mainpanel.terminate();
1291 _contentpane.removeAll();
1292 setVisible( false );
1297 private void extractTaxCodeFromNodeNames() {
1298 if ( getCurrentTreePanel() != null ) {
1299 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1300 if ( ( phy != null ) && !phy.isEmpty() ) {
1301 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1302 while ( it.hasNext() ) {
1303 final PhylogenyNode n = it.next();
1304 final String name = n.getName().trim();
1305 if ( !ForesterUtil.isEmpty( name ) ) {
1306 final String code = ForesterUtil.extractTaxonomyCodeFromNodeName( name,
1308 TAXONOMY_EXTRACTION.YES );
1309 if ( !ForesterUtil.isEmpty( code ) ) {
1310 PhylogenyMethods.setTaxonomyCode( n, code );
1318 private ControlPanel getControlPanel() {
1319 return getMainPanel().getControlPanel();
1322 private File getCurrentDir() {
1323 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1324 if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) {
1326 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1328 catch ( final Exception e ) {
1329 _current_dir = null;
1333 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1334 if ( System.getProperty( "user.home" ) != null ) {
1335 _current_dir = new File( System.getProperty( "user.home" ) );
1337 else if ( System.getProperty( "user.dir" ) != null ) {
1338 _current_dir = new File( System.getProperty( "user.dir" ) );
1341 return _current_dir;
1345 public MainPanel getMainPanel() {
1349 private double getMinNotCollapseConfidenceValue() {
1350 return _min_not_collapse;
1353 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1354 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1357 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1358 JOptionPane.showMessageDialog( this,
1359 "No species tree loaded",
1360 "Cannot execute SDI",
1361 JOptionPane.ERROR_MESSAGE );
1364 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1365 JOptionPane.showMessageDialog( this,
1366 "Species tree is not completely binary",
1367 "Cannot execute SDI",
1368 JOptionPane.ERROR_MESSAGE );
1371 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1372 JOptionPane.showMessageDialog( this,
1373 "Gene tree is not completely binary",
1374 "Cannot execute SDI",
1375 JOptionPane.ERROR_MESSAGE );
1383 private boolean isUnsavedDataPresent() {
1384 final List<TreePanel> tps = getMainPanel().getTreePanels();
1385 for( final TreePanel tp : tps ) {
1386 if ( tp.isEdited() ) {
1393 private void moveNodeNamesToSeqNames() {
1394 if ( getCurrentTreePanel() != null ) {
1395 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1396 if ( ( phy != null ) && !phy.isEmpty() ) {
1397 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.SEQUENCE_NAME );
1402 private void moveNodeNamesToTaxSn() {
1403 if ( getCurrentTreePanel() != null ) {
1404 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1405 if ( ( phy != null ) && !phy.isEmpty() ) {
1406 ForesterUtil.transferNodeNameToField( phy, PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME );
1411 private void newTree() {
1412 final Phylogeny[] phys = new Phylogeny[ 1 ];
1413 final Phylogeny phy = new Phylogeny();
1414 final PhylogenyNode node = new PhylogenyNode();
1415 phy.setRoot( node );
1416 phy.setRooted( true );
1418 Util.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1419 _mainpanel.getControlPanel().showWhole();
1420 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1421 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1422 if ( getMainPanel().getMainFrame() == null ) {
1423 // Must be "E" applet version.
1424 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1425 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1428 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1430 activateSaveAllIfNeeded();
1434 private void obtainDetailedTaxonomicInformation() {
1435 if ( getCurrentTreePanel() != null ) {
1436 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1437 if ( ( phy != null ) && !phy.isEmpty() ) {
1438 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1439 _mainpanel.getCurrentTreePanel(),
1441 new Thread( t ).start();
1446 private void obtainDetailedTaxonomicInformationDelete() {
1447 if ( getCurrentTreePanel() != null ) {
1448 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1449 if ( ( phy != null ) && !phy.isEmpty() ) {
1450 final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
1451 _mainpanel.getCurrentTreePanel(),
1454 new Thread( t ).start();
1459 private void obtainUniProtSequenceInformation() {
1460 if ( getCurrentTreePanel() != null ) {
1461 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1462 if ( ( phy != null ) && !phy.isEmpty() ) {
1463 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1464 _mainpanel.getCurrentTreePanel(),
1466 new Thread( u ).start();
1471 private void print() {
1472 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
1473 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1476 if ( !getOptions().isPrintUsingActualSize() ) {
1477 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
1478 getOptions().getPrintSizeY() - 140,
1480 getCurrentTreePanel().resetPreferredSize();
1481 getCurrentTreePanel().repaint();
1483 final String job_name = Constants.PRG_NAME;
1484 boolean error = false;
1485 String printer_name = null;
1487 printer_name = Printer.print( getCurrentTreePanel(), job_name );
1489 catch ( final Exception e ) {
1491 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
1493 if ( !error && ( printer_name != null ) ) {
1494 String msg = "Printing data sent to printer";
1495 if ( printer_name.length() > 1 ) {
1496 msg += " [" + printer_name + "]";
1498 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
1500 if ( !getOptions().isPrintUsingActualSize() ) {
1501 getControlPanel().showWhole();
1505 private void printPhylogenyToPdf( final String file_name ) {
1506 if ( !getOptions().isPrintUsingActualSize() ) {
1507 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
1508 getOptions().getPrintSizeY(),
1510 getCurrentTreePanel().resetPreferredSize();
1511 getCurrentTreePanel().repaint();
1513 String pdf_written_to = "";
1514 boolean error = false;
1516 if ( getOptions().isPrintUsingActualSize() ) {
1517 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
1518 getCurrentTreePanel(),
1519 getCurrentTreePanel().getWidth(),
1520 getCurrentTreePanel().getHeight() );
1523 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
1524 .getPrintSizeX(), getOptions().getPrintSizeY() );
1527 catch ( final IOException e ) {
1529 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1532 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
1533 JOptionPane.showMessageDialog( this,
1534 "Wrote PDF to: " + pdf_written_to,
1536 JOptionPane.INFORMATION_MESSAGE );
1539 JOptionPane.showMessageDialog( this,
1540 "There was an unknown problem when attempting to write to PDF file: \""
1543 JOptionPane.ERROR_MESSAGE );
1546 if ( !getOptions().isPrintUsingActualSize() ) {
1547 getControlPanel().showWhole();
1551 private void addExpressionValuesFromFile() {
1552 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1553 JOptionPane.showMessageDialog( this,
1554 "Need to load evolutionary tree first",
1555 "Can Not Read Expression Values",
1556 JOptionPane.WARNING_MESSAGE );
1559 final File my_dir = getCurrentDir();
1560 if ( my_dir != null ) {
1561 _values_filechooser.setCurrentDirectory( my_dir );
1563 final int result = _values_filechooser.showOpenDialog( _contentpane );
1564 final File file = _values_filechooser.getSelectedFile();
1565 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1566 BasicTable<String> t = null;
1568 t = BasicTableParser.parse( file, "\t" );
1569 if ( t.getNumberOfColumns() < 2 ) {
1570 t = BasicTableParser.parse( file, "," );
1572 if ( t.getNumberOfColumns() < 2 ) {
1573 t = BasicTableParser.parse( file, " " );
1576 catch ( final IOException e ) {
1577 JOptionPane.showMessageDialog( this,
1579 "Could Not Read Expression Value Table",
1580 JOptionPane.ERROR_MESSAGE );
1583 if ( t.getNumberOfColumns() < 2 ) {
1584 JOptionPane.showMessageDialog( this,
1585 "Table contains " + t.getNumberOfColumns() + " column(s)",
1586 "Problem with Expression Value Table",
1587 JOptionPane.ERROR_MESSAGE );
1590 if ( t.getNumberOfRows() < 1 ) {
1591 JOptionPane.showMessageDialog( this,
1592 "Table contains zero rows",
1593 "Problem with Expression Value Table",
1594 JOptionPane.ERROR_MESSAGE );
1597 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1598 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1599 JOptionPane.showMessageDialog( this,
1600 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1601 + phy.getNumberOfExternalNodes() + " external nodes",
1603 JOptionPane.WARNING_MESSAGE );
1605 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1607 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1608 final PhylogenyNode node = iter.next();
1609 final String node_name = node.getName();
1610 if ( !ForesterUtil.isEmpty( node_name ) ) {
1613 row = t.findRow( node_name );
1615 catch ( final IllegalArgumentException e ) {
1617 .showMessageDialog( this,
1619 "Error Mapping Node Identifiers to Expression Value Identifiers",
1620 JOptionPane.ERROR_MESSAGE );
1624 if ( node.isExternal() ) {
1629 final List<Double> l = new ArrayList<Double>();
1630 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1633 d = Double.parseDouble( t.getValueAsString( col, row ) );
1635 catch ( final NumberFormatException e ) {
1636 JOptionPane.showMessageDialog( this,
1637 "Could not parse \"" + t.getValueAsString( col, row )
1638 + "\" into a decimal value",
1639 "Issue with Expression Value Table",
1640 JOptionPane.ERROR_MESSAGE );
1643 stats.addValue( d );
1646 if ( !l.isEmpty() ) {
1647 if ( node.getNodeData().getProperties() != null ) {
1648 node.getNodeData().getProperties()
1649 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1651 node.getNodeData().setVector( l );
1655 if ( not_found > 0 ) {
1656 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1657 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1659 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1663 private void readPhylogeniesFromFile() {
1664 boolean exception = false;
1665 Phylogeny[] phys = null;
1666 // Set an initial directory if none set yet
1667 final File my_dir = getCurrentDir();
1668 _open_filechooser.setMultiSelectionEnabled( true );
1669 // Open file-open dialog and set current directory
1670 if ( my_dir != null ) {
1671 _open_filechooser.setCurrentDirectory( my_dir );
1673 final int result = _open_filechooser.showOpenDialog( _contentpane );
1674 // All done: get the file
1675 final File[] files = _open_filechooser.getSelectedFiles();
1676 setCurrentDir( _open_filechooser.getCurrentDirectory() );
1677 boolean nhx_or_nexus = false;
1678 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1679 for( final File file : files ) {
1680 if ( ( file != null ) && !file.isDirectory() ) {
1681 if ( _mainpanel.getCurrentTreePanel() != null ) {
1682 _mainpanel.getCurrentTreePanel().setWaitCursor();
1685 _mainpanel.setWaitCursor();
1687 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
1688 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
1690 final NHXParser nhx = new NHXParser();
1691 setSpecialOptionsForNhxParser( nhx );
1692 phys = ForesterUtil.readPhylogenies( nhx, file );
1693 nhx_or_nexus = true;
1695 catch ( final Exception e ) {
1697 exceptionOccuredDuringOpenFile( e );
1700 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
1701 warnIfNotPhyloXmlValidation( getConfiguration() );
1703 final PhyloXmlParser xml_parser = createPhyloXmlParser();
1704 phys = ForesterUtil.readPhylogenies( xml_parser, file );
1706 catch ( final Exception e ) {
1708 exceptionOccuredDuringOpenFile( e );
1711 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
1713 phys = ForesterUtil.readPhylogenies( new TolParser(), file );
1715 catch ( final Exception e ) {
1717 exceptionOccuredDuringOpenFile( e );
1720 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
1722 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
1723 setSpecialOptionsForNexParser( nex );
1724 phys = ForesterUtil.readPhylogenies( nex, file );
1725 nhx_or_nexus = true;
1727 catch ( final Exception e ) {
1729 exceptionOccuredDuringOpenFile( e );
1735 final PhylogenyParser parser = ForesterUtil
1736 .createParserDependingOnFileType( file, getConfiguration()
1737 .isValidatePhyloXmlAgainstSchema() );
1738 if ( parser instanceof NexusPhylogeniesParser ) {
1739 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
1740 setSpecialOptionsForNexParser( nex );
1741 nhx_or_nexus = true;
1743 else if ( parser instanceof NHXParser ) {
1744 final NHXParser nhx = ( NHXParser ) parser;
1745 setSpecialOptionsForNhxParser( nhx );
1746 nhx_or_nexus = true;
1748 else if ( parser instanceof PhyloXmlParser ) {
1749 warnIfNotPhyloXmlValidation( getConfiguration() );
1751 phys = ForesterUtil.readPhylogenies( parser, file );
1753 catch ( final Exception e ) {
1755 exceptionOccuredDuringOpenFile( e );
1758 if ( _mainpanel.getCurrentTreePanel() != null ) {
1759 _mainpanel.getCurrentTreePanel().setArrowCursor();
1762 _mainpanel.setArrowCursor();
1764 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
1765 boolean one_desc = false;
1766 if ( nhx_or_nexus ) {
1767 for( final Phylogeny phy : phys ) {
1768 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1769 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
1771 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
1777 Util.addPhylogeniesToTabs( phys,
1779 file.getAbsolutePath(),
1782 _mainpanel.getControlPanel().showWhole();
1783 if ( nhx_or_nexus && one_desc ) {
1785 .showMessageDialog( this,
1786 "One or more trees contain (a) node(s) with one descendant, "
1787 + ForesterUtil.LINE_SEPARATOR
1788 + "possibly indicating illegal parentheses within node names.",
1789 "Warning: Possible Error in New Hampshire Formatted Data",
1790 JOptionPane.WARNING_MESSAGE );
1796 activateSaveAllIfNeeded();
1800 public void readSeqsFromFile() {
1801 // Set an initial directory if none set yet
1802 final File my_dir = getCurrentDir();
1803 _seqs_filechooser.setMultiSelectionEnabled( false );
1804 // Open file-open dialog and set current directory
1805 if ( my_dir != null ) {
1806 _seqs_filechooser.setCurrentDirectory( my_dir );
1808 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
1809 // All done: get the seqs
1810 final File file = _seqs_filechooser.getSelectedFile();
1811 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
1812 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1813 setSeqsFile( null );
1815 List<Sequence> seqs = null;
1817 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1818 seqs = FastaParser.parse( new FileInputStream( file ) );
1819 for( final Sequence seq : seqs ) {
1820 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
1827 catch ( final MsaFormatException e ) {
1829 _mainpanel.getCurrentTreePanel().setArrowCursor();
1831 catch ( final Exception ex ) {
1834 JOptionPane.showMessageDialog( this,
1835 e.getLocalizedMessage(),
1836 "Multiple sequence file format error",
1837 JOptionPane.ERROR_MESSAGE );
1840 catch ( final IOException e ) {
1842 _mainpanel.getCurrentTreePanel().setArrowCursor();
1844 catch ( final Exception ex ) {
1847 JOptionPane.showMessageDialog( this,
1848 e.getLocalizedMessage(),
1849 "Failed to read multiple sequence file",
1850 JOptionPane.ERROR_MESSAGE );
1853 catch ( final IllegalArgumentException e ) {
1855 _mainpanel.getCurrentTreePanel().setArrowCursor();
1857 catch ( final Exception ex ) {
1860 JOptionPane.showMessageDialog( this,
1861 e.getLocalizedMessage(),
1862 "Unexpected error during reading of multiple sequence file",
1863 JOptionPane.ERROR_MESSAGE );
1866 catch ( final Exception e ) {
1868 _mainpanel.getCurrentTreePanel().setArrowCursor();
1870 catch ( final Exception ex ) {
1873 e.printStackTrace();
1874 JOptionPane.showMessageDialog( this,
1875 e.getLocalizedMessage(),
1876 "Unexpected error during reading of multiple sequence file",
1877 JOptionPane.ERROR_MESSAGE );
1880 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1881 JOptionPane.showMessageDialog( this,
1882 "Multiple sequence file is empty",
1883 "Illegal multiple sequence file",
1884 JOptionPane.ERROR_MESSAGE );
1887 if ( seqs.size() < 4 ) {
1888 JOptionPane.showMessageDialog( this,
1889 "Multiple sequence file needs to contain at least 3 sequences",
1890 "Illegal multiple sequence file",
1891 JOptionPane.ERROR_MESSAGE );
1894 // if ( msa.getLength() < 2 ) {
1895 // JOptionPane.showMessageDialog( this,
1896 // "Multiple sequence alignment needs to contain at least 2 residues",
1897 // "Illegal multiple sequence file",
1898 // JOptionPane.ERROR_MESSAGE );
1902 setSeqsFile( _seqs_filechooser.getSelectedFile() );
1907 public void readMsaFromFile() {
1908 // Set an initial directory if none set yet
1909 final File my_dir = getCurrentDir();
1910 _msa_filechooser.setMultiSelectionEnabled( false );
1911 // Open file-open dialog and set current directory
1912 if ( my_dir != null ) {
1913 _msa_filechooser.setCurrentDirectory( my_dir );
1915 final int result = _msa_filechooser.showOpenDialog( _contentpane );
1916 // All done: get the msa
1917 final File file = _msa_filechooser.getSelectedFile();
1918 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
1919 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1924 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1925 msa = FastaParser.parseMsa( new FileInputStream( file ) );
1926 System.out.println( msa.toString() );
1929 msa = GeneralMsaParser.parse( new FileInputStream( file ) );
1932 catch ( final MsaFormatException e ) {
1934 _mainpanel.getCurrentTreePanel().setArrowCursor();
1936 catch ( final Exception ex ) {
1939 JOptionPane.showMessageDialog( this,
1940 e.getLocalizedMessage(),
1941 "Multiple sequence alignment format error",
1942 JOptionPane.ERROR_MESSAGE );
1945 catch ( final IOException e ) {
1947 _mainpanel.getCurrentTreePanel().setArrowCursor();
1949 catch ( final Exception ex ) {
1952 JOptionPane.showMessageDialog( this,
1953 e.getLocalizedMessage(),
1954 "Failed to read multiple sequence alignment",
1955 JOptionPane.ERROR_MESSAGE );
1958 catch ( final IllegalArgumentException e ) {
1960 _mainpanel.getCurrentTreePanel().setArrowCursor();
1962 catch ( final Exception ex ) {
1965 JOptionPane.showMessageDialog( this,
1966 e.getLocalizedMessage(),
1967 "Unexpected error during reading of multiple sequence alignment",
1968 JOptionPane.ERROR_MESSAGE );
1971 catch ( final Exception e ) {
1973 _mainpanel.getCurrentTreePanel().setArrowCursor();
1975 catch ( final Exception ex ) {
1978 e.printStackTrace();
1979 JOptionPane.showMessageDialog( this,
1980 e.getLocalizedMessage(),
1981 "Unexpected error during reading of multiple sequence alignment",
1982 JOptionPane.ERROR_MESSAGE );
1985 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
1986 JOptionPane.showMessageDialog( this,
1987 "Multiple sequence alignment is empty",
1988 "Illegal Multiple Sequence Alignment",
1989 JOptionPane.ERROR_MESSAGE );
1992 if ( msa.getNumberOfSequences() < 4 ) {
1993 JOptionPane.showMessageDialog( this,
1994 "Multiple sequence alignment needs to contain at least 3 sequences",
1995 "Illegal multiple sequence alignment",
1996 JOptionPane.ERROR_MESSAGE );
1999 if ( msa.getLength() < 2 ) {
2000 JOptionPane.showMessageDialog( this,
2001 "Multiple sequence alignment needs to contain at least 2 residues",
2002 "Illegal multiple sequence alignment",
2003 JOptionPane.ERROR_MESSAGE );
2007 setMsaFile( _msa_filechooser.getSelectedFile() );
2013 void readPhylogeniesFromURL() {
2015 Phylogeny[] phys = null;
2016 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
2017 final String url_string = JOptionPane.showInputDialog( this,
2019 "Use URL/webservice to obtain a phylogeny",
2020 JOptionPane.QUESTION_MESSAGE );
2021 boolean nhx_or_nexus = false;
2022 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
2024 url = new URL( url_string );
2025 PhylogenyParser parser = null;
2026 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
2027 parser = new TolParser();
2030 parser = ForesterUtil.createParserDependingOnUrlContents( url, getConfiguration()
2031 .isValidatePhyloXmlAgainstSchema() );
2033 if ( parser instanceof NexusPhylogeniesParser ) {
2034 nhx_or_nexus = true;
2036 else if ( parser instanceof NHXParser ) {
2037 nhx_or_nexus = true;
2039 if ( _mainpanel.getCurrentTreePanel() != null ) {
2040 _mainpanel.getCurrentTreePanel().setWaitCursor();
2043 _mainpanel.setWaitCursor();
2045 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2046 phys = factory.create( url.openStream(), parser );
2048 catch ( final MalformedURLException e ) {
2049 JOptionPane.showMessageDialog( this,
2050 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
2052 JOptionPane.ERROR_MESSAGE );
2054 catch ( final IOException e ) {
2055 JOptionPane.showMessageDialog( this,
2056 "Could not read from " + url + "\n"
2057 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2058 "Failed to read URL",
2059 JOptionPane.ERROR_MESSAGE );
2061 catch ( final Exception e ) {
2062 JOptionPane.showMessageDialog( this,
2063 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
2064 "Unexpected Exception",
2065 JOptionPane.ERROR_MESSAGE );
2068 if ( _mainpanel.getCurrentTreePanel() != null ) {
2069 _mainpanel.getCurrentTreePanel().setArrowCursor();
2072 _mainpanel.setArrowCursor();
2075 if ( ( phys != null ) && ( phys.length > 0 ) ) {
2076 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2077 for( final Phylogeny phy : phys ) {
2078 ForesterUtil.transferInternalNodeNamesToConfidence( phy );
2081 Util.addPhylogeniesToTabs( phys,
2082 new File( url.getFile() ).getName(),
2083 new File( url.getFile() ).toString(),
2086 _mainpanel.getControlPanel().showWhole();
2089 activateSaveAllIfNeeded();
2093 private void readSpeciesTreeFromFile() {
2095 boolean exception = false;
2096 final File my_dir = getCurrentDir();
2097 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2098 if ( my_dir != null ) {
2099 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2101 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2102 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2103 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2104 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2106 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2109 catch ( final Exception e ) {
2111 exceptionOccuredDuringOpenFile( e );
2114 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2116 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
2119 catch ( final Exception e ) {
2121 exceptionOccuredDuringOpenFile( e );
2127 final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
2130 catch ( final Exception e ) {
2132 exceptionOccuredDuringOpenFile( e );
2135 if ( !exception && ( t != null ) && !t.isRooted() ) {
2138 JOptionPane.showMessageDialog( this,
2139 "Species tree is not rooted",
2140 "Species tree not loaded",
2141 JOptionPane.ERROR_MESSAGE );
2143 if ( !exception && ( t != null ) ) {
2144 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2145 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2146 final PhylogenyNode node = it.next();
2147 if ( !node.getNodeData().isHasTaxonomy() ) {
2151 .showMessageDialog( this,
2152 "Species tree contains external node(s) without taxonomy information",
2153 "Species tree not loaded",
2154 JOptionPane.ERROR_MESSAGE );
2158 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2161 JOptionPane.showMessageDialog( this,
2163 + node.getNodeData().getTaxonomy().asSimpleText()
2164 + "] is not unique in species tree",
2165 "Species tree not loaded",
2166 JOptionPane.ERROR_MESSAGE );
2170 tax_set.add( node.getNodeData().getTaxonomy() );
2175 if ( !exception && ( t != null ) ) {
2177 JOptionPane.showMessageDialog( this,
2178 "Species tree successfully loaded",
2179 "Species tree loaded",
2180 JOptionPane.INFORMATION_MESSAGE );
2182 _contentpane.repaint();
2187 private void setCurrentDir( final File current_dir ) {
2188 _current_dir = current_dir;
2191 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2192 _min_not_collapse = min_not_collapse;
2195 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2196 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2199 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2200 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2201 ForesterUtil.TAXONOMY_EXTRACTION te = ForesterUtil.TAXONOMY_EXTRACTION.NO;
2202 if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
2203 te = ForesterUtil.TAXONOMY_EXTRACTION.YES;
2205 nhx.setTaxonomyExtraction( te );
2208 private void writeAllToFile() {
2209 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2212 final File my_dir = getCurrentDir();
2213 if ( my_dir != null ) {
2214 _save_filechooser.setCurrentDirectory( my_dir );
2216 _save_filechooser.setSelectedFile( new File( "" ) );
2217 final int result = _save_filechooser.showSaveDialog( _contentpane );
2218 final File file = _save_filechooser.getSelectedFile();
2219 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2220 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2221 if ( file.exists() ) {
2222 final int i = JOptionPane.showConfirmDialog( this,
2223 file + " already exists. Overwrite?",
2225 JOptionPane.OK_CANCEL_OPTION,
2226 JOptionPane.WARNING_MESSAGE );
2227 if ( i != JOptionPane.OK_OPTION ) {
2234 catch ( final Exception e ) {
2235 JOptionPane.showMessageDialog( this,
2236 "Failed to delete: " + file,
2238 JOptionPane.WARNING_MESSAGE );
2242 final int count = getMainPanel().getTabbedPane().getTabCount();
2243 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2244 for( int i = 0; i < count; ++i ) {
2245 trees.add( getMainPanel().getPhylogeny( i ) );
2246 getMainPanel().getTreePanels().get( i ).setEdited( false );
2248 final PhylogenyWriter writer = new PhylogenyWriter();
2250 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2252 catch ( final IOException e ) {
2253 JOptionPane.showMessageDialog( this,
2254 "Failed to write to: " + file,
2256 JOptionPane.WARNING_MESSAGE );
2261 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2263 final PhylogenyWriter writer = new PhylogenyWriter();
2264 writer.toNewHampshire( t, false, true, file );
2266 catch ( final Exception e ) {
2268 exceptionOccuredDuringSaveAs( e );
2273 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2275 final PhylogenyWriter writer = new PhylogenyWriter();
2276 writer.toNexus( file, t );
2278 catch ( final Exception e ) {
2280 exceptionOccuredDuringSaveAs( e );
2285 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2287 final PhylogenyWriter writer = new PhylogenyWriter();
2288 writer.toNewHampshireX( t, file );
2290 catch ( final Exception e ) {
2292 exceptionOccuredDuringSaveAs( e );
2297 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2299 final PhylogenyWriter writer = new PhylogenyWriter();
2300 writer.toPhyloXML( file, t, 0 );
2302 catch ( final Exception e ) {
2304 exceptionOccuredDuringSaveAs( e );
2309 private void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
2310 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
2311 _mainpanel.getCurrentTreePanel().getHeight(),
2313 String file_written_to = "";
2314 boolean error = false;
2316 file_written_to = Util.writePhylogenyToGraphicsFile( file_name,
2317 _mainpanel.getCurrentTreePanel().getWidth(),
2318 _mainpanel.getCurrentTreePanel().getHeight(),
2319 _mainpanel.getCurrentTreePanel(),
2320 _mainpanel.getControlPanel(),
2324 catch ( final IOException e ) {
2326 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2329 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2330 JOptionPane.showMessageDialog( this,
2331 "Wrote image to: " + file_written_to,
2333 JOptionPane.INFORMATION_MESSAGE );
2336 JOptionPane.showMessageDialog( this,
2337 "There was an unknown problem when attempting to write to an image file: \""
2340 JOptionPane.ERROR_MESSAGE );
2343 _contentpane.repaint();
2346 private void writeToFile( final Phylogeny t ) {
2350 String initial_filename = null;
2351 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2353 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2355 catch ( final IOException e ) {
2356 initial_filename = null;
2359 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2360 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2363 _save_filechooser.setSelectedFile( new File( "" ) );
2365 final File my_dir = getCurrentDir();
2366 if ( my_dir != null ) {
2367 _save_filechooser.setCurrentDirectory( my_dir );
2369 final int result = _save_filechooser.showSaveDialog( _contentpane );
2370 final File file = _save_filechooser.getSelectedFile();
2371 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2372 boolean exception = false;
2373 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2374 if ( file.exists() ) {
2375 final int i = JOptionPane.showConfirmDialog( this,
2376 file + " already exists.\nOverwrite?",
2378 JOptionPane.OK_CANCEL_OPTION,
2379 JOptionPane.QUESTION_MESSAGE );
2380 if ( i != JOptionPane.OK_OPTION ) {
2384 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2386 ForesterUtil.copyFile( file, to );
2388 catch ( final Exception e ) {
2389 JOptionPane.showMessageDialog( this,
2390 "Failed to create backup copy " + to,
2391 "Failed to Create Backup Copy",
2392 JOptionPane.WARNING_MESSAGE );
2397 catch ( final Exception e ) {
2398 JOptionPane.showMessageDialog( this,
2399 "Failed to delete: " + file,
2401 JOptionPane.WARNING_MESSAGE );
2405 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2406 exception = writeAsNewHampshire( t, exception, file );
2408 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2409 exception = writeAsNHX( t, exception, file );
2411 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2412 exception = writeAsPhyloXml( t, exception, file );
2414 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2415 exception = writeAsNexus( t, exception, file );
2419 final String file_name = file.getName().trim().toLowerCase();
2420 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2421 || file_name.endsWith( ".tree" ) ) {
2422 exception = writeAsNewHampshire( t, exception, file );
2424 else if ( file_name.endsWith( ".nhx" ) ) {
2425 exception = writeAsNHX( t, exception, file );
2427 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2428 exception = writeAsNexus( t, exception, file );
2432 exception = writeAsPhyloXml( t, exception, file );
2436 getMainPanel().setTitleOfSelectedTab( file.getName() );
2437 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2438 getMainPanel().getCurrentTreePanel().setEdited( false );
2443 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2444 if ( ( t == null ) || t.isEmpty() ) {
2447 String initial_filename = "";
2448 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2449 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2451 if ( initial_filename.indexOf( '.' ) > 0 ) {
2452 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2454 initial_filename = initial_filename + "." + type;
2455 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2456 final File my_dir = getCurrentDir();
2457 if ( my_dir != null ) {
2458 _writetographics_filechooser.setCurrentDirectory( my_dir );
2460 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2461 File file = _writetographics_filechooser.getSelectedFile();
2462 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2463 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2464 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2465 file = new File( file.toString() + "." + type );
2467 if ( file.exists() ) {
2468 final int i = JOptionPane.showConfirmDialog( this,
2469 file + " already exists. Overwrite?",
2471 JOptionPane.OK_CANCEL_OPTION,
2472 JOptionPane.WARNING_MESSAGE );
2473 if ( i != JOptionPane.OK_OPTION ) {
2480 catch ( final Exception e ) {
2481 JOptionPane.showMessageDialog( this,
2482 "Failed to delete: " + file,
2484 JOptionPane.WARNING_MESSAGE );
2488 writePhylogenyToGraphicsFile( file.toString(), type );
2492 private void writeToPdf( final Phylogeny t ) {
2493 if ( ( t == null ) || t.isEmpty() ) {
2496 String initial_filename = "";
2497 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2498 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2500 if ( initial_filename.indexOf( '.' ) > 0 ) {
2501 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2503 initial_filename = initial_filename + ".pdf";
2504 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2505 final File my_dir = getCurrentDir();
2506 if ( my_dir != null ) {
2507 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2509 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2510 File file = _writetopdf_filechooser.getSelectedFile();
2511 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2512 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2513 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2514 file = new File( file.toString() + ".pdf" );
2516 if ( file.exists() ) {
2517 final int i = JOptionPane.showConfirmDialog( this,
2518 file + " already exists. Overwrite?",
2520 JOptionPane.OK_CANCEL_OPTION,
2521 JOptionPane.WARNING_MESSAGE );
2522 if ( i != JOptionPane.OK_OPTION ) {
2526 printPhylogenyToPdf( file.toString() );
2530 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2531 return new MainFrameApplication( phys, config, title );
2534 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2535 return new MainFrameApplication( phys, config_file_name, title );
2538 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2539 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2540 + o.getPrintSizeY() + ")" );
2543 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2544 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2547 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2548 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2550 .showMessageDialog( null,
2552 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2555 JOptionPane.WARNING_MESSAGE );
2559 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2560 _phylogenetic_inference_options = phylogenetic_inference_options;
2563 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2564 if ( _phylogenetic_inference_options == null ) {
2565 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2567 return _phylogenetic_inference_options;
2570 public Msa getMsa() {
2574 void setMsa( final Msa msa ) {
2578 void setMsaFile( final File msa_file ) {
2579 _msa_file = msa_file;
2582 public File getMsaFile() {
2586 public List<Sequence> getSeqs() {
2590 void setSeqs( final List<Sequence> seqs ) {
2594 void setSeqsFile( final File seqs_file ) {
2595 _seqs_file = seqs_file;
2598 public File getSeqsFile() {
2601 } // MainFrameApplication.
2603 class NexusFilter extends FileFilter {
2606 public boolean accept( final File f ) {
2607 final String file_name = f.getName().trim().toLowerCase();
2608 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2609 || file_name.endsWith( ".tre" ) || f.isDirectory();
2613 public String getDescription() {
2614 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2618 class NHFilter extends FileFilter {
2621 public boolean accept( final File f ) {
2622 final String file_name = f.getName().trim().toLowerCase();
2623 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2624 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2625 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2630 public String getDescription() {
2631 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2635 class NHXFilter extends FileFilter {
2638 public boolean accept( final File f ) {
2639 final String file_name = f.getName().trim().toLowerCase();
2640 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2644 public String getDescription() {
2645 return "NHX files (*.nhx)";
2649 class PdfFilter extends FileFilter {
2652 public boolean accept( final File f ) {
2653 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2657 public String getDescription() {
2658 return "PDF files (*.pdf)";
2662 class TolFilter extends FileFilter {
2665 public boolean accept( final File f ) {
2666 final String file_name = f.getName().trim().toLowerCase();
2667 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2668 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2672 public String getDescription() {
2673 return "Tree of Life files (*.tol, *.tolxml)";
2677 class XMLFilter extends FileFilter {
2680 public boolean accept( final File f ) {
2681 final String file_name = f.getName().trim().toLowerCase();
2682 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2683 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2687 public String getDescription() {
2688 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";