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.sdi.GSDI;
102 import org.forester.sdi.GSDIR;
103 import org.forester.sdi.SDIException;
104 import org.forester.sequence.Sequence;
105 import org.forester.util.BasicDescriptiveStatistics;
106 import org.forester.util.BasicTable;
107 import org.forester.util.BasicTableParser;
108 import org.forester.util.DescriptiveStatistics;
109 import org.forester.util.ForesterUtil;
110 import org.forester.util.WindowsUtils;
112 public final class MainFrameApplication extends MainFrame {
114 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
115 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
116 private final static int FRAME_X_SIZE = 800;
117 private final static int FRAME_Y_SIZE = 800;
118 // Filters for the file-open dialog (classes defined in this file)
119 private final static NHFilter nhfilter = new NHFilter();
120 private final static NHXFilter nhxfilter = new NHXFilter();
121 private final static XMLFilter xmlfilter = new XMLFilter();
122 private final static TolFilter tolfilter = new TolFilter();
123 private final static NexusFilter nexusfilter = new NexusFilter();
124 private final static PdfFilter pdffilter = new PdfFilter();
125 private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
126 private final static MsaFileFilter msafilter = new MsaFileFilter();
127 private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
128 private final static DefaultFilter defaultfilter = new DefaultFilter();
129 private static final long serialVersionUID = -799735726778865234L;
130 private final JFileChooser _values_filechooser;
131 private final JFileChooser _sequences_filechooser;
132 private final JFileChooser _open_filechooser;
133 private final JFileChooser _msa_filechooser;
134 private final JFileChooser _seqs_pi_filechooser;
135 private final JFileChooser _open_filechooser_for_species_tree;
136 private final JFileChooser _save_filechooser;
137 private final JFileChooser _writetopdf_filechooser;
138 private final JFileChooser _writetographics_filechooser;
140 private JMenu _analysis_menu;
141 private JMenuItem _load_species_tree_item;
142 private JMenuItem _gsdi_item;
143 private JMenuItem _gsdir_item;
144 private JMenuItem _lineage_inference;
145 private JMenuItem _function_analysis;
146 // Application-only print menu items
147 private JMenuItem _print_item;
148 private JMenuItem _write_to_pdf_item;
149 private JMenuItem _write_to_jpg_item;
150 private JMenuItem _write_to_gif_item;
151 private JMenuItem _write_to_tif_item;
152 private JMenuItem _write_to_png_item;
153 private JMenuItem _write_to_bmp_item;
154 private Phylogeny _species_tree;
155 private File _current_dir;
156 private ButtonGroup _radio_group_1;
157 private ButtonGroup _radio_group_2;
159 double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
160 // Phylogeny Inference menu
161 private JMenu _inference_menu;
162 private JMenuItem _inference_from_msa_item;
163 private JMenuItem _inference_from_seqs_item;
164 // Phylogeny Inference
165 private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;
166 private Msa _msa = null;
167 private File _msa_file = null;
168 private List<Sequence> _seqs = null;
169 private File _seqs_file = null;
170 JMenuItem _read_values_jmi;
171 JMenuItem _read_seqs_jmi;
173 private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
174 _configuration = config;
175 if ( _configuration == null ) {
176 throw new IllegalArgumentException( "configuration is null" );
179 setOptions( Options.createInstance( _configuration ) );
180 _mainpanel = new MainPanel( _configuration, this );
181 _open_filechooser = null;
182 _open_filechooser_for_species_tree = null;
183 _save_filechooser = null;
184 _writetopdf_filechooser = null;
185 _writetographics_filechooser = null;
186 _msa_filechooser = null;
187 _seqs_pi_filechooser = null;
188 _values_filechooser = null;
189 _sequences_filechooser = null;
190 _jmenubar = new JMenuBar();
193 _contentpane = getContentPane();
194 _contentpane.setLayout( new BorderLayout() );
195 _contentpane.add( _mainpanel, BorderLayout.CENTER );
197 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
198 // The window listener
199 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
200 addWindowListener( new WindowAdapter() {
203 public void windowClosing( final WindowEvent e ) {
207 // setVisible( true );
208 if ( ( phys != null ) && ( phys.length > 0 ) ) {
209 AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
211 getMainPanel().getControlPanel().showWholeAll();
212 getMainPanel().getControlPanel().showWhole();
214 //activateSaveAllIfNeeded();
215 // ...and its children
216 _contentpane.repaint();
219 private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
220 this( phys, config, title, null );
223 private MainFrameApplication( final Phylogeny[] phys,
224 final Configuration config,
226 final File current_dir ) {
228 _configuration = config;
229 if ( _configuration == null ) {
230 throw new IllegalArgumentException( "configuration is null" );
233 boolean synth_exception = false;
234 if ( Constants.__SYNTH_LF ) {
236 final SynthLookAndFeel synth = new SynthLookAndFeel();
237 synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
238 MainFrameApplication.class );
239 UIManager.setLookAndFeel( synth );
241 catch ( final Exception ex ) {
242 synth_exception = true;
243 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
244 "could not create synth look and feel: "
245 + ex.getLocalizedMessage() );
248 if ( !Constants.__SYNTH_LF || synth_exception ) {
249 if ( _configuration.isUseNativeUI() ) {
250 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
253 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
256 //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
258 catch ( final UnsupportedLookAndFeelException e ) {
259 AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );
261 catch ( final ClassNotFoundException e ) {
262 AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
264 catch ( final InstantiationException e ) {
265 AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
267 catch ( final IllegalAccessException e ) {
268 AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
270 if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
271 setCurrentDir( current_dir );
273 // hide until everything is ready
275 setOptions( Options.createInstance( _configuration ) );
276 setInferenceManager( InferenceManager.createInstance( _configuration ) );
277 setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
278 // _textframe = null; #~~~~
279 _species_tree = null;
281 setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
282 _mainpanel = new MainPanel( _configuration, this );
284 _open_filechooser = new JFileChooser();
285 _open_filechooser.setCurrentDirectory( new File( "." ) );
286 _open_filechooser.setMultiSelectionEnabled( false );
287 _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );
288 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );
289 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
290 _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
291 _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );
292 _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
293 _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );
294 _open_filechooser_for_species_tree = new JFileChooser();
295 _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );
296 _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );
297 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );
298 _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );
299 _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );
300 _save_filechooser = new JFileChooser();
301 _save_filechooser.setCurrentDirectory( new File( "." ) );
302 _save_filechooser.setMultiSelectionEnabled( false );
303 _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );
304 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );
305 _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );
306 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
307 _writetopdf_filechooser = new JFileChooser();
308 _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );
309 _writetographics_filechooser = new JFileChooser();
310 _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );
312 _msa_filechooser = new JFileChooser();
313 _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );
314 _msa_filechooser.setCurrentDirectory( new File( "." ) );
315 _msa_filechooser.setMultiSelectionEnabled( false );
316 _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );
317 _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );
319 _seqs_pi_filechooser = new JFileChooser();
320 _seqs_pi_filechooser.setName( "Read Sequences File" );
321 _seqs_pi_filechooser.setCurrentDirectory( new File( "." ) );
322 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
323 _seqs_pi_filechooser.addChoosableFileFilter( _seqs_pi_filechooser.getAcceptAllFileFilter() );
324 _seqs_pi_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
326 _values_filechooser = new JFileChooser();
327 _values_filechooser.setCurrentDirectory( new File( "." ) );
328 _values_filechooser.setMultiSelectionEnabled( false );
330 _sequences_filechooser = new JFileChooser();
331 _sequences_filechooser.setCurrentDirectory( new File( "." ) );
332 _sequences_filechooser.setMultiSelectionEnabled( false );
333 // build the menu bar
334 _jmenubar = new JMenuBar();
335 if ( !_configuration.isUseNativeUI() ) {
336 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
339 if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
340 buildPhylogeneticInferenceMenu();
349 setJMenuBar( _jmenubar );
350 _jmenubar.add( _help_jmenu );
351 _contentpane = getContentPane();
352 _contentpane.setLayout( new BorderLayout() );
353 _contentpane.add( _mainpanel, BorderLayout.CENTER );
355 setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
356 // addWindowFocusListener( new WindowAdapter() {
359 // public void windowGainedFocus( WindowEvent e ) {
360 // requestFocusInWindow();
363 // The window listener
364 setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
365 addWindowListener( new WindowAdapter() {
368 public void windowClosing( final WindowEvent e ) {
369 if ( isUnsavedDataPresent() ) {
370 final int r = JOptionPane.showConfirmDialog( null,
371 "Exit despite potentially unsaved changes?",
373 JOptionPane.YES_NO_OPTION );
374 if ( r != JOptionPane.YES_OPTION ) {
379 final int r = JOptionPane.showConfirmDialog( null,
380 "Exit Archaeopteryx?",
382 JOptionPane.YES_NO_OPTION );
383 if ( r != JOptionPane.YES_OPTION ) {
390 // The component listener
391 addComponentListener( new ComponentAdapter() {
394 public void componentResized( final ComponentEvent e ) {
395 if ( _mainpanel.getCurrentTreePanel() != null ) {
396 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel()
398 _mainpanel.getCurrentTreePanel()
400 getOptions().isAllowFontSizeChange() );
404 requestFocusInWindow();
405 // addKeyListener( this );
407 if ( ( phys != null ) && ( phys.length > 0 ) ) {
408 AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
410 getMainPanel().getControlPanel().showWholeAll();
411 getMainPanel().getControlPanel().showWhole();
413 activateSaveAllIfNeeded();
414 // ...and its children
415 _contentpane.repaint();
419 private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
420 // Reads the config file (false, false => not url, not applet):
421 this( phys, new Configuration( config_file, false, false, true ), title );
425 public void actionPerformed( final ActionEvent e ) {
427 super.actionPerformed( e );
428 final Object o = e.getSource();
429 // Handle app-specific actions here:
430 if ( o == _open_item ) {
431 readPhylogeniesFromFile();
433 else if ( o == _save_item ) {
434 writeToFile( _mainpanel.getCurrentPhylogeny() );
435 // If subtree currently displayed, save it, instead of complete
438 else if ( o == _new_item ) {
441 else if ( o == _save_all_item ) {
444 else if ( o == _close_item ) {
447 else if ( o == _write_to_pdf_item ) {
448 writeToPdf( _mainpanel.getCurrentPhylogeny() );
450 else if ( o == _write_to_jpg_item ) {
451 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
453 else if ( o == _write_to_png_item ) {
454 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
456 else if ( o == _write_to_gif_item ) {
457 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
459 else if ( o == _write_to_tif_item ) {
460 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
462 else if ( o == _write_to_bmp_item ) {
463 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
465 else if ( o == _print_item ) {
468 else if ( o == _load_species_tree_item ) {
469 readSpeciesTreeFromFile();
471 else if ( o == _lineage_inference ) {
472 if ( isSubtreeDisplayed() ) {
473 JOptionPane.showMessageDialog( this,
475 "Cannot infer ancestral taxonomies",
476 JOptionPane.ERROR_MESSAGE );
479 executeLineageInference();
481 else if ( o == _function_analysis ) {
482 executeFunctionAnalysis();
484 else if ( o == _obtain_detailed_taxonomic_information_jmi ) {
485 if ( isSubtreeDisplayed() ) {
488 obtainDetailedTaxonomicInformation();
490 else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
491 if ( isSubtreeDisplayed() ) {
494 obtainDetailedTaxonomicInformationDelete();
496 else if ( o == _obtain_seq_information_jmi ) {
497 obtainSequenceInformation();
499 else if ( o == _read_values_jmi ) {
500 if ( isSubtreeDisplayed() ) {
503 addExpressionValuesFromFile();
505 else if ( o == _read_seqs_jmi ) {
506 if ( isSubtreeDisplayed() ) {
509 addSequencesFromFile();
511 else if ( o == _move_node_names_to_tax_sn_jmi ) {
512 moveNodeNamesToTaxSn();
514 else if ( o == _move_node_names_to_seq_names_jmi ) {
515 moveNodeNamesToSeqNames();
517 else if ( o == _extract_tax_code_from_node_names_jmi ) {
518 extractTaxDataFromNodeNames();
520 else if ( o == _gsdi_item ) {
521 if ( isSubtreeDisplayed() ) {
526 else if ( o == _gsdir_item ) {
527 if ( isSubtreeDisplayed() ) {
532 else if ( o == _graphics_export_visible_only_cbmi ) {
533 updateOptions( getOptions() );
535 else if ( o == _antialias_print_cbmi ) {
536 updateOptions( getOptions() );
538 else if ( o == _print_black_and_white_cbmi ) {
539 updateOptions( getOptions() );
541 else if ( o == _print_using_actual_size_cbmi ) {
542 updateOptions( getOptions() );
544 else if ( o == _graphics_export_using_actual_size_cbmi ) {
545 updateOptions( getOptions() );
547 else if ( o == _print_size_mi ) {
550 else if ( o == _choose_pdf_width_mi ) {
553 else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {
554 updateOptions( getOptions() );
556 else if ( o == _replace_underscores_cbmi ) {
557 if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {
558 _extract_taxonomy_no_rbmi.setSelected( true );
560 updateOptions( getOptions() );
562 else if ( o == _collapse_below_threshold ) {
563 if ( isSubtreeDisplayed() ) {
566 collapseBelowThreshold();
568 else if ( ( o == _extract_taxonomy_pfam_rbmi ) || ( o == _extract_taxonomy_yes_rbmi ) ) {
569 if ( _replace_underscores_cbmi != null ) {
570 _replace_underscores_cbmi.setSelected( false );
572 updateOptions( getOptions() );
574 else if ( o == _inference_from_msa_item ) {
575 executePhyleneticInference( false );
577 else if ( o == _inference_from_seqs_item ) {
578 executePhyleneticInference( true );
580 _contentpane.repaint();
582 catch ( final Exception ex ) {
583 AptxUtil.unexpectedException( ex );
585 catch ( final Error err ) {
586 AptxUtil.unexpectedError( err );
591 _mainpanel.terminate();
592 _contentpane.removeAll();
598 public MainPanel getMainPanel() {
602 public Msa getMsa() {
606 public File getMsaFile() {
610 public List<Sequence> getSeqs() {
614 public File getSeqsFile() {
618 public void readMsaFromFile() {
619 // Set an initial directory if none set yet
620 final File my_dir = getCurrentDir();
621 _msa_filechooser.setMultiSelectionEnabled( false );
622 // Open file-open dialog and set current directory
623 if ( my_dir != null ) {
624 _msa_filechooser.setCurrentDirectory( my_dir );
626 final int result = _msa_filechooser.showOpenDialog( _contentpane );
627 // All done: get the msa
628 final File file = _msa_filechooser.getSelectedFile();
629 setCurrentDir( _msa_filechooser.getCurrentDirectory() );
630 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
635 final InputStream is = new FileInputStream( file );
636 if ( FastaParser.isLikelyFasta( file ) ) {
637 msa = FastaParser.parseMsa( is );
640 msa = GeneralMsaParser.parse( is );
643 catch ( final MsaFormatException e ) {
645 JOptionPane.showMessageDialog( this,
646 e.getLocalizedMessage(),
647 "Multiple sequence alignment format error",
648 JOptionPane.ERROR_MESSAGE );
651 catch ( final IOException e ) {
653 JOptionPane.showMessageDialog( this,
654 e.getLocalizedMessage(),
655 "Failed to read multiple sequence alignment",
656 JOptionPane.ERROR_MESSAGE );
659 catch ( final IllegalArgumentException e ) {
661 JOptionPane.showMessageDialog( this,
662 e.getLocalizedMessage(),
663 "Unexpected error during reading of multiple sequence alignment",
664 JOptionPane.ERROR_MESSAGE );
667 catch ( final Exception e ) {
670 JOptionPane.showMessageDialog( this,
671 e.getLocalizedMessage(),
672 "Unexpected error during reading of multiple sequence alignment",
673 JOptionPane.ERROR_MESSAGE );
676 if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
677 JOptionPane.showMessageDialog( this,
678 "Multiple sequence alignment is empty",
679 "Illegal Multiple Sequence Alignment",
680 JOptionPane.ERROR_MESSAGE );
683 if ( msa.getNumberOfSequences() < 4 ) {
684 JOptionPane.showMessageDialog( this,
685 "Multiple sequence alignment needs to contain at least 3 sequences",
686 "Illegal multiple sequence alignment",
687 JOptionPane.ERROR_MESSAGE );
690 if ( msa.getLength() < 2 ) {
691 JOptionPane.showMessageDialog( this,
692 "Multiple sequence alignment needs to contain at least 2 residues",
693 "Illegal multiple sequence alignment",
694 JOptionPane.ERROR_MESSAGE );
698 setMsaFile( _msa_filechooser.getSelectedFile() );
703 public void readSeqsFromFileforPI() {
704 // Set an initial directory if none set yet
705 final File my_dir = getCurrentDir();
706 _seqs_pi_filechooser.setMultiSelectionEnabled( false );
707 // Open file-open dialog and set current directory
708 if ( my_dir != null ) {
709 _seqs_pi_filechooser.setCurrentDirectory( my_dir );
711 final int result = _seqs_pi_filechooser.showOpenDialog( _contentpane );
712 // All done: get the seqs
713 final File file = _seqs_pi_filechooser.getSelectedFile();
714 setCurrentDir( _seqs_pi_filechooser.getCurrentDirectory() );
715 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
718 List<Sequence> seqs = null;
720 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
721 seqs = FastaParser.parse( new FileInputStream( file ) );
722 for( final Sequence seq : seqs ) {
723 System.out.println( SequenceWriter.toFasta( seq, 60 ) );
730 catch ( final MsaFormatException e ) {
732 JOptionPane.showMessageDialog( this,
733 e.getLocalizedMessage(),
734 "Multiple sequence file format error",
735 JOptionPane.ERROR_MESSAGE );
738 catch ( final IOException e ) {
740 JOptionPane.showMessageDialog( this,
741 e.getLocalizedMessage(),
742 "Failed to read multiple sequence file",
743 JOptionPane.ERROR_MESSAGE );
746 catch ( final IllegalArgumentException e ) {
748 JOptionPane.showMessageDialog( this,
749 e.getLocalizedMessage(),
750 "Unexpected error during reading of multiple sequence file",
751 JOptionPane.ERROR_MESSAGE );
754 catch ( final Exception e ) {
757 JOptionPane.showMessageDialog( this,
758 e.getLocalizedMessage(),
759 "Unexpected error during reading of multiple sequence file",
760 JOptionPane.ERROR_MESSAGE );
763 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
764 JOptionPane.showMessageDialog( this,
765 "Multiple sequence file is empty",
766 "Illegal multiple sequence file",
767 JOptionPane.ERROR_MESSAGE );
770 if ( seqs.size() < 4 ) {
771 JOptionPane.showMessageDialog( this,
772 "Multiple sequence file needs to contain at least 3 sequences",
773 "Illegal multiple sequence file",
774 JOptionPane.ERROR_MESSAGE );
777 // if ( msa.getLength() < 2 ) {
778 // JOptionPane.showMessageDialog( this,
779 // "Multiple sequence alignment needs to contain at least 2 residues",
780 // "Illegal multiple sequence file",
781 // JOptionPane.ERROR_MESSAGE );
785 setSeqsFile( _seqs_pi_filechooser.getSelectedFile() );
790 void buildAnalysisMenu() {
791 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
792 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
793 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
794 _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
795 customizeJMenuItem( _gsdi_item );
796 customizeJMenuItem( _gsdir_item );
797 customizeJMenuItem( _load_species_tree_item );
798 _analysis_menu.addSeparator();
799 _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
800 customizeJMenuItem( _lineage_inference );
801 _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
802 _jmenubar.add( _analysis_menu );
806 void buildFileMenu() {
807 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
808 _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
809 _file_jmenu.addSeparator();
810 _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
811 _file_jmenu.addSeparator();
812 final WebservicesManager webservices_manager = WebservicesManager.getInstance();
813 _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
814 .getAvailablePhylogeniesWebserviceClients().size() ];
815 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
816 final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
817 _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
818 _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
820 if ( getConfiguration().isEditable() ) {
821 _file_jmenu.addSeparator();
822 _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
823 _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
825 _file_jmenu.addSeparator();
826 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
827 _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
828 _save_all_item.setToolTipText( "Write all phylogenies to one file." );
829 _save_all_item.setEnabled( false );
830 _file_jmenu.addSeparator();
831 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
832 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
833 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
835 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
836 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
837 if ( AptxUtil.canWriteFormat( "gif" ) ) {
838 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
840 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
841 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
843 _file_jmenu.addSeparator();
844 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
845 _file_jmenu.addSeparator();
846 _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );
847 _close_item.setToolTipText( "To close the current pane." );
848 _close_item.setEnabled( true );
849 _file_jmenu.addSeparator();
850 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
851 // For print in color option item
852 customizeJMenuItem( _open_item );
854 .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );
855 customizeJMenuItem( _open_url_item );
856 for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
857 customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );
859 customizeJMenuItem( _save_item );
860 if ( getConfiguration().isEditable() ) {
861 customizeJMenuItem( _new_item );
863 customizeJMenuItem( _close_item );
864 customizeJMenuItem( _save_all_item );
865 customizeJMenuItem( _write_to_pdf_item );
866 customizeJMenuItem( _write_to_png_item );
867 customizeJMenuItem( _write_to_jpg_item );
868 customizeJMenuItem( _write_to_gif_item );
869 customizeJMenuItem( _write_to_tif_item );
870 customizeJMenuItem( _write_to_bmp_item );
871 customizeJMenuItem( _print_item );
872 customizeJMenuItem( _exit_item );
873 _jmenubar.add( _file_jmenu );
876 void buildOptionsMenu() {
877 _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );
878 _options_jmenu.addChangeListener( new ChangeListener() {
881 public void stateChanged( final ChangeEvent e ) {
882 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
883 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
885 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
886 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
887 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
888 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
889 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
890 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
892 _show_branch_length_values_cbmi,
893 _non_lined_up_cladograms_rbmi,
894 _uniform_cladograms_rbmi,
895 _ext_node_dependent_cladogram_rbmi,
896 _label_direction_cbmi );
897 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
898 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
899 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
902 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
904 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
905 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
906 _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );
907 _radio_group_1 = new ButtonGroup();
908 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
909 _radio_group_1.add( _uniform_cladograms_rbmi );
910 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
911 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );
912 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
914 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
915 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );
917 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) );
919 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) );
921 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
922 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
923 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
924 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
925 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );
926 _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );
927 _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );
928 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
929 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );
930 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );
931 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );
932 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
933 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) );
935 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
936 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
937 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
938 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
939 _options_jmenu.addSeparator();
940 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );
941 _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );
942 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );
943 _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );
944 _options_jmenu.addSeparator();
945 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
946 getConfiguration() ) );
947 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
948 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
950 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
952 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
954 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
955 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
956 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
957 _options_jmenu.addSeparator();
958 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );
960 .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );
961 _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );
963 _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );
965 .add( _extract_taxonomy_pfam_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Pfam-style Node Names" ) );
966 _extract_taxonomy_pfam_rbmi
967 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE/134-298\"" );
969 .add( _extract_taxonomy_yes_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Node Names" ) );
970 _extract_taxonomy_yes_rbmi
971 .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE\" or \"BCL2_MOUSE B-cell lymphoma 2...\"" );
972 _radio_group_2 = new ButtonGroup();
973 _radio_group_2.add( _extract_taxonomy_no_rbmi );
974 _radio_group_2.add( _extract_taxonomy_pfam_rbmi );
975 _radio_group_2.add( _extract_taxonomy_yes_rbmi );
977 _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );
979 .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );
980 _use_brackets_for_conf_in_nh_export_cbmi
981 .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );
983 .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );
984 customizeJMenuItem( _choose_font_mi );
985 customizeJMenuItem( _choose_minimal_confidence_mi );
986 customizeJMenuItem( _switch_colors_mi );
987 customizeJMenuItem( _print_size_mi );
988 customizeJMenuItem( _choose_pdf_width_mi );
989 customizeJMenuItem( _overview_placment_mi );
990 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
991 .isShowDefaultNodeShapesExternal() );
992 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
993 .isShowDefaultNodeShapesInternal() );
994 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
995 customizeJMenuItem( _cycle_node_shape_mi );
996 customizeJMenuItem( _cycle_node_fill_mi );
997 customizeJMenuItem( _choose_node_size_mi );
998 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
999 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
1000 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
1001 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
1002 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
1003 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
1004 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
1005 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
1006 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
1007 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
1008 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1009 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
1010 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1011 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
1012 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
1013 customizeCheckBoxMenuItem( _label_direction_cbmi,
1014 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
1015 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
1016 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
1017 customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()
1018 .isInternalNumberAreConfidenceForNhParsing() );
1019 customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,
1020 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );
1021 customizeRadioButtonMenuItem( _extract_taxonomy_yes_rbmi,
1022 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1023 customizeRadioButtonMenuItem( _extract_taxonomy_pfam_rbmi,
1024 getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1025 customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );
1026 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1027 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1028 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
1029 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
1030 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
1031 .isGraphicsExportUsingActualSize() );
1032 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1033 customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()
1034 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1035 customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()
1036 .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1037 _jmenubar.add( _options_jmenu );
1040 void buildPhylogeneticInferenceMenu() {
1041 final InferenceManager im = getInferenceManager();
1042 _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
1043 _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
1044 customizeJMenuItem( _inference_from_msa_item );
1045 _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
1046 if ( im.canDoMsa() ) {
1047 _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
1048 customizeJMenuItem( _inference_from_seqs_item );
1049 _inference_from_seqs_item
1050 .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
1054 .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
1055 customizeJMenuItem( _inference_from_seqs_item );
1056 _inference_from_seqs_item.setEnabled( false );
1058 _jmenubar.add( _inference_menu );
1061 void buildToolsMenu() {
1062 _tools_menu = createMenu( "Tools", getConfiguration() );
1063 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1064 customizeJMenuItem( _confcolor_item );
1065 _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );
1066 customizeJMenuItem( _color_rank_jmi );
1067 _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );
1068 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1069 customizeJMenuItem( _taxcolor_item );
1070 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
1071 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" );
1072 customizeJMenuItem( _remove_branch_color_item );
1073 _tools_menu.addSeparator();
1074 _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );
1075 customizeJMenuItem( _annotate_item );
1076 _tools_menu.addSeparator();
1077 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1078 customizeJMenuItem( _midpoint_root_item );
1079 _tools_menu.addSeparator();
1080 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1081 customizeJMenuItem( _collapse_species_specific_subtrees );
1083 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );
1084 customizeJMenuItem( _collapse_below_threshold );
1085 _collapse_below_threshold
1086 .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)" );
1087 _tools_menu.addSeparator();
1089 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );
1090 customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
1091 _extract_tax_code_from_node_names_jmi
1092 .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'" );
1094 .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
1095 customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
1096 _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
1097 _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
1098 customizeJMenuItem( _move_node_names_to_seq_names_jmi );
1099 _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
1100 _tools_menu.addSeparator();
1102 .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
1103 customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
1104 _obtain_detailed_taxonomic_information_jmi
1105 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
1107 .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
1108 customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
1109 _obtain_detailed_taxonomic_information_deleting_jmi
1110 .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
1111 _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );
1112 customizeJMenuItem( _obtain_seq_information_jmi );
1113 _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );
1114 _tools_menu.addSeparator();
1115 if ( !Constants.__RELEASE ) {
1116 _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
1117 customizeJMenuItem( _function_analysis );
1119 .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" );
1120 _tools_menu.addSeparator();
1122 _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) );
1123 customizeJMenuItem( _read_values_jmi );
1124 _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" );
1125 _jmenubar.add( _tools_menu );
1126 _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) );
1127 customizeJMenuItem( _read_seqs_jmi );
1129 .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" );
1130 _jmenubar.add( _tools_menu );
1135 if ( isUnsavedDataPresent() ) {
1136 final int r = JOptionPane.showConfirmDialog( this,
1137 "Exit despite potentially unsaved changes?",
1139 JOptionPane.YES_NO_OPTION );
1140 if ( r != JOptionPane.YES_OPTION ) {
1147 void executeFunctionAnalysis() {
1148 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1151 final GoAnnotation a = new GoAnnotation( this,
1152 _mainpanel.getCurrentTreePanel(),
1153 _mainpanel.getCurrentPhylogeny() );
1154 new Thread( a ).start();
1157 void executeGSDI() {
1158 if ( !isOKforSDI( false, true ) ) {
1161 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1162 JOptionPane.showMessageDialog( this,
1163 "Gene tree is not rooted.",
1164 "Cannot execute GSDI",
1165 JOptionPane.ERROR_MESSAGE );
1168 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1169 gene_tree.setAllNodesToNotCollapse();
1170 gene_tree.recalculateNumberOfExternalDescendants( false );
1172 final Phylogeny species_tree = _species_tree.copy();
1174 gsdi = new GSDI( gene_tree, species_tree, false, true, true );
1176 catch ( final SDIException e ) {
1177 JOptionPane.showMessageDialog( this,
1178 e.getLocalizedMessage(),
1179 "Error during GSDI",
1180 JOptionPane.ERROR_MESSAGE );
1183 catch ( final Exception e ) {
1184 AptxUtil.unexpectedException( e );
1187 gene_tree.setRerootable( false );
1188 gene_tree.clearHashIdToNodeMap();
1189 gene_tree.recalculateNumberOfExternalDescendants( true );
1190 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1191 getControlPanel().setShowEvents( true );
1193 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1194 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1196 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1198 _mainpanel.getCurrentTreePanel().setEdited( true );
1199 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1200 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1201 JOptionPane.showMessageDialog( this,
1202 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1203 + "Potential duplications: "
1204 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1205 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1206 + "Stripped gene tree nodes: "
1207 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1208 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1209 + "Number of polytomies in species tree used: " + poly + "\n",
1210 "GSDI successfully completed",
1211 JOptionPane.WARNING_MESSAGE );
1214 JOptionPane.showMessageDialog( this,
1215 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1216 + "Potential duplications: "
1217 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1218 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1219 + "Stripped gene tree nodes: "
1220 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1221 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1222 + "Number of polytomies in species tree used: " + poly + "\n",
1223 "GSDI successfully completed",
1224 JOptionPane.INFORMATION_MESSAGE );
1228 void executeGSDIR() {
1229 if ( !isOKforSDI( false, false ) ) {
1232 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1234 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1235 JOptionPane.showMessageDialog( this,
1236 "Gene tree is not completely binary",
1237 "Cannot execute GSDI",
1238 JOptionPane.ERROR_MESSAGE );
1241 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1242 gene_tree.setAllNodesToNotCollapse();
1243 gene_tree.recalculateNumberOfExternalDescendants( false );
1245 final Phylogeny species_tree = _species_tree.copy();
1247 gsdir = new GSDIR( gene_tree, species_tree, true, true );
1249 catch ( final SDIException e ) {
1250 JOptionPane.showMessageDialog( this,
1251 e.getLocalizedMessage(),
1252 "Error during GSDIR",
1253 JOptionPane.ERROR_MESSAGE );
1256 catch ( final Exception e ) {
1257 AptxUtil.unexpectedException( e );
1260 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1261 result_gene_tree.setRerootable( false );
1262 result_gene_tree.clearHashIdToNodeMap();
1263 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1264 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1265 getControlPanel().setShowEvents( true );
1267 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1268 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1270 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1272 _mainpanel.getCurrentTreePanel().setEdited( true );
1273 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1274 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1275 JOptionPane.showMessageDialog( this,
1276 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1277 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1278 + "Stripped gene tree nodes: "
1279 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1280 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1281 + "Number of polytomies in species tree used: " + poly + "\n",
1282 "GSDIR successfully completed",
1283 JOptionPane.WARNING_MESSAGE );
1286 JOptionPane.showMessageDialog( this,
1287 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1288 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1289 + "Stripped gene tree nodes: "
1290 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1291 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1292 + "Number of polytomies in species tree used: " + poly + "\n",
1293 "GSDIR successfully completed",
1294 JOptionPane.INFORMATION_MESSAGE );
1298 void executeLineageInference() {
1299 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1302 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1303 JOptionPane.showMessageDialog( this,
1304 "Phylogeny is not rooted.",
1305 "Cannot infer ancestral taxonomies",
1306 JOptionPane.ERROR_MESSAGE );
1309 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1310 _mainpanel.getCurrentTreePanel(),
1311 _mainpanel.getCurrentPhylogeny()
1313 new Thread( inferrer ).start();
1317 removeAllTextFrames();
1318 _mainpanel.terminate();
1319 _contentpane.removeAll();
1320 setVisible( false );
1325 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1326 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1329 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1330 JOptionPane.showMessageDialog( this,
1331 "No species tree loaded",
1332 "Cannot execute GSDI",
1333 JOptionPane.ERROR_MESSAGE );
1336 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1337 JOptionPane.showMessageDialog( this,
1338 "Species tree is not completely binary",
1339 "Cannot execute GSDI",
1340 JOptionPane.ERROR_MESSAGE );
1343 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1344 JOptionPane.showMessageDialog( this,
1345 "Gene tree is not completely binary",
1346 "Cannot execute GSDI",
1347 JOptionPane.ERROR_MESSAGE );
1356 void readPhylogeniesFromURL() {
1358 Phylogeny[] phys = null;
1359 final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\"";
1360 final String url_string = JOptionPane.showInputDialog( this,
1362 "Use URL/webservice to obtain a phylogeny",
1363 JOptionPane.QUESTION_MESSAGE );
1364 boolean nhx_or_nexus = false;
1365 if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
1367 url = new URL( url_string );
1368 PhylogenyParser parser = null;
1369 if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
1370 parser = new TolParser();
1373 parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
1374 .isValidatePhyloXmlAgainstSchema() );
1376 if ( parser instanceof NexusPhylogeniesParser ) {
1377 nhx_or_nexus = true;
1379 else if ( parser instanceof NHXParser ) {
1380 nhx_or_nexus = true;
1382 if ( _mainpanel.getCurrentTreePanel() != null ) {
1383 _mainpanel.getCurrentTreePanel().setWaitCursor();
1386 _mainpanel.setWaitCursor();
1388 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1389 phys = factory.create( url.openStream(), parser );
1391 catch ( final MalformedURLException e ) {
1392 JOptionPane.showMessageDialog( this,
1393 "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
1395 JOptionPane.ERROR_MESSAGE );
1397 catch ( final IOException e ) {
1398 JOptionPane.showMessageDialog( this,
1399 "Could not read from " + url + "\n"
1400 + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1401 "Failed to read URL",
1402 JOptionPane.ERROR_MESSAGE );
1404 catch ( final Exception e ) {
1405 JOptionPane.showMessageDialog( this,
1406 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1407 "Unexpected Exception",
1408 JOptionPane.ERROR_MESSAGE );
1411 if ( _mainpanel.getCurrentTreePanel() != null ) {
1412 _mainpanel.getCurrentTreePanel().setArrowCursor();
1415 _mainpanel.setArrowCursor();
1418 if ( ( phys != null ) && ( phys.length > 0 ) ) {
1419 if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
1420 for( final Phylogeny phy : phys ) {
1421 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
1424 AptxUtil.addPhylogeniesToTabs( phys,
1425 new File( url.getFile() ).getName(),
1426 new File( url.getFile() ).toString(),
1429 _mainpanel.getControlPanel().showWhole();
1432 activateSaveAllIfNeeded();
1436 void setMsa( final Msa msa ) {
1440 void setMsaFile( final File msa_file ) {
1441 _msa_file = msa_file;
1444 void setSeqs( final List<Sequence> seqs ) {
1448 void setSeqsFile( final File seqs_file ) {
1449 _seqs_file = seqs_file;
1452 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
1453 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
1454 _mainpanel.getCurrentTreePanel().getHeight(),
1456 String file_written_to = "";
1457 boolean error = false;
1459 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
1460 _mainpanel.getCurrentTreePanel().getWidth(),
1461 _mainpanel.getCurrentTreePanel().getHeight(),
1462 _mainpanel.getCurrentTreePanel(),
1463 _mainpanel.getControlPanel(),
1467 catch ( final IOException e ) {
1469 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
1472 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
1473 JOptionPane.showMessageDialog( this,
1474 "Wrote image to: " + file_written_to,
1476 JOptionPane.INFORMATION_MESSAGE );
1479 JOptionPane.showMessageDialog( this,
1480 "There was an unknown problem when attempting to write to an image file: \""
1483 JOptionPane.ERROR_MESSAGE );
1486 _contentpane.repaint();
1489 private void addSequencesFromFile() {
1490 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1491 JOptionPane.showMessageDialog( this,
1492 "Need to load evolutionary tree first",
1493 "Can Not Read Sequences",
1494 JOptionPane.WARNING_MESSAGE );
1497 final File my_dir = getCurrentDir();
1498 if ( my_dir != null ) {
1499 _sequences_filechooser.setCurrentDirectory( my_dir );
1501 final int result = _sequences_filechooser.showOpenDialog( _contentpane );
1502 final File file = _sequences_filechooser.getSelectedFile();
1503 List<Sequence> seqs = null;
1504 if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
1506 if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
1507 seqs = FastaParser.parse( new FileInputStream( file ) );
1510 JOptionPane.showMessageDialog( this,
1511 "Format does not appear to be Fasta",
1512 "Multiple sequence file format error",
1513 JOptionPane.ERROR_MESSAGE );
1517 catch ( final MsaFormatException e ) {
1519 JOptionPane.showMessageDialog( this,
1520 e.getLocalizedMessage(),
1521 "Multiple sequence file format error",
1522 JOptionPane.ERROR_MESSAGE );
1525 catch ( final IOException e ) {
1527 JOptionPane.showMessageDialog( this,
1528 e.getLocalizedMessage(),
1529 "Failed to read multiple sequence file",
1530 JOptionPane.ERROR_MESSAGE );
1533 catch ( final Exception e ) {
1535 e.printStackTrace();
1536 JOptionPane.showMessageDialog( this,
1537 e.getLocalizedMessage(),
1538 "Unexpected error during reading of multiple sequence file",
1539 JOptionPane.ERROR_MESSAGE );
1542 if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
1543 JOptionPane.showMessageDialog( this,
1544 "Multiple sequence file is empty",
1545 "Empty multiple sequence file",
1546 JOptionPane.ERROR_MESSAGE );
1551 if ( seqs != null ) {
1552 for( final Sequence seq : seqs ) {
1553 System.out.println( seq.getIdentifier() );
1555 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1556 int total_counter = 0;
1557 int attached_counter = 0;
1558 for( final Sequence seq : seqs ) {
1560 final String seq_name = seq.getIdentifier();
1561 if ( !ForesterUtil.isEmpty( seq_name ) ) {
1562 List<PhylogenyNode> nodes = phy.getNodesViaSequenceName( seq_name );
1563 if ( nodes.isEmpty() ) {
1564 nodes = phy.getNodesViaSequenceSymbol( seq_name );
1566 if ( nodes.isEmpty() ) {
1567 nodes = phy.getNodes( seq_name );
1569 if ( nodes.size() > 1 ) {
1570 JOptionPane.showMessageDialog( this,
1571 "Sequence name \"" + seq_name + "\" is not unique",
1572 "Sequence name not unique",
1573 JOptionPane.ERROR_MESSAGE );
1577 final String[] a = seq_name.split( "\\s" );
1578 if ( nodes.isEmpty() && ( a.length > 1 ) ) {
1579 final String seq_name_split = a[ 0 ];
1580 nodes = phy.getNodesViaSequenceName( seq_name_split );
1581 if ( nodes.isEmpty() ) {
1582 nodes = phy.getNodesViaSequenceSymbol( seq_name_split );
1584 if ( nodes.isEmpty() ) {
1585 nodes = phy.getNodes( seq_name_split );
1587 if ( nodes.size() > 1 ) {
1588 JOptionPane.showMessageDialog( this, "Split sequence name \"" + seq_name_split
1589 + "\" is not unique", "Sequence name not unique", JOptionPane.ERROR_MESSAGE );
1594 if ( nodes.size() == 1 ) {
1596 final PhylogenyNode n = nodes.get( 0 );
1597 if ( !n.getNodeData().isHasSequence() ) {
1598 n.getNodeData().addSequence( new org.forester.phylogeny.data.Sequence() );
1600 n.getNodeData().getSequence().setMolecularSequence( seq.getMolecularSequenceAsString() );
1601 if ( ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
1602 n.getNodeData().getSequence().setName( seq_name );
1607 if ( attached_counter > 0 ) {
1609 int ext_nodes_with_seq = 0;
1610 for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {
1612 final PhylogenyNode n = iter.next();
1613 if ( n.getNodeData().isHasSequence()
1614 && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
1615 ++ext_nodes_with_seq;
1619 if ( ext_nodes == ext_nodes_with_seq ) {
1620 s = "All " + ext_nodes_with_seq + " external nodes now have a molecular sequence attached to them.";
1623 s = ext_nodes_with_seq + " out of " + ext_nodes
1624 + " external nodes now have a molecular sequence attached to them.";
1626 if ( ( attached_counter == total_counter ) && ( ext_nodes == ext_nodes_with_seq ) ) {
1627 JOptionPane.showMessageDialog( this,
1628 "Attached all " + total_counter + " sequences to tree nodes.\n" + s,
1629 "All sequences attached",
1630 JOptionPane.INFORMATION_MESSAGE );
1633 JOptionPane.showMessageDialog( this, "Attached " + attached_counter
1634 + " sequences out of a total of " + total_counter + " sequences.\n" + s, attached_counter
1635 + " sequences attached", JOptionPane.WARNING_MESSAGE );
1639 JOptionPane.showMessageDialog( this, "No maching tree node for any of the " + total_counter
1640 + " sequences", "Could not attach any sequences", JOptionPane.ERROR_MESSAGE );
1645 private void setArrowCursor() {
1647 _mainpanel.getCurrentTreePanel().setArrowCursor();
1649 catch ( final Exception ex ) {
1654 private void addExpressionValuesFromFile() {
1655 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {
1656 JOptionPane.showMessageDialog( this,
1657 "Need to load evolutionary tree first",
1658 "Can Not Read Expression Values",
1659 JOptionPane.WARNING_MESSAGE );
1662 final File my_dir = getCurrentDir();
1663 if ( my_dir != null ) {
1664 _values_filechooser.setCurrentDirectory( my_dir );
1666 final int result = _values_filechooser.showOpenDialog( _contentpane );
1667 final File file = _values_filechooser.getSelectedFile();
1668 if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1669 BasicTable<String> t = null;
1671 t = BasicTableParser.parse( file, "\t" );
1672 if ( t.getNumberOfColumns() < 2 ) {
1673 t = BasicTableParser.parse( file, "," );
1675 if ( t.getNumberOfColumns() < 2 ) {
1676 t = BasicTableParser.parse( file, " " );
1679 catch ( final IOException e ) {
1680 JOptionPane.showMessageDialog( this,
1682 "Could Not Read Expression Value Table",
1683 JOptionPane.ERROR_MESSAGE );
1686 if ( t.getNumberOfColumns() < 2 ) {
1687 JOptionPane.showMessageDialog( this,
1688 "Table contains " + t.getNumberOfColumns() + " column(s)",
1689 "Problem with Expression Value Table",
1690 JOptionPane.ERROR_MESSAGE );
1693 if ( t.getNumberOfRows() < 1 ) {
1694 JOptionPane.showMessageDialog( this,
1695 "Table contains zero rows",
1696 "Problem with Expression Value Table",
1697 JOptionPane.ERROR_MESSAGE );
1700 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1701 if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {
1702 JOptionPane.showMessageDialog( this,
1703 "Table contains " + t.getNumberOfRows() + " rows, but tree contains "
1704 + phy.getNumberOfExternalNodes() + " external nodes",
1706 JOptionPane.WARNING_MESSAGE );
1708 final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
1710 for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
1711 final PhylogenyNode node = iter.next();
1712 final String node_name = node.getName();
1713 if ( !ForesterUtil.isEmpty( node_name ) ) {
1716 row = t.findRow( node_name );
1718 catch ( final IllegalArgumentException e ) {
1720 .showMessageDialog( this,
1722 "Error Mapping Node Identifiers to Expression Value Identifiers",
1723 JOptionPane.ERROR_MESSAGE );
1727 if ( node.isExternal() ) {
1732 final List<Double> l = new ArrayList<Double>();
1733 for( int col = 1; col < t.getNumberOfColumns(); ++col ) {
1736 d = Double.parseDouble( t.getValueAsString( col, row ) );
1738 catch ( final NumberFormatException e ) {
1739 JOptionPane.showMessageDialog( this,
1740 "Could not parse \"" + t.getValueAsString( col, row )
1741 + "\" into a decimal value",
1742 "Issue with Expression Value Table",
1743 JOptionPane.ERROR_MESSAGE );
1746 stats.addValue( d );
1749 if ( !l.isEmpty() ) {
1750 if ( node.getNodeData().getProperties() != null ) {
1751 node.getNodeData().getProperties()
1752 .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );
1754 node.getNodeData().setVector( l );
1758 if ( not_found > 0 ) {
1759 JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found
1760 + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );
1762 getCurrentTreePanel().setStatisticsForExpressionValues( stats );
1766 private void choosePdfWidth() {
1767 final String s = ( String ) JOptionPane.showInputDialog( this,
1768 "Please enter the default line width for PDF export.\n"
1769 + "[current value: "
1770 + getOptions().getPrintLineWidth() + "]\n",
1771 "Line Width for PDF Export",
1772 JOptionPane.QUESTION_MESSAGE,
1775 getOptions().getPrintLineWidth() );
1776 if ( !ForesterUtil.isEmpty( s ) ) {
1777 boolean success = true;
1779 final String m_str = s.trim();
1780 if ( !ForesterUtil.isEmpty( m_str ) ) {
1782 f = Float.parseFloat( m_str );
1784 catch ( final Exception ex ) {
1791 if ( success && ( f > 0.0 ) ) {
1792 getOptions().setPrintLineWidth( f );
1797 private void choosePrintSize() {
1798 final String s = ( String ) JOptionPane.showInputDialog( this,
1799 "Please enter values for width and height,\nseparated by a comma.\n"
1800 + "[current values: "
1801 + getOptions().getPrintSizeX() + ", "
1802 + getOptions().getPrintSizeY() + "]\n"
1803 + "[A4: " + Constants.A4_SIZE_X + ", "
1804 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
1805 + Constants.US_LETTER_SIZE_X + ", "
1806 + Constants.US_LETTER_SIZE_Y + "]",
1807 "Default Size for Graphics Export",
1808 JOptionPane.QUESTION_MESSAGE,
1811 getOptions().getPrintSizeX() + ", "
1812 + getOptions().getPrintSizeY() );
1813 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
1814 boolean success = true;
1817 final String[] str_ary = s.split( "," );
1818 if ( str_ary.length == 2 ) {
1819 final String x_str = str_ary[ 0 ].trim();
1820 final String y_str = str_ary[ 1 ].trim();
1821 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
1823 x = Integer.parseInt( x_str );
1824 y = Integer.parseInt( y_str );
1826 catch ( final Exception ex ) {
1837 if ( success && ( x > 1 ) && ( y > 1 ) ) {
1838 getOptions().setPrintSizeX( x );
1839 getOptions().setPrintSizeY( y );
1844 private void closeCurrentPane() {
1845 if ( getMainPanel().getCurrentTreePanel() != null ) {
1846 if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
1847 final int r = JOptionPane.showConfirmDialog( this,
1848 "Close tab despite potentially unsaved changes?",
1850 JOptionPane.YES_NO_OPTION );
1851 if ( r != JOptionPane.YES_OPTION ) {
1855 getMainPanel().closeCurrentPane();
1856 activateSaveAllIfNeeded();
1860 private void collapse( final Phylogeny phy, final double m ) {
1861 final PhylogenyNodeIterator it = phy.iteratorPostorder();
1862 final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
1863 double min_support = Double.MAX_VALUE;
1864 boolean conf_present = false;
1865 while ( it.hasNext() ) {
1866 final PhylogenyNode n = it.next();
1867 if ( !n.isExternal() && !n.isRoot() ) {
1868 final List<Confidence> c = n.getBranchData().getConfidences();
1869 if ( ( c != null ) && ( c.size() > 0 ) ) {
1870 conf_present = true;
1872 for( final Confidence confidence : c ) {
1873 if ( confidence.getValue() > max ) {
1874 max = confidence.getValue();
1877 if ( max < getMinNotCollapseConfidenceValue() ) {
1878 to_be_removed.add( n );
1880 if ( max < min_support ) {
1886 if ( conf_present ) {
1887 for( final PhylogenyNode node : to_be_removed ) {
1888 PhylogenyMethods.removeNode( node, phy );
1890 if ( to_be_removed.size() > 0 ) {
1891 phy.externalNodesHaveChanged();
1892 phy.clearHashIdToNodeMap();
1893 phy.recalculateNumberOfExternalDescendants( true );
1894 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1895 getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1896 getCurrentTreePanel().calculateLongestExtNodeInfo();
1897 getCurrentTreePanel().setNodeInPreorderToNull();
1898 getCurrentTreePanel().recalculateMaxDistanceToRoot();
1899 getCurrentTreePanel().resetPreferredSize();
1900 getCurrentTreePanel().setEdited( true );
1901 getCurrentTreePanel().repaint();
1904 if ( to_be_removed.size() > 0 ) {
1905 JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()
1906 + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "
1907 + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );
1910 JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "
1911 + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );
1915 JOptionPane.showMessageDialog( this,
1916 "No branch collapsed because no confidence values present",
1917 "No confidence values present",
1918 JOptionPane.INFORMATION_MESSAGE );
1922 private void collapseBelowThreshold() {
1923 if ( getCurrentTreePanel() != null ) {
1924 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
1925 if ( ( phy != null ) && !phy.isEmpty() ) {
1926 final String s = ( String ) JOptionPane.showInputDialog( this,
1927 "Please enter the minimum confidence value\n",
1928 "Minimal Confidence Value",
1929 JOptionPane.QUESTION_MESSAGE,
1932 getMinNotCollapseConfidenceValue() );
1933 if ( !ForesterUtil.isEmpty( s ) ) {
1934 boolean success = true;
1936 final String m_str = s.trim();
1937 if ( !ForesterUtil.isEmpty( m_str ) ) {
1939 m = Double.parseDouble( m_str );
1941 catch ( final Exception ex ) {
1948 if ( success && ( m >= 0.0 ) ) {
1949 setMinNotCollapseConfidenceValue( m );
1957 private PhyloXmlParser createPhyloXmlParser() {
1958 PhyloXmlParser xml_parser = null;
1959 if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
1961 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1963 catch ( final Exception e ) {
1964 JOptionPane.showMessageDialog( this,
1965 e.getLocalizedMessage(),
1966 "failed to create validating XML parser",
1967 JOptionPane.WARNING_MESSAGE );
1970 if ( xml_parser == null ) {
1971 xml_parser = new PhyloXmlParser();
1976 private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
1977 final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
1978 getPhylogeneticInferenceOptions(),
1979 from_unaligned_seqs );
1981 if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
1982 if ( !from_unaligned_seqs ) {
1983 if ( getMsa() != null ) {
1984 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
1985 getPhylogeneticInferenceOptions()
1987 new Thread( inferrer ).start();
1990 JOptionPane.showMessageDialog( this,
1991 "No multiple sequence alignment selected",
1992 "Phylogenetic Inference Not Launched",
1993 JOptionPane.WARNING_MESSAGE );
1997 if ( getSeqs() != null ) {
1998 final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
1999 getPhylogeneticInferenceOptions()
2001 new Thread( inferrer ).start();
2004 JOptionPane.showMessageDialog( this,
2005 "No input sequences selected",
2006 "Phylogenetic Inference Not Launched",
2007 JOptionPane.WARNING_MESSAGE );
2013 private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
2014 final StringBuilder sb = new StringBuilder();
2015 final StringBuilder sb_failed = new StringBuilder();
2017 int counter_failed = 0;
2018 if ( getCurrentTreePanel() != null ) {
2019 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2020 if ( ( phy != null ) && !phy.isEmpty() ) {
2021 final PhylogenyNodeIterator it = phy.iteratorExternalForward();
2022 while ( it.hasNext() ) {
2023 final PhylogenyNode n = it.next();
2024 final String name = n.getName().trim();
2025 if ( !ForesterUtil.isEmpty( name ) ) {
2026 final String nt = ParserUtils
2027 .extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
2028 if ( !ForesterUtil.isEmpty( nt ) ) {
2029 if ( counter < 15 ) {
2030 sb.append( name + ": " + nt + "\n" );
2032 else if ( counter == 15 ) {
2033 sb.append( "...\n" );
2038 if ( counter_failed < 15 ) {
2039 sb_failed.append( name + "\n" );
2041 else if ( counter_failed == 15 ) {
2042 sb_failed.append( "...\n" );
2048 if ( counter > 0 ) {
2050 String all = "all ";
2051 if ( counter_failed > 0 ) {
2053 failed = "\nCould not extract taxonomic data for " + counter_failed
2054 + " named external nodes:\n" + sb_failed;
2056 JOptionPane.showMessageDialog( this,
2057 "Extracted taxonomic data from " + all + counter
2058 + " named external nodes:\n" + sb.toString() + failed,
2059 "Taxonomic Data Extraction Completed",
2060 counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
2061 : JOptionPane.INFORMATION_MESSAGE );
2065 .showMessageDialog( this,
2066 "Could not extract any taxonomic data.\nMaybe node names are empty\n"
2067 + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
2068 + "or nodes already have taxonomic data?\n",
2069 "No Taxonomic Data Extracted",
2070 JOptionPane.ERROR_MESSAGE );
2076 private ControlPanel getControlPanel() {
2077 return getMainPanel().getControlPanel();
2080 private File getCurrentDir() {
2081 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
2082 if ( ForesterUtil.isWindowns() ) {
2084 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
2086 catch ( final Exception e ) {
2087 _current_dir = null;
2091 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
2092 if ( System.getProperty( "user.home" ) != null ) {
2093 _current_dir = new File( System.getProperty( "user.home" ) );
2095 else if ( System.getProperty( "user.dir" ) != null ) {
2096 _current_dir = new File( System.getProperty( "user.dir" ) );
2099 return _current_dir;
2102 private double getMinNotCollapseConfidenceValue() {
2103 return _min_not_collapse;
2106 private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
2107 if ( _phylogenetic_inference_options == null ) {
2108 _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
2110 return _phylogenetic_inference_options;
2113 private boolean isUnsavedDataPresent() {
2114 final List<TreePanel> tps = getMainPanel().getTreePanels();
2115 for( final TreePanel tp : tps ) {
2116 if ( tp.isEdited() ) {
2123 private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
2124 if ( getCurrentTreePanel() != null ) {
2125 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2126 if ( ( phy != null ) && !phy.isEmpty() ) {
2128 .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
2133 private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
2134 if ( getCurrentTreePanel() != null ) {
2135 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2136 if ( ( phy != null ) && !phy.isEmpty() ) {
2137 PhylogenyMethods.transferNodeNameToField( phy,
2138 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
2144 private void newTree() {
2145 final Phylogeny[] phys = new Phylogeny[ 1 ];
2146 final Phylogeny phy = new Phylogeny();
2147 final PhylogenyNode node = new PhylogenyNode();
2148 phy.setRoot( node );
2149 phy.setRooted( true );
2151 AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
2152 _mainpanel.getControlPanel().showWhole();
2153 _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2154 _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2155 if ( getMainPanel().getMainFrame() == null ) {
2156 // Must be "E" applet version.
2157 ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
2158 .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2161 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
2163 activateSaveAllIfNeeded();
2167 private void obtainDetailedTaxonomicInformation() {
2168 if ( getCurrentTreePanel() != null ) {
2169 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2170 if ( ( phy != null ) && !phy.isEmpty() ) {
2171 final TaxonomyDataManager t = new TaxonomyDataManager( this,
2172 _mainpanel.getCurrentTreePanel(),
2176 new Thread( t ).start();
2181 private void obtainDetailedTaxonomicInformationDelete() {
2182 if ( getCurrentTreePanel() != null ) {
2183 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2184 if ( ( phy != null ) && !phy.isEmpty() ) {
2185 final TaxonomyDataManager t = new TaxonomyDataManager( this,
2186 _mainpanel.getCurrentTreePanel(),
2190 new Thread( t ).start();
2195 private void obtainSequenceInformation() {
2196 if ( getCurrentTreePanel() != null ) {
2197 final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
2198 if ( ( phy != null ) && !phy.isEmpty() ) {
2199 final SequenceDataRetriver u = new SequenceDataRetriver( this,
2200 _mainpanel.getCurrentTreePanel(),
2202 new Thread( u ).start();
2207 private void print() {
2208 if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
2209 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
2212 if ( !getOptions().isPrintUsingActualSize() ) {
2213 getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80,
2214 getOptions().getPrintSizeY() - 140,
2216 getCurrentTreePanel().resetPreferredSize();
2217 getCurrentTreePanel().repaint();
2219 final String job_name = Constants.PRG_NAME;
2220 boolean error = false;
2221 String printer_name = null;
2223 printer_name = Printer.print( getCurrentTreePanel(), job_name );
2225 catch ( final Exception e ) {
2227 JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2229 if ( !error && ( printer_name != null ) ) {
2230 String msg = "Printing data sent to printer";
2231 if ( printer_name.length() > 1 ) {
2232 msg += " [" + printer_name + "]";
2234 JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2236 if ( !getOptions().isPrintUsingActualSize() ) {
2237 getControlPanel().showWhole();
2241 private void printPhylogenyToPdf( final String file_name ) {
2242 if ( !getOptions().isPrintUsingActualSize() ) {
2243 getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(),
2244 getOptions().getPrintSizeY(),
2246 getCurrentTreePanel().resetPreferredSize();
2247 getCurrentTreePanel().repaint();
2249 String pdf_written_to = "";
2250 boolean error = false;
2252 if ( getOptions().isPrintUsingActualSize() ) {
2253 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,
2254 getCurrentTreePanel(),
2255 getCurrentTreePanel().getWidth(),
2256 getCurrentTreePanel().getHeight() );
2259 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
2260 .getPrintSizeX(), getOptions().getPrintSizeY() );
2263 catch ( final IOException e ) {
2265 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2268 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2269 JOptionPane.showMessageDialog( this,
2270 "Wrote PDF to: " + pdf_written_to,
2272 JOptionPane.INFORMATION_MESSAGE );
2275 JOptionPane.showMessageDialog( this,
2276 "There was an unknown problem when attempting to write to PDF file: \""
2279 JOptionPane.ERROR_MESSAGE );
2282 if ( !getOptions().isPrintUsingActualSize() ) {
2283 getControlPanel().showWhole();
2287 private void readPhylogeniesFromFile() {
2288 boolean exception = false;
2289 Phylogeny[] phys = null;
2290 // Set an initial directory if none set yet
2291 final File my_dir = getCurrentDir();
2292 _open_filechooser.setMultiSelectionEnabled( true );
2293 // Open file-open dialog and set current directory
2294 if ( my_dir != null ) {
2295 _open_filechooser.setCurrentDirectory( my_dir );
2297 final int result = _open_filechooser.showOpenDialog( _contentpane );
2298 // All done: get the file
2299 final File[] files = _open_filechooser.getSelectedFiles();
2300 setCurrentDir( _open_filechooser.getCurrentDirectory() );
2301 boolean nhx_or_nexus = false;
2302 if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2303 for( final File file : files ) {
2304 if ( ( file != null ) && !file.isDirectory() ) {
2305 if ( _mainpanel.getCurrentTreePanel() != null ) {
2306 _mainpanel.getCurrentTreePanel().setWaitCursor();
2309 _mainpanel.setWaitCursor();
2311 if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
2312 || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
2314 final NHXParser nhx = new NHXParser();
2315 setSpecialOptionsForNhxParser( nhx );
2316 phys = PhylogenyMethods.readPhylogenies( nhx, file );
2317 nhx_or_nexus = true;
2319 catch ( final Exception e ) {
2321 exceptionOccuredDuringOpenFile( e );
2324 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2325 warnIfNotPhyloXmlValidation( getConfiguration() );
2327 final PhyloXmlParser xml_parser = createPhyloXmlParser();
2328 phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
2330 catch ( final Exception e ) {
2332 exceptionOccuredDuringOpenFile( e );
2335 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
2337 phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2339 catch ( final Exception e ) {
2341 exceptionOccuredDuringOpenFile( e );
2344 else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2346 final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
2347 setSpecialOptionsForNexParser( nex );
2348 phys = PhylogenyMethods.readPhylogenies( nex, file );
2349 nhx_or_nexus = true;
2351 catch ( final Exception e ) {
2353 exceptionOccuredDuringOpenFile( e );
2359 final PhylogenyParser parser = ParserUtils
2360 .createParserDependingOnFileType( file, getConfiguration()
2361 .isValidatePhyloXmlAgainstSchema() );
2362 if ( parser instanceof NexusPhylogeniesParser ) {
2363 final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
2364 setSpecialOptionsForNexParser( nex );
2365 nhx_or_nexus = true;
2367 else if ( parser instanceof NHXParser ) {
2368 final NHXParser nhx = ( NHXParser ) parser;
2369 setSpecialOptionsForNhxParser( nhx );
2370 nhx_or_nexus = true;
2372 else if ( parser instanceof PhyloXmlParser ) {
2373 warnIfNotPhyloXmlValidation( getConfiguration() );
2375 phys = PhylogenyMethods.readPhylogenies( parser, file );
2377 catch ( final Exception e ) {
2379 exceptionOccuredDuringOpenFile( e );
2382 if ( _mainpanel.getCurrentTreePanel() != null ) {
2383 _mainpanel.getCurrentTreePanel().setArrowCursor();
2386 _mainpanel.setArrowCursor();
2388 if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
2389 boolean one_desc = false;
2390 if ( nhx_or_nexus ) {
2391 for( final Phylogeny phy : phys ) {
2392 if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
2393 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
2395 if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
2401 AptxUtil.addPhylogeniesToTabs( phys,
2403 file.getAbsolutePath(),
2406 _mainpanel.getControlPanel().showWhole();
2407 if ( nhx_or_nexus && one_desc ) {
2409 .showMessageDialog( this,
2410 "One or more trees contain (a) node(s) with one descendant, "
2411 + ForesterUtil.LINE_SEPARATOR
2412 + "possibly indicating illegal parentheses within node names.",
2413 "Warning: Possible Error in New Hampshire Formatted Data",
2414 JOptionPane.WARNING_MESSAGE );
2420 activateSaveAllIfNeeded();
2424 private void readSpeciesTreeFromFile() {
2426 boolean exception = false;
2427 final File my_dir = getCurrentDir();
2428 _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
2429 if ( my_dir != null ) {
2430 _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
2432 final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );
2433 final File file = _open_filechooser_for_species_tree.getSelectedFile();
2434 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2435 if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
2437 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2440 catch ( final Exception e ) {
2442 exceptionOccuredDuringOpenFile( e );
2445 else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
2447 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
2450 catch ( final Exception e ) {
2452 exceptionOccuredDuringOpenFile( e );
2458 final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
2461 catch ( final Exception e ) {
2463 exceptionOccuredDuringOpenFile( e );
2466 if ( !exception && ( t != null ) && !t.isRooted() ) {
2469 JOptionPane.showMessageDialog( this,
2470 "Species tree is not rooted",
2471 "Species tree not loaded",
2472 JOptionPane.ERROR_MESSAGE );
2474 if ( !exception && ( t != null ) ) {
2475 final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
2476 for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
2477 final PhylogenyNode node = it.next();
2478 if ( !node.getNodeData().isHasTaxonomy() ) {
2482 .showMessageDialog( this,
2483 "Species tree contains external node(s) without taxonomy information",
2484 "Species tree not loaded",
2485 JOptionPane.ERROR_MESSAGE );
2489 if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {
2492 JOptionPane.showMessageDialog( this,
2494 + node.getNodeData().getTaxonomy().asSimpleText()
2495 + "] is not unique in species tree",
2496 "Species tree not loaded",
2497 JOptionPane.ERROR_MESSAGE );
2501 tax_set.add( node.getNodeData().getTaxonomy() );
2506 if ( !exception && ( t != null ) ) {
2508 JOptionPane.showMessageDialog( this,
2509 "Species tree successfully loaded",
2510 "Species tree loaded",
2511 JOptionPane.INFORMATION_MESSAGE );
2513 _contentpane.repaint();
2518 private void setCurrentDir( final File current_dir ) {
2519 _current_dir = current_dir;
2522 private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
2523 _min_not_collapse = min_not_collapse;
2526 private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
2527 _phylogenetic_inference_options = phylogenetic_inference_options;
2530 private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
2531 nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2532 nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2535 private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
2536 nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
2537 nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
2540 private void writeAllToFile() {
2541 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
2544 final File my_dir = getCurrentDir();
2545 if ( my_dir != null ) {
2546 _save_filechooser.setCurrentDirectory( my_dir );
2548 _save_filechooser.setSelectedFile( new File( "" ) );
2549 final int result = _save_filechooser.showSaveDialog( _contentpane );
2550 final File file = _save_filechooser.getSelectedFile();
2551 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2552 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2553 if ( file.exists() ) {
2554 final int i = JOptionPane.showConfirmDialog( this,
2555 file + " already exists. Overwrite?",
2557 JOptionPane.OK_CANCEL_OPTION,
2558 JOptionPane.WARNING_MESSAGE );
2559 if ( i != JOptionPane.OK_OPTION ) {
2566 catch ( final Exception e ) {
2567 JOptionPane.showMessageDialog( this,
2568 "Failed to delete: " + file,
2570 JOptionPane.WARNING_MESSAGE );
2574 final int count = getMainPanel().getTabbedPane().getTabCount();
2575 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
2576 for( int i = 0; i < count; ++i ) {
2577 final Phylogeny phy = getMainPanel().getPhylogeny( i );
2578 if ( ForesterUtil.isEmpty( phy.getName() )
2579 && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {
2580 phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );
2583 getMainPanel().getTreePanels().get( i ).setEdited( false );
2585 final PhylogenyWriter writer = new PhylogenyWriter();
2587 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
2589 catch ( final IOException e ) {
2590 JOptionPane.showMessageDialog( this,
2591 "Failed to write to: " + file,
2593 JOptionPane.WARNING_MESSAGE );
2598 private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {
2600 final PhylogenyWriter writer = new PhylogenyWriter();
2601 writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file );
2603 catch ( final Exception e ) {
2605 exceptionOccuredDuringSaveAs( e );
2610 private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {
2612 final PhylogenyWriter writer = new PhylogenyWriter();
2613 writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );
2615 catch ( final Exception e ) {
2617 exceptionOccuredDuringSaveAs( e );
2622 private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {
2624 final PhylogenyWriter writer = new PhylogenyWriter();
2625 writer.toPhyloXML( file, t, 0 );
2627 catch ( final Exception e ) {
2629 exceptionOccuredDuringSaveAs( e );
2634 private void writeToFile( final Phylogeny t ) {
2638 String initial_filename = null;
2639 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2641 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
2643 catch ( final IOException e ) {
2644 initial_filename = null;
2647 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2648 _save_filechooser.setSelectedFile( new File( initial_filename ) );
2651 _save_filechooser.setSelectedFile( new File( "" ) );
2653 final File my_dir = getCurrentDir();
2654 if ( my_dir != null ) {
2655 _save_filechooser.setCurrentDirectory( my_dir );
2657 final int result = _save_filechooser.showSaveDialog( _contentpane );
2658 final File file = _save_filechooser.getSelectedFile();
2659 setCurrentDir( _save_filechooser.getCurrentDirectory() );
2660 boolean exception = false;
2661 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2662 if ( file.exists() ) {
2663 final int i = JOptionPane.showConfirmDialog( this,
2664 file + " already exists.\nOverwrite?",
2666 JOptionPane.OK_CANCEL_OPTION,
2667 JOptionPane.QUESTION_MESSAGE );
2668 if ( i != JOptionPane.OK_OPTION ) {
2672 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
2674 ForesterUtil.copyFile( file, to );
2676 catch ( final Exception e ) {
2677 JOptionPane.showMessageDialog( this,
2678 "Failed to create backup copy " + to,
2679 "Failed to Create Backup Copy",
2680 JOptionPane.WARNING_MESSAGE );
2685 catch ( final Exception e ) {
2686 JOptionPane.showMessageDialog( this,
2687 "Failed to delete: " + file,
2689 JOptionPane.WARNING_MESSAGE );
2693 if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
2694 exception = writeAsNewHampshire( t, exception, file );
2696 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
2697 exception = writeAsPhyloXml( t, exception, file );
2699 else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
2700 exception = writeAsNexus( t, exception, file );
2704 final String file_name = file.getName().trim().toLowerCase();
2705 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2706 || file_name.endsWith( ".tree" ) ) {
2707 exception = writeAsNewHampshire( t, exception, file );
2709 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2710 exception = writeAsNexus( t, exception, file );
2714 exception = writeAsPhyloXml( t, exception, file );
2718 getMainPanel().setTitleOfSelectedTab( file.getName() );
2719 getMainPanel().getCurrentTreePanel().setTreeFile( file );
2720 getMainPanel().getCurrentTreePanel().setEdited( false );
2725 private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
2726 if ( ( t == null ) || t.isEmpty() ) {
2729 String initial_filename = "";
2730 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2731 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2733 if ( initial_filename.indexOf( '.' ) > 0 ) {
2734 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2736 initial_filename = initial_filename + "." + type;
2737 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2738 final File my_dir = getCurrentDir();
2739 if ( my_dir != null ) {
2740 _writetographics_filechooser.setCurrentDirectory( my_dir );
2742 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
2743 File file = _writetographics_filechooser.getSelectedFile();
2744 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
2745 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2746 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2747 file = new File( file.toString() + "." + type );
2749 if ( file.exists() ) {
2750 final int i = JOptionPane.showConfirmDialog( this,
2751 file + " already exists. Overwrite?",
2753 JOptionPane.OK_CANCEL_OPTION,
2754 JOptionPane.WARNING_MESSAGE );
2755 if ( i != JOptionPane.OK_OPTION ) {
2762 catch ( final Exception e ) {
2763 JOptionPane.showMessageDialog( this,
2764 "Failed to delete: " + file,
2766 JOptionPane.WARNING_MESSAGE );
2770 writePhylogenyToGraphicsFile( file.toString(), type );
2774 private void writeToPdf( final Phylogeny t ) {
2775 if ( ( t == null ) || t.isEmpty() ) {
2778 String initial_filename = "";
2779 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
2780 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
2782 if ( initial_filename.indexOf( '.' ) > 0 ) {
2783 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2785 initial_filename = initial_filename + ".pdf";
2786 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2787 final File my_dir = getCurrentDir();
2788 if ( my_dir != null ) {
2789 _writetopdf_filechooser.setCurrentDirectory( my_dir );
2791 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
2792 File file = _writetopdf_filechooser.getSelectedFile();
2793 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
2794 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2795 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2796 file = new File( file.toString() + ".pdf" );
2798 if ( file.exists() ) {
2799 final int i = JOptionPane.showConfirmDialog( this,
2800 file + " already exists. Overwrite?",
2802 JOptionPane.OK_CANCEL_OPTION,
2803 JOptionPane.WARNING_MESSAGE );
2804 if ( i != JOptionPane.OK_OPTION ) {
2808 printPhylogenyToPdf( file.toString() );
2812 public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
2813 return new MainFrameApplication( phys, config );
2816 public static MainFrame createInstance( final Phylogeny[] phys,
2817 final Configuration config,
2819 final File current_dir ) {
2820 return new MainFrameApplication( phys, config, title, current_dir );
2823 static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
2824 return new MainFrameApplication( phys, config, title );
2827 static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
2828 return new MainFrameApplication( phys, config_file_name, title );
2831 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
2832 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
2833 + o.getPrintSizeY() + ")" );
2836 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2837 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2840 static void warnIfNotPhyloXmlValidation( final Configuration c ) {
2841 if ( !c.isValidatePhyloXmlAgainstSchema() ) {
2843 .showMessageDialog( null,
2845 .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
2848 JOptionPane.WARNING_MESSAGE );
2851 } // MainFrameApplication.
2853 class DefaultFilter extends FileFilter {
2856 public boolean accept( final File f ) {
2857 final String file_name = f.getName().trim().toLowerCase();
2858 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2859 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2860 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2861 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2862 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2863 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2864 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2865 || file_name.endsWith( ".con" ) || f.isDirectory();
2869 public String getDescription() {
2870 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2874 class GraphicsFileFilter extends FileFilter {
2877 public boolean accept( final File f ) {
2878 final String file_name = f.getName().trim().toLowerCase();
2879 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2880 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2884 public String getDescription() {
2885 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2889 class MsaFileFilter extends FileFilter {
2892 public boolean accept( final File f ) {
2893 final String file_name = f.getName().trim().toLowerCase();
2894 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2895 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2899 public String getDescription() {
2900 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2904 class NexusFilter extends FileFilter {
2907 public boolean accept( final File f ) {
2908 final String file_name = f.getName().trim().toLowerCase();
2909 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2910 || file_name.endsWith( ".tre" ) || f.isDirectory();
2914 public String getDescription() {
2915 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2919 class NHFilter extends FileFilter {
2922 public boolean accept( final File f ) {
2923 final String file_name = f.getName().trim().toLowerCase();
2924 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2925 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2926 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2931 public String getDescription() {
2932 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2936 class NHXFilter extends FileFilter {
2939 public boolean accept( final File f ) {
2940 final String file_name = f.getName().trim().toLowerCase();
2941 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2945 public String getDescription() {
2946 return "NHX files (*.nhx) [deprecated]";
2950 class PdfFilter extends FileFilter {
2953 public boolean accept( final File f ) {
2954 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2958 public String getDescription() {
2959 return "PDF files (*.pdf)";
2963 class SequencesFileFilter extends FileFilter {
2966 public boolean accept( final File f ) {
2967 final String file_name = f.getName().trim().toLowerCase();
2968 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2969 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2973 public String getDescription() {
2974 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2978 class TolFilter extends FileFilter {
2981 public boolean accept( final File f ) {
2982 final String file_name = f.getName().trim().toLowerCase();
2983 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2984 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2988 public String getDescription() {
2989 return "Tree of Life files (*.tol, *.tolxml)";
2993 class XMLFilter extends FileFilter {
2996 public boolean accept( final File f ) {
2997 final String file_name = f.getName().trim().toLowerCase();
2998 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2999 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
3003 public String getDescription() {
3004 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";