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.GoAnnotation;
70 import org.forester.archaeopteryx.tools.InferenceManager;
71 import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
72 import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
73 import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
74 import org.forester.archaeopteryx.tools.SequenceDataRetriver;
75 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
76 import org.forester.archaeopteryx.webservices.WebservicesManager;
77 import org.forester.io.parsers.FastaParser;
78 import org.forester.io.parsers.GeneralMsaParser;
79 import org.forester.io.parsers.PhylogenyParser;
80 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
81 import org.forester.io.parsers.nhx.NHXParser;
82 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
83 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
84 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
85 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
86 import org.forester.io.parsers.tol.TolParser;
87 import org.forester.io.parsers.util.ParserUtils;
88 import org.forester.io.writers.PhylogenyWriter;
89 import org.forester.io.writers.SequenceWriter;
90 import org.forester.msa.Msa;
91 import org.forester.msa.MsaFormatException;
92 import org.forester.phylogeny.Phylogeny;
93 import org.forester.phylogeny.PhylogenyMethods;
94 import org.forester.phylogeny.PhylogenyNode;
95 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
96 import org.forester.phylogeny.data.Confidence;
97 import org.forester.phylogeny.data.Taxonomy;
98 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
99 import org.forester.phylogeny.factories.PhylogenyFactory;
100 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
101 import org.forester.sequence.Sequence;
102 import org.forester.util.BasicDescriptiveStatistics;
103 import org.forester.util.BasicTable;
104 import org.forester.util.BasicTableParser;
105 import org.forester.util.DescriptiveStatistics;
106 import org.forester.util.ForesterUtil;
107 import org.forester.util.WindowsUtils;
109 public final class MainFrameApplication extends MainFrame {
111 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
112 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
113 private final static int FRAME_X_SIZE = 800;
114 private final static int FRAME_Y_SIZE = 800;
115 // Filters for the file-open dialog (classes defined in this file)
116 private final static NHFilter nhfilter = new NHFilter();
117 private final static NHXFilter nhxfilter = new NHXFilter();
118 private final static XMLFilter xmlfilter = new XMLFilter();
119 private final static TolFilter tolfilter = new TolFilter();
120 private final static NexusFilter nexusfilter = new NexusFilter();
121 private final static PdfFilter pdffilter = new PdfFilter();
122 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
123 private final static MsaFileFilter msafilter = new MsaFileFilter();
124 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
125 private final static DefaultFilter defaultfilter = new DefaultFilter();
126 private static final long serialVersionUID = -799735726778865234L;
127 private final JFileChooser _values_filechooser;
128 private final JFileChooser _sequences_filechooser;
129 private final JFileChooser _open_filechooser;
130 private final JFileChooser _msa_filechooser;
131 private final JFileChooser _seqs_pi_filechooser;
132 private final JFileChooser _open_filechooser_for_species_tree;
133 private final JFileChooser _save_filechooser;
134 private final JFileChooser _writetopdf_filechooser;
135 private final JFileChooser _writetographics_filechooser;
136 // Application-only print menu items
137 private JMenuItem _print_item;
138 private JMenuItem _write_to_pdf_item;
139 private JMenuItem _write_to_jpg_item;
140 private JMenuItem _write_to_gif_item;
141 private JMenuItem _write_to_tif_item;
142 private JMenuItem _write_to_png_item;
143 private JMenuItem _write_to_bmp_item;
144 private File _current_dir;
145 private ButtonGroup _radio_group_1;
146 private ButtonGroup _radio_group_2;
148 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
149 // Phylogeny Inference menu
150 private JMenu _inference_menu;
151 private JMenuItem _inference_from_msa_item;
152 private JMenuItem _inference_from_seqs_item;
153 // Phylogeny Inference
154 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
155 private Msa _msa = null;
156 private File _msa_file = null;
157 private List<Sequence> _seqs = null;
158 private File _seqs_file = null;
159 JMenuItem _read_values_jmi;
160 JMenuItem _read_seqs_jmi;
162 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
163 _configuration = config;
164 if ( _configuration == null ) {
165 throw new IllegalArgumentException( "configuration is null" );
168 setOptions( Options.createInstance( _configuration ) );
169 _mainpanel = new MainPanel( _configuration, this );
170 _open_filechooser = null;
171 _open_filechooser_for_species_tree = null;
172 _save_filechooser = null;
173 _writetopdf_filechooser = null;
174 _writetographics_filechooser = null;
175 _msa_filechooser = null;
176 _seqs_pi_filechooser = null;
177 _values_filechooser = null;
178 _sequences_filechooser = null;
179 _jmenubar = new JMenuBar();
182 _contentpane = getContentPane();
183 _contentpane.setLayout( new BorderLayout() );
184 _contentpane.add( _mainpanel, BorderLayout.CENTER );
186 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
187 // The window listener
188 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
189 addWindowListener( new WindowAdapter() {
192 public void windowClosing( final WindowEvent e ) {
196 // setVisible( true );
197 if ( ( phys != null ) && ( phys.length > 0 ) ) {
198 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
200 getMainPanel().getControlPanel().showWholeAll();
201 getMainPanel().getControlPanel().showWhole();
203 //activateSaveAllIfNeeded();
204 // ...and its children
205 _contentpane.repaint();
208 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
209 this( phys, config, title, null );
212 private MainFrameApplication( final Phylogeny[] phys,
213 final Configuration config,
215 final File current_dir ) {
217 _configuration = config;
218 if ( _configuration == null ) {
219 throw new IllegalArgumentException( "configuration is null" );
222 boolean synth_exception = false;
223 if ( Constants.__SYNTH_LF ) {
225 final SynthLookAndFeel synth = new SynthLookAndFeel();
226 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
227 MainFrameApplication.class );
228 UIManager.setLookAndFeel( synth );
230 catch ( final Exception ex ) {
231 synth_exception = true;
232 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
233 "could not create synth look and feel: "
234 + ex.getLocalizedMessage() );
237 if ( !Constants.__SYNTH_LF || synth_exception ) {
238 if ( _configuration.isUseNativeUI() ) {
239 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
242 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
245 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
247 catch ( final UnsupportedLookAndFeelException e ) {
248 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
250 catch ( final ClassNotFoundException e ) {
251 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
253 catch ( final InstantiationException e ) {
254 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
256 catch ( final IllegalAccessException e ) {
257 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
259 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
260 setCurrentDir( current_dir );
262 // hide until everything is ready
264 setOptions( Options.createInstance( _configuration ) );
265 setInferenceManager( InferenceManager.createInstance( _configuration ) );
266 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
267 // _textframe = null; #~~~~
269 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
270 _mainpanel = new MainPanel( _configuration, this );
272 _open_filechooser = new JFileChooser();
273 _open_filechooser.setCurrentDirectory( new File( "." ) );
274 _open_filechooser.setMultiSelectionEnabled( false );
275 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
276 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
277 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
278 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
279 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
280 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
281 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
282 _open_filechooser_for_species_tree = new JFileChooser();
283 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
284 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
285 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
286 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
287 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
288 _save_filechooser = new JFileChooser();
289 _save_filechooser.setCurrentDirectory( new File( "." ) );
290 _save_filechooser.setMultiSelectionEnabled( false );
291 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
292 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
293 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
294 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
295 _writetopdf_filechooser = new JFileChooser();
296 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
297 _writetographics_filechooser = new JFileChooser();
298 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
300 _msa_filechooser = new JFileChooser();
301 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
302 _msa_filechooser.setCurrentDirectory( new File( "." ) );
303 _msa_filechooser.setMultiSelectionEnabled( false );
304 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
305 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
307 _seqs_pi_filechooser = new JFileChooser();
308 _seqs_pi_filechooser.setName( "Read Sequences File" );
309 _seqs_pi_filechooser.setCurrentDirectory( new File( "." ) );
310 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
311 _seqs_pi_filechooser.addChoosableFileFilter( _seqs_pi_filechooser.getAcceptAllFileFilter() );
312 _seqs_pi_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
314 _values_filechooser = new JFileChooser();
315 _values_filechooser.setCurrentDirectory( new File( "." ) );
316 _values_filechooser.setMultiSelectionEnabled( false );
318 _sequences_filechooser = new JFileChooser();
319 _sequences_filechooser.setCurrentDirectory( new File( "." ) );
320 _sequences_filechooser.setMultiSelectionEnabled( false );
321 // build the menu bar
322 _jmenubar = new JMenuBar();
323 if ( !_configuration.isUseNativeUI() ) {
324 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
327 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
328 buildPhylogeneticInferenceMenu();
337 setJMenuBar( _jmenubar );
338 _jmenubar.add( _help_jmenu );
339 _contentpane = getContentPane();
340 _contentpane.setLayout( new BorderLayout() );
341 _contentpane.add( _mainpanel, BorderLayout.CENTER );
343 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
344 // addWindowFocusListener( new WindowAdapter() {
347 // public void windowGainedFocus( WindowEvent e ) {
348 // requestFocusInWindow();
351 // The window listener
352 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
353 addWindowListener( new WindowAdapter() {
356 public void windowClosing( final WindowEvent e ) {
357 if ( isUnsavedDataPresent() ) {
358 final int r = JOptionPane.showConfirmDialog( null,
359 "Exit despite potentially unsaved changes?",
361 JOptionPane.YES_NO_OPTION );
362 if ( r != JOptionPane.YES_OPTION ) {
367 final int r = JOptionPane.showConfirmDialog( null,
368 "Exit Archaeopteryx?",
370 JOptionPane.YES_NO_OPTION );
371 if ( r != JOptionPane.YES_OPTION ) {
378 // The component listener
379 addComponentListener( new ComponentAdapter() {
382 public void componentResized( final ComponentEvent e ) {
383 if ( _mainpanel.getCurrentTreePanel() != null ) {
384 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel()
386 _mainpanel.getCurrentTreePanel()
388 getOptions().isAllowFontSizeChange() );
392 requestFocusInWindow();
393 // addKeyListener( this );
395 if ( ( phys != null ) && ( phys.length > 0 ) ) {
396 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
398 getMainPanel().getControlPanel().showWholeAll();
399 getMainPanel().getControlPanel().showWhole();
401 activateSaveAllIfNeeded();
402 // ...and its children
403 _contentpane.repaint();
407 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
408 // Reads the config file (false, false => not url, not applet):
409 this( phys, new Configuration( config_file, false, false, true ), title );
413 public void actionPerformed( final ActionEvent e ) {
415 super.actionPerformed( e );
416 final Object o = e.getSource();
417 // Handle app-specific actions here:
418 if ( o == _open_item ) {
419 readPhylogeniesFromFile();
421 else if ( o == _save_item ) {
422 writeToFile( _mainpanel.getCurrentPhylogeny() );
423 // If subtree currently displayed, save it, instead of complete
426 else if ( o == _new_item ) {
429 else if ( o == _save_all_item ) {
432 else if ( o == _close_item ) {
435 else if ( o == _write_to_pdf_item ) {
436 writeToPdf( _mainpanel.getCurrentPhylogeny() );
438 else if ( o == _write_to_jpg_item ) {
439 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
441 else if ( o == _write_to_png_item ) {
442 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
444 else if ( o == _write_to_gif_item ) {
445 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
447 else if ( o == _write_to_tif_item ) {
448 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
450 else if ( o == _write_to_bmp_item ) {
451 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
453 else if ( o == _print_item ) {
456 else if ( o == _load_species_tree_item ) {
457 readSpeciesTreeFromFile();
459 else if ( o == _lineage_inference ) {
460 if ( isSubtreeDisplayed() ) {
461 JOptionPane.showMessageDialog( this,
463 "Cannot infer ancestral taxonomies",
464 JOptionPane.ERROR_MESSAGE );
467 executeLineageInference();
469 else if ( o == _function_analysis ) {
470 executeFunctionAnalysis();
472 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
473 if ( isSubtreeDisplayed() ) {
476 obtainDetailedTaxonomicInformation();
478 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
479 if ( isSubtreeDisplayed() ) {
482 obtainDetailedTaxonomicInformationDelete();
484 else if ( o == _obtain_seq_information_jmi ) {
485 obtainSequenceInformation();
487 else if ( o == _read_values_jmi ) {
488 if ( isSubtreeDisplayed() ) {
491 addExpressionValuesFromFile();
493 else if ( o == _read_seqs_jmi ) {
494 if ( isSubtreeDisplayed() ) {
497 addSequencesFromFile();
499 else if ( o == _move_node_names_to_tax_sn_jmi ) {
500 moveNodeNamesToTaxSn();
502 else if ( o == _move_node_names_to_seq_names_jmi ) {
503 moveNodeNamesToSeqNames();
505 else if ( o == _extract_tax_code_from_node_names_jmi ) {
506 extractTaxDataFromNodeNames();
508 else if ( o == _graphics_export_visible_only_cbmi ) {
509 updateOptions( getOptions() );
511 else if ( o == _antialias_print_cbmi ) {
512 updateOptions( getOptions() );
514 else if ( o == _print_black_and_white_cbmi ) {
515 updateOptions( getOptions() );
517 else if ( o == _print_using_actual_size_cbmi ) {
518 updateOptions( getOptions() );
520 else if ( o == _graphics_export_using_actual_size_cbmi ) {
521 updateOptions( getOptions() );
523 else if ( o == _print_size_mi ) {
526 else if ( o == _choose_pdf_width_mi ) {
529 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
530 updateOptions( getOptions() );
532 else if ( o == _replace_underscores_cbmi ) {
533 if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
534 _extract_taxonomy_no_rbmi.setSelected( true );
536 updateOptions( getOptions() );
538 else if ( o == _collapse_below_threshold ) {
539 if ( isSubtreeDisplayed() ) {
542 collapseBelowThreshold();
544 else if ( ( o == _extract_taxonomy_pfam_rbmi ) || ( o == _extract_taxonomy_yes_rbmi ) ) {
545 if ( _replace_underscores_cbmi != null ) {
546 _replace_underscores_cbmi.setSelected( false );
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 );
887 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
888 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
890 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
891 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_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 ) );
897 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
898 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
899 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
900 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
901 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
902 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
903 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
904 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
905 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
906 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
907 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
908 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
909 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
911 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
912 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
913 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
914 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
915 _options_jmenu.addSeparator();
916 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
917 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
918 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
919 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
920 _options_jmenu.addSeparator();
921 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
922 getConfiguration() ) );
923 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
924 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
926 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
928 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
930 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
931 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
932 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
933 _options_jmenu.addSeparator();
934 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
936 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
937 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
939 _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
941 .add( _extract_taxonomy_pfam_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Pfam-style Node Names" ) );
942 _extract_taxonomy_pfam_rbmi
943 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE/134-298\"" );
945 .add( _extract_taxonomy_yes_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Node Names" ) );
946 _extract_taxonomy_yes_rbmi
947 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE\" or \"BCL2_MOUSE B-cell lymphoma 2...\"" );
948 _radio_group_2 = new ButtonGroup();
949 _radio_group_2.add( _extract_taxonomy_no_rbmi );
950 _radio_group_2.add( _extract_taxonomy_pfam_rbmi );
951 _radio_group_2.add( _extract_taxonomy_yes_rbmi );
953 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
955 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
956 _use_brackets_for_conf_in_nh_export_cbmi
957 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
959 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
960 customizeJMenuItem( _choose_font_mi );
961 customizeJMenuItem( _choose_minimal_confidence_mi );
962 customizeJMenuItem( _switch_colors_mi );
963 customizeJMenuItem( _print_size_mi );
964 customizeJMenuItem( _choose_pdf_width_mi );
965 customizeJMenuItem( _overview_placment_mi );
966 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
967 .isShowDefaultNodeShapesExternal() );
968 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
969 .isShowDefaultNodeShapesInternal() );
970 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
971 customizeJMenuItem( _cycle_node_shape_mi );
972 customizeJMenuItem( _cycle_node_fill_mi );
973 customizeJMenuItem( _choose_node_size_mi );
974 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
975 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
976 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
977 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
978 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
979 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
980 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
981 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
982 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
983 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
984 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
985 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
986 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
987 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
988 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
989 customizeCheckBoxMenuItem( _label_direction_cbmi,
990 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
991 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
992 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
993 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
994 .isInternalNumberAreConfidenceForNhParsing() );
995 customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
996 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
997 customizeRadioButtonMenuItem( _extract_taxonomy_yes_rbmi,
998 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
999 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_rbmi,
1000 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1001 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
1002 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1003 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1004 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
1005 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
1006 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
1007 .isGraphicsExportUsingActualSize() );
1008 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1009 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
1010 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1011 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
1012 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1013 _jmenubar.add( _options_jmenu );
1016 void buildPhylogeneticInferenceMenu() {
1017 final InferenceManager im = getInferenceManager();
1018 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
1019 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
1020 customizeJMenuItem( _inference_from_msa_item );
1021 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
1022 if ( im.canDoMsa() ) {
1023 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
1024 customizeJMenuItem( _inference_from_seqs_item );
1025 _inference_from_seqs_item
1026 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
1030 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
1031 customizeJMenuItem( _inference_from_seqs_item );
1032 _inference_from_seqs_item.setEnabled( false );
1034 _jmenubar.add( _inference_menu );
1037 void buildToolsMenu() {
1038 _tools_menu = createMenu( "Tools", getConfiguration() );
1039 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1040 customizeJMenuItem( _confcolor_item );
1041 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
1042 customizeJMenuItem( _color_rank_jmi );
1043 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
1044 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1045 customizeJMenuItem( _taxcolor_item );
1046 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
1047 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
1048 customizeJMenuItem( _remove_branch_color_item );
1049 _tools_menu.addSeparator();
1050 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
1051 customizeJMenuItem( _annotate_item );
1052 _tools_menu.addSeparator();
1053 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1054 customizeJMenuItem( _midpoint_root_item );
1055 _tools_menu.addSeparator();
1056 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1057 customizeJMenuItem( _collapse_species_specific_subtrees );
1059 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
1060 customizeJMenuItem( _collapse_below_threshold );
1061 _collapse_below_threshold
1062 .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)" );
1063 _tools_menu.addSeparator();
1065 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );
1066 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
1067 _extract_tax_code_from_node_names_jmi
1068 .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'" );
1070 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
1071 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
1072 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
1073 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
1074 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
1075 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
1076 _tools_menu.addSeparator();
1078 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
1079 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
1080 _obtain_detailed_taxonomic_information_jmi
1081 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
1083 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
1084 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
1085 _obtain_detailed_taxonomic_information_deleting_jmi
1086 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
1087 _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
1088 customizeJMenuItem( _obtain_seq_information_jmi );
1089 _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
1090 _tools_menu.addSeparator();
1091 if ( !Constants.__RELEASE ) {
1092 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
1093 customizeJMenuItem( _function_analysis );
1095 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
1096 _tools_menu.addSeparator();
1098 _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) );
1099 customizeJMenuItem( _read_values_jmi );
1100 _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" );
1101 _jmenubar.add( _tools_menu );
1102 _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) );
1103 customizeJMenuItem( _read_seqs_jmi );
1105 .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" );
1106 _jmenubar.add( _tools_menu );
1111 if ( isUnsavedDataPresent() ) {
1112 final int r = JOptionPane.showConfirmDialog( this,
1113 "Exit despite potentially unsaved changes?",
1115 JOptionPane.YES_NO_OPTION );
1116 if ( r != JOptionPane.YES_OPTION ) {
1123 void executeFunctionAnalysis() {
1124 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1127 final GoAnnotation a = new GoAnnotation( this,
1128 _mainpanel.getCurrentTreePanel(),
1129 _mainpanel.getCurrentPhylogeny() );
1130 new Thread( a ).start();
1133 void executeLineageInference() {
1134 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1137 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1138 JOptionPane.showMessageDialog( this,
1139 "Phylogeny is not rooted.",
1140 "Cannot infer ancestral taxonomies",
1141 JOptionPane.ERROR_MESSAGE );
1144 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1145 _mainpanel.getCurrentTreePanel(),
1146 _mainpanel.getCurrentPhylogeny()
1148 new Thread( inferrer ).start();
1152 removeAllTextFrames();
1153 _mainpanel.terminate();
1154 _contentpane.removeAll();
1155 setVisible( false );
1161 void readPhylogeniesFromURL() {
1163 Phylogeny[] phys = null;
1164 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1165 final String url_string = JOptionPane.showInputDialog( this,
1167 "Use URL/webservice to obtain a phylogeny",
1168 JOptionPane.QUESTION_MESSAGE );
1169 boolean nhx_or_nexus = false;
1170 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1172 url = new URL( url_string );
1173 PhylogenyParser parser = null;
1174 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1175 parser = new TolParser();
1178 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
1179 .isValidatePhyloXmlAgainstSchema() );
1181 if ( parser instanceof NexusPhylogeniesParser ) {
1182 nhx_or_nexus = true;
1184 else if ( parser instanceof NHXParser ) {
1185 nhx_or_nexus = true;
1187 if ( _mainpanel.getCurrentTreePanel() != null ) {
1188 _mainpanel.getCurrentTreePanel().setWaitCursor();
1191 _mainpanel.setWaitCursor();
1193 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1194 phys = factory.create( url.openStream(), parser );
1196 catch ( final MalformedURLException e ) {
1197 JOptionPane.showMessageDialog( this,
1198 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1200 JOptionPane.ERROR_MESSAGE );
1202 catch ( final IOException e ) {
1203 JOptionPane.showMessageDialog( this,
1204 "Could not read from " + url + "\n"
1205 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1206 "Failed to read URL",
1207 JOptionPane.ERROR_MESSAGE );
1209 catch ( final Exception e ) {
1210 JOptionPane.showMessageDialog( this,
1211 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1212 "Unexpected Exception",
1213 JOptionPane.ERROR_MESSAGE );
1216 if ( _mainpanel.getCurrentTreePanel() != null ) {
1217 _mainpanel.getCurrentTreePanel().setArrowCursor();
1220 _mainpanel.setArrowCursor();
1223 if ( ( phys != null ) && ( phys.length > 0 ) ) {
1224 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1225 for( final Phylogeny phy : phys ) {
1226 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
1229 AptxUtil.addPhylogeniesToTabs( phys,
1230 new File( url.getFile() ).getName(),
1231 new File( url.getFile() ).toString(),
1234 _mainpanel.getControlPanel().showWhole();
1237 activateSaveAllIfNeeded();
1241 void setMsa( final Msa msa ) {
1245 void setMsaFile( final File msa_file ) {
1246 _msa_file = msa_file;
1249 void setSeqs( final List<Sequence> seqs ) {
1253 void setSeqsFile( final File seqs_file ) {
1254 _seqs_file = seqs_file;
1257 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
1258 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
1259 _mainpanel.getCurrentTreePanel().getHeight(),
1261 String file_written_to = "";
1262 boolean error = false;
1264 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
1265 _mainpanel.getCurrentTreePanel().getWidth(),
1266 _mainpanel.getCurrentTreePanel().getHeight(),
1267 _mainpanel.getCurrentTreePanel(),
1268 _mainpanel.getControlPanel(),
1272 catch ( final IOException e ) {
1274 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1277 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
1278 JOptionPane.showMessageDialog( this,
1279 "Wrote image to: " + file_written_to,
1281 JOptionPane.INFORMATION_MESSAGE );
1284 JOptionPane.showMessageDialog( this,
1285 "There was an unknown problem when attempting to write to an image file: \""
1288 JOptionPane.ERROR_MESSAGE );
1291 _contentpane.repaint();
1294 private void addExpressionValuesFromFile() {
1295 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1296 JOptionPane.showMessageDialog( this,
1297 "Need to load evolutionary tree first",
1298 "Can Not Read Expression Values",
1299 JOptionPane.WARNING_MESSAGE );
1302 final File my_dir = getCurrentDir();
1303 if ( my_dir != null ) {
1304 _values_filechooser.setCurrentDirectory( my_dir );
1306 final int result = _values_filechooser.showOpenDialog( _contentpane );
1307 final File file = _values_filechooser.getSelectedFile();
1308 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1309 BasicTable<String> t = null;
1311 t = BasicTableParser.parse( file, '\t' );
1312 if ( t.getNumberOfColumns() < 2 ) {
1313 t = BasicTableParser.parse( file, ',' );
1315 if ( t.getNumberOfColumns() < 2 ) {
1316 t = BasicTableParser.parse( file, ' ' );
1319 catch ( final IOException e ) {
1320 JOptionPane.showMessageDialog( this,
1322 "Could Not Read Expression Value Table",
1323 JOptionPane.ERROR_MESSAGE );
1326 if ( t.getNumberOfColumns() < 2 ) {
1327 JOptionPane.showMessageDialog( this,
1328 "Table contains " + t.getNumberOfColumns() + " column(s)",
1329 "Problem with Expression Value Table",
1330 JOptionPane.ERROR_MESSAGE );
1333 if ( t.getNumberOfRows() < 1 ) {
1334 JOptionPane.showMessageDialog( this,
1335 "Table contains zero rows",
1336 "Problem with Expression Value Table",
1337 JOptionPane.ERROR_MESSAGE );
1340 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1341 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1342 JOptionPane.showMessageDialog( this,
1343 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1344 + phy.getNumberOfExternalNodes() + " external nodes",
1346 JOptionPane.WARNING_MESSAGE );
1348 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1350 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1351 final PhylogenyNode node = iter.next();
1352 final String node_name = node.getName();
1353 if ( !ForesterUtil.isEmpty( node_name ) ) {
1356 row = t.findRow( node_name );
1358 catch ( final IllegalArgumentException e ) {
1360 .showMessageDialog( this,
1362 "Error Mapping Node Identifiers to Expression Value Identifiers",
1363 JOptionPane.ERROR_MESSAGE );
1367 if ( node.isExternal() ) {
1372 final List<Double> l = new ArrayList<Double>();
1373 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1376 d = Double.parseDouble( t.getValueAsString( col, row ) );
1378 catch ( final NumberFormatException e ) {
1379 JOptionPane.showMessageDialog( this,
1380 "Could not parse \"" + t.getValueAsString( col, row )
1381 + "\" into a decimal value",
1382 "Issue with Expression Value Table",
1383 JOptionPane.ERROR_MESSAGE );
1386 stats.addValue( d );
1389 if ( !l.isEmpty() ) {
1390 if ( node.getNodeData().getProperties() != null ) {
1391 node.getNodeData().getProperties()
1392 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1394 node.getNodeData().setVector( l );
1398 if ( not_found > 0 ) {
1399 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1400 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1402 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1406 private void addSequencesFromFile() {
1407 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1408 JOptionPane.showMessageDialog( this,
1409 "Need to load evolutionary tree first",
1410 "Can Not Read Sequences",
1411 JOptionPane.WARNING_MESSAGE );
1414 final File my_dir = getCurrentDir();
1415 if ( my_dir != null ) {
1416 _sequences_filechooser.setCurrentDirectory( my_dir );
1418 final int result = _sequences_filechooser.showOpenDialog( _contentpane );
1419 final File file = _sequences_filechooser.getSelectedFile();
1420 List<Sequence> seqs = null;
1421 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1423 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1424 seqs = FastaParser.parse( new FileInputStream( file ) );
1427 JOptionPane.showMessageDialog( this,
1428 "Format does not appear to be Fasta",
1429 "Multiple sequence file format error",
1430 JOptionPane.ERROR_MESSAGE );
1434 catch ( final MsaFormatException e ) {
1436 JOptionPane.showMessageDialog( this,
1437 e.getLocalizedMessage(),
1438 "Multiple sequence file format error",
1439 JOptionPane.ERROR_MESSAGE );
1442 catch ( final IOException e ) {
1444 JOptionPane.showMessageDialog( this,
1445 e.getLocalizedMessage(),
1446 "Failed to read multiple sequence file",
1447 JOptionPane.ERROR_MESSAGE );
1450 catch ( final Exception e ) {
1452 e.printStackTrace();
1453 JOptionPane.showMessageDialog( this,
1454 e.getLocalizedMessage(),
1455 "Unexpected error during reading of multiple sequence file",
1456 JOptionPane.ERROR_MESSAGE );
1459 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1460 JOptionPane.showMessageDialog( this,
1461 "Multiple sequence file is empty",
1462 "Empty multiple sequence file",
1463 JOptionPane.ERROR_MESSAGE );
1468 if ( seqs != null ) {
1469 for( final Sequence seq : seqs ) {
1470 System.out.println( seq.getIdentifier() );
1472 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1473 int total_counter = 0;
1474 int attached_counter = 0;
1475 for( final Sequence seq : seqs ) {
1477 final String seq_name = seq.getIdentifier();
1478 if ( !ForesterUtil.isEmpty( seq_name ) ) {
1479 List<PhylogenyNode> nodes = phy.getNodesViaSequenceName( seq_name );
1480 if ( nodes.isEmpty() ) {
1481 nodes = phy.getNodesViaSequenceSymbol( seq_name );
1483 if ( nodes.isEmpty() ) {
1484 nodes = phy.getNodes( seq_name );
1486 if ( nodes.size() > 1 ) {
1487 JOptionPane.showMessageDialog( this,
1488 "Sequence name \"" + seq_name + "\" is not unique",
1489 "Sequence name not unique",
1490 JOptionPane.ERROR_MESSAGE );
1494 final String[] a = seq_name.split( "\\s" );
1495 if ( nodes.isEmpty() && ( a.length > 1 ) ) {
1496 final String seq_name_split = a[ 0 ];
1497 nodes = phy.getNodesViaSequenceName( seq_name_split );
1498 if ( nodes.isEmpty() ) {
1499 nodes = phy.getNodesViaSequenceSymbol( seq_name_split );
1501 if ( nodes.isEmpty() ) {
1502 nodes = phy.getNodes( seq_name_split );
1504 if ( nodes.size() > 1 ) {
1505 JOptionPane.showMessageDialog( this, "Split sequence name \"" + seq_name_split
1506 + "\" is not unique", "Sequence name not unique", JOptionPane.ERROR_MESSAGE );
1511 if ( nodes.size() == 1 ) {
1513 final PhylogenyNode n = nodes.get( 0 );
1514 if ( !n.getNodeData().isHasSequence() ) {
1515 n.getNodeData().addSequence( new org.forester.phylogeny.data.Sequence() );
1517 n.getNodeData().getSequence().setMolecularSequence( seq.getMolecularSequenceAsString() );
1518 if ( ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
1519 n.getNodeData().getSequence().setName( seq_name );
1524 if ( attached_counter > 0 ) {
1526 int ext_nodes_with_seq = 0;
1527 for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
1529 final PhylogenyNode n = iter.next();
1530 if ( n.getNodeData().isHasSequence()
1531 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
1532 ++ext_nodes_with_seq;
1536 if ( ext_nodes == ext_nodes_with_seq ) {
1537 s = "All " + ext_nodes_with_seq + " external nodes now have a molecular sequence attached to them.";
1540 s = ext_nodes_with_seq + " out of " + ext_nodes
1541 + " external nodes now have a molecular sequence attached to them.";
1543 if ( ( attached_counter == total_counter ) && ( ext_nodes == ext_nodes_with_seq ) ) {
1544 JOptionPane.showMessageDialog( this,
1545 "Attached all " + total_counter + " sequences to tree nodes.\n" + s,
1546 "All sequences attached",
1547 JOptionPane.INFORMATION_MESSAGE );
1550 JOptionPane.showMessageDialog( this, "Attached " + attached_counter
1551 + " sequences out of a total of " + total_counter + " sequences.\n" + s, attached_counter
1552 + " sequences attached", JOptionPane.WARNING_MESSAGE );
1556 JOptionPane.showMessageDialog( this, "No maching tree node for any of the " + total_counter
1557 + " sequences", "Could not attach any sequences", JOptionPane.ERROR_MESSAGE );
1562 private void choosePdfWidth() {
1563 final String s = ( String ) JOptionPane.showInputDialog( this,
1564 "Please enter the default line width for PDF export.\n"
1565 + "[current value: "
1566 + getOptions().getPrintLineWidth() + "]\n",
1567 "Line Width for PDF Export",
1568 JOptionPane.QUESTION_MESSAGE,
1571 getOptions().getPrintLineWidth() );
1572 if ( !ForesterUtil.isEmpty( s ) ) {
1573 boolean success = true;
1575 final String m_str = s.trim();
1576 if ( !ForesterUtil.isEmpty( m_str ) ) {
1578 f = Float.parseFloat( m_str );
1580 catch ( final Exception ex ) {
1587 if ( success && ( f > 0.0 ) ) {
1588 getOptions().setPrintLineWidth( f );
1593 private void choosePrintSize() {
1594 final String s = ( String ) JOptionPane.showInputDialog( this,
1595 "Please enter values for width and height,\nseparated by a comma.\n"
1596 + "[current values: "
1597 + getOptions().getPrintSizeX() + ", "
1598 + getOptions().getPrintSizeY() + "]\n"
1599 + "[A4: " + Constants.A4_SIZE_X + ", "
1600 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
1601 + Constants.US_LETTER_SIZE_X + ", "
1602 + Constants.US_LETTER_SIZE_Y + "]",
1603 "Default Size for Graphics Export",
1604 JOptionPane.QUESTION_MESSAGE,
1607 getOptions().getPrintSizeX() + ", "
1608 + getOptions().getPrintSizeY() );
1609 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
1610 boolean success = true;
1613 final String[] str_ary = s.split( "," );
1614 if ( str_ary.length == 2 ) {
1615 final String x_str = str_ary[ 0 ].trim();
1616 final String y_str = str_ary[ 1 ].trim();
1617 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
1619 x = Integer.parseInt( x_str );
1620 y = Integer.parseInt( y_str );
1622 catch ( final Exception ex ) {
1633 if ( success && ( x > 1 ) && ( y > 1 ) ) {
1634 getOptions().setPrintSizeX( x );
1635 getOptions().setPrintSizeY( y );
1640 private void closeCurrentPane() {
1641 if ( getMainPanel().getCurrentTreePanel() != null ) {
1642 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1643 final int r = JOptionPane.showConfirmDialog( this,
1644 "Close tab despite potentially unsaved changes?",
1646 JOptionPane.YES_NO_OPTION );
1647 if ( r != JOptionPane.YES_OPTION ) {
1651 getMainPanel().closeCurrentPane();
1652 activateSaveAllIfNeeded();
1656 private void collapse( final Phylogeny phy, final double m ) {
1657 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1658 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1659 double min_support = Double.MAX_VALUE;
1660 boolean conf_present = false;
1661 while ( it.hasNext() ) {
1662 final PhylogenyNode n = it.next();
1663 if ( !n.isExternal() && !n.isRoot() ) {
1664 final List<Confidence> c = n.getBranchData().getConfidences();
1665 if ( ( c != null ) && ( c.size() > 0 ) ) {
1666 conf_present = true;
1668 for( final Confidence confidence : c ) {
1669 if ( confidence.getValue() > max ) {
1670 max = confidence.getValue();
1673 if ( max < getMinNotCollapseConfidenceValue() ) {
1674 to_be_removed.add( n );
1676 if ( max < min_support ) {
1682 if ( conf_present ) {
1683 for( final PhylogenyNode node : to_be_removed ) {
1684 PhylogenyMethods.removeNode( node, phy );
1686 if ( to_be_removed.size() > 0 ) {
1687 phy.externalNodesHaveChanged();
1688 phy.clearHashIdToNodeMap();
1689 phy.recalculateNumberOfExternalDescendants( true );
1690 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1691 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1692 getCurrentTreePanel().calculateLongestExtNodeInfo();
1693 getCurrentTreePanel().setNodeInPreorderToNull();
1694 getCurrentTreePanel().recalculateMaxDistanceToRoot();
1695 getCurrentTreePanel().resetPreferredSize();
1696 getCurrentTreePanel().setEdited( true );
1697 getCurrentTreePanel().repaint();
1700 if ( to_be_removed.size() > 0 ) {
1701 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1702 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1703 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1706 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1707 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1711 JOptionPane.showMessageDialog( this,
1712 "No branch collapsed because no confidence values present",
1713 "No confidence values present",
1714 JOptionPane.INFORMATION_MESSAGE );
1718 private void collapseBelowThreshold() {
1719 if ( getCurrentTreePanel() != null ) {
1720 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1721 if ( ( phy != null ) && !phy.isEmpty() ) {
1722 final String s = ( String ) JOptionPane.showInputDialog( this,
1723 "Please enter the minimum confidence value\n",
1724 "Minimal Confidence Value",
1725 JOptionPane.QUESTION_MESSAGE,
1728 getMinNotCollapseConfidenceValue() );
1729 if ( !ForesterUtil.isEmpty( s ) ) {
1730 boolean success = true;
1732 final String m_str = s.trim();
1733 if ( !ForesterUtil.isEmpty( m_str ) ) {
1735 m = Double.parseDouble( m_str );
1737 catch ( final Exception ex ) {
1744 if ( success && ( m >= 0.0 ) ) {
1745 setMinNotCollapseConfidenceValue( m );
1753 private PhyloXmlParser createPhyloXmlParser() {
1754 PhyloXmlParser xml_parser = null;
1755 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1757 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1759 catch ( final Exception e ) {
1760 JOptionPane.showMessageDialog( this,
1761 e.getLocalizedMessage(),
1762 "failed to create validating XML parser",
1763 JOptionPane.WARNING_MESSAGE );
1766 if ( xml_parser == null ) {
1767 xml_parser = new PhyloXmlParser();
1772 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1773 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1774 getPhylogeneticInferenceOptions(),
1775 from_unaligned_seqs );
1777 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1778 if ( !from_unaligned_seqs ) {
1779 if ( getMsa() != null ) {
1780 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1781 getPhylogeneticInferenceOptions()
1783 new Thread( inferrer ).start();
1786 JOptionPane.showMessageDialog( this,
1787 "No multiple sequence alignment selected",
1788 "Phylogenetic Inference Not Launched",
1789 JOptionPane.WARNING_MESSAGE );
1793 if ( getSeqs() != null ) {
1794 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1795 getPhylogeneticInferenceOptions()
1797 new Thread( inferrer ).start();
1800 JOptionPane.showMessageDialog( this,
1801 "No input sequences selected",
1802 "Phylogenetic Inference Not Launched",
1803 JOptionPane.WARNING_MESSAGE );
1809 private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
1810 final StringBuilder sb = new StringBuilder();
1811 final StringBuilder sb_failed = new StringBuilder();
1813 int counter_failed = 0;
1814 if ( getCurrentTreePanel() != null ) {
1815 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1816 if ( ( phy != null ) && !phy.isEmpty() ) {
1817 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
1818 while ( it.hasNext() ) {
1819 final PhylogenyNode n = it.next();
1820 final String name = n.getName().trim();
1821 if ( !ForesterUtil.isEmpty( name ) ) {
1822 final String nt = ParserUtils
1823 .extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1824 if ( !ForesterUtil.isEmpty( nt ) ) {
1825 if ( counter < 15 ) {
1826 sb.append( name + ": " + nt + "\n" );
1828 else if ( counter == 15 ) {
1829 sb.append( "...\n" );
1834 if ( counter_failed < 15 ) {
1835 sb_failed.append( name + "\n" );
1837 else if ( counter_failed == 15 ) {
1838 sb_failed.append( "...\n" );
1844 if ( counter > 0 ) {
1846 String all = "all ";
1847 if ( counter_failed > 0 ) {
1849 failed = "\nCould not extract taxonomic data for " + counter_failed
1850 + " named external nodes:\n" + sb_failed;
1852 JOptionPane.showMessageDialog( this,
1853 "Extracted taxonomic data from " + all + counter
1854 + " named external nodes:\n" + sb.toString() + failed,
1855 "Taxonomic Data Extraction Completed",
1856 counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
1857 : JOptionPane.INFORMATION_MESSAGE );
1861 .showMessageDialog( this,
1862 "Could not extract any taxonomic data.\nMaybe node names are empty\n"
1863 + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
1864 + "or nodes already have taxonomic data?\n",
1865 "No Taxonomic Data Extracted",
1866 JOptionPane.ERROR_MESSAGE );
1872 private ControlPanel getControlPanel() {
1873 return getMainPanel().getControlPanel();
1876 private File getCurrentDir() {
1877 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1878 if ( ForesterUtil.isWindowns() ) {
1880 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1882 catch ( final Exception e ) {
1883 _current_dir = null;
1887 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1888 if ( System.getProperty( "user.home" ) != null ) {
1889 _current_dir = new File( System.getProperty( "user.home" ) );
1891 else if ( System.getProperty( "user.dir" ) != null ) {
1892 _current_dir = new File( System.getProperty( "user.dir" ) );
1895 return _current_dir;
1898 private double getMinNotCollapseConfidenceValue() {
1899 return _min_not_collapse;
1902 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
1903 if ( _phylogenetic_inference_options == null ) {
1904 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
1906 return _phylogenetic_inference_options;
1909 private boolean isUnsavedDataPresent() {
1910 final List<TreePanel> tps = getMainPanel().getTreePanels();
1911 for( final TreePanel tp : tps ) {
1912 if ( tp.isEdited() ) {
1919 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
1920 if ( getCurrentTreePanel() != null ) {
1921 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1922 if ( ( phy != null ) && !phy.isEmpty() ) {
1924 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
1929 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
1930 if ( getCurrentTreePanel() != null ) {
1931 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1932 if ( ( phy != null ) && !phy.isEmpty() ) {
1933 PhylogenyMethods.transferNodeNameToField( phy,
1934 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
1940 private void newTree() {
1941 final Phylogeny[] phys = new Phylogeny[ 1 ];
1942 final Phylogeny phy = new Phylogeny();
1943 final PhylogenyNode node = new PhylogenyNode();
1944 phy.setRoot( node );
1945 phy.setRooted( true );
1947 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
1948 _mainpanel.getControlPanel().showWhole();
1949 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1950 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1951 if ( getMainPanel().getMainFrame() == null ) {
1952 // Must be "E" applet version.
1953 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
1954 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1957 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1959 activateSaveAllIfNeeded();
1963 private void obtainDetailedTaxonomicInformation() {
1964 if ( getCurrentTreePanel() != null ) {
1965 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1966 if ( ( phy != null ) && !phy.isEmpty() ) {
1967 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1968 _mainpanel.getCurrentTreePanel(),
1972 new Thread( t ).start();
1977 private void obtainDetailedTaxonomicInformationDelete() {
1978 if ( getCurrentTreePanel() != null ) {
1979 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1980 if ( ( phy != null ) && !phy.isEmpty() ) {
1981 final TaxonomyDataManager t = new TaxonomyDataManager( this,
1982 _mainpanel.getCurrentTreePanel(),
1986 new Thread( t ).start();
1991 private void obtainSequenceInformation() {
1992 if ( getCurrentTreePanel() != null ) {
1993 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1994 if ( ( phy != null ) && !phy.isEmpty() ) {
1995 final SequenceDataRetriver u = new SequenceDataRetriver( this,
1996 _mainpanel.getCurrentTreePanel(),
1998 new Thread( u ).start();
2003 private void print() {
2004 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
2005 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
2008 if ( !getOptions().isPrintUsingActualSize() ) {
2009 getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80,
2010 getOptions().getPrintSizeY() - 140,
2012 getCurrentTreePanel().resetPreferredSize();
2013 getCurrentTreePanel().repaint();
2015 final String job_name = Constants.PRG_NAME;
2016 boolean error = false;
2017 String printer_name = null;
2019 printer_name = Printer.print( getCurrentTreePanel(), job_name );
2021 catch ( final Exception e ) {
2023 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2025 if ( !error && ( printer_name != null ) ) {
2026 String msg = "Printing data sent to printer";
2027 if ( printer_name.length() > 1 ) {
2028 msg += " [" + printer_name + "]";
2030 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2032 if ( !getOptions().isPrintUsingActualSize() ) {
2033 getControlPanel().showWhole();
2037 private void printPhylogenyToPdf( final String file_name ) {
2038 if ( !getOptions().isPrintUsingActualSize() ) {
2039 getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(),
2040 getOptions().getPrintSizeY(),
2042 getCurrentTreePanel().resetPreferredSize();
2043 getCurrentTreePanel().repaint();
2045 String pdf_written_to = "";
2046 boolean error = false;
2048 if ( getOptions().isPrintUsingActualSize() ) {
2049 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
2050 getCurrentTreePanel(),
2051 getCurrentTreePanel().getWidth(),
2052 getCurrentTreePanel().getHeight() );
2055 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
2056 .getPrintSizeX(), getOptions().getPrintSizeY() );
2059 catch ( final IOException e ) {
2061 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2064 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2065 JOptionPane.showMessageDialog( this,
2066 "Wrote PDF to: " + pdf_written_to,
2068 JOptionPane.INFORMATION_MESSAGE );
2071 JOptionPane.showMessageDialog( this,
2072 "There was an unknown problem when attempting to write to PDF file: \""
2075 JOptionPane.ERROR_MESSAGE );
2078 if ( !getOptions().isPrintUsingActualSize() ) {
2079 getControlPanel().showWhole();
2083 private void readPhylogeniesFromFile() {
2084 boolean exception = false;
2085 Phylogeny[] phys = null;
2086 // Set an initial directory if none set yet
2087 final File my_dir = getCurrentDir();
2088 _open_filechooser.setMultiSelectionEnabled( true );
2089 // Open file-open dialog and set current directory
2090 if ( my_dir != null ) {
2091 _open_filechooser.setCurrentDirectory( my_dir );
2093 final int result = _open_filechooser.showOpenDialog( _contentpane );
2094 // All done: get the file
2095 final File[] files = _open_filechooser.getSelectedFiles();
2096 setCurrentDir( _open_filechooser.getCurrentDirectory() );
2097 boolean nhx_or_nexus = false;
2098 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2099 for( final File file : files ) {
2100 if ( ( file != null ) && !file.isDirectory() ) {
2101 if ( _mainpanel.getCurrentTreePanel() != null ) {
2102 _mainpanel.getCurrentTreePanel().setWaitCursor();
2105 _mainpanel.setWaitCursor();
2107 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
2108 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
2110 final NHXParser nhx = new NHXParser();
2111 setSpecialOptionsForNhxParser( nhx );
2112 phys = PhylogenyMethods.readPhylogenies( nhx, file );
2113 nhx_or_nexus = true;
2115 catch ( final Exception e ) {
2117 exceptionOccuredDuringOpenFile( e );
2120 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2121 warnIfNotPhyloXmlValidation( getConfiguration() );
2123 final PhyloXmlParser xml_parser = createPhyloXmlParser();
2124 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
2126 catch ( final Exception e ) {
2128 exceptionOccuredDuringOpenFile( e );
2131 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
2133 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2135 catch ( final Exception e ) {
2137 exceptionOccuredDuringOpenFile( e );
2140 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2142 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
2143 setSpecialOptionsForNexParser( nex );
2144 phys = PhylogenyMethods.readPhylogenies( nex, file );
2145 nhx_or_nexus = true;
2147 catch ( final Exception e ) {
2149 exceptionOccuredDuringOpenFile( e );
2155 final PhylogenyParser parser = ParserUtils
2156 .createParserDependingOnFileType( file, getConfiguration()
2157 .isValidatePhyloXmlAgainstSchema() );
2158 if ( parser instanceof NexusPhylogeniesParser ) {
2159 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
2160 setSpecialOptionsForNexParser( nex );
2161 nhx_or_nexus = true;
2163 else if ( parser instanceof NHXParser ) {
2164 final NHXParser nhx = ( NHXParser ) parser;
2165 setSpecialOptionsForNhxParser( nhx );
2166 nhx_or_nexus = true;
2168 else if ( parser instanceof PhyloXmlParser ) {
2169 warnIfNotPhyloXmlValidation( getConfiguration() );
2171 phys = PhylogenyMethods.readPhylogenies( parser, file );
2173 catch ( final Exception e ) {
2175 exceptionOccuredDuringOpenFile( e );
2178 if ( _mainpanel.getCurrentTreePanel() != null ) {
2179 _mainpanel.getCurrentTreePanel().setArrowCursor();
2182 _mainpanel.setArrowCursor();
2184 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
2185 boolean one_desc = false;
2186 if ( nhx_or_nexus ) {
2187 for( final Phylogeny phy : phys ) {
2188 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2189 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
2191 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
2197 AptxUtil.addPhylogeniesToTabs( phys,
2199 file.getAbsolutePath(),
2202 _mainpanel.getControlPanel().showWhole();
2203 if ( nhx_or_nexus && one_desc ) {
2205 .showMessageDialog( this,
2206 "One or more trees contain (a) node(s) with one descendant, "
2207 + ForesterUtil.LINE_SEPARATOR
2208 + "possibly indicating illegal parentheses within node names.",
2209 "Warning: Possible Error in New Hampshire Formatted Data",
2210 JOptionPane.WARNING_MESSAGE );
2216 activateSaveAllIfNeeded();
2220 private void readSpeciesTreeFromFile() {
2222 boolean exception = false;
2223 final File my_dir = getCurrentDir();
2224 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2225 if ( my_dir != null ) {
2226 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2228 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2229 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2230 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2231 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2233 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), 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( new PhyloXmlParser(), file );
2257 catch ( final Exception e ) {
2259 exceptionOccuredDuringOpenFile( e );
2262 if ( !exception && ( t != null ) && !t.isRooted() ) {
2265 JOptionPane.showMessageDialog( this,
2266 "Species tree is not rooted",
2267 "Species tree not loaded",
2268 JOptionPane.ERROR_MESSAGE );
2270 if ( !exception && ( t != null ) ) {
2271 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2272 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2273 final PhylogenyNode node = it.next();
2274 if ( !node.getNodeData().isHasTaxonomy() ) {
2278 .showMessageDialog( this,
2279 "Species tree contains external node(s) without taxonomy information",
2280 "Species tree not loaded",
2281 JOptionPane.ERROR_MESSAGE );
2285 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2288 JOptionPane.showMessageDialog( this,
2290 + node.getNodeData().getTaxonomy().asSimpleText()
2291 + "] is not unique in species tree",
2292 "Species tree not loaded",
2293 JOptionPane.ERROR_MESSAGE );
2297 tax_set.add( node.getNodeData().getTaxonomy() );
2302 if ( !exception && ( t != null ) ) {
2303 setSpeciesTree( t );
2304 JOptionPane.showMessageDialog( this,
2305 "Species tree successfully loaded",
2306 "Species tree loaded",
2307 JOptionPane.INFORMATION_MESSAGE );
2309 _contentpane.repaint();
2314 private void setArrowCursor() {
2316 _mainpanel.getCurrentTreePanel().setArrowCursor();
2318 catch ( final Exception ex ) {
2323 private void setCurrentDir( final File current_dir ) {
2324 _current_dir = current_dir;
2327 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2328 _min_not_collapse = min_not_collapse;
2331 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2332 _phylogenetic_inference_options = phylogenetic_inference_options;
2335 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2336 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2337 nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2340 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2341 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2342 nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2345 private void writeAllToFile() {
2346 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2349 final File my_dir = getCurrentDir();
2350 if ( my_dir != null ) {
2351 _save_filechooser.setCurrentDirectory( my_dir );
2353 _save_filechooser.setSelectedFile( new File( "" ) );
2354 final int result = _save_filechooser.showSaveDialog( _contentpane );
2355 final File file = _save_filechooser.getSelectedFile();
2356 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2357 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2358 if ( file.exists() ) {
2359 final int i = JOptionPane.showConfirmDialog( this,
2360 file + " already exists. Overwrite?",
2362 JOptionPane.OK_CANCEL_OPTION,
2363 JOptionPane.WARNING_MESSAGE );
2364 if ( i != JOptionPane.OK_OPTION ) {
2371 catch ( final Exception e ) {
2372 JOptionPane.showMessageDialog( this,
2373 "Failed to delete: " + file,
2375 JOptionPane.WARNING_MESSAGE );
2379 final int count = getMainPanel().getTabbedPane().getTabCount();
2380 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2381 for( int i = 0; i < count; ++i ) {
2382 final Phylogeny phy = getMainPanel().getPhylogeny( i );
2383 if ( ForesterUtil.isEmpty( phy.getName() )
2384 && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {
2385 phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );
2388 getMainPanel().getTreePanels().get( i ).setEdited( false );
2390 final PhylogenyWriter writer = new PhylogenyWriter();
2392 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2394 catch ( final IOException e ) {
2395 JOptionPane.showMessageDialog( this,
2396 "Failed to write to: " + file,
2398 JOptionPane.WARNING_MESSAGE );
2403 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2405 final PhylogenyWriter writer = new PhylogenyWriter();
2406 writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
2408 catch ( final Exception e ) {
2410 exceptionOccuredDuringSaveAs( e );
2415 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2417 final PhylogenyWriter writer = new PhylogenyWriter();
2418 writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
2420 catch ( final Exception e ) {
2422 exceptionOccuredDuringSaveAs( e );
2427 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2429 final PhylogenyWriter writer = new PhylogenyWriter();
2430 writer.toPhyloXML( file, t, 0 );
2432 catch ( final Exception e ) {
2434 exceptionOccuredDuringSaveAs( e );
2439 private void writeToFile( final Phylogeny t ) {
2443 String initial_filename = null;
2444 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2446 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2448 catch ( final IOException e ) {
2449 initial_filename = null;
2452 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2453 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2456 _save_filechooser.setSelectedFile( new File( "" ) );
2458 final File my_dir = getCurrentDir();
2459 if ( my_dir != null ) {
2460 _save_filechooser.setCurrentDirectory( my_dir );
2462 final int result = _save_filechooser.showSaveDialog( _contentpane );
2463 final File file = _save_filechooser.getSelectedFile();
2464 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2465 boolean exception = false;
2466 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2467 if ( file.exists() ) {
2468 final int i = JOptionPane.showConfirmDialog( this,
2469 file + " already exists.\nOverwrite?",
2471 JOptionPane.OK_CANCEL_OPTION,
2472 JOptionPane.QUESTION_MESSAGE );
2473 if ( i != JOptionPane.OK_OPTION ) {
2477 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2479 ForesterUtil.copyFile( file, to );
2481 catch ( final Exception e ) {
2482 JOptionPane.showMessageDialog( this,
2483 "Failed to create backup copy " + to,
2484 "Failed to Create Backup Copy",
2485 JOptionPane.WARNING_MESSAGE );
2490 catch ( final Exception e ) {
2491 JOptionPane.showMessageDialog( this,
2492 "Failed to delete: " + file,
2494 JOptionPane.WARNING_MESSAGE );
2498 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2499 exception = writeAsNewHampshire( t, exception, file );
2501 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2502 exception = writeAsPhyloXml( t, exception, file );
2504 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2505 exception = writeAsNexus( t, exception, file );
2509 final String file_name = file.getName().trim().toLowerCase();
2510 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2511 || file_name.endsWith( ".tree" ) ) {
2512 exception = writeAsNewHampshire( t, exception, file );
2514 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2515 exception = writeAsNexus( t, exception, file );
2519 exception = writeAsPhyloXml( t, exception, file );
2523 getMainPanel().setTitleOfSelectedTab( file.getName() );
2524 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2525 getMainPanel().getCurrentTreePanel().setEdited( false );
2530 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2531 if ( ( t == null ) || t.isEmpty() ) {
2534 String initial_filename = "";
2535 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2536 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2538 if ( initial_filename.indexOf( '.' ) > 0 ) {
2539 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2541 initial_filename = initial_filename + "." + type;
2542 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2543 final File my_dir = getCurrentDir();
2544 if ( my_dir != null ) {
2545 _writetographics_filechooser.setCurrentDirectory( my_dir );
2547 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2548 File file = _writetographics_filechooser.getSelectedFile();
2549 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2550 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2551 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2552 file = new File( file.toString() + "." + type );
2554 if ( file.exists() ) {
2555 final int i = JOptionPane.showConfirmDialog( this,
2556 file + " already exists. Overwrite?",
2558 JOptionPane.OK_CANCEL_OPTION,
2559 JOptionPane.WARNING_MESSAGE );
2560 if ( i != JOptionPane.OK_OPTION ) {
2567 catch ( final Exception e ) {
2568 JOptionPane.showMessageDialog( this,
2569 "Failed to delete: " + file,
2571 JOptionPane.WARNING_MESSAGE );
2575 writePhylogenyToGraphicsFile( file.toString(), type );
2579 private void writeToPdf( final Phylogeny t ) {
2580 if ( ( t == null ) || t.isEmpty() ) {
2583 String initial_filename = "";
2584 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2585 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2587 if ( initial_filename.indexOf( '.' ) > 0 ) {
2588 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2590 initial_filename = initial_filename + ".pdf";
2591 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2592 final File my_dir = getCurrentDir();
2593 if ( my_dir != null ) {
2594 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2596 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2597 File file = _writetopdf_filechooser.getSelectedFile();
2598 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2599 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2600 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2601 file = new File( file.toString() + ".pdf" );
2603 if ( file.exists() ) {
2604 final int i = JOptionPane.showConfirmDialog( this,
2605 file + " already exists. Overwrite?",
2607 JOptionPane.OK_CANCEL_OPTION,
2608 JOptionPane.WARNING_MESSAGE );
2609 if ( i != JOptionPane.OK_OPTION ) {
2613 printPhylogenyToPdf( file.toString() );
2617 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
2618 return new MainFrameApplication( phys, config );
2621 public static MainFrame createInstance( final Phylogeny[] phys,
2622 final Configuration config,
2624 final File current_dir ) {
2625 return new MainFrameApplication( phys, config, title, current_dir );
2628 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2629 return new MainFrameApplication( phys, config, title );
2632 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2633 return new MainFrameApplication( phys, config_file_name, title );
2636 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2637 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2638 + o.getPrintSizeY() + ")" );
2641 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2642 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2645 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2646 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2648 .showMessageDialog( null,
2650 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2653 JOptionPane.WARNING_MESSAGE );
2656 } // MainFrameApplication.
2658 class DefaultFilter extends FileFilter {
2661 public boolean accept( final File f ) {
2662 final String file_name = f.getName().trim().toLowerCase();
2663 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2664 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2665 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2666 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2667 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2668 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2669 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2670 || file_name.endsWith( ".con" ) || f.isDirectory();
2674 public String getDescription() {
2675 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2679 class GraphicsFileFilter extends FileFilter {
2682 public boolean accept( final File f ) {
2683 final String file_name = f.getName().trim().toLowerCase();
2684 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2685 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2689 public String getDescription() {
2690 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2694 class MsaFileFilter extends FileFilter {
2697 public boolean accept( final File f ) {
2698 final String file_name = f.getName().trim().toLowerCase();
2699 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2700 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2704 public String getDescription() {
2705 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2709 class NexusFilter extends FileFilter {
2712 public boolean accept( final File f ) {
2713 final String file_name = f.getName().trim().toLowerCase();
2714 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2715 || file_name.endsWith( ".tre" ) || f.isDirectory();
2719 public String getDescription() {
2720 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2724 class NHFilter extends FileFilter {
2727 public boolean accept( final File f ) {
2728 final String file_name = f.getName().trim().toLowerCase();
2729 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2730 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2731 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2736 public String getDescription() {
2737 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2741 class NHXFilter extends FileFilter {
2744 public boolean accept( final File f ) {
2745 final String file_name = f.getName().trim().toLowerCase();
2746 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2750 public String getDescription() {
2751 return "NHX files (*.nhx) [deprecated]";
2755 class PdfFilter extends FileFilter {
2758 public boolean accept( final File f ) {
2759 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2763 public String getDescription() {
2764 return "PDF files (*.pdf)";
2768 class SequencesFileFilter extends FileFilter {
2771 public boolean accept( final File f ) {
2772 final String file_name = f.getName().trim().toLowerCase();
2773 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2774 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2778 public String getDescription() {
2779 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2783 class TolFilter extends FileFilter {
2786 public boolean accept( final File f ) {
2787 final String file_name = f.getName().trim().toLowerCase();
2788 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2789 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2793 public String getDescription() {
2794 return "Tree of Life files (*.tol, *.tolxml)";
2798 class XMLFilter extends FileFilter {
2801 public boolean accept( final File f ) {
2802 final String file_name = f.getName().trim().toLowerCase();
2803 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2804 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2808 public String getDescription() {
2809 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";