X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrameApplication.java;h=07984fc9f85909947b6e75233847a1b028ec08f6;hb=f3d4d888187b8cbdea5d2ea2e7637a0da11afb43;hp=774190c30253cccc88a58794a022957958607bb0;hpb=9fdc3a8d3b5a51e22b5357164e6b3c46e6332024;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 774190c..07984fc 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -57,16 +57,13 @@ import javax.swing.UnsupportedLookAndFeelException; import javax.swing.WindowConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import javax.swing.filechooser.FileFilter; -import javax.swing.plaf.synth.SynthLookAndFeel; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; import org.forester.analysis.TaxonomyDataManager; -import org.forester.archaeopteryx.AptxUtil.GraphicsExportType; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE; -import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer; -import org.forester.archaeopteryx.tools.GoAnnotation; import org.forester.archaeopteryx.tools.InferenceManager; import org.forester.archaeopteryx.tools.PhyloInferenceDialog; import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions; @@ -82,10 +79,8 @@ import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; import org.forester.io.parsers.phyloxml.PhyloXmlParser; -import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.io.parsers.tol.TolParser; import org.forester.io.parsers.util.ParserUtils; -import org.forester.io.writers.PhylogenyWriter; import org.forester.io.writers.SequenceWriter; import org.forester.msa.Msa; import org.forester.msa.MsaFormatException; @@ -94,70 +89,52 @@ import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.Confidence; +import org.forester.phylogeny.data.PhylogenyDataUtil; +import org.forester.phylogeny.data.Sequence; import org.forester.phylogeny.data.Taxonomy; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; -import org.forester.sequence.Sequence; +import org.forester.sequence.MolecularSequence; import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.BasicTable; import org.forester.util.BasicTableParser; import org.forester.util.DescriptiveStatistics; import org.forester.util.ForesterUtil; -import org.forester.util.WindowsUtils; public final class MainFrameApplication extends MainFrame { - static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies"; - static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information"; - private final static int FRAME_X_SIZE = 800; - private final static int FRAME_Y_SIZE = 800; + private final static int FRAME_X_SIZE = 900; + private final static int FRAME_Y_SIZE = 900; // Filters for the file-open dialog (classes defined in this file) - private final static NHFilter nhfilter = new NHFilter(); - private final static NHXFilter nhxfilter = new NHXFilter(); - private final static XMLFilter xmlfilter = new XMLFilter(); - private final static TolFilter tolfilter = new TolFilter(); - private final static NexusFilter nexusfilter = new NexusFilter(); - private final static PdfFilter pdffilter = new PdfFilter(); - private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter(); - private final static MsaFileFilter msafilter = new MsaFileFilter(); - private final static SequencesFileFilter seqsfilter = new SequencesFileFilter(); - private final static DefaultFilter defaultfilter = new DefaultFilter(); - private static final long serialVersionUID = -799735726778865234L; - private final JFileChooser _values_filechooser; - private final JFileChooser _sequences_filechooser; - private final JFileChooser _open_filechooser; - private final JFileChooser _msa_filechooser; - private final JFileChooser _seqs_pi_filechooser; - private final JFileChooser _open_filechooser_for_species_tree; - private final JFileChooser _save_filechooser; - private final JFileChooser _writetopdf_filechooser; - private final JFileChooser _writetographics_filechooser; + private static final long serialVersionUID = -799735726778865234L; + private static final boolean PREPROCESS_TREES = false; + private final JFileChooser _values_filechooser; + private final JFileChooser _sequences_filechooser; + private final JFileChooser _open_filechooser; + private final JFileChooser _msa_filechooser; + private final JFileChooser _seqs_pi_filechooser; + private final JFileChooser _open_filechooser_for_species_tree; // Application-only print menu items - private JMenuItem _print_item; - private JMenuItem _write_to_pdf_item; - private JMenuItem _write_to_jpg_item; - private JMenuItem _write_to_gif_item; - private JMenuItem _write_to_tif_item; - private JMenuItem _write_to_png_item; - private JMenuItem _write_to_bmp_item; - private File _current_dir; - private ButtonGroup _radio_group_1; - private ButtonGroup _radio_group_2; + private JMenuItem _collapse_below_threshold; + private JMenuItem _collapse_below_branch_length; + private ButtonGroup _radio_group_1; + private ButtonGroup _radio_group_2; // Others: - double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT; + double _min_not_collapse = AptxConstants.MIN_NOT_COLLAPSE_DEFAULT; + double _min_not_collapse_bl = 0.001; // Phylogeny Inference menu - private JMenu _inference_menu; - private JMenuItem _inference_from_msa_item; - private JMenuItem _inference_from_seqs_item; + private JMenu _inference_menu; + private JMenuItem _inference_from_msa_item; + private JMenuItem _inference_from_seqs_item; // Phylogeny Inference - private PhylogeneticInferenceOptions _phylogenetic_inference_options = null; - private Msa _msa = null; - private File _msa_file = null; - private List _seqs = null; - private File _seqs_file = null; - JMenuItem _read_values_jmi; - JMenuItem _read_seqs_jmi; + private PhylogeneticInferenceOptions _phylogenetic_inference_options = null; + private Msa _msa = null; + private File _msa_file = null; + private List _seqs = null; + private File _seqs_file = null; + JMenuItem _read_values_jmi; + JMenuItem _read_seqs_jmi; private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) { _configuration = config; @@ -186,10 +163,10 @@ public final class MainFrameApplication extends MainFrame { setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE ); // The window listener setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); - addWindowListener( new WindowAdapter() { + addInternalFrameListener( new InternalFrameAdapter() { @Override - public void windowClosing( final WindowEvent e ) { + public void internalFrameClosing (final InternalFrameEvent e ) { exit(); } } ); @@ -219,30 +196,12 @@ public final class MainFrameApplication extends MainFrame { throw new IllegalArgumentException( "configuration is null" ); } try { - boolean synth_exception = false; - if ( Constants.__SYNTH_LF ) { - try { - final SynthLookAndFeel synth = new SynthLookAndFeel(); - synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ), - MainFrameApplication.class ); - UIManager.setLookAndFeel( synth ); - } - catch ( final Exception ex ) { - synth_exception = true; - ForesterUtil.printWarningMessage( Constants.PRG_NAME, - "could not create synth look and feel: " - + ex.getLocalizedMessage() ); - } + if ( _configuration.isUseNativeUI() ) { + UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); } - if ( !Constants.__SYNTH_LF || synth_exception ) { - if ( _configuration.isUseNativeUI() ) { - UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); - } - else { - UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() ); - } + else { + UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() ); } - //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" ); } catch ( final UnsupportedLookAndFeelException e ) { AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() ); @@ -264,67 +223,62 @@ public final class MainFrameApplication extends MainFrame { setOptions( Options.createInstance( _configuration ) ); setInferenceManager( InferenceManager.createInstance( _configuration ) ); setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) ); - // _textframe = null; #~~~~ // set title - setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" ); + setTitle( AptxConstants.PRG_NAME + " " + AptxConstants.VERSION + " (" + AptxConstants.PRG_DATE + ")" ); _mainpanel = new MainPanel( _configuration, this ); // The file dialogs _open_filechooser = new JFileChooser(); - _open_filechooser.setCurrentDirectory( new File( "." ) ); - _open_filechooser.setMultiSelectionEnabled( false ); - _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter ); - _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter ); - _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter ); - _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter ); - _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter ); + _open_filechooser.setMultiSelectionEnabled( true ); + _open_filechooser.addChoosableFileFilter( MainFrame.xmlfilter ); + _open_filechooser.addChoosableFileFilter( MainFrame.nhxfilter ); + _open_filechooser.addChoosableFileFilter( MainFrame.nhfilter ); + _open_filechooser.addChoosableFileFilter( MainFrame.nexusfilter ); + _open_filechooser.addChoosableFileFilter( MainFrame.tolfilter ); _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() ); - _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter ); + _open_filechooser.setFileFilter( MainFrame.defaultfilter ); _open_filechooser_for_species_tree = new JFileChooser(); - _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) ); _open_filechooser_for_species_tree.setMultiSelectionEnabled( false ); - _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter ); - _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter ); - _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter ); - _save_filechooser = new JFileChooser(); - _save_filechooser.setCurrentDirectory( new File( "." ) ); - _save_filechooser.setMultiSelectionEnabled( false ); - _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter ); - _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter ); - _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter ); - _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() ); - _writetopdf_filechooser = new JFileChooser(); - _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter ); - _writetographics_filechooser = new JFileChooser(); - _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter ); + _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrame.xmlfilter ); + _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrame.tolfilter ); + _open_filechooser_for_species_tree.setFileFilter( MainFrame.xmlfilter ); // Msa: _msa_filechooser = new JFileChooser(); _msa_filechooser.setName( "Read Multiple Sequence Alignment File" ); - _msa_filechooser.setCurrentDirectory( new File( "." ) ); _msa_filechooser.setMultiSelectionEnabled( false ); _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() ); - _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter ); + _msa_filechooser.addChoosableFileFilter( MainFrame.msafilter ); // Seqs: _seqs_pi_filechooser = new JFileChooser(); _seqs_pi_filechooser.setName( "Read Sequences File" ); - _seqs_pi_filechooser.setCurrentDirectory( new File( "." ) ); _seqs_pi_filechooser.setMultiSelectionEnabled( false ); _seqs_pi_filechooser.addChoosableFileFilter( _seqs_pi_filechooser.getAcceptAllFileFilter() ); - _seqs_pi_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter ); + _seqs_pi_filechooser.addChoosableFileFilter( MainFrame.seqsfilter ); // Expression _values_filechooser = new JFileChooser(); - _values_filechooser.setCurrentDirectory( new File( "." ) ); _values_filechooser.setMultiSelectionEnabled( false ); // Sequences _sequences_filechooser = new JFileChooser(); - _sequences_filechooser.setCurrentDirectory( new File( "." ) ); _sequences_filechooser.setMultiSelectionEnabled( false ); + try { + final String home_dir = System.getProperty( "user.home" ); + _open_filechooser.setCurrentDirectory( new File( home_dir ) ); + _open_filechooser_for_species_tree.setCurrentDirectory( new File( home_dir ) ); + _msa_filechooser.setCurrentDirectory( new File( home_dir ) ); + _seqs_pi_filechooser.setCurrentDirectory( new File( home_dir ) ); + _values_filechooser.setCurrentDirectory( new File( home_dir ) ); + _sequences_filechooser.setCurrentDirectory( new File( home_dir ) ); + } + catch ( final Exception e ) { + e.printStackTrace(); + // Do nothing. Not important. + } // build the menu bar _jmenubar = new JMenuBar(); if ( !_configuration.isUseNativeUI() ) { _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() ); } buildFileMenu(); - if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) { + if ( AptxConstants.__ALLOW_PHYLOGENETIC_INFERENCE ) { buildPhylogeneticInferenceMenu(); } buildAnalysisMenu(); @@ -350,42 +304,40 @@ public final class MainFrameApplication extends MainFrame { // } ); // The window listener setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); - addWindowListener( new WindowAdapter() { + + addInternalFrameListener( new InternalFrameAdapter() { @Override - public void windowClosing( final WindowEvent e ) { + public void internalFrameClosing( final InternalFrameEvent e ) { + if (MainFrameApplication.this.getParent() == null) { if ( isUnsavedDataPresent() ) { - final int r = JOptionPane.showConfirmDialog( null, - "Exit despite potentially unsaved changes?", - "Exit?", + final int r = JOptionPane.showConfirmDialog( _mainpanel, + "Close Archaeopteryx despite potentially unsaved changes?", + "Close viewer?", JOptionPane.YES_NO_OPTION ); if ( r != JOptionPane.YES_OPTION ) { return; } } else { - final int r = JOptionPane.showConfirmDialog( null, - "Exit Archaeopteryx?", - "Exit?", - JOptionPane.YES_NO_OPTION ); + final int r = JOptionPane + .showConfirmDialog( null, "Exit Archaeopteryx?", "Exit?", JOptionPane.YES_NO_OPTION ); if ( r != JOptionPane.YES_OPTION ) { return; } - } + }} exit(); - } - } ); + + } }); // The component listener addComponentListener( new ComponentAdapter() { @Override public void componentResized( final ComponentEvent e ) { if ( _mainpanel.getCurrentTreePanel() != null ) { - _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel() - .getWidth(), - _mainpanel.getCurrentTreePanel() - .getHeight(), - getOptions().isAllowFontSizeChange() ); + _mainpanel.getCurrentTreePanel() + .calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(), + _mainpanel.getCurrentTreePanel().getHeight() ); } } } ); @@ -418,57 +370,18 @@ public final class MainFrameApplication extends MainFrame { if ( o == _open_item ) { readPhylogeniesFromFile(); } - else if ( o == _save_item ) { - writeToFile( _mainpanel.getCurrentPhylogeny() ); - // If subtree currently displayed, save it, instead of complete - // tree. + if ( o == _open_url_item ) { + readPhylogeniesFromURL(); } else if ( o == _new_item ) { newTree(); } - else if ( o == _save_all_item ) { - writeAllToFile(); - } else if ( o == _close_item ) { closeCurrentPane(); } - else if ( o == _write_to_pdf_item ) { - writeToPdf( _mainpanel.getCurrentPhylogeny() ); - } - else if ( o == _write_to_jpg_item ) { - writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG ); - } - else if ( o == _write_to_png_item ) { - writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG ); - } - else if ( o == _write_to_gif_item ) { - writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF ); - } - else if ( o == _write_to_tif_item ) { - writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF ); - } - else if ( o == _write_to_bmp_item ) { - writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP ); - } - else if ( o == _print_item ) { - print(); - } else if ( o == _load_species_tree_item ) { readSpeciesTreeFromFile(); } - else if ( o == _lineage_inference ) { - if ( isSubtreeDisplayed() ) { - JOptionPane.showMessageDialog( this, - "Subtree is shown.", - "Cannot infer ancestral taxonomies", - JOptionPane.ERROR_MESSAGE ); - return; - } - executeLineageInference(); - } - else if ( o == _function_analysis ) { - executeFunctionAnalysis(); - } else if ( o == _obtain_detailed_taxonomic_information_jmi ) { if ( isSubtreeDisplayed() ) { return; @@ -505,27 +418,6 @@ public final class MainFrameApplication extends MainFrame { else if ( o == _extract_tax_code_from_node_names_jmi ) { extractTaxDataFromNodeNames(); } - else if ( o == _graphics_export_visible_only_cbmi ) { - updateOptions( getOptions() ); - } - else if ( o == _antialias_print_cbmi ) { - updateOptions( getOptions() ); - } - else if ( o == _print_black_and_white_cbmi ) { - updateOptions( getOptions() ); - } - else if ( o == _print_using_actual_size_cbmi ) { - updateOptions( getOptions() ); - } - else if ( o == _graphics_export_using_actual_size_cbmi ) { - updateOptions( getOptions() ); - } - else if ( o == _print_size_mi ) { - choosePrintSize(); - } - else if ( o == _choose_pdf_width_mi ) { - choosePdfWidth(); - } else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) { updateOptions( getOptions() ); } @@ -535,12 +427,22 @@ public final class MainFrameApplication extends MainFrame { } updateOptions( getOptions() ); } + else if ( o == _allow_errors_in_distance_to_parent_cbmi ) { + updateOptions( getOptions() ); + } else if ( o == _collapse_below_threshold ) { if ( isSubtreeDisplayed() ) { return; } collapseBelowThreshold(); } + + else if ( o == _collapse_below_branch_length ) { + if ( isSubtreeDisplayed() ) { + return; + } + collapseBelowBranchLengthThreshold(); + } else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi ) || ( o == _extract_taxonomy_agressive_rbmi ) ) { if ( _replace_underscores_cbmi != null ) { @@ -587,7 +489,7 @@ public final class MainFrameApplication extends MainFrame { return _msa_file; } - public List getSeqs() { + public List getSeqs() { return _seqs; } @@ -617,7 +519,7 @@ public final class MainFrameApplication extends MainFrame { msa = FastaParser.parseMsa( is ); } else { - msa = GeneralMsaParser.parse( is ); + msa = GeneralMsaParser.parseMsa( is ); } } catch ( final MsaFormatException e ) { @@ -695,11 +597,11 @@ public final class MainFrameApplication extends MainFrame { if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { setSeqsFile( null ); setSeqs( null ); - List seqs = null; + List seqs = null; try { if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { seqs = FastaParser.parse( new FileInputStream( file ) ); - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { System.out.println( SequenceWriter.toFasta( seq, 60 ) ); } } @@ -767,685 +669,161 @@ public final class MainFrameApplication extends MainFrame { } } - void buildAnalysisMenu() { - _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() ); - _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) ); - _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) ); - _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) ); - customizeJMenuItem( _gsdi_item ); - customizeJMenuItem( _gsdir_item ); - customizeJMenuItem( _load_species_tree_item ); - _analysis_menu.addSeparator(); - _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) ); - customizeJMenuItem( _lineage_inference ); - _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" ); - _jmenubar.add( _analysis_menu ); - } - - @Override - void buildFileMenu() { - _file_jmenu = MainFrame.createMenu( "File", getConfiguration() ); - _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) ); - _file_jmenu.addSeparator(); - _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) ); - _file_jmenu.addSeparator(); - final WebservicesManager webservices_manager = WebservicesManager.getInstance(); - _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager - .getAvailablePhylogeniesWebserviceClients().size() ]; - for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) { - final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i ); - _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() ); - _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] ); - } - if ( getConfiguration().isEditable() ) { - _file_jmenu.addSeparator(); - _file_jmenu.add( _new_item = new JMenuItem( "New" ) ); - _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" ); - } - _file_jmenu.addSeparator(); - _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) ); - _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) ); - _save_all_item.setToolTipText( "Write all phylogenies to one file." ); - _save_all_item.setEnabled( false ); - _file_jmenu.addSeparator(); - _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) ); - if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) { - _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) ); - } - _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) ); - _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) ); - if ( AptxUtil.canWriteFormat( "gif" ) ) { - _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) ); - } - if ( AptxUtil.canWriteFormat( "bmp" ) ) { - _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) ); + private void addExpressionValuesFromFile() { + if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) { + JOptionPane.showMessageDialog( this, + "Need to load evolutionary tree first", + "Can Not Read Expression Values", + JOptionPane.WARNING_MESSAGE ); + return; } - _file_jmenu.addSeparator(); - _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) ); - _file_jmenu.addSeparator(); - _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) ); - _close_item.setToolTipText( "To close the current pane." ); - _close_item.setEnabled( true ); - _file_jmenu.addSeparator(); - _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) ); - // For print in color option item - customizeJMenuItem( _open_item ); - _open_item - .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) ); - customizeJMenuItem( _open_url_item ); - for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) { - customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] ); + final File my_dir = getCurrentDir(); + if ( my_dir != null ) { + _values_filechooser.setCurrentDirectory( my_dir ); } - customizeJMenuItem( _save_item ); - if ( getConfiguration().isEditable() ) { - customizeJMenuItem( _new_item ); + final int result = _values_filechooser.showOpenDialog( _contentpane ); + final File file = _values_filechooser.getSelectedFile(); + if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) { + BasicTable t = null; + try { + t = BasicTableParser.parse( file, '\t' ); + if ( t.getNumberOfColumns() < 2 ) { + t = BasicTableParser.parse( file, ',' ); + } + if ( t.getNumberOfColumns() < 2 ) { + t = BasicTableParser.parse( file, ' ' ); + } + } + catch ( final IOException e ) { + JOptionPane.showMessageDialog( this, + e.getMessage(), + "Could Not Read Expression Value Table", + JOptionPane.ERROR_MESSAGE ); + return; + } + if ( t.getNumberOfColumns() < 2 ) { + JOptionPane.showMessageDialog( this, + "Table contains " + t.getNumberOfColumns() + " column(s)", + "Problem with Expression Value Table", + JOptionPane.ERROR_MESSAGE ); + return; + } + if ( t.getNumberOfRows() < 1 ) { + JOptionPane.showMessageDialog( this, + "Table contains zero rows", + "Problem with Expression Value Table", + JOptionPane.ERROR_MESSAGE ); + return; + } + final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); + if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) { + JOptionPane.showMessageDialog( this, + "Table contains " + t.getNumberOfRows() + " rows, but tree contains " + + phy.getNumberOfExternalNodes() + " external nodes", + "Warning", + JOptionPane.WARNING_MESSAGE ); + } + final DescriptiveStatistics stats = new BasicDescriptiveStatistics(); + int not_found = 0; + for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) { + final PhylogenyNode node = iter.next(); + final String node_name = node.getName(); + if ( !ForesterUtil.isEmpty( node_name ) ) { + int row = -1; + try { + row = t.findRow( node_name ); + } + catch ( final IllegalArgumentException e ) { + JOptionPane.showMessageDialog( this, + e.getMessage(), + "Error Mapping Node Identifiers to Expression Value Identifiers", + JOptionPane.ERROR_MESSAGE ); + return; + } + if ( row < 0 ) { + if ( node.isExternal() ) { + not_found++; + } + continue; + } + final List l = new ArrayList(); + for( int col = 1; col < t.getNumberOfColumns(); ++col ) { + double d = -100; + try { + d = Double.parseDouble( t.getValueAsString( col, row ) ); + } + catch ( final NumberFormatException e ) { + JOptionPane.showMessageDialog( this, + "Could not parse \"" + t.getValueAsString( col, row ) + + "\" into a decimal value", + "Issue with Expression Value Table", + JOptionPane.ERROR_MESSAGE ); + return; + } + stats.addValue( d ); + l.add( d ); + } + if ( !l.isEmpty() ) { + + node.getNodeData().setVector( l ); + } + } + } + if ( not_found > 0 ) { + JOptionPane + .showMessageDialog( this, + "Could not fine expression values for " + not_found + " external node(s)", + "Warning", + JOptionPane.WARNING_MESSAGE ); + } + getCurrentTreePanel().setStatisticsForExpressionValues( stats ); } - customizeJMenuItem( _close_item ); - customizeJMenuItem( _save_all_item ); - customizeJMenuItem( _write_to_pdf_item ); - customizeJMenuItem( _write_to_png_item ); - customizeJMenuItem( _write_to_jpg_item ); - customizeJMenuItem( _write_to_gif_item ); - customizeJMenuItem( _write_to_tif_item ); - customizeJMenuItem( _write_to_bmp_item ); - customizeJMenuItem( _print_item ); - customizeJMenuItem( _exit_item ); - _jmenubar.add( _file_jmenu ); } - void buildOptionsMenu() { - _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() ); - _options_jmenu.addChangeListener( new ChangeListener() { - - @Override - public void stateChanged( final ChangeEvent e ) { - MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() ); - MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() ); - MainFrame - .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() ); - MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame - .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) ); - setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() ); - setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() ); - MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(), - _show_scale_cbmi, - _show_branch_length_values_cbmi, - _non_lined_up_cladograms_rbmi, - _uniform_cladograms_rbmi, - _ext_node_dependent_cladogram_rbmi, - _label_direction_cbmi ); - MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() ); - MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() ); - MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() ); - } - } ); - _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) ); - _options_jmenu - .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) ); - _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) ); - _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) ); - _radio_group_1 = new ButtonGroup(); - _radio_group_1.add( _ext_node_dependent_cladogram_rbmi ); - _radio_group_1.add( _uniform_cladograms_rbmi ); - _radio_group_1.add( _non_lined_up_cladograms_rbmi ); - _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) ); - _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) ); - _options_jmenu - .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) ); - _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) ); - _options_jmenu - .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) ); - _options_jmenu - .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) ); - _options_jmenu - .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) ); - _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) ); - _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) ); - _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) ); - _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) ); - _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP ); - _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) ); - _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP ); - _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) ); - _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) ); - _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) ); - if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) { - _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) ); - } - _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) ); - _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) ); - _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) ); - _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) ); - _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) ); - _options_jmenu.addSeparator(); - _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) ); - _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) ); - _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) ); - _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) ); - _options_jmenu.addSeparator(); - _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ), - getConfiguration() ) ); - _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) ); - _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) ); - _options_jmenu - .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) ); - _options_jmenu - .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) ); - _options_jmenu - .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) ); - _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) ); - _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) ); - _options_jmenu.addSeparator(); - _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) ); - _options_jmenu - .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) ); - _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) ); - // - _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) ); - _options_jmenu - .add( _extract_taxonomy_pfam_strict_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style Node Names" ) ); - _options_jmenu - .add( _extract_taxonomy_pfam_relaxed_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style like Node Names" ) ); - _options_jmenu - .add( _extract_taxonomy_agressive_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids/Scientific Names from Node Names" ) ); - _extract_taxonomy_pfam_strict_rbmi - .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"BCL2_MOUSE/123-304\" or \"BCL2_10090/123-304\"" ); - _extract_taxonomy_pfam_relaxed_rbmi - .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"bax_MOUSE\" or \"bax_10090\"" ); - _extract_taxonomy_agressive_rbmi - .setToolTipText( "To extract taxonomy codes/ids or scientific names from node names in the form of e.g. \"MOUSE\" or \"10090\" or \"xyz_Nematostella_vectensis\"" ); - _radio_group_2 = new ButtonGroup(); - _radio_group_2.add( _extract_taxonomy_no_rbmi ); - _radio_group_2.add( _extract_taxonomy_pfam_strict_rbmi ); - _radio_group_2.add( _extract_taxonomy_pfam_relaxed_rbmi ); - _radio_group_2.add( _extract_taxonomy_agressive_rbmi ); - // - _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) ); - _options_jmenu - .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) ); - _use_brackets_for_conf_in_nh_export_cbmi - .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" ); - _options_jmenu - .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) ); - customizeJMenuItem( _choose_font_mi ); - customizeJMenuItem( _choose_minimal_confidence_mi ); - customizeJMenuItem( _switch_colors_mi ); - customizeJMenuItem( _print_size_mi ); - customizeJMenuItem( _choose_pdf_width_mi ); - customizeJMenuItem( _overview_placment_mi ); - customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions() - .isShowDefaultNodeShapesExternal() ); - customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions() - .isShowDefaultNodeShapesInternal() ); - customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() ); - customizeJMenuItem( _cycle_node_shape_mi ); - customizeJMenuItem( _cycle_node_fill_mi ); - customizeJMenuItem( _choose_node_size_mi ); - customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() ); - customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); - customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); - customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() ); - customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() ); - customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() ); - customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() ); - customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); - customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ); - customizeRadioButtonMenuItem( _uniform_cladograms_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); - customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); - customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() ); - customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() ); - customizeCheckBoxMenuItem( _label_direction_cbmi, - getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL ); - customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() ); - customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() ); - customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions() - .isInternalNumberAreConfidenceForNhParsing() ); - customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi, - getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO ); - customizeRadioButtonMenuItem( _extract_taxonomy_pfam_strict_rbmi, - getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); - customizeRadioButtonMenuItem( _extract_taxonomy_pfam_relaxed_rbmi, - getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); - customizeRadioButtonMenuItem( _extract_taxonomy_agressive_rbmi, - getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.AGGRESSIVE ); - customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() ); - customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() ); - customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() ); - customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() ); - customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() ); - customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions() - .isGraphicsExportUsingActualSize() ); - customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() ); - customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions() - .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ); - customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions() - .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ); - _jmenubar.add( _options_jmenu ); - } - - void buildPhylogeneticInferenceMenu() { - final InferenceManager im = getInferenceManager(); - _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() ); - _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) ); - customizeJMenuItem( _inference_from_msa_item ); - _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" ); - if ( im.canDoMsa() ) { - _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) ); - customizeJMenuItem( _inference_from_seqs_item ); - _inference_from_seqs_item - .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" ); - } - else { - _inference_menu - .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) ); - customizeJMenuItem( _inference_from_seqs_item ); - _inference_from_seqs_item.setEnabled( false ); - } - _jmenubar.add( _inference_menu ); - } - - void buildToolsMenu() { - _tools_menu = createMenu( "Tools", getConfiguration() ); - _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) ); - customizeJMenuItem( _confcolor_item ); - _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) ); - customizeJMenuItem( _color_rank_jmi ); - _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" ); - _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) ); - customizeJMenuItem( _taxcolor_item ); - _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) ); - _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" ); - customizeJMenuItem( _remove_branch_color_item ); - _tools_menu.addSeparator(); - _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) ); - customizeJMenuItem( _annotate_item ); - _tools_menu.addSeparator(); - _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) ); - customizeJMenuItem( _midpoint_root_item ); - _tools_menu.addSeparator(); - _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) ); - customizeJMenuItem( _collapse_species_specific_subtrees ); - _tools_menu - .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) ); - customizeJMenuItem( _collapse_below_threshold ); - _collapse_below_threshold - .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)" ); - _tools_menu.addSeparator(); - _tools_menu - .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) ); - customizeJMenuItem( _extract_tax_code_from_node_names_jmi ); - _extract_tax_code_from_node_names_jmi - .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'" ); - _tools_menu - .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) ); - customizeJMenuItem( _move_node_names_to_tax_sn_jmi ); - _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" ); - _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) ); - customizeJMenuItem( _move_node_names_to_seq_names_jmi ); - _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" ); - _tools_menu.addSeparator(); - _tools_menu - .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) ); - customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi ); - _obtain_detailed_taxonomic_information_jmi - .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" ); - _tools_menu - .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) ); - customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi ); - _obtain_detailed_taxonomic_information_deleting_jmi - .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" ); - _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) ); - customizeJMenuItem( _obtain_seq_information_jmi ); - _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" ); - _tools_menu.addSeparator(); - if ( !Constants.__RELEASE ) { - _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) ); - customizeJMenuItem( _function_analysis ); - _function_analysis - .setToolTipText( "To add UniProtKB annotations for sequences with appropriate identifiers" ); - _tools_menu.addSeparator(); - } - _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) ); - customizeJMenuItem( _read_values_jmi ); - _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" ); - _jmenubar.add( _tools_menu ); - _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) ); - customizeJMenuItem( _read_seqs_jmi ); - _read_seqs_jmi - .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" ); - _jmenubar.add( _tools_menu ); - } - - @Override - void close() { - if ( isUnsavedDataPresent() ) { - final int r = JOptionPane.showConfirmDialog( this, - "Exit despite potentially unsaved changes?", - "Exit?", - JOptionPane.YES_NO_OPTION ); - if ( r != JOptionPane.YES_OPTION ) { - return; - } - } - exit(); - } - - void executeFunctionAnalysis() { - if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) { - return; - } - final GoAnnotation a = new GoAnnotation( this, - _mainpanel.getCurrentTreePanel(), - _mainpanel.getCurrentPhylogeny() ); - new Thread( a ).start(); - } - - void executeLineageInference() { - if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) { - return; - } - if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) { + private void addSequencesFromFile() { + if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) { JOptionPane.showMessageDialog( this, - "Phylogeny is not rooted.", - "Cannot infer ancestral taxonomies", - JOptionPane.ERROR_MESSAGE ); + "Need to load evolutionary tree first", + "Can Not Read Sequences", + JOptionPane.WARNING_MESSAGE ); return; } - final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this, - _mainpanel.getCurrentTreePanel(), - _mainpanel.getCurrentPhylogeny() - .copy() ); - new Thread( inferrer ).start(); - } - - void exit() { - removeAllTextFrames(); - _mainpanel.terminate(); - _contentpane.removeAll(); - setVisible( false ); - dispose(); - System.exit( 0 ); - } - - @Override - void readPhylogeniesFromURL() { - URL url = null; - Phylogeny[] phys = null; - final String message = "Please enter a complete URL, for example \"http://www.phyloxml.org/examples/apaf.xml\""; - final String url_string = JOptionPane.showInputDialog( this, - message, - "Use URL/webservice to obtain a phylogeny", - JOptionPane.QUESTION_MESSAGE ); - boolean nhx_or_nexus = false; - if ( ( url_string != null ) && ( url_string.length() > 0 ) ) { + final File my_dir = getCurrentDir(); + if ( my_dir != null ) { + _sequences_filechooser.setCurrentDirectory( my_dir ); + } + final int result = _sequences_filechooser.showOpenDialog( _contentpane ); + final File file = _sequences_filechooser.getSelectedFile(); + List seqs = null; + if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { try { - url = new URL( url_string ); - PhylogenyParser parser = null; - if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) { - parser = new TolParser(); + final FileInputStream fis1 = new FileInputStream( file ); + if ( FastaParser.isLikelyFasta( fis1 ) ) { + final FileInputStream fis2 = new FileInputStream( file ); + seqs = FastaParser.parse( fis2 ); + try { + fis2.close(); + } + catch ( final Exception e ) { + // Ignore. + } } else { - parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration() - .isValidatePhyloXmlAgainstSchema() ); - } - if ( parser instanceof NexusPhylogeniesParser ) { - nhx_or_nexus = true; - } - else if ( parser instanceof NHXParser ) { - nhx_or_nexus = true; + JOptionPane.showMessageDialog( this, + "Format does not appear to be Fasta", + "Multiple sequence file format error", + JOptionPane.ERROR_MESSAGE ); + return; } - if ( _mainpanel.getCurrentTreePanel() != null ) { - _mainpanel.getCurrentTreePanel().setWaitCursor(); + try { + fis1.close(); } - else { - _mainpanel.setWaitCursor(); + catch ( final Exception e ) { + // Ignore. } - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - phys = factory.create( url.openStream(), parser ); } - catch ( final MalformedURLException e ) { - JOptionPane.showMessageDialog( this, - "Malformed URL: " + url + "\n" + e.getLocalizedMessage(), - "Malformed URL", - JOptionPane.ERROR_MESSAGE ); - } - catch ( final IOException e ) { - JOptionPane.showMessageDialog( this, - "Could not read from " + url + "\n" - + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), - "Failed to read URL", - JOptionPane.ERROR_MESSAGE ); - } - catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, - ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), - "Unexpected Exception", - JOptionPane.ERROR_MESSAGE ); - } - finally { - if ( _mainpanel.getCurrentTreePanel() != null ) { - _mainpanel.getCurrentTreePanel().setArrowCursor(); - } - else { - _mainpanel.setArrowCursor(); - } - } - if ( ( phys != null ) && ( phys.length > 0 ) ) { - if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) { - for( final Phylogeny phy : phys ) { - PhylogenyMethods.transferInternalNodeNamesToConfidence( phy ); - } - } - AptxUtil.addPhylogeniesToTabs( phys, - new File( url.getFile() ).getName(), - new File( url.getFile() ).toString(), - getConfiguration(), - getMainPanel() ); - _mainpanel.getControlPanel().showWhole(); - } - } - activateSaveAllIfNeeded(); - System.gc(); - } - - void setMsa( final Msa msa ) { - _msa = msa; - } - - void setMsaFile( final File msa_file ) { - _msa_file = msa_file; - } - - void setSeqs( final List seqs ) { - _seqs = seqs; - } - - void setSeqsFile( final File seqs_file ) { - _seqs_file = seqs_file; - } - - void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) { - _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(), - _mainpanel.getCurrentTreePanel().getHeight(), - true ); - String file_written_to = ""; - boolean error = false; - try { - file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name, - _mainpanel.getCurrentTreePanel().getWidth(), - _mainpanel.getCurrentTreePanel().getHeight(), - _mainpanel.getCurrentTreePanel(), - _mainpanel.getControlPanel(), - type, - getOptions() ); - } - catch ( final IOException e ) { - error = true; - JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE ); - } - if ( !error ) { - if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) { - JOptionPane.showMessageDialog( this, - "Wrote image to: " + file_written_to, - "Graphics Export", - JOptionPane.INFORMATION_MESSAGE ); - } - else { - JOptionPane.showMessageDialog( this, - "There was an unknown problem when attempting to write to an image file: \"" - + file_name + "\"", - "Error", - JOptionPane.ERROR_MESSAGE ); - } - } - _contentpane.repaint(); - } - - private void addExpressionValuesFromFile() { - if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) { - JOptionPane.showMessageDialog( this, - "Need to load evolutionary tree first", - "Can Not Read Expression Values", - JOptionPane.WARNING_MESSAGE ); - return; - } - final File my_dir = getCurrentDir(); - if ( my_dir != null ) { - _values_filechooser.setCurrentDirectory( my_dir ); - } - final int result = _values_filechooser.showOpenDialog( _contentpane ); - final File file = _values_filechooser.getSelectedFile(); - if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) { - BasicTable t = null; - try { - t = BasicTableParser.parse( file, '\t' ); - if ( t.getNumberOfColumns() < 2 ) { - t = BasicTableParser.parse( file, ',' ); - } - if ( t.getNumberOfColumns() < 2 ) { - t = BasicTableParser.parse( file, ' ' ); - } - } - catch ( final IOException e ) { - JOptionPane.showMessageDialog( this, - e.getMessage(), - "Could Not Read Expression Value Table", - JOptionPane.ERROR_MESSAGE ); - return; - } - if ( t.getNumberOfColumns() < 2 ) { - JOptionPane.showMessageDialog( this, - "Table contains " + t.getNumberOfColumns() + " column(s)", - "Problem with Expression Value Table", - JOptionPane.ERROR_MESSAGE ); - return; - } - if ( t.getNumberOfRows() < 1 ) { - JOptionPane.showMessageDialog( this, - "Table contains zero rows", - "Problem with Expression Value Table", - JOptionPane.ERROR_MESSAGE ); - return; - } - final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); - if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) { - JOptionPane.showMessageDialog( this, - "Table contains " + t.getNumberOfRows() + " rows, but tree contains " - + phy.getNumberOfExternalNodes() + " external nodes", - "Warning", - JOptionPane.WARNING_MESSAGE ); - } - final DescriptiveStatistics stats = new BasicDescriptiveStatistics(); - int not_found = 0; - for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) { - final PhylogenyNode node = iter.next(); - final String node_name = node.getName(); - if ( !ForesterUtil.isEmpty( node_name ) ) { - int row = -1; - try { - row = t.findRow( node_name ); - } - catch ( final IllegalArgumentException e ) { - JOptionPane - .showMessageDialog( this, - e.getMessage(), - "Error Mapping Node Identifiers to Expression Value Identifiers", - JOptionPane.ERROR_MESSAGE ); - return; - } - if ( row < 0 ) { - if ( node.isExternal() ) { - not_found++; - } - continue; - } - final List l = new ArrayList(); - for( int col = 1; col < t.getNumberOfColumns(); ++col ) { - double d = -100; - try { - d = Double.parseDouble( t.getValueAsString( col, row ) ); - } - catch ( final NumberFormatException e ) { - JOptionPane.showMessageDialog( this, - "Could not parse \"" + t.getValueAsString( col, row ) - + "\" into a decimal value", - "Issue with Expression Value Table", - JOptionPane.ERROR_MESSAGE ); - return; - } - stats.addValue( d ); - l.add( d ); - } - if ( !l.isEmpty() ) { - if ( node.getNodeData().getProperties() != null ) { - node.getNodeData().getProperties() - .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF ); - } - node.getNodeData().setVector( l ); - } - } - } - if ( not_found > 0 ) { - JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found - + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE ); - } - getCurrentTreePanel().setStatisticsForExpressionValues( stats ); - } - } - - private void addSequencesFromFile() { - if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) { - JOptionPane.showMessageDialog( this, - "Need to load evolutionary tree first", - "Can Not Read Sequences", - JOptionPane.WARNING_MESSAGE ); - return; - } - final File my_dir = getCurrentDir(); - if ( my_dir != null ) { - _sequences_filechooser.setCurrentDirectory( my_dir ); - } - final int result = _sequences_filechooser.showOpenDialog( _contentpane ); - final File file = _sequences_filechooser.getSelectedFile(); - List seqs = null; - if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { - try { - if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { - seqs = FastaParser.parse( new FileInputStream( file ) ); - } - else { - JOptionPane.showMessageDialog( this, - "Format does not appear to be Fasta", - "Multiple sequence file format error", - JOptionPane.ERROR_MESSAGE ); - return; - } - } - catch ( final MsaFormatException e ) { - setArrowCursor(); + catch ( final MsaFormatException e ) { + setArrowCursor(); JOptionPane.showMessageDialog( this, e.getLocalizedMessage(), "Multiple sequence file format error", @@ -1479,13 +857,13 @@ public final class MainFrameApplication extends MainFrame { } } if ( seqs != null ) { - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { System.out.println( seq.getIdentifier() ); } final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); int total_counter = 0; int attached_counter = 0; - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { ++total_counter; final String seq_name = seq.getIdentifier(); if ( !ForesterUtil.isEmpty( seq_name ) ) { @@ -1494,6 +872,9 @@ public final class MainFrameApplication extends MainFrame { nodes = phy.getNodesViaSequenceSymbol( seq_name ); } if ( nodes.isEmpty() ) { + nodes = phy.getNodesViaGeneName( seq_name ); + } + if ( nodes.isEmpty() ) { nodes = phy.getNodes( seq_name ); } if ( nodes.size() > 1 ) { @@ -1515,8 +896,11 @@ public final class MainFrameApplication extends MainFrame { nodes = phy.getNodes( seq_name_split ); } if ( nodes.size() > 1 ) { - JOptionPane.showMessageDialog( this, "Split sequence name \"" + seq_name_split - + "\" is not unique", "Sequence name not unique", JOptionPane.ERROR_MESSAGE ); + JOptionPane.showMessageDialog( this, + "Split sequence name \"" + seq_name_split + + "\" is not unique", + "Sequence name not unique", + JOptionPane.ERROR_MESSAGE ); setArrowCursor(); return; } @@ -1560,92 +944,18 @@ public final class MainFrameApplication extends MainFrame { JOptionPane.INFORMATION_MESSAGE ); } else { - JOptionPane.showMessageDialog( this, "Attached " + attached_counter - + " sequences out of a total of " + total_counter + " sequences.\n" + s, attached_counter - + " sequences attached", JOptionPane.WARNING_MESSAGE ); - } - } - else { - JOptionPane.showMessageDialog( this, "No maching tree node for any of the " + total_counter - + " sequences", "Could not attach any sequences", JOptionPane.ERROR_MESSAGE ); - } - } - } - - private void choosePdfWidth() { - final String s = ( String ) JOptionPane.showInputDialog( this, - "Please enter the default line width for PDF export.\n" - + "[current value: " - + getOptions().getPrintLineWidth() + "]\n", - "Line Width for PDF Export", - JOptionPane.QUESTION_MESSAGE, - null, - null, - getOptions().getPrintLineWidth() ); - if ( !ForesterUtil.isEmpty( s ) ) { - boolean success = true; - float f = 0.0f; - final String m_str = s.trim(); - if ( !ForesterUtil.isEmpty( m_str ) ) { - try { - f = Float.parseFloat( m_str ); - } - catch ( final Exception ex ) { - success = false; - } - } - else { - success = false; - } - if ( success && ( f > 0.0 ) ) { - getOptions().setPrintLineWidth( f ); - } - } - } - - private void choosePrintSize() { - final String s = ( String ) JOptionPane.showInputDialog( this, - "Please enter values for width and height,\nseparated by a comma.\n" - + "[current values: " - + getOptions().getPrintSizeX() + ", " - + getOptions().getPrintSizeY() + "]\n" - + "[A4: " + Constants.A4_SIZE_X + ", " - + Constants.A4_SIZE_Y + "]\n" + "[US Letter: " - + Constants.US_LETTER_SIZE_X + ", " - + Constants.US_LETTER_SIZE_Y + "]", - "Default Size for Graphics Export", - JOptionPane.QUESTION_MESSAGE, - null, - null, - getOptions().getPrintSizeX() + ", " - + getOptions().getPrintSizeY() ); - if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) { - boolean success = true; - int x = 0; - int y = 0; - final String[] str_ary = s.split( "," ); - if ( str_ary.length == 2 ) { - final String x_str = str_ary[ 0 ].trim(); - final String y_str = str_ary[ 1 ].trim(); - if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) { - try { - x = Integer.parseInt( x_str ); - y = Integer.parseInt( y_str ); - } - catch ( final Exception ex ) { - success = false; - } - } - else { - success = false; + JOptionPane.showMessageDialog( this, + "Attached " + attached_counter + " sequences out of a total of " + + total_counter + " sequences.\n" + s, + attached_counter + " sequences attached", + JOptionPane.WARNING_MESSAGE ); } } else { - success = false; - } - if ( success && ( x > 1 ) && ( y > 1 ) ) { - getOptions().setPrintSizeX( x ); - getOptions().setPrintSizeY( y ); + JOptionPane.showMessageDialog( this, + "No maching tree node for any of the " + total_counter + " sequences", + "Could not attach any sequences", + JOptionPane.ERROR_MESSAGE ); } } } @@ -1666,7 +976,7 @@ public final class MainFrameApplication extends MainFrame { } } - private void collapse( final Phylogeny phy, final double m ) { + private void collapseBelowThreshold( final Phylogeny phy ) { final PhylogenyNodeIterator it = phy.iteratorPostorder(); final List to_be_removed = new ArrayList(); double min_support = Double.MAX_VALUE; @@ -1711,13 +1021,19 @@ public final class MainFrameApplication extends MainFrame { repaint(); } if ( to_be_removed.size() > 0 ) { - JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size() - + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed " - + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE ); + JOptionPane.showMessageDialog( this, + "Collapsed " + to_be_removed.size() + + " branches with\nconfidence values below " + + getMinNotCollapseConfidenceValue(), + "Collapsed " + to_be_removed.size() + " branches", + JOptionPane.INFORMATION_MESSAGE ); } else { - JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is " - + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE ); + JOptionPane.showMessageDialog( this, + "No branch collapsed,\nminimum confidence value per branch is " + + min_support, + "No branch collapsed", + JOptionPane.INFORMATION_MESSAGE ); } } else { @@ -1728,17 +1044,17 @@ public final class MainFrameApplication extends MainFrame { } } - private void collapseBelowThreshold() { + private void collapseBelowBranchLengthThreshold() { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); if ( ( phy != null ) && !phy.isEmpty() ) { final String s = ( String ) JOptionPane.showInputDialog( this, - "Please enter the minimum confidence value\n", - "Minimal Confidence Value", + "Please enter the minimum branch length value\n", + "Minimal Branch Length Value", JOptionPane.QUESTION_MESSAGE, null, null, - getMinNotCollapseConfidenceValue() ); + getMinNotCollapseBlValue() ); if ( !ForesterUtil.isEmpty( s ) ) { boolean success = true; double m = 0.0; @@ -1755,30 +1071,126 @@ public final class MainFrameApplication extends MainFrame { success = false; } if ( success && ( m >= 0.0 ) ) { - setMinNotCollapseConfidenceValue( m ); - collapse( phy, m ); + setMinNotCollapseBlValue( m ); + collapseBl( phy ); } } } } } - private PhyloXmlParser createPhyloXmlParser() { - PhyloXmlParser xml_parser = null; - if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) { - try { - xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating(); - } - catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, - e.getLocalizedMessage(), - "failed to create validating XML parser", - JOptionPane.WARNING_MESSAGE ); - } - } - if ( xml_parser == null ) { - xml_parser = new PhyloXmlParser(); - } + private void collapseBelowThreshold() { + if ( getCurrentTreePanel() != null ) { + final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); + if ( ( phy != null ) && !phy.isEmpty() ) { + final String s = ( String ) JOptionPane.showInputDialog( this, + "Please enter the minimum confidence value\n", + "Minimal Confidence Value", + JOptionPane.QUESTION_MESSAGE, + null, + null, + getMinNotCollapseConfidenceValue() ); + if ( !ForesterUtil.isEmpty( s ) ) { + boolean success = true; + double m = 0.0; + final String m_str = s.trim(); + if ( !ForesterUtil.isEmpty( m_str ) ) { + try { + m = Double.parseDouble( m_str ); + } + catch ( final Exception ex ) { + success = false; + } + } + else { + success = false; + } + if ( success && ( m >= 0.0 ) ) { + setMinNotCollapseConfidenceValue( m ); + collapseBelowThreshold( phy ); + } + } + } + } + } + + private void collapseBl( final Phylogeny phy ) { + final PhylogenyNodeIterator it = phy.iteratorPostorder(); + final List to_be_removed = new ArrayList(); + double min_bl = Double.MAX_VALUE; + boolean bl_present = false; + while ( it.hasNext() ) { + final PhylogenyNode n = it.next(); + if ( !n.isExternal() && !n.isRoot() ) { + final double bl = n.getDistanceToParent(); + if ( bl != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { + bl_present = true; + if ( bl < getMinNotCollapseBlValue() ) { + to_be_removed.add( n ); + } + if ( bl < min_bl ) { + min_bl = bl; + } + } + } + } + if ( bl_present ) { + for( final PhylogenyNode node : to_be_removed ) { + PhylogenyMethods.removeNode( node, phy ); + } + if ( to_be_removed.size() > 0 ) { + phy.externalNodesHaveChanged(); + phy.clearHashIdToNodeMap(); + phy.recalculateNumberOfExternalDescendants( true ); + getCurrentTreePanel().resetNodeIdToDistToLeafMap(); + getCurrentTreePanel().updateSetOfCollapsedExternalNodes(); + getCurrentTreePanel().calculateLongestExtNodeInfo(); + getCurrentTreePanel().setNodeInPreorderToNull(); + getCurrentTreePanel().recalculateMaxDistanceToRoot(); + getCurrentTreePanel().resetPreferredSize(); + getCurrentTreePanel().setEdited( true ); + getCurrentTreePanel().repaint(); + repaint(); + } + if ( to_be_removed.size() > 0 ) { + JOptionPane.showMessageDialog( this, + "Collapsed " + to_be_removed.size() + + " branches with\nbranch length values below " + + getMinNotCollapseBlValue(), + "Collapsed " + to_be_removed.size() + " branches", + JOptionPane.INFORMATION_MESSAGE ); + } + else { + JOptionPane.showMessageDialog( this, + "No branch collapsed,\nminimum branch length is " + min_bl, + "No branch collapsed", + JOptionPane.INFORMATION_MESSAGE ); + } + } + else { + JOptionPane.showMessageDialog( this, + "No branch collapsed because no branch length values present", + "No branch length values present", + JOptionPane.INFORMATION_MESSAGE ); + } + } + + private PhyloXmlParser createPhyloXmlParser() { + PhyloXmlParser xml_parser = null; + if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) { + try { + xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating(); + } + catch ( final Exception e ) { + JOptionPane.showMessageDialog( this, + e.getLocalizedMessage(), + "failed to create validating XML parser", + JOptionPane.WARNING_MESSAGE ); + } + } + if ( xml_parser == null ) { + xml_parser = PhyloXmlParser.createPhyloXmlParser(); + } return xml_parser; } @@ -1792,7 +1204,8 @@ public final class MainFrameApplication extends MainFrame { if ( getMsa() != null ) { final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(), getPhylogeneticInferenceOptions() - .copy(), this ); + .copy(), + this ); new Thread( inferrer ).start(); } else { @@ -1806,7 +1219,8 @@ public final class MainFrameApplication extends MainFrame { if ( getSeqs() != null ) { final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(), getPhylogeneticInferenceOptions() - .copy(), this ); + .copy(), + this ); new Thread( inferrer ).start(); } else { @@ -1859,8 +1273,8 @@ public final class MainFrameApplication extends MainFrame { String all = "all "; if ( counter_failed > 0 ) { all = ""; - failed = "\nCould not extract taxonomic data for " + counter_failed - + " named external nodes:\n" + sb_failed; + failed = "\nCould not extract taxonomic data for " + counter_failed + " named external nodes:\n" + + sb_failed; } JOptionPane.showMessageDialog( this, "Extracted taxonomic data from " + all + counter @@ -1870,42 +1284,19 @@ public final class MainFrameApplication extends MainFrame { : JOptionPane.INFORMATION_MESSAGE ); } else { - JOptionPane - .showMessageDialog( this, - "Could not extract any taxonomic data.\nMaybe node names are empty\n" - + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n" - + "or nodes already have taxonomic data?\n", - "No Taxonomic Data Extracted", - JOptionPane.ERROR_MESSAGE ); + JOptionPane.showMessageDialog( this, + "Could not extract any taxonomic data.\nMaybe node names are empty\n" + + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n" + + "or nodes already have taxonomic data?\n", + "No Taxonomic Data Extracted", + JOptionPane.ERROR_MESSAGE ); } } } } - private ControlPanel getControlPanel() { - return getMainPanel().getControlPanel(); - } - - private File getCurrentDir() { - if ( ( _current_dir == null ) || !_current_dir.canRead() ) { - if ( ForesterUtil.isWindows() ) { - try { - _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() ); - } - catch ( final Exception e ) { - _current_dir = null; - } - } - } - if ( ( _current_dir == null ) || !_current_dir.canRead() ) { - if ( System.getProperty( "user.home" ) != null ) { - _current_dir = new File( System.getProperty( "user.home" ) ); - } - else if ( System.getProperty( "user.dir" ) != null ) { - _current_dir = new File( System.getProperty( "user.dir" ) ); - } - } - return _current_dir; + private double getMinNotCollapseBlValue() { + return _min_not_collapse_bl; } private double getMinNotCollapseConfidenceValue() { @@ -1933,8 +1324,9 @@ public final class MainFrameApplication extends MainFrame { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); if ( ( phy != null ) && !phy.isEmpty() ) { - PhylogenyMethods - .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false ); + PhylogenyMethods.transferNodeNameToField( phy, + PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, + false ); } } } @@ -1961,14 +1353,9 @@ public final class MainFrameApplication extends MainFrame { _mainpanel.getControlPanel().showWhole(); _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ); _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ); - if ( getMainPanel().getMainFrame() == null ) { - // Must be "E" applet version. - ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() ) - .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ); - } - else { - getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ); - } + + getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ); + activateSaveAllIfNeeded(); System.gc(); } @@ -2013,84 +1400,28 @@ public final class MainFrameApplication extends MainFrame { } } - private void print() { - if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) - || getCurrentTreePanel().getPhylogeny().isEmpty() ) { - return; - } - if ( !getOptions().isPrintUsingActualSize() ) { - getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80, - getOptions().getPrintSizeY() - 140, - true ); - getCurrentTreePanel().resetPreferredSize(); - getCurrentTreePanel().repaint(); - } - final String job_name = Constants.PRG_NAME; - boolean error = false; - String printer_name = null; - try { - printer_name = Printer.print( getCurrentTreePanel(), job_name ); - } - catch ( final Exception e ) { - error = true; - JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE ); - } - if ( !error && ( printer_name != null ) ) { - String msg = "Printing data sent to printer"; - if ( printer_name.length() > 1 ) { - msg += " [" + printer_name + "]"; - } - JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE ); - } - if ( !getOptions().isPrintUsingActualSize() ) { - getControlPanel().showWhole(); - } - } - - private void printPhylogenyToPdf( final String file_name ) { - if ( !getOptions().isPrintUsingActualSize() ) { - getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(), - getOptions().getPrintSizeY(), - true ); - getCurrentTreePanel().resetPreferredSize(); - getCurrentTreePanel().repaint(); - } - String pdf_written_to = ""; - boolean error = false; - try { - if ( getOptions().isPrintUsingActualSize() ) { - pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, - getCurrentTreePanel(), - getCurrentTreePanel().getWidth(), - getCurrentTreePanel().getHeight() ); - } - else { - pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions() - .getPrintSizeX(), getOptions().getPrintSizeY() ); - } - } - catch ( final IOException e ) { - error = true; - JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE ); - } - if ( !error ) { - if ( !ForesterUtil.isEmpty( pdf_written_to ) ) { - JOptionPane.showMessageDialog( this, - "Wrote PDF to: " + pdf_written_to, - "Information", - JOptionPane.INFORMATION_MESSAGE ); - } - else { - JOptionPane.showMessageDialog( this, - "There was an unknown problem when attempting to write to PDF file: \"" - + file_name + "\"", - "Error", - JOptionPane.ERROR_MESSAGE ); + private void preProcessTreesUponReading( final Phylogeny[] phys ) { + for( final Phylogeny phy : phys ) { + if ( ( phy != null ) && !phy.isEmpty() ) { + for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) { + final PhylogenyNode n = it.next(); + if ( n.isExternal() ) { + if ( n.getNodeData().isHasSequence() ) { + final Sequence s = n.getNodeData().getSequence(); + if ( ForesterUtil.isEmpty( s.getGeneName() ) || s.getGeneName().startsWith( "LOC" ) ) { + if ( ( s.getAccession() != null ) + && !ForesterUtil.isEmpty( s.getAccession().getValue() ) ) { + s.setGeneName( s.getAccession().getValue() ); + } + else if ( !ForesterUtil.isEmpty( n.getName() ) ) { + s.setGeneName( n.getName() ); + } + } + } + } + } } } - if ( !getOptions().isPrintUsingActualSize() ) { - getControlPanel().showWhole(); - } } private void readPhylogeniesFromFile() { @@ -2098,7 +1429,6 @@ public final class MainFrameApplication extends MainFrame { Phylogeny[] phys = null; // Set an initial directory if none set yet final File my_dir = getCurrentDir(); - _open_filechooser.setMultiSelectionEnabled( true ); // Open file-open dialog and set current directory if ( my_dir != null ) { _open_filechooser.setCurrentDirectory( my_dir ); @@ -2117,8 +1447,8 @@ public final class MainFrameApplication extends MainFrame { else { _mainpanel.setWaitCursor(); } - if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) - || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) { + if ( ( _open_filechooser.getFileFilter() == MainFrame.nhfilter ) + || ( _open_filechooser.getFileFilter() == MainFrame.nhxfilter ) ) { try { final NHXParser nhx = new NHXParser(); setSpecialOptionsForNhxParser( nhx ); @@ -2130,7 +1460,7 @@ public final class MainFrameApplication extends MainFrame { exceptionOccuredDuringOpenFile( e ); } } - else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) { + else if ( _open_filechooser.getFileFilter() == MainFrame.xmlfilter ) { warnIfNotPhyloXmlValidation( getConfiguration() ); try { final PhyloXmlParser xml_parser = createPhyloXmlParser(); @@ -2141,7 +1471,7 @@ public final class MainFrameApplication extends MainFrame { exceptionOccuredDuringOpenFile( e ); } } - else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) { + else if ( _open_filechooser.getFileFilter() == MainFrame.tolfilter ) { try { phys = PhylogenyMethods.readPhylogenies( new TolParser(), file ); } @@ -2150,7 +1480,7 @@ public final class MainFrameApplication extends MainFrame { exceptionOccuredDuringOpenFile( e ); } } - else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) { + else if ( _open_filechooser.getFileFilter() == MainFrame.nexusfilter ) { try { final NexusPhylogeniesParser nex = new NexusPhylogeniesParser(); setSpecialOptionsForNexParser( nex ); @@ -2166,8 +1496,9 @@ public final class MainFrameApplication extends MainFrame { else { try { final PhylogenyParser parser = ParserUtils - .createParserDependingOnFileType( file, getConfiguration() - .isValidatePhyloXmlAgainstSchema() ); + .createParserDependingOnFileType( file, + getConfiguration() + .isValidatePhyloXmlAgainstSchema() ); if ( parser instanceof NexusPhylogeniesParser ) { final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser; setSpecialOptionsForNexParser( nex ); @@ -2199,7 +1530,7 @@ public final class MainFrameApplication extends MainFrame { if ( nhx_or_nexus ) { for( final Phylogeny phy : phys ) { if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) { - PhylogenyMethods.transferInternalNodeNamesToConfidence( phy ); + PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" ); } if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) { one_desc = true; @@ -2207,6 +1538,9 @@ public final class MainFrameApplication extends MainFrame { } } } + if ( PREPROCESS_TREES ) { + preProcessTreesUponReading( phys ); + } AptxUtil.addPhylogeniesToTabs( phys, file.getName(), file.getAbsolutePath(), @@ -2214,13 +1548,12 @@ public final class MainFrameApplication extends MainFrame { getMainPanel() ); _mainpanel.getControlPanel().showWhole(); if ( nhx_or_nexus && one_desc ) { - JOptionPane - .showMessageDialog( this, - "One or more trees contain (a) node(s) with one descendant, " - + ForesterUtil.LINE_SEPARATOR - + "possibly indicating illegal parentheses within node names.", - "Warning: Possible Error in New Hampshire Formatted Data", - JOptionPane.WARNING_MESSAGE ); + JOptionPane.showMessageDialog( this, + "One or more trees contain (a) node(s) with one descendant, " + + ForesterUtil.LINE_SEPARATOR + + "possibly indicating illegal parentheses within node names.", + "Warning: Possible Error in New Hampshire Formatted Data", + JOptionPane.WARNING_MESSAGE ); } } } @@ -2241,9 +1574,10 @@ public final class MainFrameApplication extends MainFrame { final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane ); final File file = _open_filechooser_for_species_tree.getSelectedFile(); if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { - if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) { + if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrame.xmlfilter ) { try { - final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file ); + final Phylogeny[] trees = PhylogenyMethods + .readPhylogenies( PhyloXmlParser.createPhyloXmlParserXsdValidating(), file ); t = trees[ 0 ]; } catch ( final Exception e ) { @@ -2251,7 +1585,7 @@ public final class MainFrameApplication extends MainFrame { exceptionOccuredDuringOpenFile( e ); } } - else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) { + else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrame.tolfilter ) { try { final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file ); t = trees[ 0 ]; @@ -2264,7 +1598,8 @@ public final class MainFrameApplication extends MainFrame { // "*.*": else { try { - final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file ); + final Phylogeny[] trees = PhylogenyMethods + .readPhylogenies( PhyloXmlParser.createPhyloXmlParserXsdValidating(), file ); t = trees[ 0 ]; } catch ( final Exception e ) { @@ -2287,23 +1622,22 @@ public final class MainFrameApplication extends MainFrame { if ( !node.getNodeData().isHasTaxonomy() ) { exception = true; t = null; - JOptionPane - .showMessageDialog( this, - "Species tree contains external node(s) without taxonomy information", - "Species tree not loaded", - JOptionPane.ERROR_MESSAGE ); + JOptionPane.showMessageDialog( this, + "Species tree contains external node(s) without taxonomy information", + "Species tree not loaded", + JOptionPane.ERROR_MESSAGE ); break; } else { if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) { exception = true; t = null; - JOptionPane.showMessageDialog( this, - "Taxonomy [" - + node.getNodeData().getTaxonomy().asSimpleText() - + "] is not unique in species tree", - "Species tree not loaded", - JOptionPane.ERROR_MESSAGE ); + JOptionPane + .showMessageDialog( this, + "Taxonomy [" + node.getNodeData().getTaxonomy().asSimpleText() + + "] is not unique in species tree", + "Species tree not loaded", + JOptionPane.ERROR_MESSAGE ); break; } else { @@ -2333,8 +1667,8 @@ public final class MainFrameApplication extends MainFrame { } } - private void setCurrentDir( final File current_dir ) { - _current_dir = current_dir; + private void setMinNotCollapseBlValue( final double min_not_collapse_bl ) { + _min_not_collapse_bl = min_not_collapse_bl; } private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) { @@ -2348,283 +1682,534 @@ public final class MainFrameApplication extends MainFrame { private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) { nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() ); nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() ); + nex.setParseBeastStyleExtendedTags( getOptions().isParseBeastStyleExtendedNexusTags() ); } private void setSpecialOptionsForNhxParser( final NHXParser nhx ) { nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() ); nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() ); + nhx.setAllowErrorsInDistanceToParent( getOptions().isAllowErrorsInDistanceToParent() ); + nhx.setParseBeastStyleExtendedTags( getOptions().isParseBeastStyleExtendedNexusTags() ); + } + + void buildAnalysisMenu() { + _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() ); + _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) ); + _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) ); + _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) ); + customizeJMenuItem( _gsdi_item ); + customizeJMenuItem( _gsdir_item ); + customizeJMenuItem( _load_species_tree_item ); + _analysis_menu.addSeparator(); + _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) ); + customizeJMenuItem( _lineage_inference ); + _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" ); + _jmenubar.add( _analysis_menu ); + } + + @Override + void buildFileMenu() { + _file_jmenu = MainFrame.createMenu( "File", getConfiguration() ); + _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) ); + _file_jmenu.addSeparator(); + _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) ); + _file_jmenu.addSeparator(); + final WebservicesManager webservices_manager = WebservicesManager.getInstance(); + _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager + .getAvailablePhylogeniesWebserviceClients().size() ]; + for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) { + final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i ); + _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() ); + _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] ); + } + if ( getConfiguration().isEditable() ) { + _file_jmenu.addSeparator(); + _file_jmenu.add( _new_item = new JMenuItem( "New" ) ); + _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" ); + } + _file_jmenu.addSeparator(); + _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) ); + _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) ); + _save_all_item.setToolTipText( "Write all phylogenies to one file." ); + _save_all_item.setEnabled( false ); + _file_jmenu.addSeparator(); + _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) ); + if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) + || AptxUtil.canWriteFormat( "TIF" ) ) { + _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) ); + } + _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) ); + _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) ); + if ( AptxUtil.canWriteFormat( "gif" ) ) { + _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) ); + } + if ( AptxUtil.canWriteFormat( "bmp" ) ) { + _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) ); + } + _file_jmenu.addSeparator(); + _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) ); + _file_jmenu.addSeparator(); + _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) ); + _close_item.setToolTipText( "To close the current pane." ); + _close_item.setEnabled( true ); + _file_jmenu.addSeparator(); + _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) ); + customizeJMenuItem( _open_item ); + _open_item.setFont( new Font( _open_item.getFont().getFontName(), + Font.BOLD, + _open_item.getFont().getSize() + 4 ) ); + customizeJMenuItem( _open_url_item ); + for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) { + customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] ); + } + customizeJMenuItem( _save_item ); + if ( getConfiguration().isEditable() ) { + customizeJMenuItem( _new_item ); + } + customizeJMenuItem( _close_item ); + customizeJMenuItem( _save_all_item ); + customizeJMenuItem( _write_to_pdf_item ); + customizeJMenuItem( _write_to_png_item ); + customizeJMenuItem( _write_to_jpg_item ); + customizeJMenuItem( _write_to_gif_item ); + customizeJMenuItem( _write_to_tif_item ); + customizeJMenuItem( _write_to_bmp_item ); + customizeJMenuItem( _print_item ); + customizeJMenuItem( _exit_item ); + _jmenubar.add( _file_jmenu ); + } + + void buildOptionsMenu() { + _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() ); + _options_jmenu.addChangeListener( new ChangeListener() { + + @Override + public void stateChanged( final ChangeEvent e ) { + MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() ); + MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() ); + MainFrame.setTextMinSupportMenuItem( _choose_minimal_confidence_mi, + getOptions(), + getCurrentTreePanel() ); + MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, + MainFrame.createCurrentFontDesc( getMainPanel() + .getTreeFontSet() ) ); + // MainFrame.setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() ); + MainFrame.setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() ); + MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() ); + MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() ); + MainFrame.setCycleDataReturnMenuItem( _cycle_data_return, getOptions() ); + MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() ); + try { + getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB(); + getMainPanel().getControlPanel().setVisibilityOfX(); + } + catch ( final Exception ignore ) { + // do nothing, not important. + } + } + } ); + _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) ); + _options_jmenu + .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) ); + _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) ); + _radio_group_1 = new ButtonGroup(); + _radio_group_1.add( _ext_node_dependent_cladogram_rbmi ); + _radio_group_1.add( _non_lined_up_cladograms_rbmi ); + _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) ); + _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) ); + _options_jmenu + .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) ); + _options_jmenu + .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) ); + _options_jmenu + .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) ); + + _options_jmenu + .add( _collapsed_with_average_height_cbmi = new JCheckBoxMenuItem( "Proportional Height of Collapsed Subtrees" ) ); + + + _options_jmenu + .add( _show_abbreviated_labels_for_collapsed_nodes_cbmi = new JCheckBoxMenuItem( "Add Abbreviated Labels to Collapsed Subtrees" ) ); + + + + _options_jmenu + .add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) ); + + + + if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) { + _options_jmenu + .add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) ); + _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) ); + } + _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) ); + _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) ); + _options_jmenu.add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( COLOR_BY_TAXONOMIC_GROUP ) ); + _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) ); + _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP ); + _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) ); + _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) ); + _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP ); + _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) ); + _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) ); + _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) ); + _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) ); + _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) ); + _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) ); + _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) ); + _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) ); + _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) ); + _options_jmenu.addSeparator(); + _options_jmenu.add( _cycle_data_return = new JMenuItem( "Cycle Data Return" ) ); + _options_jmenu.addSeparator(); + _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) ); + _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) ); + _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) ); + _options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) ); + _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP ); + _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) ); + _options_jmenu + .add( _color_all_found_nodes_when_coloring_subtree_cbmi = new JCheckBoxMenuItem( "Colorize All Found Nodes When Colorizing Subtree(s)" ) ); + _options_jmenu.addSeparator(); + _options_jmenu + .add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ), getConfiguration() ) ); + _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) ); + _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) ); + _options_jmenu + .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) ); + _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) ); + _options_jmenu.addSeparator(); + _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Read:" ), getConfiguration() ) ); + _options_jmenu + .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) ); + _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) ); + _options_jmenu + .add( _parse_beast_style_extended_nexus_tags_cbmi = new JCheckBoxMenuItem( "Parse BEAST-style extended Newick/Nexus tags" ) ); + _parse_beast_style_extended_nexus_tags_cbmi + .setToolTipText( "to parse elements in the form of \"[&!color=#800080]\" in Newick/Nexus formatted trees" ); + _options_jmenu + .add( _allow_errors_in_distance_to_parent_cbmi = new JCheckBoxMenuItem( "Ignore Distance Values Format Errors" ) ); + _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) ); + _options_jmenu + .add( _extract_taxonomy_pfam_strict_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style Node Names" ) ); + _options_jmenu + .add( _extract_taxonomy_pfam_relaxed_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style like Node Names" ) ); + _options_jmenu + .add( _extract_taxonomy_agressive_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids/Scientific Names from Node Names" ) ); + _extract_taxonomy_pfam_strict_rbmi + .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"BCL2_MOUSE/123-304\" or \"BCL2_10090/123-304\"" ); + _extract_taxonomy_pfam_relaxed_rbmi + .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"bax_MOUSE\" or \"bax_10090\"" ); + _extract_taxonomy_agressive_rbmi + .setToolTipText( "To extract taxonomy codes/ids or scientific names from node names in the form of e.g. \"MOUSE\" or \"10090\" or \"xyz_Nematostella_vectensis\"" ); + _radio_group_2 = new ButtonGroup(); + _radio_group_2.add( _extract_taxonomy_no_rbmi ); + _radio_group_2.add( _extract_taxonomy_pfam_strict_rbmi ); + _radio_group_2.add( _extract_taxonomy_pfam_relaxed_rbmi ); + _radio_group_2.add( _extract_taxonomy_agressive_rbmi ); + _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Save:" ), getConfiguration() ) ); + _options_jmenu + .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) ); + _use_brackets_for_conf_in_nh_export_cbmi + .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" ); + _options_jmenu + .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) ); + customizeJMenuItem( _choose_font_mi ); + customizeJMenuItem( _choose_minimal_confidence_mi ); + customizeJMenuItem( _switch_colors_mi ); + customizeJMenuItem( _choose_pdf_width_mi ); + customizeJMenuItem( _overview_placment_mi ); + customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, + getOptions().isShowDefaultNodeShapesExternal() ); + customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, + getOptions().isShowDefaultNodeShapesInternal() ); + customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, + getOptions().isShowDefaultNodeShapesForMarkedNodes() ); + customizeJMenuItem( _cycle_node_shape_mi ); + customizeJMenuItem( _cycle_node_fill_mi ); + customizeJMenuItem( _choose_node_size_mi ); + customizeJMenuItem( _cycle_data_return ); + customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, + getOptions().isColorLabelsSameAsParentBranch() ); + customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() ); + customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); + customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); + customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() ); + customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() ); + customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() ); + customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() ); + customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); + customizeCheckBoxMenuItem( _collapsed_with_average_height_cbmi, getOptions().isCollapsedWithAverageHeigh() ); + customizeCheckBoxMenuItem( _show_abbreviated_labels_for_collapsed_nodes_cbmi, getOptions().isShowAbbreviatedLabelsForCollapsedNodes() ); + + customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi, + getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ); + customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, + getOptions().getCladogramType() == CLADOGRAM_TYPE.LINED_UP ); + customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() ); + customizeCheckBoxMenuItem( _label_direction_cbmi, + getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL ); + customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() ); + customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() ); + customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, + getOptions().isInternalNumberAreConfidenceForNhParsing() ); + customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO ); + customizeRadioButtonMenuItem( _extract_taxonomy_pfam_strict_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + customizeRadioButtonMenuItem( _extract_taxonomy_pfam_relaxed_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + customizeRadioButtonMenuItem( _extract_taxonomy_agressive_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.AGGRESSIVE ); + customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() ); + customizeCheckBoxMenuItem( _allow_errors_in_distance_to_parent_cbmi, + getOptions().isReplaceUnderscoresInNhParsing() ); + customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() ); + customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() ); + customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() ); + customizeCheckBoxMenuItem( _color_all_found_nodes_when_coloring_subtree_cbmi, + getOptions().isColorAllFoundNodesWhenColoringSubtree() ); + customizeCheckBoxMenuItem( _parse_beast_style_extended_nexus_tags_cbmi, + getOptions().isParseBeastStyleExtendedNexusTags() ); + customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() ); + customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() ); + customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, + getOptions() + .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ); + customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, + getOptions() + .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ); + customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() ); + customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() ); + _jmenubar.add( _options_jmenu ); + } + + void buildPhylogeneticInferenceMenu() { + final InferenceManager im = getInferenceManager(); + _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() ); + _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) ); + customizeJMenuItem( _inference_from_msa_item ); + _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" ); + if ( im.canDoMsa() ) { + _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) ); + customizeJMenuItem( _inference_from_seqs_item ); + _inference_from_seqs_item + .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" ); + } + else { + _inference_menu + .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) ); + customizeJMenuItem( _inference_from_seqs_item ); + _inference_from_seqs_item.setEnabled( false ); + } + _jmenubar.add( _inference_menu ); + } + + void buildToolsMenu() { + _tools_menu = createMenu( "Tools", getConfiguration() ); + _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) ); + customizeJMenuItem( _confcolor_item ); + _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) ); + customizeJMenuItem( _color_rank_jmi ); + _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" ); + _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) ); + customizeJMenuItem( _taxcolor_item ); + _tools_menu.addSeparator(); + _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) ); + _remove_visual_styles_item + .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny" ); + customizeJMenuItem( _remove_visual_styles_item ); + _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) ); + _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny" ); + customizeJMenuItem( _remove_branch_color_item ); + _tools_menu.addSeparator(); + _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) ); + customizeJMenuItem( _annotate_item ); + _tools_menu.addSeparator(); + _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) ); + customizeJMenuItem( _midpoint_root_item ); + _tools_menu.addSeparator(); + _tools_menu.add( _delete_selected_nodes_item = new JMenuItem( "Delete Selected Nodes" ) ); + _delete_selected_nodes_item.setToolTipText( "To delete all selected external nodes" ); + customizeJMenuItem( _delete_selected_nodes_item ); + _tools_menu.add( _delete_not_selected_nodes_item = new JMenuItem( "Retain Selected Nodes" ) ); + _delete_not_selected_nodes_item.setToolTipText( "To delete all not selected external nodes" ); + customizeJMenuItem( _delete_not_selected_nodes_item ); + _tools_menu.addSeparator(); + _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Single Taxonomy-Subtrees" ) ); + customizeJMenuItem( _collapse_species_specific_subtrees ); + _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse subtrees associated with only one taxonomy (such as species specific subtrees)" ); + _tools_menu + .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) ); + customizeJMenuItem( _collapse_below_threshold ); + _collapse_below_threshold + .setToolTipText( "To (permanently) 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)" ); + // + _tools_menu + .add( _collapse_below_branch_length = new JMenuItem( "Collapse Branches with Branch Lengths Below Threshold into Multifurcations" ) ); + customizeJMenuItem( _collapse_below_branch_length ); + _collapse_below_branch_length + .setToolTipText( "To (permanently) collapse branches with branches with branch lengths below a threshold into multifurcations" ); + // + _tools_menu.addSeparator(); + _tools_menu + .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) ); + customizeJMenuItem( _extract_tax_code_from_node_names_jmi ); + _extract_tax_code_from_node_names_jmi + .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'" ); + _tools_menu + .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) ); + customizeJMenuItem( _move_node_names_to_tax_sn_jmi ); + _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" ); + _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) ); + customizeJMenuItem( _move_node_names_to_seq_names_jmi ); + _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" ); + _tools_menu.addSeparator(); + _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) ); + customizeJMenuItem( _obtain_seq_information_jmi ); + _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" ); + _tools_menu + .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) ); + customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi ); + _obtain_detailed_taxonomic_information_jmi + .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" ); + _tools_menu + .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) ); + customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi ); + _obtain_detailed_taxonomic_information_deleting_jmi + .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" ); + _tools_menu.addSeparator(); + _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) ); + customizeJMenuItem( _read_values_jmi ); + _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" ); + _jmenubar.add( _tools_menu ); + _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) ); + customizeJMenuItem( _read_seqs_jmi ); + _read_seqs_jmi + .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" ); + _jmenubar.add( _tools_menu ); } - private void writeAllToFile() { - if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) { - return; - } - final File my_dir = getCurrentDir(); - if ( my_dir != null ) { - _save_filechooser.setCurrentDirectory( my_dir ); - } - _save_filechooser.setSelectedFile( new File( "" ) ); - final int result = _save_filechooser.showSaveDialog( _contentpane ); - final File file = _save_filechooser.getSelectedFile(); - setCurrentDir( _save_filechooser.getCurrentDirectory() ); - if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { - if ( file.exists() ) { - final int i = JOptionPane.showConfirmDialog( this, - file + " already exists. Overwrite?", - "Warning", - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE ); - if ( i != JOptionPane.OK_OPTION ) { - return; - } - else { - try { - file.delete(); - } - catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, - "Failed to delete: " + file, - "Error", - JOptionPane.WARNING_MESSAGE ); - } - } - } - final int count = getMainPanel().getTabbedPane().getTabCount(); - final List trees = new ArrayList(); - for( int i = 0; i < count; ++i ) { - final Phylogeny phy = getMainPanel().getPhylogeny( i ); - if ( ForesterUtil.isEmpty( phy.getName() ) - && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) { - phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) ); - } - trees.add( phy ); - getMainPanel().getTreePanels().get( i ).setEdited( false ); - } - final PhylogenyWriter writer = new PhylogenyWriter(); - try { - writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR ); - } - catch ( final IOException e ) { - JOptionPane.showMessageDialog( this, - "Failed to write to: " + file, - "Error", - JOptionPane.WARNING_MESSAGE ); + @Override + void close() { + if ( isUnsavedDataPresent() ) { + final int r = JOptionPane.showConfirmDialog( this, + "Exit despite potentially unsaved changes?", + "Exit?", + JOptionPane.YES_NO_OPTION ); + if ( r != JOptionPane.YES_OPTION ) { + return; } } + exit(); } - private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) { - try { - final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toNewHampshire( t, false, true, getOptions().getNhConversionSupportValueStyle(), file ); - } - catch ( final Exception e ) { - exception = true; - exceptionOccuredDuringSaveAs( e ); - } - return exception; - } - - private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) { - try { - final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() ); - } - catch ( final Exception e ) { - exception = true; - exceptionOccuredDuringSaveAs( e ); - } - return exception; - } - - private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) { - try { - final PhylogenyWriter writer = new PhylogenyWriter(); - writer.toPhyloXML( file, t, 0 ); - } - catch ( final Exception e ) { - exception = true; - exceptionOccuredDuringSaveAs( e ); - } - return exception; + void exit() { + removeAllTextFrames(); + _mainpanel.terminate(); + _contentpane.removeAll(); + setVisible( false ); + dispose(); + // System.exit( 0 ); //TODO reconfirm that this is OK, then remove. } - private void writeToFile( final Phylogeny t ) { - if ( t == null ) { - return; - } - String initial_filename = null; - if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) { + void readPhylogeniesFromURL() { + URL url = null; + Phylogeny[] phys = null; + final String message = "Please enter a complete URL, for example \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\""; + final String url_string = JOptionPane + .showInputDialog( this, + message, + "Use URL/webservice to obtain a phylogeny", + JOptionPane.QUESTION_MESSAGE ); + boolean nhx_or_nexus = false; + if ( ( url_string != null ) && ( url_string.length() > 0 ) ) { try { - initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath(); - } - catch ( final IOException e ) { - initial_filename = null; - } - } - if ( !ForesterUtil.isEmpty( initial_filename ) ) { - _save_filechooser.setSelectedFile( new File( initial_filename ) ); - } - else { - _save_filechooser.setSelectedFile( new File( "" ) ); - } - final File my_dir = getCurrentDir(); - if ( my_dir != null ) { - _save_filechooser.setCurrentDirectory( my_dir ); - } - final int result = _save_filechooser.showSaveDialog( _contentpane ); - final File file = _save_filechooser.getSelectedFile(); - setCurrentDir( _save_filechooser.getCurrentDirectory() ); - boolean exception = false; - if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { - if ( file.exists() ) { - final int i = JOptionPane.showConfirmDialog( this, - file + " already exists.\nOverwrite?", - "Overwrite?", - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE ); - if ( i != JOptionPane.OK_OPTION ) { - return; + url = new URL( url_string ); + PhylogenyParser parser = null; + if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) { + parser = new TolParser(); } else { - final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX ); - try { - ForesterUtil.copyFile( file, to ); - } - catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, - "Failed to create backup copy " + to, - "Failed to Create Backup Copy", - JOptionPane.WARNING_MESSAGE ); - } - try { - file.delete(); - } - catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, - "Failed to delete: " + file, - "Failed to Delete", - JOptionPane.WARNING_MESSAGE ); - } + parser = ParserUtils + .createParserDependingOnUrlContents( url, + getConfiguration().isValidatePhyloXmlAgainstSchema() ); } - } - if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) { - exception = writeAsNewHampshire( t, exception, file ); - } - else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) { - exception = writeAsPhyloXml( t, exception, file ); - } - else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) { - exception = writeAsNexus( t, exception, file ); - } - // "*.*": - else { - final String file_name = file.getName().trim().toLowerCase(); - if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" ) - || file_name.endsWith( ".tree" ) ) { - exception = writeAsNewHampshire( t, exception, file ); + if ( parser instanceof NexusPhylogeniesParser ) { + nhx_or_nexus = true; + } + else if ( parser instanceof NHXParser ) { + nhx_or_nexus = true; } - else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) { - exception = writeAsNexus( t, exception, file ); + if ( _mainpanel.getCurrentTreePanel() != null ) { + _mainpanel.getCurrentTreePanel().setWaitCursor(); } - // XML is default: else { - exception = writeAsPhyloXml( t, exception, file ); + _mainpanel.setWaitCursor(); } + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + phys = factory.create( url.openStream(), parser ); } - if ( !exception ) { - getMainPanel().setTitleOfSelectedTab( file.getName() ); - getMainPanel().getCurrentTreePanel().setTreeFile( file ); - getMainPanel().getCurrentTreePanel().setEdited( false ); + catch ( final MalformedURLException e ) { + JOptionPane.showMessageDialog( this, + "Malformed URL: " + url + "\n" + e.getLocalizedMessage(), + "Malformed URL", + JOptionPane.ERROR_MESSAGE ); } - } - } - - private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) { - if ( ( t == null ) || t.isEmpty() ) { - return; - } - String initial_filename = ""; - if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) { - initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString(); - } - if ( initial_filename.indexOf( '.' ) > 0 ) { - initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) ); - } - initial_filename = initial_filename + "." + type; - _writetographics_filechooser.setSelectedFile( new File( initial_filename ) ); - final File my_dir = getCurrentDir(); - if ( my_dir != null ) { - _writetographics_filechooser.setCurrentDirectory( my_dir ); - } - final int result = _writetographics_filechooser.showSaveDialog( _contentpane ); - File file = _writetographics_filechooser.getSelectedFile(); - setCurrentDir( _writetographics_filechooser.getCurrentDirectory() ); - if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { - if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) { - file = new File( file.toString() + "." + type ); - } - if ( file.exists() ) { - final int i = JOptionPane.showConfirmDialog( this, - file + " already exists. Overwrite?", - "Warning", - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE ); - if ( i != JOptionPane.OK_OPTION ) { - return; + catch ( final IOException e ) { + JOptionPane.showMessageDialog( this, + "Could not read from " + url + "\n" + + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), + "Failed to read URL", + JOptionPane.ERROR_MESSAGE ); + } + catch ( final Exception e ) { + JOptionPane.showMessageDialog( this, + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ), + "Unexpected Exception", + JOptionPane.ERROR_MESSAGE ); + } + finally { + if ( _mainpanel.getCurrentTreePanel() != null ) { + _mainpanel.getCurrentTreePanel().setArrowCursor(); } else { - try { - file.delete(); - } - catch ( final Exception e ) { - JOptionPane.showMessageDialog( this, - "Failed to delete: " + file, - "Error", - JOptionPane.WARNING_MESSAGE ); + _mainpanel.setArrowCursor(); + } + } + if ( ( phys != null ) && ( phys.length > 0 ) ) { + if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) { + for( final Phylogeny phy : phys ) { + PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" ); } } + AptxUtil.addPhylogeniesToTabs( phys, + new File( url.getFile() ).getName(), + new File( url.getFile() ).toString(), + getConfiguration(), + getMainPanel() ); + _mainpanel.getControlPanel().showWhole(); } - writePhylogenyToGraphicsFile( file.toString(), type ); } + activateSaveAllIfNeeded(); + System.gc(); } - private void writeToPdf( final Phylogeny t ) { - if ( ( t == null ) || t.isEmpty() ) { - return; - } - String initial_filename = ""; - if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) { - initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString(); - } - if ( initial_filename.indexOf( '.' ) > 0 ) { - initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) ); - } - initial_filename = initial_filename + ".pdf"; - _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) ); - final File my_dir = getCurrentDir(); - if ( my_dir != null ) { - _writetopdf_filechooser.setCurrentDirectory( my_dir ); - } - final int result = _writetopdf_filechooser.showSaveDialog( _contentpane ); - File file = _writetopdf_filechooser.getSelectedFile(); - setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() ); - if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) { - if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) { - file = new File( file.toString() + ".pdf" ); - } - if ( file.exists() ) { - final int i = JOptionPane.showConfirmDialog( this, - file + " already exists. Overwrite?", - "WARNING", - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE ); - if ( i != JOptionPane.OK_OPTION ) { - return; - } - } - printPhylogenyToPdf( file.toString() ); - } + void setMsa( final Msa msa ) { + _msa = msa; + } + + void setMsaFile( final File msa_file ) { + _msa_file = msa_file; + } + + void setSeqs( final List seqs ) { + _seqs = seqs; + } + + void setSeqsFile( final File seqs_file ) { + _seqs_file = seqs_file; } public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) { @@ -2646,179 +2231,14 @@ public final class MainFrameApplication extends MainFrame { return new MainFrameApplication( phys, config_file_name, title ); } - static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) { - mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", " - + o.getPrintSizeY() + ")" ); - } - - static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) { - mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" ); - } - static void warnIfNotPhyloXmlValidation( final Configuration c ) { if ( !c.isValidatePhyloXmlAgainstSchema() ) { - JOptionPane - .showMessageDialog( null, - ForesterUtil - .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]", - 80 ), - "Warning", - JOptionPane.WARNING_MESSAGE ); + JOptionPane.showMessageDialog( null, + ForesterUtil.wordWrap( + "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]", + 80 ), + "Warning", + JOptionPane.WARNING_MESSAGE ); } } } // MainFrameApplication. - -class DefaultFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" ) - || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" ) - || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" ) - || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) - || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" ) - || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" ) - || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) - || file_name.endsWith( ".con" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)"; - } -} - -class GraphicsFileFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" ) - || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)"; - } -} - -class MsaFileFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" ) - || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)"; - } -} - -class NexusFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" ) - || file_name.endsWith( ".tre" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "Nexus files (*.nex, *.nexus, *.nx, *.tre)"; - } -} // NexusFilter - -class NHFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" ) - || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" ) - || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" ) - || f.isDirectory(); - } - - @Override - public String getDescription() { - return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)"; - } -} // NHFilter - -class NHXFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".nhx" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "NHX files (*.nhx) [deprecated]"; - } -} - -class PdfFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "PDF files (*.pdf)"; - } -} // PdfFilter - -class SequencesFileFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" ) - || file_name.endsWith( ".seqs" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )"; - } -} - -class TolFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f - .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) ); - } - - @Override - public String getDescription() { - return "Tree of Life files (*.tol, *.tolxml)"; - } -} // TolFilter - -class XMLFilter extends FileFilter { - - @Override - public boolean accept( final File f ) { - final String file_name = f.getName().trim().toLowerCase(); - return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" ) - || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory(); - } - - @Override - public String getDescription() { - return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)"; - } -} // XMLFilter