2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
27 package org.forester.archaeopteryx;
29 import java.awt.BorderLayout;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.net.MalformedURLException;
42 import java.util.ArrayList;
43 import java.util.HashSet;
44 import java.util.List;
47 import javax.swing.ButtonGroup;
48 import javax.swing.JCheckBoxMenuItem;
49 import javax.swing.JFileChooser;
50 import javax.swing.JMenu;
51 import javax.swing.JMenuBar;
52 import javax.swing.JMenuItem;
53 import javax.swing.JOptionPane;
54 import javax.swing.JRadioButtonMenuItem;
55 import javax.swing.UIManager;
56 import javax.swing.UnsupportedLookAndFeelException;
57 import javax.swing.WindowConstants;
58 import javax.swing.event.ChangeEvent;
59 import javax.swing.event.ChangeListener;
60 import javax.swing.filechooser.FileFilter;
61 import javax.swing.plaf.synth.SynthLookAndFeel;
63 import org.forester.analysis.TaxonomyDataManager;
64 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
65 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
66 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
67 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
68 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
69 import org.forester.archaeopteryx.tools.GoAnnotation;
70 import org.forester.archaeopteryx.tools.InferenceManager;
71 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
72 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
73 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
74 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
75 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
76 import org.forester.archaeopteryx.webservices.WebservicesManager;
77 import org.forester.io.parsers.FastaParser;
78 import org.forester.io.parsers.GeneralMsaParser;
79 import org.forester.io.parsers.PhylogenyParser;
80 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
81 import org.forester.io.parsers.nhx.NHXParser;
82 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
83 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
84 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
85 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
86 import org.forester.io.parsers.tol.TolParser;
87 import org.forester.io.parsers.util.ParserUtils;
88 import org.forester.io.writers.PhylogenyWriter;
89 import org.forester.io.writers.SequenceWriter;
90 import org.forester.msa.Msa;
91 import org.forester.msa.MsaFormatException;
92 import org.forester.phylogeny.Phylogeny;
93 import org.forester.phylogeny.PhylogenyMethods;
94 import org.forester.phylogeny.PhylogenyNode;
95 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
96 import org.forester.phylogeny.data.Confidence;
97 import org.forester.phylogeny.data.Taxonomy;
98 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
99 import org.forester.phylogeny.factories.PhylogenyFactory;
100 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
101 import org.forester.sdi.GSDI;
102 import org.forester.sdi.GSDIR;
103 import org.forester.sdi.SDIException;
104 import org.forester.sdi.SDIR;
105 import org.forester.sequence.Sequence;
106 import org.forester.util.BasicDescriptiveStatistics;
107 import org.forester.util.BasicTable;
108 import org.forester.util.BasicTableParser;
109 import org.forester.util.DescriptiveStatistics;
110 import org.forester.util.ForesterUtil;
111 import org.forester.util.WindowsUtils;
113 public final class MainFrameApplication extends MainFrame {
115 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
116 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
117 private final static int FRAME_X_SIZE = 800;
118 private final static int FRAME_Y_SIZE = 800;
119 // Filters for the file-open dialog (classes defined in this file)
120 private final static NHFilter nhfilter = new NHFilter();
121 private final static NHXFilter nhxfilter = new NHXFilter();
122 private final static XMLFilter xmlfilter = new XMLFilter();
123 private final static TolFilter tolfilter = new TolFilter();
124 private final static NexusFilter nexusfilter = new NexusFilter();
125 private final static PdfFilter pdffilter = new PdfFilter();
126 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
127 private final static MsaFileFilter msafilter = new MsaFileFilter();
128 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
129 private final static DefaultFilter defaultfilter = new DefaultFilter();
130 private static final long serialVersionUID = -799735726778865234L;
131 private final JFileChooser _values_filechooser;
132 private final JFileChooser _open_filechooser;
133 private final JFileChooser _msa_filechooser;
134 private final JFileChooser _seqs_filechooser;
135 private final JFileChooser _open_filechooser_for_species_tree;
136 private final JFileChooser _save_filechooser;
137 private final JFileChooser _writetopdf_filechooser;
138 private final JFileChooser _writetographics_filechooser;
140 private JMenu _analysis_menu;
141 private JMenuItem _load_species_tree_item;
142 private JMenuItem _gsdi_item;
143 private JMenuItem _gsdir_item;
144 private JMenuItem _root_min_dups_item;
145 private JMenuItem _root_min_cost_l_item;
146 private JMenuItem _lineage_inference;
147 private JMenuItem _function_analysis;
148 // Application-only print menu items
149 private JMenuItem _print_item;
150 private JMenuItem _write_to_pdf_item;
151 private JMenuItem _write_to_jpg_item;
152 private JMenuItem _write_to_gif_item;
153 private JMenuItem _write_to_tif_item;
154 private JMenuItem _write_to_png_item;
155 private JMenuItem _write_to_bmp_item;
156 private Phylogeny _species_tree;
157 private File _current_dir;
158 private ButtonGroup _radio_group_1;
159 private ButtonGroup _radio_group_2;
161 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
162 // Phylogeny Inference menu
163 private JMenu _inference_menu;
164 private JMenuItem _inference_from_msa_item;
165 private JMenuItem _inference_from_seqs_item;
166 // Phylogeny Inference
167 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
168 private Msa _msa = null;
169 private File _msa_file = null;
170 private List<Sequence> _seqs = null;
171 private File _seqs_file = null;
172 // expression values menu:
173 JMenuItem _read_values_jmi;
175 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
176 _configuration = config;
177 if ( _configuration == null ) {
178 throw new IllegalArgumentException( "configuration is null" );
181 setOptions( Options.createInstance( _configuration ) );
182 _mainpanel = new MainPanel( _configuration, this );
183 _open_filechooser = null;
184 _open_filechooser_for_species_tree = null;
185 _save_filechooser = null;
186 _writetopdf_filechooser = null;
187 _writetographics_filechooser = null;
188 _msa_filechooser = null;
189 _seqs_filechooser = null;
190 _values_filechooser = null;
191 _jmenubar = new JMenuBar();
194 _contentpane = getContentPane();
195 _contentpane.setLayout( new BorderLayout() );
196 _contentpane.add( _mainpanel, BorderLayout.CENTER );
198 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
199 // The window listener
200 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
201 addWindowListener( new WindowAdapter() {
204 public void windowClosing( final WindowEvent e ) {
208 // setVisible( true );
209 if ( ( phys != null ) && ( phys.length > 0 ) ) {
210 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
212 getMainPanel().getControlPanel().showWholeAll();
213 getMainPanel().getControlPanel().showWhole();
215 //activateSaveAllIfNeeded();
216 // ...and its children
217 _contentpane.repaint();
220 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
221 this( phys, config, title, null );
224 private MainFrameApplication( final Phylogeny[] phys,
225 final Configuration config,
227 final File current_dir ) {
229 _configuration = config;
230 if ( _configuration == null ) {
231 throw new IllegalArgumentException( "configuration is null" );
234 boolean synth_exception = false;
235 if ( Constants.__SYNTH_LF ) {
237 final SynthLookAndFeel synth = new SynthLookAndFeel();
238 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
239 MainFrameApplication.class );
240 UIManager.setLookAndFeel( synth );
242 catch ( final Exception ex ) {
243 synth_exception = true;
244 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
245 "could not create synth look and feel: "
246 + ex.getLocalizedMessage() );
249 if ( !Constants.__SYNTH_LF || synth_exception ) {
250 if ( _configuration.isUseNativeUI() ) {
251 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
254 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
257 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
259 catch ( final UnsupportedLookAndFeelException e ) {
260 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
262 catch ( final ClassNotFoundException e ) {
263 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
265 catch ( final InstantiationException e ) {
266 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
268 catch ( final IllegalAccessException e ) {
269 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
272 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
273 setCurrentDir( current_dir );
275 // hide until everything is ready
277 setOptions( Options.createInstance( _configuration ) );
278 setInferenceManager( InferenceManager.createInstance( _configuration ) );
279 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
280 // _textframe = null; #~~~~
281 _species_tree = null;
283 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
284 _mainpanel = new MainPanel( _configuration, this );
286 _open_filechooser = new JFileChooser();
287 _open_filechooser.setCurrentDirectory( new File( "." ) );
288 _open_filechooser.setMultiSelectionEnabled( false );
289 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
290 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
291 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
292 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
293 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
294 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
295 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
296 _open_filechooser_for_species_tree = new JFileChooser();
297 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
298 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
299 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
300 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
301 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
302 _save_filechooser = new JFileChooser();
303 _save_filechooser.setCurrentDirectory( new File( "." ) );
304 _save_filechooser.setMultiSelectionEnabled( false );
305 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
306 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
307 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
308 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
309 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
310 _writetopdf_filechooser = new JFileChooser();
311 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
312 _writetographics_filechooser = new JFileChooser();
313 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
315 _msa_filechooser = new JFileChooser();
316 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
317 _msa_filechooser.setCurrentDirectory( new File( "." ) );
318 _msa_filechooser.setMultiSelectionEnabled( false );
319 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
320 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
322 _seqs_filechooser = new JFileChooser();
323 _seqs_filechooser.setName( "Read Sequences File" );
324 _seqs_filechooser.setCurrentDirectory( new File( "." ) );
325 _seqs_filechooser.setMultiSelectionEnabled( false );
326 _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
327 _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
329 _values_filechooser = new JFileChooser();
330 _values_filechooser.setCurrentDirectory( new File( "." ) );
331 _values_filechooser.setMultiSelectionEnabled( false );
332 // build the menu bar
333 _jmenubar = new JMenuBar();
334 if ( !_configuration.isUseNativeUI() ) {
335 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
338 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
339 buildPhylogeneticInferenceMenu();
348 setJMenuBar( _jmenubar );
349 _jmenubar.add( _help_jmenu );
350 _contentpane = getContentPane();
351 _contentpane.setLayout( new BorderLayout() );
352 _contentpane.add( _mainpanel, BorderLayout.CENTER );
354 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
355 // addWindowFocusListener( new WindowAdapter() {
358 // public void windowGainedFocus( WindowEvent e ) {
359 // requestFocusInWindow();
362 // The window listener
363 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
364 addWindowListener( new WindowAdapter() {
367 public void windowClosing( final WindowEvent e ) {
368 if ( isUnsavedDataPresent() ) {
369 final int r = JOptionPane.showConfirmDialog( null,
370 "Exit despite potentially unsaved changes?",
372 JOptionPane.YES_NO_OPTION );
373 if ( r != JOptionPane.YES_OPTION ) {
378 final int r = JOptionPane.showConfirmDialog( null,
379 "Exit Archaeopteryx?",
381 JOptionPane.YES_NO_OPTION );
382 if ( r != JOptionPane.YES_OPTION ) {
389 // The component listener
390 addComponentListener( new ComponentAdapter() {
393 public void componentResized( final ComponentEvent e ) {
394 if ( _mainpanel.getCurrentTreePanel() != null ) {
395 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel()
397 _mainpanel.getCurrentTreePanel()
403 requestFocusInWindow();
404 // addKeyListener( this );
406 if ( ( phys != null ) && ( phys.length > 0 ) ) {
407 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
409 getMainPanel().getControlPanel().showWholeAll();
410 getMainPanel().getControlPanel().showWhole();
412 activateSaveAllIfNeeded();
413 // ...and its children
414 _contentpane.repaint();
418 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
419 // Reads the config file (false, false => not url, not applet):
420 this( phys, new Configuration( config_file, false, false, true ), title );
424 public void actionPerformed( final ActionEvent e ) {
426 super.actionPerformed( e );
427 final Object o = e.getSource();
428 // Handle app-specific actions here:
429 if ( o == _open_item ) {
430 readPhylogeniesFromFile();
432 else if ( o == _save_item ) {
433 writeToFile( _mainpanel.getCurrentPhylogeny() );
434 // If subtree currently displayed, save it, instead of complete
437 else if ( o == _new_item ) {
440 else if ( o == _save_all_item ) {
443 else if ( o == _close_item ) {
446 else if ( o == _write_to_pdf_item ) {
447 writeToPdf( _mainpanel.getCurrentPhylogeny() );
449 else if ( o == _write_to_jpg_item ) {
450 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
452 else if ( o == _write_to_png_item ) {
453 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
455 else if ( o == _write_to_gif_item ) {
456 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
458 else if ( o == _write_to_tif_item ) {
459 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
461 else if ( o == _write_to_bmp_item ) {
462 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
464 else if ( o == _print_item ) {
467 else if ( o == _load_species_tree_item ) {
468 readSpeciesTreeFromFile();
470 else if ( o == _lineage_inference ) {
471 if ( isSubtreeDisplayed() ) {
472 JOptionPane.showMessageDialog( this,
474 "Cannot infer ancestral taxonomies",
475 JOptionPane.ERROR_MESSAGE );
478 executeLineageInference();
480 else if ( o == _function_analysis ) {
481 executeFunctionAnalysis();
483 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
484 if ( isSubtreeDisplayed() ) {
487 obtainDetailedTaxonomicInformation();
489 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
490 if ( isSubtreeDisplayed() ) {
493 obtainDetailedTaxonomicInformationDelete();
495 else if ( o == _obtain_seq_information_jmi ) {
496 obtainSequenceInformation();
498 else if ( o == _read_values_jmi ) {
499 if ( isSubtreeDisplayed() ) {
502 addExpressionValuesFromFile();
504 else if ( o == _move_node_names_to_tax_sn_jmi ) {
505 moveNodeNamesToTaxSn();
507 else if ( o == _move_node_names_to_seq_names_jmi ) {
508 moveNodeNamesToSeqNames();
510 else if ( o == _extract_tax_code_from_node_names_jmi ) {
511 extractTaxCodeFromNodeNames();
513 else if ( o == _gsdi_item ) {
514 if ( isSubtreeDisplayed() ) {
519 else if ( o == _gsdir_item ) {
520 if ( isSubtreeDisplayed() ) {
525 else if ( o == _root_min_dups_item ) {
526 if ( isSubtreeDisplayed() ) {
529 executeSDIR( false );
531 else if ( o == _root_min_cost_l_item ) {
532 if ( isSubtreeDisplayed() ) {
537 else if ( o == _graphics_export_visible_only_cbmi ) {
538 updateOptions( getOptions() );
540 else if ( o == _antialias_print_cbmi ) {
541 updateOptions( getOptions() );
543 else if ( o == _print_black_and_white_cbmi ) {
544 updateOptions( getOptions() );
546 else if ( o == _print_using_actual_size_cbmi ) {
547 updateOptions( getOptions() );
549 else if ( o == _graphics_export_using_actual_size_cbmi ) {
550 updateOptions( getOptions() );
552 else if ( o == _print_size_mi ) {
555 else if ( o == _choose_pdf_width_mi ) {
558 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
559 updateOptions( getOptions() );
561 else if ( o == _replace_underscores_cbmi ) {
562 if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
563 _extract_taxonomy_no_rbmi.setSelected( true );
565 updateOptions( getOptions() );
567 else if ( o == _collapse_below_threshold ) {
568 if ( isSubtreeDisplayed() ) {
571 collapseBelowThreshold();
573 else if ( ( o == _extract_taxonomy_pfam_rbmi ) || ( o == _extract_taxonomy_yes_rbmi ) ) {
574 if ( _replace_underscores_cbmi != null ) {
575 _replace_underscores_cbmi.setSelected( false );
577 updateOptions( getOptions() );
579 else if ( o == _inference_from_msa_item ) {
580 executePhyleneticInference( false );
582 else if ( o == _inference_from_seqs_item ) {
583 executePhyleneticInference( true );
585 _contentpane.repaint();
587 catch ( final Exception ex ) {
588 AptxUtil.unexpectedException( ex );
590 catch ( final Error err ) {
591 AptxUtil.unexpectedError( err );
596 _mainpanel.terminate();
597 _contentpane.removeAll();
603 public MainPanel getMainPanel() {
607 public Msa getMsa() {
611 public File getMsaFile() {
615 public List<Sequence> getSeqs() {
619 public File getSeqsFile() {
623 public void readMsaFromFile() {
624 // Set an initial directory if none set yet
625 final File my_dir = getCurrentDir();
626 _msa_filechooser.setMultiSelectionEnabled( false );
627 // Open file-open dialog and set current directory
628 if ( my_dir != null ) {
629 _msa_filechooser.setCurrentDirectory( my_dir );
631 final int result = _msa_filechooser.showOpenDialog( _contentpane );
632 // All done: get the msa
633 final File file = _msa_filechooser.getSelectedFile();
634 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
635 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
640 final InputStream is = new FileInputStream( file );
641 if ( FastaParser.isLikelyFasta( file ) ) {
642 msa = FastaParser.parseMsa( is );
645 msa = GeneralMsaParser.parse( is );
648 catch ( final MsaFormatException e ) {
650 _mainpanel.getCurrentTreePanel().setArrowCursor();
652 catch ( final Exception ex ) {
655 JOptionPane.showMessageDialog( this,
656 e.getLocalizedMessage(),
657 "Multiple sequence alignment format error",
658 JOptionPane.ERROR_MESSAGE );
661 catch ( final IOException e ) {
663 _mainpanel.getCurrentTreePanel().setArrowCursor();
665 catch ( final Exception ex ) {
668 JOptionPane.showMessageDialog( this,
669 e.getLocalizedMessage(),
670 "Failed to read multiple sequence alignment",
671 JOptionPane.ERROR_MESSAGE );
674 catch ( final IllegalArgumentException e ) {
676 _mainpanel.getCurrentTreePanel().setArrowCursor();
678 catch ( final Exception ex ) {
681 JOptionPane.showMessageDialog( this,
682 e.getLocalizedMessage(),
683 "Unexpected error during reading of multiple sequence alignment",
684 JOptionPane.ERROR_MESSAGE );
687 catch ( final Exception e ) {
689 _mainpanel.getCurrentTreePanel().setArrowCursor();
691 catch ( final Exception ex ) {
695 JOptionPane.showMessageDialog( this,
696 e.getLocalizedMessage(),
697 "Unexpected error during reading of multiple sequence alignment",
698 JOptionPane.ERROR_MESSAGE );
701 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
702 JOptionPane.showMessageDialog( this,
703 "Multiple sequence alignment is empty",
704 "Illegal Multiple Sequence Alignment",
705 JOptionPane.ERROR_MESSAGE );
708 if ( msa.getNumberOfSequences() < 4 ) {
709 JOptionPane.showMessageDialog( this,
710 "Multiple sequence alignment needs to contain at least 3 sequences",
711 "Illegal multiple sequence alignment",
712 JOptionPane.ERROR_MESSAGE );
715 if ( msa.getLength() < 2 ) {
716 JOptionPane.showMessageDialog( this,
717 "Multiple sequence alignment needs to contain at least 2 residues",
718 "Illegal multiple sequence alignment",
719 JOptionPane.ERROR_MESSAGE );
723 setMsaFile( _msa_filechooser.getSelectedFile() );
728 public void readSeqsFromFile() {
729 // Set an initial directory if none set yet
730 final File my_dir = getCurrentDir();
731 _seqs_filechooser.setMultiSelectionEnabled( false );
732 // Open file-open dialog and set current directory
733 if ( my_dir != null ) {
734 _seqs_filechooser.setCurrentDirectory( my_dir );
736 final int result = _seqs_filechooser.showOpenDialog( _contentpane );
737 // All done: get the seqs
738 final File file = _seqs_filechooser.getSelectedFile();
739 setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
740 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
743 List<Sequence> seqs = null;
745 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
746 seqs = FastaParser.parse( new FileInputStream( file ) );
747 for( final Sequence seq : seqs ) {
748 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
755 catch ( final MsaFormatException e ) {
757 _mainpanel.getCurrentTreePanel().setArrowCursor();
759 catch ( final Exception ex ) {
762 JOptionPane.showMessageDialog( this,
763 e.getLocalizedMessage(),
764 "Multiple sequence file format error",
765 JOptionPane.ERROR_MESSAGE );
768 catch ( final IOException e ) {
770 _mainpanel.getCurrentTreePanel().setArrowCursor();
772 catch ( final Exception ex ) {
775 JOptionPane.showMessageDialog( this,
776 e.getLocalizedMessage(),
777 "Failed to read multiple sequence file",
778 JOptionPane.ERROR_MESSAGE );
781 catch ( final IllegalArgumentException e ) {
783 _mainpanel.getCurrentTreePanel().setArrowCursor();
785 catch ( final Exception ex ) {
788 JOptionPane.showMessageDialog( this,
789 e.getLocalizedMessage(),
790 "Unexpected error during reading of multiple sequence file",
791 JOptionPane.ERROR_MESSAGE );
794 catch ( final Exception e ) {
796 _mainpanel.getCurrentTreePanel().setArrowCursor();
798 catch ( final Exception ex ) {
802 JOptionPane.showMessageDialog( this,
803 e.getLocalizedMessage(),
804 "Unexpected error during reading of multiple sequence file",
805 JOptionPane.ERROR_MESSAGE );
808 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
809 JOptionPane.showMessageDialog( this,
810 "Multiple sequence file is empty",
811 "Illegal multiple sequence file",
812 JOptionPane.ERROR_MESSAGE );
815 if ( seqs.size() < 4 ) {
816 JOptionPane.showMessageDialog( this,
817 "Multiple sequence file needs to contain at least 3 sequences",
818 "Illegal multiple sequence file",
819 JOptionPane.ERROR_MESSAGE );
822 // if ( msa.getLength() < 2 ) {
823 // JOptionPane.showMessageDialog( this,
824 // "Multiple sequence alignment needs to contain at least 2 residues",
825 // "Illegal multiple sequence file",
826 // JOptionPane.ERROR_MESSAGE );
830 setSeqsFile( _seqs_filechooser.getSelectedFile() );
835 void buildAnalysisMenu() {
836 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
837 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
838 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (re-rooting)" ) );
839 _analysis_menu.addSeparator();
840 _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
841 _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
842 _analysis_menu.addSeparator();
843 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
844 customizeJMenuItem( _gsdi_item );
845 customizeJMenuItem( _gsdir_item );
846 customizeJMenuItem( _root_min_dups_item );
847 customizeJMenuItem( _root_min_cost_l_item );
848 customizeJMenuItem( _load_species_tree_item );
849 _analysis_menu.addSeparator();
850 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
851 customizeJMenuItem( _lineage_inference );
852 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
853 _jmenubar.add( _analysis_menu );
857 void buildFileMenu() {
858 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
859 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
860 _file_jmenu.addSeparator();
861 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
862 _file_jmenu.addSeparator();
863 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
864 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
865 .getAvailablePhylogeniesWebserviceClients().size() ];
866 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
867 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
868 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
869 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
871 if ( getConfiguration().isEditable() ) {
872 _file_jmenu.addSeparator();
873 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
874 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
876 _file_jmenu.addSeparator();
877 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
878 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
879 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
880 _save_all_item.setEnabled( false );
881 _file_jmenu.addSeparator();
882 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
883 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
884 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
886 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
887 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
888 if ( AptxUtil.canWriteFormat( "gif" ) ) {
889 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
891 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
892 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
894 _file_jmenu.addSeparator();
895 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
896 _file_jmenu.addSeparator();
897 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
898 _close_item.setToolTipText( "To close the current pane." );
899 _close_item.setEnabled( true );
900 _file_jmenu.addSeparator();
901 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
902 // For print in color option item
903 customizeJMenuItem( _open_item );
905 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
906 customizeJMenuItem( _open_url_item );
907 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
908 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
910 customizeJMenuItem( _save_item );
911 if ( getConfiguration().isEditable() ) {
912 customizeJMenuItem( _new_item );
914 customizeJMenuItem( _close_item );
915 customizeJMenuItem( _save_all_item );
916 customizeJMenuItem( _write_to_pdf_item );
917 customizeJMenuItem( _write_to_png_item );
918 customizeJMenuItem( _write_to_jpg_item );
919 customizeJMenuItem( _write_to_gif_item );
920 customizeJMenuItem( _write_to_tif_item );
921 customizeJMenuItem( _write_to_bmp_item );
922 customizeJMenuItem( _print_item );
923 customizeJMenuItem( _exit_item );
924 _jmenubar.add( _file_jmenu );
927 void buildOptionsMenu() {
928 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
929 _options_jmenu.addChangeListener( new ChangeListener() {
932 public void stateChanged( final ChangeEvent e ) {
933 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
934 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
936 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
937 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
938 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
939 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
940 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
941 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
943 _show_branch_length_values_cbmi,
944 _non_lined_up_cladograms_rbmi,
945 _uniform_cladograms_rbmi,
946 _ext_node_dependent_cladogram_rbmi,
947 _label_direction_cbmi );
948 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
949 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
950 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
953 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
955 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
956 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
957 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
958 _radio_group_1 = new ButtonGroup();
959 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
960 _radio_group_1.add( _uniform_cladograms_rbmi );
961 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
962 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
963 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
965 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
966 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
967 _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
969 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
970 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
971 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
972 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
973 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
974 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
975 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
976 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
977 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
978 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
979 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
980 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
981 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
983 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
984 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
985 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
986 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
987 _options_jmenu.addSeparator();
988 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
989 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
990 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
991 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
992 _options_jmenu.addSeparator();
993 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
994 getConfiguration() ) );
995 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
996 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
998 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
1000 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
1002 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
1003 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
1004 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
1005 _options_jmenu.addSeparator();
1006 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
1008 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
1009 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
1011 _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
1013 .add( _extract_taxonomy_pfam_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Pfam-style Node Names" ) );
1014 _extract_taxonomy_pfam_rbmi
1015 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE/134-298\"" );
1017 .add( _extract_taxonomy_yes_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Node Names" ) );
1018 _extract_taxonomy_yes_rbmi
1019 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE\" or \"BCL2_MOUSE B-cell lymphoma 2...\"" );
1020 _radio_group_2 = new ButtonGroup();
1021 _radio_group_2.add( _extract_taxonomy_no_rbmi );
1022 _radio_group_2.add( _extract_taxonomy_pfam_rbmi );
1023 _radio_group_2.add( _extract_taxonomy_yes_rbmi );
1025 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
1027 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
1028 _use_brackets_for_conf_in_nh_export_cbmi
1029 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
1031 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
1032 customizeJMenuItem( _choose_font_mi );
1033 customizeJMenuItem( _choose_minimal_confidence_mi );
1034 customizeJMenuItem( _switch_colors_mi );
1035 customizeJMenuItem( _print_size_mi );
1036 customizeJMenuItem( _choose_pdf_width_mi );
1037 customizeJMenuItem( _overview_placment_mi );
1038 customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
1039 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
1040 customizeJMenuItem( _cycle_node_shape_mi );
1041 customizeJMenuItem( _cycle_node_fill_mi );
1042 customizeJMenuItem( _choose_node_size_mi );
1043 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
1044 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
1045 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
1046 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
1047 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
1048 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
1049 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
1050 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
1051 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
1052 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
1053 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1054 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
1055 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1056 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
1057 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
1058 customizeCheckBoxMenuItem( _label_direction_cbmi,
1059 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
1060 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
1061 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
1062 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
1063 .isInternalNumberAreConfidenceForNhParsing() );
1064 customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
1065 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
1066 customizeRadioButtonMenuItem( _extract_taxonomy_yes_rbmi,
1067 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.YES );
1068 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_rbmi,
1069 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
1070 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
1071 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1072 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1073 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
1074 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
1075 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
1076 .isGraphicsExportUsingActualSize() );
1077 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1078 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
1079 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1080 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
1081 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1082 _jmenubar.add( _options_jmenu );
1085 void buildPhylogeneticInferenceMenu() {
1086 final InferenceManager im = getInferenceManager();
1087 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
1088 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
1089 customizeJMenuItem( _inference_from_msa_item );
1090 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
1091 if ( im.canDoMsa() ) {
1092 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
1093 customizeJMenuItem( _inference_from_seqs_item );
1094 _inference_from_seqs_item
1095 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
1099 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
1100 customizeJMenuItem( _inference_from_seqs_item );
1101 _inference_from_seqs_item.setEnabled( false );
1103 _jmenubar.add( _inference_menu );
1106 void buildToolsMenu() {
1107 _tools_menu = createMenu( "Tools", getConfiguration() );
1108 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1109 customizeJMenuItem( _confcolor_item );
1110 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
1111 customizeJMenuItem( _color_rank_jmi );
1112 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
1113 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1114 customizeJMenuItem( _taxcolor_item );
1115 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
1116 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
1117 customizeJMenuItem( _remove_branch_color_item );
1118 _tools_menu.addSeparator();
1119 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
1120 customizeJMenuItem( _annotate_item );
1121 _tools_menu.addSeparator();
1122 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1123 customizeJMenuItem( _midpoint_root_item );
1124 _tools_menu.addSeparator();
1125 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1126 customizeJMenuItem( _collapse_species_specific_subtrees );
1128 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
1129 customizeJMenuItem( _collapse_below_threshold );
1130 _collapse_below_threshold
1131 .setToolTipText( "To collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );
1132 _tools_menu.addSeparator();
1134 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
1135 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
1136 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
1137 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
1138 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
1139 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
1141 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
1142 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
1143 _extract_tax_code_from_node_names_jmi
1144 .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
1145 _tools_menu.addSeparator();
1147 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
1148 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
1149 _obtain_detailed_taxonomic_information_jmi
1150 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
1152 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
1153 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
1154 _obtain_detailed_taxonomic_information_deleting_jmi
1155 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
1156 _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
1157 customizeJMenuItem( _obtain_seq_information_jmi );
1158 _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
1159 _tools_menu.addSeparator();
1160 if ( !Constants.__RELEASE ) {
1161 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
1162 customizeJMenuItem( _function_analysis );
1164 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
1165 _tools_menu.addSeparator();
1167 _tools_menu.add( _read_values_jmi = new JMenuItem( "Read Vector/Expression Values" ) );
1168 customizeJMenuItem( _read_values_jmi );
1169 _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
1170 _jmenubar.add( _tools_menu );
1175 if ( isUnsavedDataPresent() ) {
1176 final int r = JOptionPane.showConfirmDialog( this,
1177 "Exit despite potentially unsaved changes?",
1179 JOptionPane.YES_NO_OPTION );
1180 if ( r != JOptionPane.YES_OPTION ) {
1187 void executeFunctionAnalysis() {
1188 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1191 final GoAnnotation a = new GoAnnotation( this,
1192 _mainpanel.getCurrentTreePanel(),
1193 _mainpanel.getCurrentPhylogeny() );
1194 new Thread( a ).start();
1197 void executeGSDI() {
1198 if ( !isOKforSDI( false, true ) ) {
1201 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1202 JOptionPane.showMessageDialog( this,
1203 "Gene tree is not rooted.",
1204 "Cannot execute GSDI",
1205 JOptionPane.ERROR_MESSAGE );
1208 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1209 gene_tree.setAllNodesToNotCollapse();
1210 gene_tree.recalculateNumberOfExternalDescendants( false );
1212 final Phylogeny species_tree = _species_tree.copy();
1214 gsdi = new GSDI( gene_tree, species_tree, false, true, true );
1216 catch ( final SDIException e ) {
1217 JOptionPane.showMessageDialog( this,
1218 e.getLocalizedMessage(),
1219 "Error during GSDI",
1220 JOptionPane.ERROR_MESSAGE );
1223 catch ( final Exception e ) {
1224 AptxUtil.unexpectedException( e );
1227 gene_tree.setRerootable( false );
1228 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1229 _mainpanel.getCurrentPhylogeny().clearHashIdToNodeMap();
1230 _mainpanel.getCurrentPhylogeny().recalculateNumberOfExternalDescendants( true );
1231 _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1232 _mainpanel.getCurrentTreePanel().setEdited( true );
1233 getControlPanel().setShowEvents( true );
1235 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1236 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1238 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1240 _mainpanel.getCurrentTreePanel().setEdited( true );
1241 JOptionPane.showMessageDialog( this, "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1242 + "Potential duplications: " + gsdi.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
1243 + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
1246 void executeGSDIR() {
1247 if ( !isOKforSDI( false, true ) ) {
1250 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1251 gene_tree.setAllNodesToNotCollapse();
1252 gene_tree.recalculateNumberOfExternalDescendants( false );
1254 final Phylogeny species_tree = _species_tree.copy();
1256 gsdir = new GSDIR( gene_tree, species_tree, true, true );
1258 catch ( final SDIException e ) {
1259 JOptionPane.showMessageDialog( this,
1260 e.getLocalizedMessage(),
1261 "Error during GSDIR",
1262 JOptionPane.ERROR_MESSAGE );
1265 catch ( final Exception e ) {
1266 AptxUtil.unexpectedException( e );
1269 final List<Phylogeny> assigned_trees = gsdir.getMinDuplicationsSumGeneTrees();
1270 final List<Integer> shortests = GSDIR.getIndexesOfShortestTree( assigned_trees );
1271 final Phylogeny result_gene_tree = assigned_trees.get( shortests.get( 0 ) );
1272 result_gene_tree.setRerootable( false );
1273 result_gene_tree.clearHashIdToNodeMap();
1274 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1275 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1276 getControlPanel().setShowEvents( true );
1278 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1279 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1281 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1283 _mainpanel.getCurrentTreePanel().setEdited( true );
1284 JOptionPane.showMessageDialog( this,
1285 "Duplications (min): " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: "
1286 + gsdir.getSpeciationsSum() + "\n"
1287 + "Number of root positions minimizing duplications sum: "
1288 + gsdir.getMinDuplicationsSumGeneTrees().size() + "\n"
1289 + "Number of shortest trees: " + shortests.size(),
1290 "GSDIR successfully completed",
1291 JOptionPane.INFORMATION_MESSAGE );
1294 void executeLineageInference() {
1295 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1298 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1299 JOptionPane.showMessageDialog( this,
1300 "Phylogeny is not rooted.",
1301 "Cannot infer ancestral taxonomies",
1302 JOptionPane.ERROR_MESSAGE );
1305 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1306 _mainpanel.getCurrentTreePanel(),
1307 _mainpanel.getCurrentPhylogeny()
1309 new Thread( inferrer ).start();
1312 void executeSDIR( final boolean minimize_cost ) {
1313 if ( !isOKforSDI( true, true ) ) {
1316 Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1317 final SDIR sdiunrooted = new SDIR();
1318 gene_tree.setAllNodesToNotCollapse();
1319 gene_tree.recalculateNumberOfExternalDescendants( false );
1321 gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
1322 !minimize_cost, // minimize sum of dups
1323 true, // minimize height
1324 true, // return tree(s)
1325 1 )[ 0 ]; // # of trees to return
1327 catch ( final Exception e ) {
1328 JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
1331 final int duplications = sdiunrooted.getMinimalDuplications();
1332 gene_tree.setRerootable( false );
1333 _mainpanel.getCurrentTreePanel().setTree( gene_tree );
1334 getControlPanel().setShowEvents( true );
1336 _mainpanel.getCurrentTreePanel().setEdited( true );
1337 JOptionPane.showMessageDialog( this,
1338 "Number of duplications: " + duplications,
1339 "SDIR successfully completed",
1340 JOptionPane.INFORMATION_MESSAGE );
1344 removeAllTextFrames();
1345 _mainpanel.terminate();
1346 _contentpane.removeAll();
1347 setVisible( false );
1352 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1353 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1356 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1357 JOptionPane.showMessageDialog( this,
1358 "No species tree loaded",
1359 "Cannot execute SDI",
1360 JOptionPane.ERROR_MESSAGE );
1363 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1364 JOptionPane.showMessageDialog( this,
1365 "Species tree is not completely binary",
1366 "Cannot execute SDI",
1367 JOptionPane.ERROR_MESSAGE );
1370 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1371 JOptionPane.showMessageDialog( this,
1372 "Gene tree is not completely binary",
1373 "Cannot execute SDI",
1374 JOptionPane.ERROR_MESSAGE );
1383 void readPhylogeniesFromURL() {
1385 Phylogeny[] phys = null;
1386 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1387 final String url_string = JOptionPane.showInputDialog( this,
1389 "Use URL/webservice to obtain a phylogeny",
1390 JOptionPane.QUESTION_MESSAGE );
1391 boolean nhx_or_nexus = false;
1392 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1394 url = new URL( url_string );
1395 PhylogenyParser parser = null;
1396 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1397 parser = new TolParser();
1400 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
1401 .isValidatePhyloXmlAgainstSchema() );
1403 if ( parser instanceof NexusPhylogeniesParser ) {
1404 nhx_or_nexus = true;
1406 else if ( parser instanceof NHXParser ) {
1407 nhx_or_nexus = true;
1409 if ( _mainpanel.getCurrentTreePanel() != null ) {
1410 _mainpanel.getCurrentTreePanel().setWaitCursor();
1413 _mainpanel.setWaitCursor();
1415 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1416 phys = factory.create( url.openStream(), parser );
1418 catch ( final MalformedURLException e ) {
1419 JOptionPane.showMessageDialog( this,
1420 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1422 JOptionPane.ERROR_MESSAGE );
1424 catch ( final IOException e ) {
1425 JOptionPane.showMessageDialog( this,
1426 "Could not read from " + url + "\n"
1427 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1428 "Failed to read URL",
1429 JOptionPane.ERROR_MESSAGE );
1431 catch ( final Exception e ) {
1432 JOptionPane.showMessageDialog( this,
1433 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1434 "Unexpected Exception",
1435 JOptionPane.ERROR_MESSAGE );
1438 if ( _mainpanel.getCurrentTreePanel() != null ) {
1439 _mainpanel.getCurrentTreePanel().setArrowCursor();
1442 _mainpanel.setArrowCursor();
1445 if ( ( phys != null ) && ( phys.length > 0 ) ) {
1446 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1447 for( final Phylogeny phy : phys ) {
1448 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
1451 AptxUtil.addPhylogeniesToTabs( phys,
1452 new File( url.getFile() ).getName(),
1453 new File( url.getFile() ).toString(),
1456 _mainpanel.getControlPanel().showWhole();
1459 activateSaveAllIfNeeded();
1463 void setMsa( final Msa msa ) {
1467 void setMsaFile( final File msa_file ) {
1468 _msa_file = msa_file;
1471 void setSeqs( final List<Sequence> seqs ) {
1475 void setSeqsFile( final File seqs_file ) {
1476 _seqs_file = seqs_file;
1479 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
1480 _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
1481 _mainpanel.getCurrentTreePanel().getHeight(),
1483 String file_written_to = "";
1484 boolean error = false;
1486 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
1487 _mainpanel.getCurrentTreePanel().getWidth(),
1488 _mainpanel.getCurrentTreePanel().getHeight(),
1489 _mainpanel.getCurrentTreePanel(),
1490 _mainpanel.getControlPanel(),
1494 catch ( final IOException e ) {
1496 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1499 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
1500 JOptionPane.showMessageDialog( this,
1501 "Wrote image to: " + file_written_to,
1503 JOptionPane.INFORMATION_MESSAGE );
1506 JOptionPane.showMessageDialog( this,
1507 "There was an unknown problem when attempting to write to an image file: \""
1510 JOptionPane.ERROR_MESSAGE );
1513 _contentpane.repaint();
1516 private void addExpressionValuesFromFile() {
1517 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1518 JOptionPane.showMessageDialog( this,
1519 "Need to load evolutionary tree first",
1520 "Can Not Read Expression Values",
1521 JOptionPane.WARNING_MESSAGE );
1524 final File my_dir = getCurrentDir();
1525 if ( my_dir != null ) {
1526 _values_filechooser.setCurrentDirectory( my_dir );
1528 final int result = _values_filechooser.showOpenDialog( _contentpane );
1529 final File file = _values_filechooser.getSelectedFile();
1530 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1531 BasicTable<String> t = null;
1533 t = BasicTableParser.parse( file, "\t" );
1534 if ( t.getNumberOfColumns() < 2 ) {
1535 t = BasicTableParser.parse( file, "," );
1537 if ( t.getNumberOfColumns() < 2 ) {
1538 t = BasicTableParser.parse( file, " " );
1541 catch ( final IOException e ) {
1542 JOptionPane.showMessageDialog( this,
1544 "Could Not Read Expression Value Table",
1545 JOptionPane.ERROR_MESSAGE );
1548 if ( t.getNumberOfColumns() < 2 ) {
1549 JOptionPane.showMessageDialog( this,
1550 "Table contains " + t.getNumberOfColumns() + " column(s)",
1551 "Problem with Expression Value Table",
1552 JOptionPane.ERROR_MESSAGE );
1555 if ( t.getNumberOfRows() < 1 ) {
1556 JOptionPane.showMessageDialog( this,
1557 "Table contains zero rows",
1558 "Problem with Expression Value Table",
1559 JOptionPane.ERROR_MESSAGE );
1562 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1563 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1564 JOptionPane.showMessageDialog( this,
1565 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1566 + phy.getNumberOfExternalNodes() + " external nodes",
1568 JOptionPane.WARNING_MESSAGE );
1570 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1572 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1573 final PhylogenyNode node = iter.next();
1574 final String node_name = node.getName();
1575 if ( !ForesterUtil.isEmpty( node_name ) ) {
1578 row = t.findRow( node_name );
1580 catch ( final IllegalArgumentException e ) {
1582 .showMessageDialog( this,
1584 "Error Mapping Node Identifiers to Expression Value Identifiers",
1585 JOptionPane.ERROR_MESSAGE );
1589 if ( node.isExternal() ) {
1594 final List<Double> l = new ArrayList<Double>();
1595 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1598 d = Double.parseDouble( t.getValueAsString( col, row ) );
1600 catch ( final NumberFormatException e ) {
1601 JOptionPane.showMessageDialog( this,
1602 "Could not parse \"" + t.getValueAsString( col, row )
1603 + "\" into a decimal value",
1604 "Issue with Expression Value Table",
1605 JOptionPane.ERROR_MESSAGE );
1608 stats.addValue( d );
1611 if ( !l.isEmpty() ) {
1612 if ( node.getNodeData().getProperties() != null ) {
1613 node.getNodeData().getProperties()
1614 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1616 node.getNodeData().setVector( l );
1620 if ( not_found > 0 ) {
1621 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1622 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1624 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1628 private void choosePdfWidth() {
1629 final String s = ( String ) JOptionPane.showInputDialog( this,
1630 "Please enter the default line width for PDF export.\n"
1631 + "[current value: "
1632 + getOptions().getPrintLineWidth() + "]\n",
1633 "Line Width for PDF Export",
1634 JOptionPane.QUESTION_MESSAGE,
1637 getOptions().getPrintLineWidth() );
1638 if ( !ForesterUtil.isEmpty( s ) ) {
1639 boolean success = true;
1641 final String m_str = s.trim();
1642 if ( !ForesterUtil.isEmpty( m_str ) ) {
1644 f = Float.parseFloat( m_str );
1646 catch ( final Exception ex ) {
1653 if ( success && ( f > 0.0 ) ) {
1654 getOptions().setPrintLineWidth( f );
1659 private void choosePrintSize() {
1660 final String s = ( String ) JOptionPane.showInputDialog( this,
1661 "Please enter values for width and height,\nseparated by a comma.\n"
1662 + "[current values: "
1663 + getOptions().getPrintSizeX() + ", "
1664 + getOptions().getPrintSizeY() + "]\n"
1665 + "[A4: " + Constants.A4_SIZE_X + ", "
1666 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
1667 + Constants.US_LETTER_SIZE_X + ", "
1668 + Constants.US_LETTER_SIZE_Y + "]",
1669 "Default Size for Graphics Export",
1670 JOptionPane.QUESTION_MESSAGE,
1673 getOptions().getPrintSizeX() + ", "
1674 + getOptions().getPrintSizeY() );
1675 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
1676 boolean success = true;
1679 final String[] str_ary = s.split( "," );
1680 if ( str_ary.length == 2 ) {
1681 final String x_str = str_ary[ 0 ].trim();
1682 final String y_str = str_ary[ 1 ].trim();
1683 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
1685 x = Integer.parseInt( x_str );
1686 y = Integer.parseInt( y_str );
1688 catch ( final Exception ex ) {
1699 if ( success && ( x > 1 ) && ( y > 1 ) ) {
1700 getOptions().setPrintSizeX( x );
1701 getOptions().setPrintSizeY( y );
1706 private void closeCurrentPane() {
1707 if ( getMainPanel().getCurrentTreePanel() != null ) {
1708 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1709 final int r = JOptionPane.showConfirmDialog( this,
1710 "Close tab despite potentially unsaved changes?",
1712 JOptionPane.YES_NO_OPTION );
1713 if ( r != JOptionPane.YES_OPTION ) {
1717 getMainPanel().closeCurrentPane();
1718 activateSaveAllIfNeeded();
1722 private void collapse( final Phylogeny phy, final double m ) {
1723 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1724 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1725 double min_support = Double.MAX_VALUE;
1726 boolean conf_present = false;
1727 while ( it.hasNext() ) {
1728 final PhylogenyNode n = it.next();
1729 if ( !n.isExternal() && !n.isRoot() ) {
1730 final List<Confidence> c = n.getBranchData().getConfidences();
1731 if ( ( c != null ) && ( c.size() > 0 ) ) {
1732 conf_present = true;
1734 for( final Confidence confidence : c ) {
1735 if ( confidence.getValue() > max ) {
1736 max = confidence.getValue();
1739 if ( max < getMinNotCollapseConfidenceValue() ) {
1740 to_be_removed.add( n );
1742 if ( max < min_support ) {
1748 if ( conf_present ) {
1749 for( final PhylogenyNode node : to_be_removed ) {
1750 PhylogenyMethods.removeNode( node, phy );
1752 if ( to_be_removed.size() > 0 ) {
1753 phy.externalNodesHaveChanged();
1754 phy.clearHashIdToNodeMap();
1755 phy.recalculateNumberOfExternalDescendants( true );
1756 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1757 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1758 getCurrentTreePanel().calculateLongestExtNodeInfo();
1759 getCurrentTreePanel().setNodeInPreorderToNull();
1760 getCurrentTreePanel().recalculateMaxDistanceToRoot();
1761 getCurrentTreePanel().resetPreferredSize();
1762 getCurrentTreePanel().setEdited( true );
1763 getCurrentTreePanel().repaint();
1766 if ( to_be_removed.size() > 0 ) {
1767 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1768 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1769 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1772 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1773 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1777 JOptionPane.showMessageDialog( this,
1778 "No branch collapsed because no confidence values present",
1779 "No confidence values present",
1780 JOptionPane.INFORMATION_MESSAGE );
1784 private void collapseBelowThreshold() {
1785 if ( getCurrentTreePanel() != null ) {
1786 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1787 if ( ( phy != null ) && !phy.isEmpty() ) {
1788 final String s = ( String ) JOptionPane.showInputDialog( this,
1789 "Please enter the minimum confidence value\n",
1790 "Minimal Confidence Value",
1791 JOptionPane.QUESTION_MESSAGE,
1794 getMinNotCollapseConfidenceValue() );
1795 if ( !ForesterUtil.isEmpty( s ) ) {
1796 boolean success = true;
1798 final String m_str = s.trim();
1799 if ( !ForesterUtil.isEmpty( m_str ) ) {
1801 m = Double.parseDouble( m_str );
1803 catch ( final Exception ex ) {
1810 if ( success && ( m >= 0.0 ) ) {
1811 setMinNotCollapseConfidenceValue( m );
1819 private PhyloXmlParser createPhyloXmlParser() {
1820 PhyloXmlParser xml_parser = null;
1821 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1823 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1825 catch ( final Exception e ) {
1826 JOptionPane.showMessageDialog( this,
1827 e.getLocalizedMessage(),
1828 "failed to create validating XML parser",
1829 JOptionPane.WARNING_MESSAGE );
1832 if ( xml_parser == null ) {
1833 xml_parser = new PhyloXmlParser();
1838 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1839 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1840 getPhylogeneticInferenceOptions(),
1841 from_unaligned_seqs );
1843 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1844 if ( !from_unaligned_seqs ) {
1845 if ( getMsa() != null ) {
1846 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1847 getPhylogeneticInferenceOptions()
1849 new Thread( inferrer ).start();
1852 JOptionPane.showMessageDialog( this,
1853 "No multiple sequence alignment selected",
1854 "Phylogenetic Inference Not Launched",
1855 JOptionPane.WARNING_MESSAGE );
1859 if ( getSeqs() != null ) {
1860 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1861 getPhylogeneticInferenceOptions()
1863 new Thread( inferrer ).start();
1866 JOptionPane.showMessageDialog( this,
1867 "No input sequences selected",
1868 "Phylogenetic Inference Not Launched",
1869 JOptionPane.WARNING_MESSAGE );
1875 private void extractTaxCodeFromNodeNames() throws PhyloXmlDataFormatException {
1876 if ( getCurrentTreePanel() != null ) {
1877 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1878 if ( ( phy != null ) && !phy.isEmpty() ) {
1879 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1880 while ( it.hasNext() ) {
1881 final PhylogenyNode n = it.next();
1882 final String name = n.getName().trim();
1883 if ( !ForesterUtil.isEmpty( name ) ) {
1884 final String code = ParserUtils
1885 .extractTaxonomyCodeFromNodeName( name, NHXParser.TAXONOMY_EXTRACTION.YES );
1886 if ( !ForesterUtil.isEmpty( code ) ) {
1887 PhylogenyMethods.setTaxonomyCode( n, code );
1895 private ControlPanel getControlPanel() {
1896 return getMainPanel().getControlPanel();
1899 private File getCurrentDir() {
1900 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1901 if ( ForesterUtil.isWindowns() ) {
1903 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1905 catch ( final Exception e ) {
1906 _current_dir = null;
1910 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1911 if ( System.getProperty( "user.home" ) != null ) {
1912 _current_dir = new File( System.getProperty( "user.home" ) );
1914 else if ( System.getProperty( "user.dir" ) != null ) {
1915 _current_dir = new File( System.getProperty( "user.dir" ) );
1918 return _current_dir;
1921 private double getMinNotCollapseConfidenceValue() {
1922 return _min_not_collapse;
1925 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
1926 if ( _phylogenetic_inference_options == null ) {
1927 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
1929 return _phylogenetic_inference_options;
1932 private boolean isUnsavedDataPresent() {
1933 final List<TreePanel> tps = getMainPanel().getTreePanels();
1934 for( final TreePanel tp : tps ) {
1935 if ( tp.isEdited() ) {
1942 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
1943 if ( getCurrentTreePanel() != null ) {
1944 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1945 if ( ( phy != null ) && !phy.isEmpty() ) {
1947 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
1952 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
1953 if ( getCurrentTreePanel() != null ) {
1954 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1955 if ( ( phy != null ) && !phy.isEmpty() ) {
1956 PhylogenyMethods.transferNodeNameToField( phy,
1957 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
1963 private void newTree() {
1964 final Phylogeny[] phys = new Phylogeny[ 1 ];
1965 final Phylogeny phy = new Phylogeny();
1966 final PhylogenyNode node = new PhylogenyNode();
1967 phy.setRoot( node );
1968 phy.setRooted( true );
1970 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1971 _mainpanel.getControlPanel().showWhole();
1972 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1973 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1974 if ( getMainPanel().getMainFrame() == null ) {
1975 // Must be "E" applet version.
1976 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1977 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1980 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1982 activateSaveAllIfNeeded();
1986 private void obtainDetailedTaxonomicInformation() {
1987 if ( getCurrentTreePanel() != null ) {
1988 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1989 if ( ( phy != null ) && !phy.isEmpty() ) {
1990 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1991 _mainpanel.getCurrentTreePanel(),
1995 new Thread( t ).start();
2000 private void obtainDetailedTaxonomicInformationDelete() {
2001 if ( getCurrentTreePanel() != null ) {
2002 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2003 if ( ( phy != null ) && !phy.isEmpty() ) {
2004 final TaxonomyDataManager t = new TaxonomyDataManager( this,
2005 _mainpanel.getCurrentTreePanel(),
2009 new Thread( t ).start();
2014 private void obtainSequenceInformation() {
2015 if ( getCurrentTreePanel() != null ) {
2016 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2017 if ( ( phy != null ) && !phy.isEmpty() ) {
2018 final SequenceDataRetriver u = new SequenceDataRetriver( this,
2019 _mainpanel.getCurrentTreePanel(),
2021 new Thread( u ).start();
2026 private void print() {
2027 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
2028 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
2031 if ( !getOptions().isPrintUsingActualSize() ) {
2032 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX() - 80,
2033 getOptions().getPrintSizeY() - 140,
2035 getCurrentTreePanel().resetPreferredSize();
2036 getCurrentTreePanel().repaint();
2038 final String job_name = Constants.PRG_NAME;
2039 boolean error = false;
2040 String printer_name = null;
2042 printer_name = Printer.print( getCurrentTreePanel(), job_name );
2044 catch ( final Exception e ) {
2046 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2048 if ( !error && ( printer_name != null ) ) {
2049 String msg = "Printing data sent to printer";
2050 if ( printer_name.length() > 1 ) {
2051 msg += " [" + printer_name + "]";
2053 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2055 if ( !getOptions().isPrintUsingActualSize() ) {
2056 getControlPanel().showWhole();
2060 private void printPhylogenyToPdf( final String file_name ) {
2061 if ( !getOptions().isPrintUsingActualSize() ) {
2062 getCurrentTreePanel().setParametersForPainting( getOptions().getPrintSizeX(),
2063 getOptions().getPrintSizeY(),
2065 getCurrentTreePanel().resetPreferredSize();
2066 getCurrentTreePanel().repaint();
2068 String pdf_written_to = "";
2069 boolean error = false;
2071 if ( getOptions().isPrintUsingActualSize() ) {
2072 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
2073 getCurrentTreePanel(),
2074 getCurrentTreePanel().getWidth(),
2075 getCurrentTreePanel().getHeight() );
2078 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
2079 .getPrintSizeX(), getOptions().getPrintSizeY() );
2082 catch ( final IOException e ) {
2084 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2087 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2088 JOptionPane.showMessageDialog( this,
2089 "Wrote PDF to: " + pdf_written_to,
2091 JOptionPane.INFORMATION_MESSAGE );
2094 JOptionPane.showMessageDialog( this,
2095 "There was an unknown problem when attempting to write to PDF file: \""
2098 JOptionPane.ERROR_MESSAGE );
2101 if ( !getOptions().isPrintUsingActualSize() ) {
2102 getControlPanel().showWhole();
2106 private void readPhylogeniesFromFile() {
2107 boolean exception = false;
2108 Phylogeny[] phys = null;
2109 // Set an initial directory if none set yet
2110 final File my_dir = getCurrentDir();
2111 _open_filechooser.setMultiSelectionEnabled( true );
2112 // Open file-open dialog and set current directory
2113 if ( my_dir != null ) {
2114 _open_filechooser.setCurrentDirectory( my_dir );
2116 final int result = _open_filechooser.showOpenDialog( _contentpane );
2117 // All done: get the file
2118 final File[] files = _open_filechooser.getSelectedFiles();
2119 setCurrentDir( _open_filechooser.getCurrentDirectory() );
2120 boolean nhx_or_nexus = false;
2121 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2122 for( final File file : files ) {
2123 if ( ( file != null ) && !file.isDirectory() ) {
2124 if ( _mainpanel.getCurrentTreePanel() != null ) {
2125 _mainpanel.getCurrentTreePanel().setWaitCursor();
2128 _mainpanel.setWaitCursor();
2130 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
2131 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
2133 final NHXParser nhx = new NHXParser();
2134 setSpecialOptionsForNhxParser( nhx );
2135 phys = PhylogenyMethods.readPhylogenies( nhx, file );
2136 nhx_or_nexus = true;
2138 catch ( final Exception e ) {
2140 exceptionOccuredDuringOpenFile( e );
2143 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2144 warnIfNotPhyloXmlValidation( getConfiguration() );
2146 final PhyloXmlParser xml_parser = createPhyloXmlParser();
2147 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
2149 catch ( final Exception e ) {
2151 exceptionOccuredDuringOpenFile( e );
2154 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
2156 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2158 catch ( final Exception e ) {
2160 exceptionOccuredDuringOpenFile( e );
2163 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2165 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
2166 setSpecialOptionsForNexParser( nex );
2167 phys = PhylogenyMethods.readPhylogenies( nex, file );
2168 nhx_or_nexus = true;
2170 catch ( final Exception e ) {
2172 exceptionOccuredDuringOpenFile( e );
2178 final PhylogenyParser parser = ParserUtils
2179 .createParserDependingOnFileType( file, getConfiguration()
2180 .isValidatePhyloXmlAgainstSchema() );
2181 if ( parser instanceof NexusPhylogeniesParser ) {
2182 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
2183 setSpecialOptionsForNexParser( nex );
2184 nhx_or_nexus = true;
2186 else if ( parser instanceof NHXParser ) {
2187 final NHXParser nhx = ( NHXParser ) parser;
2188 setSpecialOptionsForNhxParser( nhx );
2189 nhx_or_nexus = true;
2191 else if ( parser instanceof PhyloXmlParser ) {
2192 warnIfNotPhyloXmlValidation( getConfiguration() );
2194 phys = PhylogenyMethods.readPhylogenies( parser, file );
2196 catch ( final Exception e ) {
2198 exceptionOccuredDuringOpenFile( e );
2201 if ( _mainpanel.getCurrentTreePanel() != null ) {
2202 _mainpanel.getCurrentTreePanel().setArrowCursor();
2205 _mainpanel.setArrowCursor();
2207 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
2208 boolean one_desc = false;
2209 if ( nhx_or_nexus ) {
2210 for( final Phylogeny phy : phys ) {
2211 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2212 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
2214 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
2220 AptxUtil.addPhylogeniesToTabs( phys,
2222 file.getAbsolutePath(),
2225 _mainpanel.getControlPanel().showWhole();
2226 if ( nhx_or_nexus && one_desc ) {
2228 .showMessageDialog( this,
2229 "One or more trees contain (a) node(s) with one descendant, "
2230 + ForesterUtil.LINE_SEPARATOR
2231 + "possibly indicating illegal parentheses within node names.",
2232 "Warning: Possible Error in New Hampshire Formatted Data",
2233 JOptionPane.WARNING_MESSAGE );
2239 activateSaveAllIfNeeded();
2243 private void readSpeciesTreeFromFile() {
2245 boolean exception = false;
2246 final File my_dir = getCurrentDir();
2247 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2248 if ( my_dir != null ) {
2249 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2251 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2252 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2253 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2254 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2256 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2259 catch ( final Exception e ) {
2261 exceptionOccuredDuringOpenFile( e );
2264 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2266 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2269 catch ( final Exception e ) {
2271 exceptionOccuredDuringOpenFile( e );
2277 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2280 catch ( final Exception e ) {
2282 exceptionOccuredDuringOpenFile( e );
2285 if ( !exception && ( t != null ) && !t.isRooted() ) {
2288 JOptionPane.showMessageDialog( this,
2289 "Species tree is not rooted",
2290 "Species tree not loaded",
2291 JOptionPane.ERROR_MESSAGE );
2293 if ( !exception && ( t != null ) ) {
2294 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2295 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2296 final PhylogenyNode node = it.next();
2297 if ( !node.getNodeData().isHasTaxonomy() ) {
2301 .showMessageDialog( this,
2302 "Species tree contains external node(s) without taxonomy information",
2303 "Species tree not loaded",
2304 JOptionPane.ERROR_MESSAGE );
2308 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2311 JOptionPane.showMessageDialog( this,
2313 + node.getNodeData().getTaxonomy().asSimpleText()
2314 + "] is not unique in species tree",
2315 "Species tree not loaded",
2316 JOptionPane.ERROR_MESSAGE );
2320 tax_set.add( node.getNodeData().getTaxonomy() );
2325 if ( !exception && ( t != null ) ) {
2327 JOptionPane.showMessageDialog( this,
2328 "Species tree successfully loaded",
2329 "Species tree loaded",
2330 JOptionPane.INFORMATION_MESSAGE );
2332 _contentpane.repaint();
2337 private void setCurrentDir( final File current_dir ) {
2338 _current_dir = current_dir;
2341 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2342 _min_not_collapse = min_not_collapse;
2345 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2346 _phylogenetic_inference_options = phylogenetic_inference_options;
2349 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2350 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2351 nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2354 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2355 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2356 nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2359 private void writeAllToFile() {
2360 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2363 final File my_dir = getCurrentDir();
2364 if ( my_dir != null ) {
2365 _save_filechooser.setCurrentDirectory( my_dir );
2367 _save_filechooser.setSelectedFile( new File( "" ) );
2368 final int result = _save_filechooser.showSaveDialog( _contentpane );
2369 final File file = _save_filechooser.getSelectedFile();
2370 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2371 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2372 if ( file.exists() ) {
2373 final int i = JOptionPane.showConfirmDialog( this,
2374 file + " already exists. Overwrite?",
2376 JOptionPane.OK_CANCEL_OPTION,
2377 JOptionPane.WARNING_MESSAGE );
2378 if ( i != JOptionPane.OK_OPTION ) {
2385 catch ( final Exception e ) {
2386 JOptionPane.showMessageDialog( this,
2387 "Failed to delete: " + file,
2389 JOptionPane.WARNING_MESSAGE );
2393 final int count = getMainPanel().getTabbedPane().getTabCount();
2394 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2395 for( int i = 0; i < count; ++i ) {
2396 trees.add( getMainPanel().getPhylogeny( i ) );
2397 getMainPanel().getTreePanels().get( i ).setEdited( false );
2399 final PhylogenyWriter writer = new PhylogenyWriter();
2401 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2403 catch ( final IOException e ) {
2404 JOptionPane.showMessageDialog( this,
2405 "Failed to write to: " + file,
2407 JOptionPane.WARNING_MESSAGE );
2412 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2414 final PhylogenyWriter writer = new PhylogenyWriter();
2415 writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
2417 catch ( final Exception e ) {
2419 exceptionOccuredDuringSaveAs( e );
2424 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2426 final PhylogenyWriter writer = new PhylogenyWriter();
2427 writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
2429 catch ( final Exception e ) {
2431 exceptionOccuredDuringSaveAs( e );
2436 private boolean writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
2438 final PhylogenyWriter writer = new PhylogenyWriter();
2439 writer.toNewHampshireX( t, file );
2441 catch ( final Exception e ) {
2443 exceptionOccuredDuringSaveAs( e );
2448 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2450 final PhylogenyWriter writer = new PhylogenyWriter();
2451 writer.toPhyloXML( file, t, 0 );
2453 catch ( final Exception e ) {
2455 exceptionOccuredDuringSaveAs( e );
2460 private void writeToFile( final Phylogeny t ) {
2464 String initial_filename = null;
2465 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2467 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2469 catch ( final IOException e ) {
2470 initial_filename = null;
2473 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2474 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2477 _save_filechooser.setSelectedFile( new File( "" ) );
2479 final File my_dir = getCurrentDir();
2480 if ( my_dir != null ) {
2481 _save_filechooser.setCurrentDirectory( my_dir );
2483 final int result = _save_filechooser.showSaveDialog( _contentpane );
2484 final File file = _save_filechooser.getSelectedFile();
2485 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2486 boolean exception = false;
2487 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2488 if ( file.exists() ) {
2489 final int i = JOptionPane.showConfirmDialog( this,
2490 file + " already exists.\nOverwrite?",
2492 JOptionPane.OK_CANCEL_OPTION,
2493 JOptionPane.QUESTION_MESSAGE );
2494 if ( i != JOptionPane.OK_OPTION ) {
2498 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2500 ForesterUtil.copyFile( file, to );
2502 catch ( final Exception e ) {
2503 JOptionPane.showMessageDialog( this,
2504 "Failed to create backup copy " + to,
2505 "Failed to Create Backup Copy",
2506 JOptionPane.WARNING_MESSAGE );
2511 catch ( final Exception e ) {
2512 JOptionPane.showMessageDialog( this,
2513 "Failed to delete: " + file,
2515 JOptionPane.WARNING_MESSAGE );
2519 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2520 exception = writeAsNewHampshire( t, exception, file );
2522 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
2523 exception = writeAsNHX( t, exception, file );
2525 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2526 exception = writeAsPhyloXml( t, exception, file );
2528 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2529 exception = writeAsNexus( t, exception, file );
2533 final String file_name = file.getName().trim().toLowerCase();
2534 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2535 || file_name.endsWith( ".tree" ) ) {
2536 exception = writeAsNewHampshire( t, exception, file );
2538 else if ( file_name.endsWith( ".nhx" ) ) {
2539 exception = writeAsNHX( t, exception, file );
2541 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2542 exception = writeAsNexus( t, exception, file );
2546 exception = writeAsPhyloXml( t, exception, file );
2550 getMainPanel().setTitleOfSelectedTab( file.getName() );
2551 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2552 getMainPanel().getCurrentTreePanel().setEdited( false );
2557 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2558 if ( ( t == null ) || t.isEmpty() ) {
2561 String initial_filename = "";
2562 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2563 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2565 if ( initial_filename.indexOf( '.' ) > 0 ) {
2566 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2568 initial_filename = initial_filename + "." + type;
2569 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2570 final File my_dir = getCurrentDir();
2571 if ( my_dir != null ) {
2572 _writetographics_filechooser.setCurrentDirectory( my_dir );
2574 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2575 File file = _writetographics_filechooser.getSelectedFile();
2576 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2577 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2578 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2579 file = new File( file.toString() + "." + type );
2581 if ( file.exists() ) {
2582 final int i = JOptionPane.showConfirmDialog( this,
2583 file + " already exists. Overwrite?",
2585 JOptionPane.OK_CANCEL_OPTION,
2586 JOptionPane.WARNING_MESSAGE );
2587 if ( i != JOptionPane.OK_OPTION ) {
2594 catch ( final Exception e ) {
2595 JOptionPane.showMessageDialog( this,
2596 "Failed to delete: " + file,
2598 JOptionPane.WARNING_MESSAGE );
2602 writePhylogenyToGraphicsFile( file.toString(), type );
2606 private void writeToPdf( final Phylogeny t ) {
2607 if ( ( t == null ) || t.isEmpty() ) {
2610 String initial_filename = "";
2611 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2612 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2614 if ( initial_filename.indexOf( '.' ) > 0 ) {
2615 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2617 initial_filename = initial_filename + ".pdf";
2618 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2619 final File my_dir = getCurrentDir();
2620 if ( my_dir != null ) {
2621 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2623 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2624 File file = _writetopdf_filechooser.getSelectedFile();
2625 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2626 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2627 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2628 file = new File( file.toString() + ".pdf" );
2630 if ( file.exists() ) {
2631 final int i = JOptionPane.showConfirmDialog( this,
2632 file + " already exists. Overwrite?",
2634 JOptionPane.OK_CANCEL_OPTION,
2635 JOptionPane.WARNING_MESSAGE );
2636 if ( i != JOptionPane.OK_OPTION ) {
2640 printPhylogenyToPdf( file.toString() );
2644 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
2645 return new MainFrameApplication( phys, config );
2648 public static MainFrame createInstance( final Phylogeny[] phys,
2649 final Configuration config,
2651 final File current_dir ) {
2652 return new MainFrameApplication( phys, config, title, current_dir );
2655 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2656 return new MainFrameApplication( phys, config, title );
2659 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2660 return new MainFrameApplication( phys, config_file_name, title );
2663 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2664 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2665 + o.getPrintSizeY() + ")" );
2668 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2669 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2672 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2673 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2675 .showMessageDialog( null,
2677 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2680 JOptionPane.WARNING_MESSAGE );
2683 } // MainFrameApplication.
2685 class DefaultFilter extends FileFilter {
2688 public boolean accept( final File f ) {
2689 final String file_name = f.getName().trim().toLowerCase();
2690 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2691 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2692 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2693 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2694 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2695 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2696 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2697 || file_name.endsWith( ".con" ) || f.isDirectory();
2701 public String getDescription() {
2702 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2706 class GraphicsFileFilter extends FileFilter {
2709 public boolean accept( final File f ) {
2710 final String file_name = f.getName().trim().toLowerCase();
2711 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2712 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2716 public String getDescription() {
2717 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2721 class MsaFileFilter extends FileFilter {
2724 public boolean accept( final File f ) {
2725 final String file_name = f.getName().trim().toLowerCase();
2726 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2727 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2731 public String getDescription() {
2732 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2736 class NexusFilter extends FileFilter {
2739 public boolean accept( final File f ) {
2740 final String file_name = f.getName().trim().toLowerCase();
2741 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2742 || file_name.endsWith( ".tre" ) || f.isDirectory();
2746 public String getDescription() {
2747 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2751 class NHFilter extends FileFilter {
2754 public boolean accept( final File f ) {
2755 final String file_name = f.getName().trim().toLowerCase();
2756 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2757 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2758 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2763 public String getDescription() {
2764 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2768 class NHXFilter extends FileFilter {
2771 public boolean accept( final File f ) {
2772 final String file_name = f.getName().trim().toLowerCase();
2773 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2777 public String getDescription() {
2778 return "NHX files (*.nhx)";
2782 class PdfFilter extends FileFilter {
2785 public boolean accept( final File f ) {
2786 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2790 public String getDescription() {
2791 return "PDF files (*.pdf)";
2795 class SequencesFileFilter extends FileFilter {
2798 public boolean accept( final File f ) {
2799 final String file_name = f.getName().trim().toLowerCase();
2800 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2801 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2805 public String getDescription() {
2806 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2810 class TolFilter extends FileFilter {
2813 public boolean accept( final File f ) {
2814 final String file_name = f.getName().trim().toLowerCase();
2815 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2816 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2820 public String getDescription() {
2821 return "Tree of Life files (*.tol, *.tolxml)";
2825 class XMLFilter extends FileFilter {
2828 public boolean accept( final File f ) {
2829 final String file_name = f.getName().trim().toLowerCase();
2830 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2831 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2835 public String getDescription() {
2836 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";