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: https://sites.google.com/site/cmzmasek/home/software/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.InferenceManager;
70 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
71 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
72 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
73 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
74 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
75 import org.forester.archaeopteryx.webservices.WebservicesManager;
76 import org.forester.io.parsers.FastaParser;
77 import org.forester.io.parsers.GeneralMsaParser;
78 import org.forester.io.parsers.PhylogenyParser;
79 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
80 import org.forester.io.parsers.nhx.NHXParser;
81 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
82 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
83 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
84 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
85 import org.forester.io.parsers.tol.TolParser;
86 import org.forester.io.parsers.util.ParserUtils;
87 import org.forester.io.writers.PhylogenyWriter;
88 import org.forester.io.writers.SequenceWriter;
89 import org.forester.msa.Msa;
90 import org.forester.msa.MsaFormatException;
91 import org.forester.phylogeny.Phylogeny;
92 import org.forester.phylogeny.PhylogenyMethods;
93 import org.forester.phylogeny.PhylogenyNode;
94 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
95 import org.forester.phylogeny.data.Confidence;
96 import org.forester.phylogeny.data.Taxonomy;
97 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
98 import org.forester.phylogeny.factories.PhylogenyFactory;
99 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
100 import org.forester.sequence.Sequence;
101 import org.forester.util.BasicDescriptiveStatistics;
102 import org.forester.util.BasicTable;
103 import org.forester.util.BasicTableParser;
104 import org.forester.util.DescriptiveStatistics;
105 import org.forester.util.ForesterUtil;
106 import org.forester.util.WindowsUtils;
108 public final class MainFrameApplication extends MainFrame {
110 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
111 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
112 private final static int FRAME_X_SIZE = 800;
113 private final static int FRAME_Y_SIZE = 800;
114 // Filters for the file-open dialog (classes defined in this file)
115 private final static NHFilter nhfilter = new NHFilter();
116 private final static NHXFilter nhxfilter = new NHXFilter();
117 private final static XMLFilter xmlfilter = new XMLFilter();
118 private final static TolFilter tolfilter = new TolFilter();
119 private final static NexusFilter nexusfilter = new NexusFilter();
120 private final static PdfFilter pdffilter = new PdfFilter();
121 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
122 private final static MsaFileFilter msafilter = new MsaFileFilter();
123 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
124 private final static DefaultFilter defaultfilter = new DefaultFilter();
125 private static final long serialVersionUID = -799735726778865234L;
126 private final JFileChooser _values_filechooser;
127 private final JFileChooser _sequences_filechooser;
128 private final JFileChooser _open_filechooser;
129 private final JFileChooser _msa_filechooser;
130 private final JFileChooser _seqs_pi_filechooser;
131 private final JFileChooser _open_filechooser_for_species_tree;
132 private final JFileChooser _save_filechooser;
133 private final JFileChooser _writetopdf_filechooser;
134 private final JFileChooser _writetographics_filechooser;
135 // Application-only print menu items
136 private JMenuItem _print_item;
137 private JMenuItem _write_to_pdf_item;
138 private JMenuItem _write_to_jpg_item;
139 private JMenuItem _write_to_gif_item;
140 private JMenuItem _write_to_tif_item;
141 private JMenuItem _write_to_png_item;
142 private JMenuItem _write_to_bmp_item;
143 private File _current_dir;
144 private ButtonGroup _radio_group_1;
145 private ButtonGroup _radio_group_2;
147 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
148 // Phylogeny Inference menu
149 private JMenu _inference_menu;
150 private JMenuItem _inference_from_msa_item;
151 private JMenuItem _inference_from_seqs_item;
152 // Phylogeny Inference
153 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
154 private Msa _msa = null;
155 private File _msa_file = null;
156 private List<Sequence> _seqs = null;
157 private File _seqs_file = null;
158 JMenuItem _read_values_jmi;
159 JMenuItem _read_seqs_jmi;
161 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
162 _configuration = config;
163 if ( _configuration == null ) {
164 throw new IllegalArgumentException( "configuration is null" );
167 setOptions( Options.createInstance( _configuration ) );
168 _mainpanel = new MainPanel( _configuration, this );
169 _open_filechooser = null;
170 _open_filechooser_for_species_tree = null;
171 _save_filechooser = null;
172 _writetopdf_filechooser = null;
173 _writetographics_filechooser = null;
174 _msa_filechooser = null;
175 _seqs_pi_filechooser = null;
176 _values_filechooser = null;
177 _sequences_filechooser = null;
178 _jmenubar = new JMenuBar();
181 _contentpane = getContentPane();
182 _contentpane.setLayout( new BorderLayout() );
183 _contentpane.add( _mainpanel, BorderLayout.CENTER );
185 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
186 // The window listener
187 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
188 addWindowListener( new WindowAdapter() {
191 public void windowClosing( final WindowEvent e ) {
195 // setVisible( true );
196 if ( ( phys != null ) && ( phys.length > 0 ) ) {
197 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
199 getMainPanel().getControlPanel().showWholeAll();
200 getMainPanel().getControlPanel().showWhole();
202 //activateSaveAllIfNeeded();
203 // ...and its children
204 _contentpane.repaint();
207 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
208 this( phys, config, title, null );
211 private MainFrameApplication( final Phylogeny[] phys,
212 final Configuration config,
214 final File current_dir ) {
216 _configuration = config;
217 if ( _configuration == null ) {
218 throw new IllegalArgumentException( "configuration is null" );
221 boolean synth_exception = false;
222 if ( Constants.__SYNTH_LF ) {
224 final SynthLookAndFeel synth = new SynthLookAndFeel();
225 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
226 MainFrameApplication.class );
227 UIManager.setLookAndFeel( synth );
229 catch ( final Exception ex ) {
230 synth_exception = true;
231 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
232 "could not create synth look and feel: "
233 + ex.getLocalizedMessage() );
236 if ( !Constants.__SYNTH_LF || synth_exception ) {
237 if ( _configuration.isUseNativeUI() ) {
238 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
241 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
244 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
246 catch ( final UnsupportedLookAndFeelException e ) {
247 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
249 catch ( final ClassNotFoundException e ) {
250 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
252 catch ( final InstantiationException e ) {
253 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
255 catch ( final IllegalAccessException e ) {
256 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
258 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
259 setCurrentDir( current_dir );
261 // hide until everything is ready
263 setOptions( Options.createInstance( _configuration ) );
264 setInferenceManager( InferenceManager.createInstance( _configuration ) );
265 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
266 // _textframe = null; #~~~~
268 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
269 _mainpanel = new MainPanel( _configuration, this );
271 _open_filechooser = new JFileChooser();
272 _open_filechooser.setCurrentDirectory( new File( "." ) );
273 _open_filechooser.setMultiSelectionEnabled( false );
274 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
275 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
276 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
277 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
278 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
279 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
280 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
281 _open_filechooser_for_species_tree = new JFileChooser();
282 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
283 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
284 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
285 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
286 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
287 _save_filechooser = new JFileChooser();
288 _save_filechooser.setCurrentDirectory( new File( "." ) );
289 _save_filechooser.setMultiSelectionEnabled( false );
290 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
291 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
292 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
293 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
294 _writetopdf_filechooser = new JFileChooser();
295 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
296 _writetographics_filechooser = new JFileChooser();
297 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
299 _msa_filechooser = new JFileChooser();
300 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
301 _msa_filechooser.setCurrentDirectory( new File( "." ) );
302 _msa_filechooser.setMultiSelectionEnabled( false );
303 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
304 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
306 _seqs_pi_filechooser = new JFileChooser();
307 _seqs_pi_filechooser.setName( "Read Sequences File" );
308 _seqs_pi_filechooser.setCurrentDirectory( new File( "." ) );
309 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
310 _seqs_pi_filechooser.addChoosableFileFilter( _seqs_pi_filechooser.getAcceptAllFileFilter() );
311 _seqs_pi_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
313 _values_filechooser = new JFileChooser();
314 _values_filechooser.setCurrentDirectory( new File( "." ) );
315 _values_filechooser.setMultiSelectionEnabled( false );
317 _sequences_filechooser = new JFileChooser();
318 _sequences_filechooser.setCurrentDirectory( new File( "." ) );
319 _sequences_filechooser.setMultiSelectionEnabled( false );
320 // build the menu bar
321 _jmenubar = new JMenuBar();
322 if ( !_configuration.isUseNativeUI() ) {
323 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
326 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
327 buildPhylogeneticInferenceMenu();
336 setJMenuBar( _jmenubar );
337 _jmenubar.add( _help_jmenu );
338 _contentpane = getContentPane();
339 _contentpane.setLayout( new BorderLayout() );
340 _contentpane.add( _mainpanel, BorderLayout.CENTER );
342 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
343 // addWindowFocusListener( new WindowAdapter() {
346 // public void windowGainedFocus( WindowEvent e ) {
347 // requestFocusInWindow();
350 // The window listener
351 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
352 addWindowListener( new WindowAdapter() {
355 public void windowClosing( final WindowEvent e ) {
356 if ( isUnsavedDataPresent() ) {
357 final int r = JOptionPane.showConfirmDialog( null,
358 "Exit despite potentially unsaved changes?",
360 JOptionPane.YES_NO_OPTION );
361 if ( r != JOptionPane.YES_OPTION ) {
366 final int r = JOptionPane.showConfirmDialog( null,
367 "Exit Archaeopteryx?",
369 JOptionPane.YES_NO_OPTION );
370 if ( r != JOptionPane.YES_OPTION ) {
377 // The component listener
378 addComponentListener( new ComponentAdapter() {
381 public void componentResized( final ComponentEvent e ) {
382 if ( _mainpanel.getCurrentTreePanel() != null ) {
383 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel()
385 _mainpanel.getCurrentTreePanel()
387 getOptions().isAllowFontSizeChange() );
391 requestFocusInWindow();
392 // addKeyListener( this );
394 if ( ( phys != null ) && ( phys.length > 0 ) ) {
395 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
397 getMainPanel().getControlPanel().showWholeAll();
398 getMainPanel().getControlPanel().showWhole();
400 activateSaveAllIfNeeded();
401 // ...and its children
402 _contentpane.repaint();
406 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
407 // Reads the config file (false, false => not url, not applet):
408 this( phys, new Configuration( config_file, false, false, true ), title );
412 public void actionPerformed( final ActionEvent e ) {
414 super.actionPerformed( e );
415 final Object o = e.getSource();
416 // Handle app-specific actions here:
417 if ( o == _open_item ) {
418 readPhylogeniesFromFile();
420 else if ( o == _save_item ) {
421 writeToFile( _mainpanel.getCurrentPhylogeny() );
422 // If subtree currently displayed, save it, instead of complete
425 else if ( o == _new_item ) {
428 else if ( o == _save_all_item ) {
431 else if ( o == _close_item ) {
434 else if ( o == _write_to_pdf_item ) {
435 writeToPdf( _mainpanel.getCurrentPhylogeny() );
437 else if ( o == _write_to_jpg_item ) {
438 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
440 else if ( o == _write_to_png_item ) {
441 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
443 else if ( o == _write_to_gif_item ) {
444 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
446 else if ( o == _write_to_tif_item ) {
447 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
449 else if ( o == _write_to_bmp_item ) {
450 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
452 else if ( o == _print_item ) {
455 else if ( o == _load_species_tree_item ) {
456 readSpeciesTreeFromFile();
458 else if ( o == _lineage_inference ) {
459 if ( isSubtreeDisplayed() ) {
460 JOptionPane.showMessageDialog( this,
462 "Cannot infer ancestral taxonomies",
463 JOptionPane.ERROR_MESSAGE );
466 executeLineageInference();
468 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
469 if ( isSubtreeDisplayed() ) {
472 obtainDetailedTaxonomicInformation();
474 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
475 if ( isSubtreeDisplayed() ) {
478 obtainDetailedTaxonomicInformationDelete();
480 else if ( o == _obtain_seq_information_jmi ) {
481 obtainSequenceInformation();
483 else if ( o == _read_values_jmi ) {
484 if ( isSubtreeDisplayed() ) {
487 addExpressionValuesFromFile();
489 else if ( o == _read_seqs_jmi ) {
490 if ( isSubtreeDisplayed() ) {
493 addSequencesFromFile();
495 else if ( o == _move_node_names_to_tax_sn_jmi ) {
496 moveNodeNamesToTaxSn();
498 else if ( o == _move_node_names_to_seq_names_jmi ) {
499 moveNodeNamesToSeqNames();
501 else if ( o == _extract_tax_code_from_node_names_jmi ) {
502 extractTaxDataFromNodeNames();
504 else if ( o == _graphics_export_visible_only_cbmi ) {
505 updateOptions( getOptions() );
507 else if ( o == _antialias_print_cbmi ) {
508 updateOptions( getOptions() );
510 else if ( o == _print_black_and_white_cbmi ) {
511 updateOptions( getOptions() );
513 else if ( o == _print_using_actual_size_cbmi ) {
514 updateOptions( getOptions() );
516 else if ( o == _graphics_export_using_actual_size_cbmi ) {
517 updateOptions( getOptions() );
519 else if ( o == _print_size_mi ) {
522 else if ( o == _choose_pdf_width_mi ) {
525 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
526 updateOptions( getOptions() );
528 else if ( o == _replace_underscores_cbmi ) {
529 if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
530 _extract_taxonomy_no_rbmi.setSelected( true );
532 updateOptions( getOptions() );
534 else if ( o == _collapse_below_threshold ) {
535 if ( isSubtreeDisplayed() ) {
538 collapseBelowThreshold();
540 else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi )
541 || ( o == _extract_taxonomy_agressive_rbmi ) ) {
542 if ( _replace_underscores_cbmi != null ) {
543 _replace_underscores_cbmi.setSelected( false );
545 updateOptions( getOptions() );
547 else if ( o == _extract_taxonomy_no_rbmi ) {
548 updateOptions( getOptions() );
550 else if ( o == _inference_from_msa_item ) {
551 executePhyleneticInference( false );
553 else if ( o == _inference_from_seqs_item ) {
554 executePhyleneticInference( true );
556 _contentpane.repaint();
558 catch ( final Exception ex ) {
559 AptxUtil.unexpectedException( ex );
561 catch ( final Error err ) {
562 AptxUtil.unexpectedError( err );
567 _mainpanel.terminate();
568 _contentpane.removeAll();
574 public MainPanel getMainPanel() {
578 public Msa getMsa() {
582 public File getMsaFile() {
586 public List<Sequence> getSeqs() {
590 public File getSeqsFile() {
594 public void readMsaFromFile() {
595 // Set an initial directory if none set yet
596 final File my_dir = getCurrentDir();
597 _msa_filechooser.setMultiSelectionEnabled( false );
598 // Open file-open dialog and set current directory
599 if ( my_dir != null ) {
600 _msa_filechooser.setCurrentDirectory( my_dir );
602 final int result = _msa_filechooser.showOpenDialog( _contentpane );
603 // All done: get the msa
604 final File file = _msa_filechooser.getSelectedFile();
605 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
606 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
611 final InputStream is = new FileInputStream( file );
612 if ( FastaParser.isLikelyFasta( file ) ) {
613 msa = FastaParser.parseMsa( is );
616 msa = GeneralMsaParser.parse( is );
619 catch ( final MsaFormatException e ) {
621 JOptionPane.showMessageDialog( this,
622 e.getLocalizedMessage(),
623 "Multiple sequence alignment format error",
624 JOptionPane.ERROR_MESSAGE );
627 catch ( final IOException e ) {
629 JOptionPane.showMessageDialog( this,
630 e.getLocalizedMessage(),
631 "Failed to read multiple sequence alignment",
632 JOptionPane.ERROR_MESSAGE );
635 catch ( final IllegalArgumentException e ) {
637 JOptionPane.showMessageDialog( this,
638 e.getLocalizedMessage(),
639 "Unexpected error during reading of multiple sequence alignment",
640 JOptionPane.ERROR_MESSAGE );
643 catch ( final Exception e ) {
646 JOptionPane.showMessageDialog( this,
647 e.getLocalizedMessage(),
648 "Unexpected error during reading of multiple sequence alignment",
649 JOptionPane.ERROR_MESSAGE );
652 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
653 JOptionPane.showMessageDialog( this,
654 "Multiple sequence alignment is empty",
655 "Illegal Multiple Sequence Alignment",
656 JOptionPane.ERROR_MESSAGE );
659 if ( msa.getNumberOfSequences() < 4 ) {
660 JOptionPane.showMessageDialog( this,
661 "Multiple sequence alignment needs to contain at least 3 sequences",
662 "Illegal multiple sequence alignment",
663 JOptionPane.ERROR_MESSAGE );
666 if ( msa.getLength() < 2 ) {
667 JOptionPane.showMessageDialog( this,
668 "Multiple sequence alignment needs to contain at least 2 residues",
669 "Illegal multiple sequence alignment",
670 JOptionPane.ERROR_MESSAGE );
674 setMsaFile( _msa_filechooser.getSelectedFile() );
679 public void readSeqsFromFileforPI() {
680 // Set an initial directory if none set yet
681 final File my_dir = getCurrentDir();
682 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
683 // Open file-open dialog and set current directory
684 if ( my_dir != null ) {
685 _seqs_pi_filechooser.setCurrentDirectory( my_dir );
687 final int result = _seqs_pi_filechooser.showOpenDialog( _contentpane );
688 // All done: get the seqs
689 final File file = _seqs_pi_filechooser.getSelectedFile();
690 setCurrentDir( _seqs_pi_filechooser.getCurrentDirectory() );
691 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
694 List<Sequence> seqs = null;
696 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
697 seqs = FastaParser.parse( new FileInputStream( file ) );
698 for( final Sequence seq : seqs ) {
699 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
706 catch ( final MsaFormatException e ) {
708 JOptionPane.showMessageDialog( this,
709 e.getLocalizedMessage(),
710 "Multiple sequence file format error",
711 JOptionPane.ERROR_MESSAGE );
714 catch ( final IOException e ) {
716 JOptionPane.showMessageDialog( this,
717 e.getLocalizedMessage(),
718 "Failed to read multiple sequence file",
719 JOptionPane.ERROR_MESSAGE );
722 catch ( final IllegalArgumentException e ) {
724 JOptionPane.showMessageDialog( this,
725 e.getLocalizedMessage(),
726 "Unexpected error during reading of multiple sequence file",
727 JOptionPane.ERROR_MESSAGE );
730 catch ( final Exception e ) {
733 JOptionPane.showMessageDialog( this,
734 e.getLocalizedMessage(),
735 "Unexpected error during reading of multiple sequence file",
736 JOptionPane.ERROR_MESSAGE );
739 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
740 JOptionPane.showMessageDialog( this,
741 "Multiple sequence file is empty",
742 "Illegal multiple sequence file",
743 JOptionPane.ERROR_MESSAGE );
746 if ( seqs.size() < 4 ) {
747 JOptionPane.showMessageDialog( this,
748 "Multiple sequence file needs to contain at least 3 sequences",
749 "Illegal multiple sequence file",
750 JOptionPane.ERROR_MESSAGE );
753 // if ( msa.getLength() < 2 ) {
754 // JOptionPane.showMessageDialog( this,
755 // "Multiple sequence alignment needs to contain at least 2 residues",
756 // "Illegal multiple sequence file",
757 // JOptionPane.ERROR_MESSAGE );
761 setSeqsFile( _seqs_pi_filechooser.getSelectedFile() );
766 void buildAnalysisMenu() {
767 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
768 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
769 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
770 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
771 customizeJMenuItem( _gsdi_item );
772 customizeJMenuItem( _gsdir_item );
773 customizeJMenuItem( _load_species_tree_item );
774 _analysis_menu.addSeparator();
775 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
776 customizeJMenuItem( _lineage_inference );
777 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
778 _jmenubar.add( _analysis_menu );
782 void buildFileMenu() {
783 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
784 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
785 _file_jmenu.addSeparator();
786 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
787 _file_jmenu.addSeparator();
788 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
789 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
790 .getAvailablePhylogeniesWebserviceClients().size() ];
791 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
792 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
793 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
794 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
796 if ( getConfiguration().isEditable() ) {
797 _file_jmenu.addSeparator();
798 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
799 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
801 _file_jmenu.addSeparator();
802 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
803 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
804 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
805 _save_all_item.setEnabled( false );
806 _file_jmenu.addSeparator();
807 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
808 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
809 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
811 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
812 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
813 if ( AptxUtil.canWriteFormat( "gif" ) ) {
814 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
816 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
817 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
819 _file_jmenu.addSeparator();
820 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
821 _file_jmenu.addSeparator();
822 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
823 _close_item.setToolTipText( "To close the current pane." );
824 _close_item.setEnabled( true );
825 _file_jmenu.addSeparator();
826 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
827 // For print in color option item
828 customizeJMenuItem( _open_item );
830 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
831 customizeJMenuItem( _open_url_item );
832 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
833 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
835 customizeJMenuItem( _save_item );
836 if ( getConfiguration().isEditable() ) {
837 customizeJMenuItem( _new_item );
839 customizeJMenuItem( _close_item );
840 customizeJMenuItem( _save_all_item );
841 customizeJMenuItem( _write_to_pdf_item );
842 customizeJMenuItem( _write_to_png_item );
843 customizeJMenuItem( _write_to_jpg_item );
844 customizeJMenuItem( _write_to_gif_item );
845 customizeJMenuItem( _write_to_tif_item );
846 customizeJMenuItem( _write_to_bmp_item );
847 customizeJMenuItem( _print_item );
848 customizeJMenuItem( _exit_item );
849 _jmenubar.add( _file_jmenu );
852 void buildOptionsMenu() {
853 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
854 _options_jmenu.addChangeListener( new ChangeListener() {
857 public void stateChanged( final ChangeEvent e ) {
858 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
859 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
861 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
862 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
863 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
864 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
865 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
866 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
868 _show_branch_length_values_cbmi,
869 _non_lined_up_cladograms_rbmi,
870 _uniform_cladograms_rbmi,
871 _ext_node_dependent_cladogram_rbmi,
872 _label_direction_cbmi );
873 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
874 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
875 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
878 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
880 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
881 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
882 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
883 _radio_group_1 = new ButtonGroup();
884 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
885 _radio_group_1.add( _uniform_cladograms_rbmi );
886 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
888 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
889 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
891 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
893 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) );
895 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) );
896 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
897 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
899 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) );
900 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
901 _options_jmenu.add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( COLOR_BY_TAXONOMIC_GROUP ) );
903 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
904 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
905 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
906 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
907 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
908 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
909 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
910 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
911 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
912 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
913 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
914 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
915 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
916 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
917 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
919 _options_jmenu.addSeparator();
920 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
921 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
922 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
923 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
924 _options_jmenu.addSeparator();
925 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
926 getConfiguration() ) );
927 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
928 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
930 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
932 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
934 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
935 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
936 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
937 _options_jmenu.addSeparator();
938 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
940 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
941 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
943 _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
945 .add( _extract_taxonomy_pfam_strict_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style Node Names" ) );
947 .add( _extract_taxonomy_pfam_relaxed_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style like Node Names" ) );
949 .add( _extract_taxonomy_agressive_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids/Scientific Names from Node Names" ) );
950 _extract_taxonomy_pfam_strict_rbmi
951 .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"BCL2_MOUSE/123-304\" or \"BCL2_10090/123-304\"" );
952 _extract_taxonomy_pfam_relaxed_rbmi
953 .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"bax_MOUSE\" or \"bax_10090\"" );
954 _extract_taxonomy_agressive_rbmi
955 .setToolTipText( "To extract taxonomy codes/ids or scientific names from node names in the form of e.g. \"MOUSE\" or \"10090\" or \"xyz_Nematostella_vectensis\"" );
956 _radio_group_2 = new ButtonGroup();
957 _radio_group_2.add( _extract_taxonomy_no_rbmi );
958 _radio_group_2.add( _extract_taxonomy_pfam_strict_rbmi );
959 _radio_group_2.add( _extract_taxonomy_pfam_relaxed_rbmi );
960 _radio_group_2.add( _extract_taxonomy_agressive_rbmi );
962 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
964 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
965 _use_brackets_for_conf_in_nh_export_cbmi
966 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
968 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
969 customizeJMenuItem( _choose_font_mi );
970 customizeJMenuItem( _choose_minimal_confidence_mi );
971 customizeJMenuItem( _switch_colors_mi );
972 customizeJMenuItem( _print_size_mi );
973 customizeJMenuItem( _choose_pdf_width_mi );
974 customizeJMenuItem( _overview_placment_mi );
975 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
976 .isShowDefaultNodeShapesExternal() );
977 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
978 .isShowDefaultNodeShapesInternal() );
979 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
980 customizeJMenuItem( _cycle_node_shape_mi );
981 customizeJMenuItem( _cycle_node_fill_mi );
982 customizeJMenuItem( _choose_node_size_mi );
983 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
984 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
985 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
986 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
987 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
988 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
989 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
990 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
991 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
992 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
993 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
994 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
995 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
996 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
997 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
998 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
999 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
1000 customizeCheckBoxMenuItem( _label_direction_cbmi,
1001 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
1002 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
1003 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
1004 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
1005 .isInternalNumberAreConfidenceForNhParsing() );
1006 customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
1007 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
1008 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_strict_rbmi,
1009 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1010 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_relaxed_rbmi,
1011 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1012 customizeRadioButtonMenuItem( _extract_taxonomy_agressive_rbmi,
1013 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.AGGRESSIVE );
1014 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
1015 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1016 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1017 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
1018 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
1019 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
1020 .isGraphicsExportUsingActualSize() );
1021 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1022 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
1023 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1024 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
1025 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1026 _jmenubar.add( _options_jmenu );
1029 void buildPhylogeneticInferenceMenu() {
1030 final InferenceManager im = getInferenceManager();
1031 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
1032 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
1033 customizeJMenuItem( _inference_from_msa_item );
1034 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
1035 if ( im.canDoMsa() ) {
1036 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
1037 customizeJMenuItem( _inference_from_seqs_item );
1038 _inference_from_seqs_item
1039 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
1043 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
1044 customizeJMenuItem( _inference_from_seqs_item );
1045 _inference_from_seqs_item.setEnabled( false );
1047 _jmenubar.add( _inference_menu );
1050 void buildToolsMenu() {
1051 _tools_menu = createMenu( "Tools", getConfiguration() );
1052 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1053 customizeJMenuItem( _confcolor_item );
1054 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
1055 customizeJMenuItem( _color_rank_jmi );
1056 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
1057 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1058 customizeJMenuItem( _taxcolor_item );
1059 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
1060 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
1061 customizeJMenuItem( _remove_branch_color_item );
1062 _tools_menu.addSeparator();
1063 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
1064 customizeJMenuItem( _annotate_item );
1065 _tools_menu.addSeparator();
1066 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1067 customizeJMenuItem( _midpoint_root_item );
1068 _tools_menu.addSeparator();
1069 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1070 customizeJMenuItem( _collapse_species_specific_subtrees );
1072 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
1073 customizeJMenuItem( _collapse_below_threshold );
1074 _collapse_below_threshold
1075 .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)" );
1076 _tools_menu.addSeparator();
1078 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );
1079 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
1080 _extract_tax_code_from_node_names_jmi
1081 .setToolTipText( "To extract SwissProt/Uniprot taxonomic codes (mnemonics) from nodes names in the form of 'xyz_CAEEL', Uniprot/NCBI identifiers form of 'xyz_6239', or scientific names form of 'xyz_Caenorhabditis_elegans'" );
1083 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
1084 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
1085 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
1086 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
1087 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
1088 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
1089 _tools_menu.addSeparator();
1090 _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
1091 customizeJMenuItem( _obtain_seq_information_jmi );
1092 _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
1094 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
1095 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
1096 _obtain_detailed_taxonomic_information_jmi
1097 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
1099 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
1100 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
1101 _obtain_detailed_taxonomic_information_deleting_jmi
1102 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
1103 _tools_menu.addSeparator();
1104 _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) );
1105 customizeJMenuItem( _read_values_jmi );
1106 _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" );
1107 _jmenubar.add( _tools_menu );
1108 _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) );
1109 customizeJMenuItem( _read_seqs_jmi );
1111 .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" );
1112 _jmenubar.add( _tools_menu );
1117 if ( isUnsavedDataPresent() ) {
1118 final int r = JOptionPane.showConfirmDialog( this,
1119 "Exit despite potentially unsaved changes?",
1121 JOptionPane.YES_NO_OPTION );
1122 if ( r != JOptionPane.YES_OPTION ) {
1129 void executeLineageInference() {
1130 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1133 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1134 JOptionPane.showMessageDialog( this,
1135 "Phylogeny is not rooted.",
1136 "Cannot infer ancestral taxonomies",
1137 JOptionPane.ERROR_MESSAGE );
1140 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1141 _mainpanel.getCurrentTreePanel(),
1142 _mainpanel.getCurrentPhylogeny()
1144 new Thread( inferrer ).start();
1148 removeAllTextFrames();
1149 _mainpanel.terminate();
1150 _contentpane.removeAll();
1151 setVisible( false );
1157 void readPhylogeniesFromURL() {
1159 Phylogeny[] phys = null;
1160 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1161 final String url_string = JOptionPane.showInputDialog( this,
1163 "Use URL/webservice to obtain a phylogeny",
1164 JOptionPane.QUESTION_MESSAGE );
1165 boolean nhx_or_nexus = false;
1166 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1168 url = new URL( url_string );
1169 PhylogenyParser parser = null;
1170 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1171 parser = new TolParser();
1174 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
1175 .isValidatePhyloXmlAgainstSchema() );
1177 if ( parser instanceof NexusPhylogeniesParser ) {
1178 nhx_or_nexus = true;
1180 else if ( parser instanceof NHXParser ) {
1181 nhx_or_nexus = true;
1183 if ( _mainpanel.getCurrentTreePanel() != null ) {
1184 _mainpanel.getCurrentTreePanel().setWaitCursor();
1187 _mainpanel.setWaitCursor();
1189 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1190 phys = factory.create( url.openStream(), parser );
1192 catch ( final MalformedURLException e ) {
1193 JOptionPane.showMessageDialog( this,
1194 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1196 JOptionPane.ERROR_MESSAGE );
1198 catch ( final IOException e ) {
1199 JOptionPane.showMessageDialog( this,
1200 "Could not read from " + url + "\n"
1201 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1202 "Failed to read URL",
1203 JOptionPane.ERROR_MESSAGE );
1205 catch ( final Exception e ) {
1206 JOptionPane.showMessageDialog( this,
1207 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1208 "Unexpected Exception",
1209 JOptionPane.ERROR_MESSAGE );
1212 if ( _mainpanel.getCurrentTreePanel() != null ) {
1213 _mainpanel.getCurrentTreePanel().setArrowCursor();
1216 _mainpanel.setArrowCursor();
1219 if ( ( phys != null ) && ( phys.length > 0 ) ) {
1220 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1221 for( final Phylogeny phy : phys ) {
1222 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
1225 AptxUtil.addPhylogeniesToTabs( phys,
1226 new File( url.getFile() ).getName(),
1227 new File( url.getFile() ).toString(),
1230 _mainpanel.getControlPanel().showWhole();
1233 activateSaveAllIfNeeded();
1237 void setMsa( final Msa msa ) {
1241 void setMsaFile( final File msa_file ) {
1242 _msa_file = msa_file;
1245 void setSeqs( final List<Sequence> seqs ) {
1249 void setSeqsFile( final File seqs_file ) {
1250 _seqs_file = seqs_file;
1253 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
1254 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
1255 _mainpanel.getCurrentTreePanel().getHeight(),
1257 String file_written_to = "";
1258 boolean error = false;
1260 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
1261 _mainpanel.getCurrentTreePanel().getWidth(),
1262 _mainpanel.getCurrentTreePanel().getHeight(),
1263 _mainpanel.getCurrentTreePanel(),
1264 _mainpanel.getControlPanel(),
1268 catch ( final IOException e ) {
1270 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1273 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
1274 JOptionPane.showMessageDialog( this,
1275 "Wrote image to: " + file_written_to,
1277 JOptionPane.INFORMATION_MESSAGE );
1280 JOptionPane.showMessageDialog( this,
1281 "There was an unknown problem when attempting to write to an image file: \""
1284 JOptionPane.ERROR_MESSAGE );
1287 _contentpane.repaint();
1290 private void addExpressionValuesFromFile() {
1291 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1292 JOptionPane.showMessageDialog( this,
1293 "Need to load evolutionary tree first",
1294 "Can Not Read Expression Values",
1295 JOptionPane.WARNING_MESSAGE );
1298 final File my_dir = getCurrentDir();
1299 if ( my_dir != null ) {
1300 _values_filechooser.setCurrentDirectory( my_dir );
1302 final int result = _values_filechooser.showOpenDialog( _contentpane );
1303 final File file = _values_filechooser.getSelectedFile();
1304 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1305 BasicTable<String> t = null;
1307 t = BasicTableParser.parse( file, '\t' );
1308 if ( t.getNumberOfColumns() < 2 ) {
1309 t = BasicTableParser.parse( file, ',' );
1311 if ( t.getNumberOfColumns() < 2 ) {
1312 t = BasicTableParser.parse( file, ' ' );
1315 catch ( final IOException e ) {
1316 JOptionPane.showMessageDialog( this,
1318 "Could Not Read Expression Value Table",
1319 JOptionPane.ERROR_MESSAGE );
1322 if ( t.getNumberOfColumns() < 2 ) {
1323 JOptionPane.showMessageDialog( this,
1324 "Table contains " + t.getNumberOfColumns() + " column(s)",
1325 "Problem with Expression Value Table",
1326 JOptionPane.ERROR_MESSAGE );
1329 if ( t.getNumberOfRows() < 1 ) {
1330 JOptionPane.showMessageDialog( this,
1331 "Table contains zero rows",
1332 "Problem with Expression Value Table",
1333 JOptionPane.ERROR_MESSAGE );
1336 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1337 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1338 JOptionPane.showMessageDialog( this,
1339 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1340 + phy.getNumberOfExternalNodes() + " external nodes",
1342 JOptionPane.WARNING_MESSAGE );
1344 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1346 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1347 final PhylogenyNode node = iter.next();
1348 final String node_name = node.getName();
1349 if ( !ForesterUtil.isEmpty( node_name ) ) {
1352 row = t.findRow( node_name );
1354 catch ( final IllegalArgumentException e ) {
1356 .showMessageDialog( this,
1358 "Error Mapping Node Identifiers to Expression Value Identifiers",
1359 JOptionPane.ERROR_MESSAGE );
1363 if ( node.isExternal() ) {
1368 final List<Double> l = new ArrayList<Double>();
1369 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1372 d = Double.parseDouble( t.getValueAsString( col, row ) );
1374 catch ( final NumberFormatException e ) {
1375 JOptionPane.showMessageDialog( this,
1376 "Could not parse \"" + t.getValueAsString( col, row )
1377 + "\" into a decimal value",
1378 "Issue with Expression Value Table",
1379 JOptionPane.ERROR_MESSAGE );
1382 stats.addValue( d );
1385 if ( !l.isEmpty() ) {
1386 if ( node.getNodeData().getProperties() != null ) {
1387 node.getNodeData().getProperties()
1388 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1390 node.getNodeData().setVector( l );
1394 if ( not_found > 0 ) {
1395 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1396 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1398 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1402 private void addSequencesFromFile() {
1403 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1404 JOptionPane.showMessageDialog( this,
1405 "Need to load evolutionary tree first",
1406 "Can Not Read Sequences",
1407 JOptionPane.WARNING_MESSAGE );
1410 final File my_dir = getCurrentDir();
1411 if ( my_dir != null ) {
1412 _sequences_filechooser.setCurrentDirectory( my_dir );
1414 final int result = _sequences_filechooser.showOpenDialog( _contentpane );
1415 final File file = _sequences_filechooser.getSelectedFile();
1416 List<Sequence> seqs = null;
1417 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1419 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1420 seqs = FastaParser.parse( new FileInputStream( file ) );
1423 JOptionPane.showMessageDialog( this,
1424 "Format does not appear to be Fasta",
1425 "Multiple sequence file format error",
1426 JOptionPane.ERROR_MESSAGE );
1430 catch ( final MsaFormatException e ) {
1432 JOptionPane.showMessageDialog( this,
1433 e.getLocalizedMessage(),
1434 "Multiple sequence file format error",
1435 JOptionPane.ERROR_MESSAGE );
1438 catch ( final IOException e ) {
1440 JOptionPane.showMessageDialog( this,
1441 e.getLocalizedMessage(),
1442 "Failed to read multiple sequence file",
1443 JOptionPane.ERROR_MESSAGE );
1446 catch ( final Exception e ) {
1448 e.printStackTrace();
1449 JOptionPane.showMessageDialog( this,
1450 e.getLocalizedMessage(),
1451 "Unexpected error during reading of multiple sequence file",
1452 JOptionPane.ERROR_MESSAGE );
1455 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1456 JOptionPane.showMessageDialog( this,
1457 "Multiple sequence file is empty",
1458 "Empty multiple sequence file",
1459 JOptionPane.ERROR_MESSAGE );
1464 if ( seqs != null ) {
1465 for( final Sequence seq : seqs ) {
1466 System.out.println( seq.getIdentifier() );
1468 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1469 int total_counter = 0;
1470 int attached_counter = 0;
1471 for( final Sequence seq : seqs ) {
1473 final String seq_name = seq.getIdentifier();
1474 if ( !ForesterUtil.isEmpty( seq_name ) ) {
1475 List<PhylogenyNode> nodes = phy.getNodesViaSequenceName( seq_name );
1476 if ( nodes.isEmpty() ) {
1477 nodes = phy.getNodesViaSequenceSymbol( seq_name );
1479 if ( nodes.isEmpty() ) {
1480 nodes = phy.getNodesViaGeneName( seq_name );
1482 if ( nodes.isEmpty() ) {
1483 nodes = phy.getNodes( seq_name );
1485 if ( nodes.size() > 1 ) {
1486 JOptionPane.showMessageDialog( this,
1487 "Sequence name \"" + seq_name + "\" is not unique",
1488 "Sequence name not unique",
1489 JOptionPane.ERROR_MESSAGE );
1493 final String[] a = seq_name.split( "\\s" );
1494 if ( nodes.isEmpty() && ( a.length > 1 ) ) {
1495 final String seq_name_split = a[ 0 ];
1496 nodes = phy.getNodesViaSequenceName( seq_name_split );
1497 if ( nodes.isEmpty() ) {
1498 nodes = phy.getNodesViaSequenceSymbol( seq_name_split );
1500 if ( nodes.isEmpty() ) {
1501 nodes = phy.getNodes( seq_name_split );
1503 if ( nodes.size() > 1 ) {
1504 JOptionPane.showMessageDialog( this, "Split sequence name \"" + seq_name_split
1505 + "\" is not unique", "Sequence name not unique", JOptionPane.ERROR_MESSAGE );
1510 if ( nodes.size() == 1 ) {
1512 final PhylogenyNode n = nodes.get( 0 );
1513 if ( !n.getNodeData().isHasSequence() ) {
1514 n.getNodeData().addSequence( new org.forester.phylogeny.data.Sequence() );
1516 n.getNodeData().getSequence().setMolecularSequence( seq.getMolecularSequenceAsString() );
1517 if ( ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
1518 n.getNodeData().getSequence().setName( seq_name );
1523 if ( attached_counter > 0 ) {
1525 int ext_nodes_with_seq = 0;
1526 for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
1528 final PhylogenyNode n = iter.next();
1529 if ( n.getNodeData().isHasSequence()
1530 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
1531 ++ext_nodes_with_seq;
1535 if ( ext_nodes == ext_nodes_with_seq ) {
1536 s = "All " + ext_nodes_with_seq + " external nodes now have a molecular sequence attached to them.";
1539 s = ext_nodes_with_seq + " out of " + ext_nodes
1540 + " external nodes now have a molecular sequence attached to them.";
1542 if ( ( attached_counter == total_counter ) && ( ext_nodes == ext_nodes_with_seq ) ) {
1543 JOptionPane.showMessageDialog( this,
1544 "Attached all " + total_counter + " sequences to tree nodes.\n" + s,
1545 "All sequences attached",
1546 JOptionPane.INFORMATION_MESSAGE );
1549 JOptionPane.showMessageDialog( this, "Attached " + attached_counter
1550 + " sequences out of a total of " + total_counter + " sequences.\n" + s, attached_counter
1551 + " sequences attached", JOptionPane.WARNING_MESSAGE );
1555 JOptionPane.showMessageDialog( this, "No maching tree node for any of the " + total_counter
1556 + " sequences", "Could not attach any sequences", JOptionPane.ERROR_MESSAGE );
1561 private void choosePdfWidth() {
1562 final String s = ( String ) JOptionPane.showInputDialog( this,
1563 "Please enter the default line width for PDF export.\n"
1564 + "[current value: "
1565 + getOptions().getPrintLineWidth() + "]\n",
1566 "Line Width for PDF Export",
1567 JOptionPane.QUESTION_MESSAGE,
1570 getOptions().getPrintLineWidth() );
1571 if ( !ForesterUtil.isEmpty( s ) ) {
1572 boolean success = true;
1574 final String m_str = s.trim();
1575 if ( !ForesterUtil.isEmpty( m_str ) ) {
1577 f = Float.parseFloat( m_str );
1579 catch ( final Exception ex ) {
1586 if ( success && ( f > 0.0 ) ) {
1587 getOptions().setPrintLineWidth( f );
1592 private void choosePrintSize() {
1593 final String s = ( String ) JOptionPane.showInputDialog( this,
1594 "Please enter values for width and height,\nseparated by a comma.\n"
1595 + "[current values: "
1596 + getOptions().getPrintSizeX() + ", "
1597 + getOptions().getPrintSizeY() + "]\n"
1598 + "[A4: " + Constants.A4_SIZE_X + ", "
1599 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
1600 + Constants.US_LETTER_SIZE_X + ", "
1601 + Constants.US_LETTER_SIZE_Y + "]",
1602 "Default Size for Graphics Export",
1603 JOptionPane.QUESTION_MESSAGE,
1606 getOptions().getPrintSizeX() + ", "
1607 + getOptions().getPrintSizeY() );
1608 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
1609 boolean success = true;
1612 final String[] str_ary = s.split( "," );
1613 if ( str_ary.length == 2 ) {
1614 final String x_str = str_ary[ 0 ].trim();
1615 final String y_str = str_ary[ 1 ].trim();
1616 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
1618 x = Integer.parseInt( x_str );
1619 y = Integer.parseInt( y_str );
1621 catch ( final Exception ex ) {
1632 if ( success && ( x > 1 ) && ( y > 1 ) ) {
1633 getOptions().setPrintSizeX( x );
1634 getOptions().setPrintSizeY( y );
1639 private void closeCurrentPane() {
1640 if ( getMainPanel().getCurrentTreePanel() != null ) {
1641 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1642 final int r = JOptionPane.showConfirmDialog( this,
1643 "Close tab despite potentially unsaved changes?",
1645 JOptionPane.YES_NO_OPTION );
1646 if ( r != JOptionPane.YES_OPTION ) {
1650 getMainPanel().closeCurrentPane();
1651 activateSaveAllIfNeeded();
1655 private void collapse( final Phylogeny phy, final double m ) {
1656 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1657 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1658 double min_support = Double.MAX_VALUE;
1659 boolean conf_present = false;
1660 while ( it.hasNext() ) {
1661 final PhylogenyNode n = it.next();
1662 if ( !n.isExternal() && !n.isRoot() ) {
1663 final List<Confidence> c = n.getBranchData().getConfidences();
1664 if ( ( c != null ) && ( c.size() > 0 ) ) {
1665 conf_present = true;
1667 for( final Confidence confidence : c ) {
1668 if ( confidence.getValue() > max ) {
1669 max = confidence.getValue();
1672 if ( max < getMinNotCollapseConfidenceValue() ) {
1673 to_be_removed.add( n );
1675 if ( max < min_support ) {
1681 if ( conf_present ) {
1682 for( final PhylogenyNode node : to_be_removed ) {
1683 PhylogenyMethods.removeNode( node, phy );
1685 if ( to_be_removed.size() > 0 ) {
1686 phy.externalNodesHaveChanged();
1687 phy.clearHashIdToNodeMap();
1688 phy.recalculateNumberOfExternalDescendants( true );
1689 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1690 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1691 getCurrentTreePanel().calculateLongestExtNodeInfo();
1692 getCurrentTreePanel().setNodeInPreorderToNull();
1693 getCurrentTreePanel().recalculateMaxDistanceToRoot();
1694 getCurrentTreePanel().resetPreferredSize();
1695 getCurrentTreePanel().setEdited( true );
1696 getCurrentTreePanel().repaint();
1699 if ( to_be_removed.size() > 0 ) {
1700 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1701 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1702 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1705 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1706 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1710 JOptionPane.showMessageDialog( this,
1711 "No branch collapsed because no confidence values present",
1712 "No confidence values present",
1713 JOptionPane.INFORMATION_MESSAGE );
1717 private void collapseBelowThreshold() {
1718 if ( getCurrentTreePanel() != null ) {
1719 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1720 if ( ( phy != null ) && !phy.isEmpty() ) {
1721 final String s = ( String ) JOptionPane.showInputDialog( this,
1722 "Please enter the minimum confidence value\n",
1723 "Minimal Confidence Value",
1724 JOptionPane.QUESTION_MESSAGE,
1727 getMinNotCollapseConfidenceValue() );
1728 if ( !ForesterUtil.isEmpty( s ) ) {
1729 boolean success = true;
1731 final String m_str = s.trim();
1732 if ( !ForesterUtil.isEmpty( m_str ) ) {
1734 m = Double.parseDouble( m_str );
1736 catch ( final Exception ex ) {
1743 if ( success && ( m >= 0.0 ) ) {
1744 setMinNotCollapseConfidenceValue( m );
1752 private PhyloXmlParser createPhyloXmlParser() {
1753 PhyloXmlParser xml_parser = null;
1754 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1756 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1758 catch ( final Exception e ) {
1759 JOptionPane.showMessageDialog( this,
1760 e.getLocalizedMessage(),
1761 "failed to create validating XML parser",
1762 JOptionPane.WARNING_MESSAGE );
1765 if ( xml_parser == null ) {
1766 xml_parser = PhyloXmlParser.createPhyloXmlParser();
1771 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1772 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1773 getPhylogeneticInferenceOptions(),
1774 from_unaligned_seqs );
1776 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1777 if ( !from_unaligned_seqs ) {
1778 if ( getMsa() != null ) {
1779 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1780 getPhylogeneticInferenceOptions()
1782 new Thread( inferrer ).start();
1785 JOptionPane.showMessageDialog( this,
1786 "No multiple sequence alignment selected",
1787 "Phylogenetic Inference Not Launched",
1788 JOptionPane.WARNING_MESSAGE );
1792 if ( getSeqs() != null ) {
1793 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1794 getPhylogeneticInferenceOptions()
1796 new Thread( inferrer ).start();
1799 JOptionPane.showMessageDialog( this,
1800 "No input sequences selected",
1801 "Phylogenetic Inference Not Launched",
1802 JOptionPane.WARNING_MESSAGE );
1808 private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
1809 final StringBuilder sb = new StringBuilder();
1810 final StringBuilder sb_failed = new StringBuilder();
1812 int counter_failed = 0;
1813 if ( getCurrentTreePanel() != null ) {
1814 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1815 if ( ( phy != null ) && !phy.isEmpty() ) {
1816 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
1817 while ( it.hasNext() ) {
1818 final PhylogenyNode n = it.next();
1819 final String name = n.getName().trim();
1820 if ( !ForesterUtil.isEmpty( name ) ) {
1821 final String nt = ParserUtils.extractTaxonomyDataFromNodeName( n,
1822 TAXONOMY_EXTRACTION.AGGRESSIVE );
1823 if ( !ForesterUtil.isEmpty( nt ) ) {
1824 if ( counter < 15 ) {
1825 sb.append( name + ": " + nt + "\n" );
1827 else if ( counter == 15 ) {
1828 sb.append( "...\n" );
1833 if ( counter_failed < 15 ) {
1834 sb_failed.append( name + "\n" );
1836 else if ( counter_failed == 15 ) {
1837 sb_failed.append( "...\n" );
1843 if ( counter > 0 ) {
1845 String all = "all ";
1846 if ( counter_failed > 0 ) {
1848 failed = "\nCould not extract taxonomic data for " + counter_failed
1849 + " named external nodes:\n" + sb_failed;
1851 JOptionPane.showMessageDialog( this,
1852 "Extracted taxonomic data from " + all + counter
1853 + " named external nodes:\n" + sb.toString() + failed,
1854 "Taxonomic Data Extraction Completed",
1855 counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
1856 : JOptionPane.INFORMATION_MESSAGE );
1860 .showMessageDialog( this,
1861 "Could not extract any taxonomic data.\nMaybe node names are empty\n"
1862 + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
1863 + "or nodes already have taxonomic data?\n",
1864 "No Taxonomic Data Extracted",
1865 JOptionPane.ERROR_MESSAGE );
1871 private ControlPanel getControlPanel() {
1872 return getMainPanel().getControlPanel();
1875 private File getCurrentDir() {
1876 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1877 if ( ForesterUtil.isWindows() ) {
1879 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1881 catch ( final Exception e ) {
1882 _current_dir = null;
1886 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1887 if ( System.getProperty( "user.home" ) != null ) {
1888 _current_dir = new File( System.getProperty( "user.home" ) );
1890 else if ( System.getProperty( "user.dir" ) != null ) {
1891 _current_dir = new File( System.getProperty( "user.dir" ) );
1894 return _current_dir;
1897 private double getMinNotCollapseConfidenceValue() {
1898 return _min_not_collapse;
1901 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
1902 if ( _phylogenetic_inference_options == null ) {
1903 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
1905 return _phylogenetic_inference_options;
1908 private boolean isUnsavedDataPresent() {
1909 final List<TreePanel> tps = getMainPanel().getTreePanels();
1910 for( final TreePanel tp : tps ) {
1911 if ( tp.isEdited() ) {
1918 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
1919 if ( getCurrentTreePanel() != null ) {
1920 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1921 if ( ( phy != null ) && !phy.isEmpty() ) {
1923 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
1928 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
1929 if ( getCurrentTreePanel() != null ) {
1930 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1931 if ( ( phy != null ) && !phy.isEmpty() ) {
1932 PhylogenyMethods.transferNodeNameToField( phy,
1933 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
1939 private void newTree() {
1940 final Phylogeny[] phys = new Phylogeny[ 1 ];
1941 final Phylogeny phy = new Phylogeny();
1942 final PhylogenyNode node = new PhylogenyNode();
1943 phy.setRoot( node );
1944 phy.setRooted( true );
1946 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1947 _mainpanel.getControlPanel().showWhole();
1948 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1949 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1950 if ( getMainPanel().getMainFrame() == null ) {
1951 // Must be "E" applet version.
1952 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1953 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1956 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1958 activateSaveAllIfNeeded();
1962 private void obtainDetailedTaxonomicInformation() {
1963 if ( getCurrentTreePanel() != null ) {
1964 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1965 if ( ( phy != null ) && !phy.isEmpty() ) {
1966 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1967 _mainpanel.getCurrentTreePanel(),
1971 new Thread( t ).start();
1976 private void obtainDetailedTaxonomicInformationDelete() {
1977 if ( getCurrentTreePanel() != null ) {
1978 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1979 if ( ( phy != null ) && !phy.isEmpty() ) {
1980 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1981 _mainpanel.getCurrentTreePanel(),
1985 new Thread( t ).start();
1990 private void obtainSequenceInformation() {
1991 if ( getCurrentTreePanel() != null ) {
1992 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1993 if ( ( phy != null ) && !phy.isEmpty() ) {
1994 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1995 _mainpanel.getCurrentTreePanel(),
1997 new Thread( u ).start();
2002 private void print() {
2003 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
2004 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
2007 if ( !getOptions().isPrintUsingActualSize() ) {
2008 getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80,
2009 getOptions().getPrintSizeY() - 140,
2011 getCurrentTreePanel().resetPreferredSize();
2012 getCurrentTreePanel().repaint();
2014 final String job_name = Constants.PRG_NAME;
2015 boolean error = false;
2016 String printer_name = null;
2018 printer_name = Printer.print( getCurrentTreePanel(), job_name );
2020 catch ( final Exception e ) {
2022 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2024 if ( !error && ( printer_name != null ) ) {
2025 String msg = "Printing data sent to printer";
2026 if ( printer_name.length() > 1 ) {
2027 msg += " [" + printer_name + "]";
2029 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2031 if ( !getOptions().isPrintUsingActualSize() ) {
2032 getControlPanel().showWhole();
2036 private void printPhylogenyToPdf( final String file_name ) {
2037 if ( !getOptions().isPrintUsingActualSize() ) {
2038 getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(),
2039 getOptions().getPrintSizeY(),
2041 getCurrentTreePanel().resetPreferredSize();
2042 getCurrentTreePanel().repaint();
2044 String pdf_written_to = "";
2045 boolean error = false;
2047 if ( getOptions().isPrintUsingActualSize() ) {
2048 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
2049 getCurrentTreePanel(),
2050 getCurrentTreePanel().getWidth(),
2051 getCurrentTreePanel().getHeight() );
2054 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
2055 .getPrintSizeX(), getOptions().getPrintSizeY() );
2058 catch ( final IOException e ) {
2060 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2063 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2064 JOptionPane.showMessageDialog( this,
2065 "Wrote PDF to: " + pdf_written_to,
2067 JOptionPane.INFORMATION_MESSAGE );
2070 JOptionPane.showMessageDialog( this,
2071 "There was an unknown problem when attempting to write to PDF file: \""
2074 JOptionPane.ERROR_MESSAGE );
2077 if ( !getOptions().isPrintUsingActualSize() ) {
2078 getControlPanel().showWhole();
2082 private void readPhylogeniesFromFile() {
2083 boolean exception = false;
2084 Phylogeny[] phys = null;
2085 // Set an initial directory if none set yet
2086 final File my_dir = getCurrentDir();
2087 _open_filechooser.setMultiSelectionEnabled( true );
2088 // Open file-open dialog and set current directory
2089 if ( my_dir != null ) {
2090 _open_filechooser.setCurrentDirectory( my_dir );
2092 final int result = _open_filechooser.showOpenDialog( _contentpane );
2093 // All done: get the file
2094 final File[] files = _open_filechooser.getSelectedFiles();
2095 setCurrentDir( _open_filechooser.getCurrentDirectory() );
2096 boolean nhx_or_nexus = false;
2097 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2098 for( final File file : files ) {
2099 if ( ( file != null ) && !file.isDirectory() ) {
2100 if ( _mainpanel.getCurrentTreePanel() != null ) {
2101 _mainpanel.getCurrentTreePanel().setWaitCursor();
2104 _mainpanel.setWaitCursor();
2106 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
2107 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
2109 final NHXParser nhx = new NHXParser();
2110 setSpecialOptionsForNhxParser( nhx );
2111 phys = PhylogenyMethods.readPhylogenies( nhx, file );
2112 nhx_or_nexus = true;
2114 catch ( final Exception e ) {
2116 exceptionOccuredDuringOpenFile( e );
2119 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2120 warnIfNotPhyloXmlValidation( getConfiguration() );
2122 final PhyloXmlParser xml_parser = createPhyloXmlParser();
2123 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
2125 catch ( final Exception e ) {
2127 exceptionOccuredDuringOpenFile( e );
2130 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
2132 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2134 catch ( final Exception e ) {
2136 exceptionOccuredDuringOpenFile( e );
2139 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2141 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
2142 setSpecialOptionsForNexParser( nex );
2143 phys = PhylogenyMethods.readPhylogenies( nex, file );
2144 nhx_or_nexus = true;
2146 catch ( final Exception e ) {
2148 exceptionOccuredDuringOpenFile( e );
2154 final PhylogenyParser parser = ParserUtils
2155 .createParserDependingOnFileType( file, getConfiguration()
2156 .isValidatePhyloXmlAgainstSchema() );
2157 if ( parser instanceof NexusPhylogeniesParser ) {
2158 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
2159 setSpecialOptionsForNexParser( nex );
2160 nhx_or_nexus = true;
2162 else if ( parser instanceof NHXParser ) {
2163 final NHXParser nhx = ( NHXParser ) parser;
2164 setSpecialOptionsForNhxParser( nhx );
2165 nhx_or_nexus = true;
2167 else if ( parser instanceof PhyloXmlParser ) {
2168 warnIfNotPhyloXmlValidation( getConfiguration() );
2170 phys = PhylogenyMethods.readPhylogenies( parser, file );
2172 catch ( final Exception e ) {
2174 exceptionOccuredDuringOpenFile( e );
2177 if ( _mainpanel.getCurrentTreePanel() != null ) {
2178 _mainpanel.getCurrentTreePanel().setArrowCursor();
2181 _mainpanel.setArrowCursor();
2183 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
2184 boolean one_desc = false;
2185 if ( nhx_or_nexus ) {
2186 for( final Phylogeny phy : phys ) {
2187 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2188 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
2190 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
2196 AptxUtil.addPhylogeniesToTabs( phys,
2198 file.getAbsolutePath(),
2201 _mainpanel.getControlPanel().showWhole();
2202 if ( nhx_or_nexus && one_desc ) {
2204 .showMessageDialog( this,
2205 "One or more trees contain (a) node(s) with one descendant, "
2206 + ForesterUtil.LINE_SEPARATOR
2207 + "possibly indicating illegal parentheses within node names.",
2208 "Warning: Possible Error in New Hampshire Formatted Data",
2209 JOptionPane.WARNING_MESSAGE );
2215 activateSaveAllIfNeeded();
2219 private void readSpeciesTreeFromFile() {
2221 boolean exception = false;
2222 final File my_dir = getCurrentDir();
2223 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2224 if ( my_dir != null ) {
2225 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2227 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2228 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2229 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2230 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2232 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser
2233 .createPhyloXmlParserXsdValidating(), file );
2236 catch ( final Exception e ) {
2238 exceptionOccuredDuringOpenFile( e );
2241 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2243 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2246 catch ( final Exception e ) {
2248 exceptionOccuredDuringOpenFile( e );
2254 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser
2255 .createPhyloXmlParserXsdValidating(), file );
2258 catch ( final Exception e ) {
2260 exceptionOccuredDuringOpenFile( e );
2263 if ( !exception && ( t != null ) && !t.isRooted() ) {
2266 JOptionPane.showMessageDialog( this,
2267 "Species tree is not rooted",
2268 "Species tree not loaded",
2269 JOptionPane.ERROR_MESSAGE );
2271 if ( !exception && ( t != null ) ) {
2272 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2273 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2274 final PhylogenyNode node = it.next();
2275 if ( !node.getNodeData().isHasTaxonomy() ) {
2279 .showMessageDialog( this,
2280 "Species tree contains external node(s) without taxonomy information",
2281 "Species tree not loaded",
2282 JOptionPane.ERROR_MESSAGE );
2286 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2289 JOptionPane.showMessageDialog( this,
2291 + node.getNodeData().getTaxonomy().asSimpleText()
2292 + "] is not unique in species tree",
2293 "Species tree not loaded",
2294 JOptionPane.ERROR_MESSAGE );
2298 tax_set.add( node.getNodeData().getTaxonomy() );
2303 if ( !exception && ( t != null ) ) {
2304 setSpeciesTree( t );
2305 JOptionPane.showMessageDialog( this,
2306 "Species tree successfully loaded",
2307 "Species tree loaded",
2308 JOptionPane.INFORMATION_MESSAGE );
2310 _contentpane.repaint();
2315 private void setArrowCursor() {
2317 _mainpanel.getCurrentTreePanel().setArrowCursor();
2319 catch ( final Exception ex ) {
2324 private void setCurrentDir( final File current_dir ) {
2325 _current_dir = current_dir;
2328 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2329 _min_not_collapse = min_not_collapse;
2332 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2333 _phylogenetic_inference_options = phylogenetic_inference_options;
2336 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2337 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2338 nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2341 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2342 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2343 nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2346 private void writeAllToFile() {
2347 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2350 final File my_dir = getCurrentDir();
2351 if ( my_dir != null ) {
2352 _save_filechooser.setCurrentDirectory( my_dir );
2354 _save_filechooser.setSelectedFile( new File( "" ) );
2355 final int result = _save_filechooser.showSaveDialog( _contentpane );
2356 final File file = _save_filechooser.getSelectedFile();
2357 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2358 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2359 if ( file.exists() ) {
2360 final int i = JOptionPane.showConfirmDialog( this,
2361 file + " already exists. Overwrite?",
2363 JOptionPane.OK_CANCEL_OPTION,
2364 JOptionPane.WARNING_MESSAGE );
2365 if ( i != JOptionPane.OK_OPTION ) {
2372 catch ( final Exception e ) {
2373 JOptionPane.showMessageDialog( this,
2374 "Failed to delete: " + file,
2376 JOptionPane.WARNING_MESSAGE );
2380 final int count = getMainPanel().getTabbedPane().getTabCount();
2381 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2382 for( int i = 0; i < count; ++i ) {
2383 final Phylogeny phy = getMainPanel().getPhylogeny( i );
2384 if ( ForesterUtil.isEmpty( phy.getName() )
2385 && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {
2386 phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );
2389 getMainPanel().getTreePanels().get( i ).setEdited( false );
2391 final PhylogenyWriter writer = new PhylogenyWriter();
2393 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2395 catch ( final IOException e ) {
2396 JOptionPane.showMessageDialog( this,
2397 "Failed to write to: " + file,
2399 JOptionPane.WARNING_MESSAGE );
2404 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2406 final PhylogenyWriter writer = new PhylogenyWriter();
2407 writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
2409 catch ( final Exception e ) {
2411 exceptionOccuredDuringSaveAs( e );
2416 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2418 final PhylogenyWriter writer = new PhylogenyWriter();
2419 writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
2421 catch ( final Exception e ) {
2423 exceptionOccuredDuringSaveAs( e );
2428 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2430 final PhylogenyWriter writer = new PhylogenyWriter();
2431 writer.toPhyloXML( file, t, 0 );
2433 catch ( final Exception e ) {
2435 exceptionOccuredDuringSaveAs( e );
2440 private void writeToFile( final Phylogeny t ) {
2444 String initial_filename = null;
2445 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2447 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2449 catch ( final IOException e ) {
2450 initial_filename = null;
2453 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2454 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2457 _save_filechooser.setSelectedFile( new File( "" ) );
2459 final File my_dir = getCurrentDir();
2460 if ( my_dir != null ) {
2461 _save_filechooser.setCurrentDirectory( my_dir );
2463 final int result = _save_filechooser.showSaveDialog( _contentpane );
2464 final File file = _save_filechooser.getSelectedFile();
2465 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2466 boolean exception = false;
2467 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2468 if ( file.exists() ) {
2469 final int i = JOptionPane.showConfirmDialog( this,
2470 file + " already exists.\nOverwrite?",
2472 JOptionPane.OK_CANCEL_OPTION,
2473 JOptionPane.QUESTION_MESSAGE );
2474 if ( i != JOptionPane.OK_OPTION ) {
2478 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2480 ForesterUtil.copyFile( file, to );
2482 catch ( final Exception e ) {
2483 JOptionPane.showMessageDialog( this,
2484 "Failed to create backup copy " + to,
2485 "Failed to Create Backup Copy",
2486 JOptionPane.WARNING_MESSAGE );
2491 catch ( final Exception e ) {
2492 JOptionPane.showMessageDialog( this,
2493 "Failed to delete: " + file,
2495 JOptionPane.WARNING_MESSAGE );
2499 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2500 exception = writeAsNewHampshire( t, exception, file );
2502 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2503 exception = writeAsPhyloXml( t, exception, file );
2505 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2506 exception = writeAsNexus( t, exception, file );
2510 final String file_name = file.getName().trim().toLowerCase();
2511 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2512 || file_name.endsWith( ".tree" ) ) {
2513 exception = writeAsNewHampshire( t, exception, file );
2515 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2516 exception = writeAsNexus( t, exception, file );
2520 exception = writeAsPhyloXml( t, exception, file );
2524 getMainPanel().setTitleOfSelectedTab( file.getName() );
2525 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2526 getMainPanel().getCurrentTreePanel().setEdited( false );
2531 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2532 if ( ( t == null ) || t.isEmpty() ) {
2535 String initial_filename = "";
2536 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2537 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2539 if ( initial_filename.indexOf( '.' ) > 0 ) {
2540 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2542 initial_filename = initial_filename + "." + type;
2543 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2544 final File my_dir = getCurrentDir();
2545 if ( my_dir != null ) {
2546 _writetographics_filechooser.setCurrentDirectory( my_dir );
2548 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2549 File file = _writetographics_filechooser.getSelectedFile();
2550 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2551 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2552 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2553 file = new File( file.toString() + "." + type );
2555 if ( file.exists() ) {
2556 final int i = JOptionPane.showConfirmDialog( this,
2557 file + " already exists. Overwrite?",
2559 JOptionPane.OK_CANCEL_OPTION,
2560 JOptionPane.WARNING_MESSAGE );
2561 if ( i != JOptionPane.OK_OPTION ) {
2568 catch ( final Exception e ) {
2569 JOptionPane.showMessageDialog( this,
2570 "Failed to delete: " + file,
2572 JOptionPane.WARNING_MESSAGE );
2576 writePhylogenyToGraphicsFile( file.toString(), type );
2580 private void writeToPdf( final Phylogeny t ) {
2581 if ( ( t == null ) || t.isEmpty() ) {
2584 String initial_filename = "";
2585 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2586 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2588 if ( initial_filename.indexOf( '.' ) > 0 ) {
2589 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2591 initial_filename = initial_filename + ".pdf";
2592 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2593 final File my_dir = getCurrentDir();
2594 if ( my_dir != null ) {
2595 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2597 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2598 File file = _writetopdf_filechooser.getSelectedFile();
2599 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2600 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2601 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2602 file = new File( file.toString() + ".pdf" );
2604 if ( file.exists() ) {
2605 final int i = JOptionPane.showConfirmDialog( this,
2606 file + " already exists. Overwrite?",
2608 JOptionPane.OK_CANCEL_OPTION,
2609 JOptionPane.WARNING_MESSAGE );
2610 if ( i != JOptionPane.OK_OPTION ) {
2614 printPhylogenyToPdf( file.toString() );
2618 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
2619 return new MainFrameApplication( phys, config );
2622 public static MainFrame createInstance( final Phylogeny[] phys,
2623 final Configuration config,
2625 final File current_dir ) {
2626 return new MainFrameApplication( phys, config, title, current_dir );
2629 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2630 return new MainFrameApplication( phys, config, title );
2633 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2634 return new MainFrameApplication( phys, config_file_name, title );
2637 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2638 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2639 + o.getPrintSizeY() + ")" );
2642 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2643 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2646 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2647 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2649 .showMessageDialog( null,
2651 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2654 JOptionPane.WARNING_MESSAGE );
2657 } // MainFrameApplication.
2659 class DefaultFilter extends FileFilter {
2662 public boolean accept( final File f ) {
2663 final String file_name = f.getName().trim().toLowerCase();
2664 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2665 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2666 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2667 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2668 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2669 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2670 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2671 || file_name.endsWith( ".con" ) || f.isDirectory();
2675 public String getDescription() {
2676 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2680 class GraphicsFileFilter extends FileFilter {
2683 public boolean accept( final File f ) {
2684 final String file_name = f.getName().trim().toLowerCase();
2685 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2686 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2690 public String getDescription() {
2691 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2695 class MsaFileFilter extends FileFilter {
2698 public boolean accept( final File f ) {
2699 final String file_name = f.getName().trim().toLowerCase();
2700 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2701 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2705 public String getDescription() {
2706 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2710 class NexusFilter extends FileFilter {
2713 public boolean accept( final File f ) {
2714 final String file_name = f.getName().trim().toLowerCase();
2715 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2716 || file_name.endsWith( ".tre" ) || f.isDirectory();
2720 public String getDescription() {
2721 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2725 class NHFilter extends FileFilter {
2728 public boolean accept( final File f ) {
2729 final String file_name = f.getName().trim().toLowerCase();
2730 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2731 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2732 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2737 public String getDescription() {
2738 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2742 class NHXFilter extends FileFilter {
2745 public boolean accept( final File f ) {
2746 final String file_name = f.getName().trim().toLowerCase();
2747 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2751 public String getDescription() {
2752 return "NHX files (*.nhx) [deprecated]";
2756 class PdfFilter extends FileFilter {
2759 public boolean accept( final File f ) {
2760 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2764 public String getDescription() {
2765 return "PDF files (*.pdf)";
2769 class SequencesFileFilter extends FileFilter {
2772 public boolean accept( final File f ) {
2773 final String file_name = f.getName().trim().toLowerCase();
2774 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2775 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2779 public String getDescription() {
2780 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2784 class TolFilter extends FileFilter {
2787 public boolean accept( final File f ) {
2788 final String file_name = f.getName().trim().toLowerCase();
2789 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2790 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2794 public String getDescription() {
2795 return "Tree of Life files (*.tol, *.tolxml)";
2799 class XMLFilter extends FileFilter {
2802 public boolean accept( final File f ) {
2803 final String file_name = f.getName().trim().toLowerCase();
2804 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2805 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2809 public String getDescription() {
2810 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";