-// $Id:
-// FORESTER -- software libraries and applications
-// for evolutionary biology research and applications.
-//
-// Copyright (C) 2008-2009 Christian M. Zmasek
-// Copyright (C) 2008-2009 Burnham Institute for Medical Research
-// Copyright (C) 2003-2007 Ethalinda K.S. Cannon
-// All rights reserved
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-//
-// Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
-
-package org.forester.archaeopteryx;
-
-import java.awt.BorderLayout;
-import java.awt.Font;
-import java.awt.event.ActionEvent;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JFileChooser;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.UIManager;
-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 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;
-import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
-import org.forester.archaeopteryx.tools.SequenceDataRetriver;
-import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
-import org.forester.archaeopteryx.webservices.WebservicesManager;
-import org.forester.io.parsers.FastaParser;
-import org.forester.io.parsers.GeneralMsaParser;
-import org.forester.io.parsers.PhylogenyParser;
-import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
-import org.forester.io.parsers.nhx.NHXParser;
-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;
-import org.forester.phylogeny.Phylogeny;
-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.Taxonomy;
-import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
-import org.forester.phylogeny.factories.PhylogenyFactory;
-import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
-import org.forester.sdi.GSDI;
-import org.forester.sdi.SDIR;
-import org.forester.sequence.Sequence;
-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;
-
-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 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 )";
- }
-}
-
-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;
- // 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 _open_filechooser;
- private final JFileChooser _msa_filechooser;
- private final JFileChooser _seqs_filechooser;
- private final JFileChooser _open_filechooser_for_species_tree;
- private final JFileChooser _save_filechooser;
- private final JFileChooser _writetopdf_filechooser;
- private final JFileChooser _writetographics_filechooser;
- // Analysis menu
- private JMenu _analysis_menu;
- private JMenuItem _load_species_tree_item;
- private JMenuItem _gsdi_item;
- private JMenuItem _root_min_dups_item;
- private JMenuItem _root_min_cost_l_item;
- private JMenuItem _lineage_inference;
- private JMenuItem _function_analysis;
- // 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 Phylogeny _species_tree;
- private File _current_dir;
- private ButtonGroup _radio_group_1;
- // Others:
- double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;
- // Phylogeny Inference menu
- 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<Sequence> _seqs = null;
- private File _seqs_file = null;
- // expression values menu:
- JMenuItem _read_values_jmi;
-
- private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {
- this( phys, config, title, null );
- }
-
- private MainFrameApplication( final Phylogeny[] phys,
- final Configuration config,
- final String title,
- final File current_dir ) {
- super();
- _configuration = config;
- if ( _configuration == null ) {
- 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 ( !Constants.__SYNTH_LF || synth_exception ) {
- if ( _configuration.isUseNativeUI() ) {
- UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
- }
- 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() );
- }
- catch ( final ClassNotFoundException e ) {
- AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );
- }
- catch ( final InstantiationException e ) {
- AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );
- }
- catch ( final IllegalAccessException e ) {
- AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );
- }
- catch ( final Exception e ) {
- AptxUtil.dieWithSystemError( e.toString() );
- }
- if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {
- setCurrentDir( current_dir );
- }
- // hide until everything is ready
- setVisible( false );
- setOptions( Options.createInstance( _configuration ) );
- setInferenceManager( InferenceManager.createInstance( _configuration ) );
- setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
- // _textframe = null; #~~~~
- _species_tree = null;
- // set title
- setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.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.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );
- _open_filechooser.setFileFilter( MainFrameApplication.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.nhxfilter );
- _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 );
- // 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 );
- // Seqs:
- _seqs_filechooser = new JFileChooser();
- _seqs_filechooser.setName( "Read Sequences File" );
- _seqs_filechooser.setCurrentDirectory( new File( "." ) );
- _seqs_filechooser.setMultiSelectionEnabled( false );
- _seqs_filechooser.addChoosableFileFilter( _seqs_filechooser.getAcceptAllFileFilter() );
- _seqs_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );
- // Expression
- _values_filechooser = new JFileChooser();
- _values_filechooser.setCurrentDirectory( new File( "." ) );
- _values_filechooser.setMultiSelectionEnabled( false );
- // build the menu bar
- _jmenubar = new JMenuBar();
- if ( !_configuration.isUseNativeUI() ) {
- _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
- }
- buildFileMenu();
- if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {
- buildPhylogeneticInferenceMenu();
- }
- buildAnalysisMenu();
- buildToolsMenu();
- buildViewMenu();
- buildFontSizeMenu();
- buildOptionsMenu();
- buildTypeMenu();
- buildHelpMenu();
- setJMenuBar( _jmenubar );
- _jmenubar.add( _help_jmenu );
- _contentpane = getContentPane();
- _contentpane.setLayout( new BorderLayout() );
- _contentpane.add( _mainpanel, BorderLayout.CENTER );
- // App is this big
- setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
- // addWindowFocusListener( new WindowAdapter() {
- //
- // @Override
- // public void windowGainedFocus( WindowEvent e ) {
- // requestFocusInWindow();
- // }
- // } );
- // The window listener
- setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
- addWindowListener( new WindowAdapter() {
-
- @Override
- public void windowClosing( final WindowEvent e ) {
- if ( isUnsavedDataPresent() ) {
- final int r = JOptionPane.showConfirmDialog( null,
- "Exit despite potentially unsaved changes?",
- "Exit?",
- JOptionPane.YES_NO_OPTION );
- if ( r != JOptionPane.YES_OPTION ) {
- return;
- }
- }
- else {
- 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().setParametersForPainting( _mainpanel.getCurrentTreePanel()
- .getWidth(),
- _mainpanel.getCurrentTreePanel()
- .getHeight(),
- false );
- }
- }
- } );
- requestFocusInWindow();
- // addKeyListener( this );
- setVisible( true );
- if ( ( phys != null ) && ( phys.length > 0 ) ) {
- AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );
- validate();
- getMainPanel().getControlPanel().showWholeAll();
- getMainPanel().getControlPanel().showWhole();
- }
- activateSaveAllIfNeeded();
- // ...and its children
- _contentpane.repaint();
- System.gc();
- }
-
- private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {
- _configuration = config;
- if ( _configuration == null ) {
- throw new IllegalArgumentException( "configuration is null" );
- }
- setVisible( false );
- setOptions( Options.createInstance( _configuration ) );
- _mainpanel = new MainPanel( _configuration, this );
- _open_filechooser = null;
- _open_filechooser_for_species_tree = null;
- _save_filechooser = null;
- _writetopdf_filechooser = null;
- _writetographics_filechooser = null;
- _msa_filechooser = null;
- _seqs_filechooser = null;
- _values_filechooser = null;
- _jmenubar = new JMenuBar();
- buildFileMenu();
- buildTypeMenu();
- _contentpane = getContentPane();
- _contentpane.setLayout( new BorderLayout() );
- _contentpane.add( _mainpanel, BorderLayout.CENTER );
- // App is this big
- setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );
- // The window listener
- setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
- addWindowListener( new WindowAdapter() {
-
- @Override
- public void windowClosing( final WindowEvent e ) {
- exit();
- }
- } );
- // setVisible( true );
- if ( ( phys != null ) && ( phys.length > 0 ) ) {
- AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );
- validate();
- getMainPanel().getControlPanel().showWholeAll();
- getMainPanel().getControlPanel().showWhole();
- }
- //activateSaveAllIfNeeded();
- // ...and its children
- _contentpane.repaint();
- }
-
- private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {
- // Reads the config file (false, false => not url, not applet):
- this( phys, new Configuration( config_file, false, false, true ), title );
- }
-
- @Override
- public void actionPerformed( final ActionEvent e ) {
- try {
- super.actionPerformed( e );
- final Object o = e.getSource();
- // Handle app-specific actions here:
- if ( o == _open_item ) {
- readPhylogeniesFromFile();
- }
- else if ( o == _save_item ) {
- writeToFile( _mainpanel.getCurrentPhylogeny() );
- // If subtree currently displayed, save it, instead of complete
- // tree.
- }
- 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;
- }
- obtainDetailedTaxonomicInformation();
- }
- else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- obtainDetailedTaxonomicInformationDelete();
- }
- else if ( o == _obtain_seq_information_jmi ) {
- obtainSequenceInformation();
- }
- else if ( o == _read_values_jmi ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- addExpressionValuesFromFile();
- }
- else if ( o == _move_node_names_to_tax_sn_jmi ) {
- moveNodeNamesToTaxSn();
- }
- else if ( o == _move_node_names_to_seq_names_jmi ) {
- moveNodeNamesToSeqNames();
- }
- else if ( o == _extract_tax_code_from_node_names_jmi ) {
- extractTaxCodeFromNodeNames();
- }
- else if ( o == _gsdi_item ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- executeGSDI();
- }
- else if ( o == _root_min_dups_item ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- executeSDIR( false );
- }
- else if ( o == _root_min_cost_l_item ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- executeSDIR( true );
- }
- 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() );
- }
- else if ( o == _replace_underscores_cbmi ) {
- if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) {
- _extract_pfam_style_tax_codes_cbmi.setSelected( false );
- }
- updateOptions( getOptions() );
- }
- else if ( o == _collapse_below_threshold ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- collapseBelowThreshold();
- }
- else if ( o == _extract_pfam_style_tax_codes_cbmi ) {
- if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) {
- _replace_underscores_cbmi.setSelected( false );
- }
- updateOptions( getOptions() );
- }
- else if ( o == _inference_from_msa_item ) {
- executePhyleneticInference( false );
- }
- else if ( o == _inference_from_seqs_item ) {
- executePhyleneticInference( true );
- }
- _contentpane.repaint();
- }
- catch ( final Exception ex ) {
- AptxUtil.unexpectedException( ex );
- }
- catch ( final Error err ) {
- AptxUtil.unexpectedError( err );
- }
- }
-
- void buildAnalysisMenu() {
- _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
- _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
- _analysis_menu.addSeparator();
- _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) );
- _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) );
- _analysis_menu.addSeparator();
- _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
- customizeJMenuItem( _gsdi_item );
- customizeJMenuItem( _root_min_dups_item );
- customizeJMenuItem( _root_min_cost_l_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 );
- }
-
- 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 );
- }
-
- @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" ) );
- // 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 ] );
- }
- 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() ) );
- 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_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
- _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( _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_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) );
- _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_cbmi, getOptions().isShowDefaultNodeShapes() );
- 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( _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() );
- customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions()
- .isExtractPfamTaxonomyCodesInNhParsing() );
- 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 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( _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
- .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Codes from Node Names" ) );
- customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
- _extract_tax_code_from_node_names_jmi
- .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
- _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( "Read Vector/Expression Values" ) );
- customizeJMenuItem( _read_values_jmi );
- _read_values_jmi.setToolTipText( "To add vector (e.g. gene expression) values (beta)" );
- _jmenubar.add( _tools_menu );
- }
-
- 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;
- }
- }
- else {
- success = false;
- }
- if ( success && ( x > 1 ) && ( y > 1 ) ) {
- getOptions().setPrintSizeX( x );
- getOptions().setPrintSizeY( y );
- }
- }
- }
-
- @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 void closeCurrentPane() {
- if ( getMainPanel().getCurrentTreePanel() != null ) {
- if ( getMainPanel().getCurrentTreePanel().isEdited() ) {
- final int r = JOptionPane.showConfirmDialog( this,
- "Close tab despite potentially unsaved changes?",
- "Close Tab?",
- JOptionPane.YES_NO_OPTION );
- if ( r != JOptionPane.YES_OPTION ) {
- return;
- }
- }
- getMainPanel().closeCurrentPane();
- activateSaveAllIfNeeded();
- }
- }
-
- private void collapse( final Phylogeny phy, final double m ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();
- double min_support = Double.MAX_VALUE;
- boolean conf_present = false;
- while ( it.hasNext() ) {
- final PhylogenyNode n = it.next();
- if ( !n.isExternal() && !n.isRoot() ) {
- final List<Confidence> c = n.getBranchData().getConfidences();
- if ( ( c != null ) && ( c.size() > 0 ) ) {
- conf_present = true;
- double max = 0;
- for( final Confidence confidence : c ) {
- if ( confidence.getValue() > max ) {
- max = confidence.getValue();
- }
- }
- if ( max < getMinNotCollapseConfidenceValue() ) {
- to_be_removed.add( n );
- }
- if ( max < min_support ) {
- min_support = max;
- }
- }
- }
- }
- if ( conf_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\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 );
- }
- }
- else {
- JOptionPane.showMessageDialog( this,
- "No branch collapsed because no confidence values present",
- "No confidence values present",
- JOptionPane.INFORMATION_MESSAGE );
- }
- }
-
- 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 );
- collapse( phy, m );
- }
- }
- }
- }
- }
-
- 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();
- }
- return xml_parser;
- }
-
- void executeGSDI() {
- if ( !isOKforSDI( false, true ) ) {
- return;
- }
- if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
- JOptionPane.showMessageDialog( this,
- "Gene tree is not rooted.",
- "Cannot execute GSDI",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
- gene_tree.setAllNodesToNotCollapse();
- gene_tree.recalculateNumberOfExternalDescendants( false );
- GSDI gsdi = null;
- try {
- gsdi = new GSDI( gene_tree, _species_tree.copy(), false, true, true );
- }
- catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
- }
- gene_tree.setRerootable( false );
- _mainpanel.getCurrentTreePanel().setTree( gene_tree );
- _mainpanel.getCurrentPhylogeny().clearHashIdToNodeMap();
- _mainpanel.getCurrentPhylogeny().recalculateNumberOfExternalDescendants( true );
- _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap();
- _mainpanel.getCurrentTreePanel().setEdited( true );
- getControlPanel().setShowEvents( true );
- showWhole();
- final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
- _mainpanel.addPhylogenyInNewTab( gsdi.getSpeciesTree(), getConfiguration(), "species tree", null );
- showWhole();
- _mainpanel.getTabbedPane().setSelectedIndex( selected );
- showWhole();
- _mainpanel.getCurrentTreePanel().setEdited( true );
- JOptionPane.showMessageDialog( this, "Duplications: " + gsdi.getDuplicationsSum() + "\n"
- + "Potential duplications: " + gsdi.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: "
- + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE );
- }
-
- 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() ) {
- JOptionPane.showMessageDialog( this,
- "Phylogeny is not rooted.",
- "Cannot infer ancestral taxonomies",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
- _mainpanel.getCurrentTreePanel(),
- _mainpanel.getCurrentPhylogeny()
- .copy() );
- new Thread( inferrer ).start();
- }
-
- private void executePhyleneticInference( final boolean from_unaligned_seqs ) {
- final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,
- getPhylogeneticInferenceOptions(),
- from_unaligned_seqs );
- dialog.activate();
- if ( dialog.getValue() == JOptionPane.OK_OPTION ) {
- if ( !from_unaligned_seqs ) {
- if ( getMsa() != null ) {
- final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
- getPhylogeneticInferenceOptions()
- .copy(), this );
- new Thread( inferrer ).start();
- }
- else {
- JOptionPane.showMessageDialog( this,
- "No multiple sequence alignment selected",
- "Phylogenetic Inference Not Launched",
- JOptionPane.WARNING_MESSAGE );
- }
- }
- else {
- if ( getSeqs() != null ) {
- final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
- getPhylogeneticInferenceOptions()
- .copy(), this );
- new Thread( inferrer ).start();
- }
- else {
- JOptionPane.showMessageDialog( this,
- "No input sequences selected",
- "Phylogenetic Inference Not Launched",
- JOptionPane.WARNING_MESSAGE );
- }
- }
- }
- }
-
- void executeSDIR( final boolean minimize_cost ) {
- if ( !isOKforSDI( true, true ) ) {
- return;
- }
- Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
- final SDIR sdiunrooted = new SDIR();
- gene_tree.setAllNodesToNotCollapse();
- gene_tree.recalculateNumberOfExternalDescendants( false );
- try {
- gene_tree = sdiunrooted.infer( gene_tree, _species_tree, minimize_cost, // minimize cost
- !minimize_cost, // minimize sum of dups
- true, // minimize height
- true, // return tree(s)
- 1 )[ 0 ]; // # of trees to return
- }
- catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during SDIR", JOptionPane.ERROR_MESSAGE );
- return;
- }
- final int duplications = sdiunrooted.getMinimalDuplications();
- gene_tree.setRerootable( false );
- _mainpanel.getCurrentTreePanel().setTree( gene_tree );
- getControlPanel().setShowEvents( true );
- showWhole();
- _mainpanel.getCurrentTreePanel().setEdited( true );
- JOptionPane.showMessageDialog( this,
- "Number of duplications: " + duplications,
- "SDIR successfully completed",
- JOptionPane.INFORMATION_MESSAGE );
- }
-
- void exit() {
- removeAllTextFrames();
- _mainpanel.terminate();
- _contentpane.removeAll();
- setVisible( false );
- dispose();
- System.exit( 0 );
- }
-
- public void end() {
- _mainpanel.terminate();
- _contentpane.removeAll();
- setVisible( false );
- dispose();
- }
-
- private void extractTaxCodeFromNodeNames() throws PhyloXmlDataFormatException {
- if ( getCurrentTreePanel() != null ) {
- final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
- if ( ( phy != null ) && !phy.isEmpty() ) {
- final PhylogenyNodeIterator it = phy.iteratorPostorder();
- while ( it.hasNext() ) {
- final PhylogenyNode n = it.next();
- final String name = n.getName().trim();
- if ( !ForesterUtil.isEmpty( name ) ) {
- final String code = ParserUtils
- .extractTaxonomyCodeFromNodeName( name, PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
- if ( !ForesterUtil.isEmpty( code ) ) {
- PhylogenyMethods.setTaxonomyCode( n, code );
- }
- }
- }
- }
- }
- }
-
- private ControlPanel getControlPanel() {
- return getMainPanel().getControlPanel();
- }
-
- private File getCurrentDir() {
- if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
- if ( ForesterUtil.isWindowns() ) {
- 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;
- }
-
- @Override
- public MainPanel getMainPanel() {
- return _mainpanel;
- }
-
- private double getMinNotCollapseConfidenceValue() {
- return _min_not_collapse;
- }
-
- boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
- if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
- return false;
- }
- else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
- JOptionPane.showMessageDialog( this,
- "No species tree loaded",
- "Cannot execute SDI",
- JOptionPane.ERROR_MESSAGE );
- return false;
- }
- else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
- JOptionPane.showMessageDialog( this,
- "Species tree is not completely binary",
- "Cannot execute SDI",
- JOptionPane.ERROR_MESSAGE );
- return false;
- }
- else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
- JOptionPane.showMessageDialog( this,
- "Gene tree is not completely binary",
- "Cannot execute SDI",
- JOptionPane.ERROR_MESSAGE );
- return false;
- }
- else {
- return true;
- }
- }
-
- private boolean isUnsavedDataPresent() {
- final List<TreePanel> tps = getMainPanel().getTreePanels();
- for( final TreePanel tp : tps ) {
- if ( tp.isEdited() ) {
- return true;
- }
- }
- return false;
- }
-
- private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {
- if ( getCurrentTreePanel() != null ) {
- final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
- if ( ( phy != null ) && !phy.isEmpty() ) {
- PhylogenyMethods
- .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );
- }
- }
- }
-
- private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {
- if ( getCurrentTreePanel() != null ) {
- final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
- if ( ( phy != null ) && !phy.isEmpty() ) {
- PhylogenyMethods.transferNodeNameToField( phy,
- PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
- false );
- }
- }
- }
-
- private void newTree() {
- final Phylogeny[] phys = new Phylogeny[ 1 ];
- final Phylogeny phy = new Phylogeny();
- final PhylogenyNode node = new PhylogenyNode();
- phy.setRoot( node );
- phy.setRooted( true );
- phys[ 0 ] = phy;
- AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );
- _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 );
- }
- activateSaveAllIfNeeded();
- System.gc();
- }
-
- private void obtainDetailedTaxonomicInformation() {
- if ( getCurrentTreePanel() != null ) {
- final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
- if ( ( phy != null ) && !phy.isEmpty() ) {
- final TaxonomyDataManager t = new TaxonomyDataManager( this,
- _mainpanel.getCurrentTreePanel(),
- phy.copy(),
- false,
- true );
- new Thread( t ).start();
- }
- }
- }
-
- private void obtainDetailedTaxonomicInformationDelete() {
- if ( getCurrentTreePanel() != null ) {
- final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
- if ( ( phy != null ) && !phy.isEmpty() ) {
- final TaxonomyDataManager t = new TaxonomyDataManager( this,
- _mainpanel.getCurrentTreePanel(),
- phy.copy(),
- true,
- true );
- new Thread( t ).start();
- }
- }
- }
-
- private void obtainSequenceInformation() {
- if ( getCurrentTreePanel() != null ) {
- final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
- if ( ( phy != null ) && !phy.isEmpty() ) {
- final SequenceDataRetriver u = new SequenceDataRetriver( this,
- _mainpanel.getCurrentTreePanel(),
- phy.copy() );
- new Thread( u ).start();
- }
- }
- }
-
- private void print() {
- if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
- || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
- return;
- }
- if ( !getOptions().isPrintUsingActualSize() ) {
- getCurrentTreePanel().setParametersForPainting( 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().setParametersForPainting( 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 );
- }
- }
- if ( !getOptions().isPrintUsingActualSize() ) {
- getControlPanel().showWhole();
- }
- }
-
- 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<String> 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<Double> l = new ArrayList<Double>();
- 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 readPhylogeniesFromFile() {
- boolean exception = false;
- 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 );
- }
- final int result = _open_filechooser.showOpenDialog( _contentpane );
- // All done: get the file
- final File[] files = _open_filechooser.getSelectedFiles();
- setCurrentDir( _open_filechooser.getCurrentDirectory() );
- boolean nhx_or_nexus = false;
- if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
- for( final File file : files ) {
- if ( ( file != null ) && !file.isDirectory() ) {
- if ( _mainpanel.getCurrentTreePanel() != null ) {
- _mainpanel.getCurrentTreePanel().setWaitCursor();
- }
- else {
- _mainpanel.setWaitCursor();
- }
- if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )
- || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {
- try {
- final NHXParser nhx = new NHXParser();
- setSpecialOptionsForNhxParser( nhx );
- phys = PhylogenyMethods.readPhylogenies( nhx, file );
- nhx_or_nexus = true;
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {
- warnIfNotPhyloXmlValidation( getConfiguration() );
- try {
- final PhyloXmlParser xml_parser = createPhyloXmlParser();
- phys = PhylogenyMethods.readPhylogenies( xml_parser, file );
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
- try {
- phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {
- try {
- final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
- setSpecialOptionsForNexParser( nex );
- phys = PhylogenyMethods.readPhylogenies( nex, file );
- nhx_or_nexus = true;
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- // "*.*":
- else {
- try {
- final PhylogenyParser parser = ParserUtils
- .createParserDependingOnFileType( file, getConfiguration()
- .isValidatePhyloXmlAgainstSchema() );
- if ( parser instanceof NexusPhylogeniesParser ) {
- final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;
- setSpecialOptionsForNexParser( nex );
- nhx_or_nexus = true;
- }
- else if ( parser instanceof NHXParser ) {
- final NHXParser nhx = ( NHXParser ) parser;
- setSpecialOptionsForNhxParser( nhx );
- nhx_or_nexus = true;
- }
- else if ( parser instanceof PhyloXmlParser ) {
- warnIfNotPhyloXmlValidation( getConfiguration() );
- }
- phys = PhylogenyMethods.readPhylogenies( parser, file );
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- if ( _mainpanel.getCurrentTreePanel() != null ) {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- else {
- _mainpanel.setArrowCursor();
- }
- if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {
- boolean one_desc = false;
- if ( nhx_or_nexus ) {
- for( final Phylogeny phy : phys ) {
- if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {
- PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
- }
- if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {
- one_desc = true;
- break;
- }
- }
- }
- AptxUtil.addPhylogeniesToTabs( phys,
- file.getName(),
- file.getAbsolutePath(),
- getConfiguration(),
- 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 );
- }
- }
- }
- }
- }
- activateSaveAllIfNeeded();
- System.gc();
- }
-
- public void readSeqsFromFile() {
- // Set an initial directory if none set yet
- final File my_dir = getCurrentDir();
- _seqs_filechooser.setMultiSelectionEnabled( false );
- // Open file-open dialog and set current directory
- if ( my_dir != null ) {
- _seqs_filechooser.setCurrentDirectory( my_dir );
- }
- final int result = _seqs_filechooser.showOpenDialog( _contentpane );
- // All done: get the seqs
- final File file = _seqs_filechooser.getSelectedFile();
- setCurrentDir( _seqs_filechooser.getCurrentDirectory() );
- if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
- setSeqsFile( null );
- setSeqs( null );
- List<Sequence> seqs = null;
- try {
- if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {
- seqs = FastaParser.parse( new FileInputStream( file ) );
- for( final Sequence seq : seqs ) {
- System.out.println( SequenceWriter.toFasta( seq, 60 ) );
- }
- }
- else {
- //TODO error
- }
- }
- catch ( final MsaFormatException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Multiple sequence file format error",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IOException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Failed to read multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IllegalArgumentException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final Exception e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- e.printStackTrace();
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence file is empty",
- "Illegal multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( seqs.size() < 4 ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence file needs to contain at least 3 sequences",
- "Illegal multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- // if ( msa.getLength() < 2 ) {
- // JOptionPane.showMessageDialog( this,
- // "Multiple sequence alignment needs to contain at least 2 residues",
- // "Illegal multiple sequence file",
- // JOptionPane.ERROR_MESSAGE );
- // return;
- // }
- System.gc();
- setSeqsFile( _seqs_filechooser.getSelectedFile() );
- setSeqs( seqs );
- }
- }
-
- public void readMsaFromFile() {
- // Set an initial directory if none set yet
- final File my_dir = getCurrentDir();
- _msa_filechooser.setMultiSelectionEnabled( false );
- // Open file-open dialog and set current directory
- if ( my_dir != null ) {
- _msa_filechooser.setCurrentDirectory( my_dir );
- }
- final int result = _msa_filechooser.showOpenDialog( _contentpane );
- // All done: get the msa
- final File file = _msa_filechooser.getSelectedFile();
- setCurrentDir( _msa_filechooser.getCurrentDirectory() );
- if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {
- setMsaFile( null );
- setMsa( null );
- Msa msa = null;
- try {
- final InputStream is = new FileInputStream( file );
- if ( FastaParser.isLikelyFasta( file ) ) {
- msa = FastaParser.parseMsa( is );
- }
- else {
- msa = GeneralMsaParser.parse( is );
- }
- }
- catch ( final MsaFormatException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Multiple sequence alignment format error",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IOException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Failed to read multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IllegalArgumentException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final Exception e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
- catch ( final Exception ex ) {
- // Do nothing.
- }
- e.printStackTrace();
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment is empty",
- "Illegal Multiple Sequence Alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( msa.getNumberOfSequences() < 4 ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment needs to contain at least 3 sequences",
- "Illegal multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- if ( msa.getLength() < 2 ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment needs to contain at least 2 residues",
- "Illegal multiple sequence alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- System.gc();
- setMsaFile( _msa_filechooser.getSelectedFile() );
- setMsa( msa );
- }
- }
-
- @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 ) ) {
- try {
- url = new URL( url_string );
- PhylogenyParser parser = null;
- if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {
- parser = new TolParser();
- }
- else {
- parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()
- .isValidatePhyloXmlAgainstSchema() );
- }
- if ( parser instanceof NexusPhylogeniesParser ) {
- nhx_or_nexus = true;
- }
- else if ( parser instanceof NHXParser ) {
- nhx_or_nexus = true;
- }
- if ( _mainpanel.getCurrentTreePanel() != null ) {
- _mainpanel.getCurrentTreePanel().setWaitCursor();
- }
- else {
- _mainpanel.setWaitCursor();
- }
- 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();
- }
-
- private void readSpeciesTreeFromFile() {
- Phylogeny t = null;
- boolean exception = false;
- final File my_dir = getCurrentDir();
- _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );
- if ( my_dir != null ) {
- _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );
- }
- 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 ) {
- try {
- final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
- t = trees[ 0 ];
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
- try {
- final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );
- t = trees[ 0 ];
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- // "*.*":
- else {
- try {
- final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new PhyloXmlParser(), file );
- t = trees[ 0 ];
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
- }
- if ( !exception && ( t != null ) && !t.isRooted() ) {
- exception = true;
- t = null;
- JOptionPane.showMessageDialog( this,
- "Species tree is not rooted",
- "Species tree not loaded",
- JOptionPane.ERROR_MESSAGE );
- }
- if ( !exception && ( t != null ) ) {
- final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();
- for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {
- final PhylogenyNode node = it.next();
- 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 );
- 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 );
- break;
- }
- else {
- tax_set.add( node.getNodeData().getTaxonomy() );
- }
- }
- }
- }
- if ( !exception && ( t != null ) ) {
- _species_tree = t;
- JOptionPane.showMessageDialog( this,
- "Species tree successfully loaded",
- "Species tree loaded",
- JOptionPane.INFORMATION_MESSAGE );
- }
- _contentpane.repaint();
- System.gc();
- }
- }
-
- private void setCurrentDir( final File current_dir ) {
- _current_dir = current_dir;
- }
-
- private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {
- _min_not_collapse = min_not_collapse;
- }
-
- private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
- nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
- }
-
- private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
- nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
- PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO;
- if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) {
- te = PhylogenyMethods.TAXONOMY_EXTRACTION.YES;
- }
- nhx.setTaxonomyExtraction( te );
- }
-
- 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<Phylogeny> trees = new ArrayList<Phylogeny>();
- for( int i = 0; i < count; ++i ) {
- trees.add( getMainPanel().getPhylogeny( i ) );
- 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 );
- }
- }
- }
-
- 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 writeAsNHX( final Phylogeny t, boolean exception, final File file ) {
- try {
- final PhylogenyWriter writer = new PhylogenyWriter();
- writer.toNewHampshireX( t, file );
- }
- 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 writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
- _mainpanel.getCurrentTreePanel().setParametersForPainting( _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 writeToFile( final Phylogeny t ) {
- if ( t == null ) {
- return;
- }
- String initial_filename = null;
- if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
- 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;
- }
- 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 );
- }
- }
- }
- if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {
- exception = writeAsNewHampshire( t, exception, file );
- }
- else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) {
- exception = writeAsNHX( 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 );
- }
- else if ( file_name.endsWith( ".nhx" ) ) {
- exception = writeAsNHX( t, exception, file );
- }
- else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
- exception = writeAsNexus( t, exception, file );
- }
- // XML is default:
- else {
- exception = writeAsPhyloXml( t, exception, file );
- }
- }
- if ( !exception ) {
- getMainPanel().setTitleOfSelectedTab( file.getName() );
- getMainPanel().getCurrentTreePanel().setTreeFile( file );
- getMainPanel().getCurrentTreePanel().setEdited( false );
- }
- }
- }
-
- 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;
- }
- else {
- try {
- file.delete();
- }
- catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this,
- "Failed to delete: " + file,
- "Error",
- JOptionPane.WARNING_MESSAGE );
- }
- }
- }
- writePhylogenyToGraphicsFile( file.toString(), type );
- }
- }
-
- 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() );
- }
- }
-
- static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
- return new MainFrameApplication( phys, config, title );
- }
-
- public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {
- return new MainFrameApplication( phys, config );
- }
-
- static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
- return new MainFrameApplication( phys, config_file_name, title );
- }
-
- public static MainFrame createInstance( final Phylogeny[] phys,
- final Configuration config,
- final String title,
- final File current_dir ) {
- return new MainFrameApplication( phys, config, title, current_dir );
- }
-
- 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 );
- }
- }
-
- private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
- _phylogenetic_inference_options = phylogenetic_inference_options;
- }
-
- private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
- if ( _phylogenetic_inference_options == null ) {
- _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
- }
- return _phylogenetic_inference_options;
- }
-
- public Msa getMsa() {
- return _msa;
- }
-
- void setMsa( final Msa msa ) {
- _msa = msa;
- }
-
- void setMsaFile( final File msa_file ) {
- _msa_file = msa_file;
- }
-
- public File getMsaFile() {
- return _msa_file;
- }
-
- public List<Sequence> getSeqs() {
- return _seqs;
- }
-
- void setSeqs( final List<Sequence> seqs ) {
- _seqs = seqs;
- }
-
- void setSeqsFile( final File seqs_file ) {
- _seqs_file = seqs_file;
- }
-
- public File getSeqsFile() {
- return _seqs_file;
- }
-} // MainFrameApplication.
-
-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)";
- }
-}
-
-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 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
+// $Id:\r
+// FORESTER -- software libraries and applications\r
+// for evolutionary biology research and applications.\r
+//\r
+// Copyright (C) 2008-2009 Christian M. Zmasek\r
+// Copyright (C) 2008-2009 Burnham Institute for Medical Research\r
+// Copyright (C) 2003-2007 Ethalinda K.S. Cannon\r
+// All rights reserved\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// Lesser General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this library; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+//\r
+// Contact: phylosoft @ gmail . com\r
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester\r
+\r
+package org.forester.archaeopteryx;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Font;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ComponentAdapter;\r
+import java.awt.event.ComponentEvent;\r
+import java.awt.event.WindowAdapter;\r
+import java.awt.event.WindowEvent;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import javax.swing.ButtonGroup;\r
+import javax.swing.JCheckBoxMenuItem;\r
+import javax.swing.JFileChooser;\r
+import javax.swing.JMenu;\r
+import javax.swing.JMenuBar;\r
+import javax.swing.JMenuItem;\r
+import javax.swing.JOptionPane;\r
+import javax.swing.JRadioButtonMenuItem;\r
+import javax.swing.UIManager;\r
+import javax.swing.UnsupportedLookAndFeelException;\r
+import javax.swing.WindowConstants;\r
+import javax.swing.event.ChangeEvent;\r
+import javax.swing.event.ChangeListener;\r
+import javax.swing.filechooser.FileFilter;\r
+import javax.swing.plaf.synth.SynthLookAndFeel;\r
+\r
+import org.forester.analysis.TaxonomyDataManager;\r
+import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;\r
+import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;\r
+import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;\r
+import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;\r
+import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;\r
+import org.forester.archaeopteryx.tools.InferenceManager;\r
+import org.forester.archaeopteryx.tools.PhyloInferenceDialog;\r
+import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;\r
+import org.forester.archaeopteryx.tools.PhylogeneticInferrer;\r
+import org.forester.archaeopteryx.tools.SequenceDataRetriver;\r
+import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;\r
+import org.forester.archaeopteryx.webservices.WebservicesManager;\r
+import org.forester.io.parsers.FastaParser;\r
+import org.forester.io.parsers.GeneralMsaParser;\r
+import org.forester.io.parsers.PhylogenyParser;\r
+import org.forester.io.parsers.nexus.NexusPhylogeniesParser;\r
+import org.forester.io.parsers.nhx.NHXParser;\r
+import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;\r
+import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;\r
+import org.forester.io.parsers.phyloxml.PhyloXmlParser;\r
+import org.forester.io.parsers.phyloxml.PhyloXmlUtil;\r
+import org.forester.io.parsers.tol.TolParser;\r
+import org.forester.io.parsers.util.ParserUtils;\r
+import org.forester.io.writers.PhylogenyWriter;\r
+import org.forester.io.writers.SequenceWriter;\r
+import org.forester.msa.Msa;\r
+import org.forester.msa.MsaFormatException;\r
+import org.forester.phylogeny.Phylogeny;\r
+import org.forester.phylogeny.PhylogenyMethods;\r
+import org.forester.phylogeny.PhylogenyNode;\r
+import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;\r
+import org.forester.phylogeny.data.Confidence;\r
+import org.forester.phylogeny.data.PhylogenyDataUtil;\r
+import org.forester.phylogeny.data.Sequence;\r
+import org.forester.phylogeny.data.Taxonomy;\r
+import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;\r
+import org.forester.phylogeny.factories.PhylogenyFactory;\r
+import org.forester.phylogeny.iterators.PhylogenyNodeIterator;\r
+import org.forester.sequence.MolecularSequence;\r
+import org.forester.util.BasicDescriptiveStatistics;\r
+import org.forester.util.BasicTable;\r
+import org.forester.util.BasicTableParser;\r
+import org.forester.util.DescriptiveStatistics;\r
+import org.forester.util.ForesterUtil;\r
+import org.forester.util.WindowsUtils;\r
+\r
+public final class MainFrameApplication extends MainFrame {\r
+\r
+ static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";\r
+ static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";\r
+ private final static int FRAME_X_SIZE = 800;\r
+ private final static int FRAME_Y_SIZE = 800;\r
+ // Filters for the file-open dialog (classes defined in this file)\r
+ private final static NHFilter nhfilter = new NHFilter();\r
+ private final static NHXFilter nhxfilter = new NHXFilter();\r
+ private final static XMLFilter xmlfilter = new XMLFilter();\r
+ private final static TolFilter tolfilter = new TolFilter();\r
+ private final static NexusFilter nexusfilter = new NexusFilter();\r
+ private final static PdfFilter pdffilter = new PdfFilter();\r
+ private final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();\r
+ private final static MsaFileFilter msafilter = new MsaFileFilter();\r
+ private final static SequencesFileFilter seqsfilter = new SequencesFileFilter();\r
+ private final static DefaultFilter defaultfilter = new DefaultFilter();\r
+ private static final long serialVersionUID = -799735726778865234L;\r
+ private static final boolean PREPROCESS_TREES = false;\r
+ private final JFileChooser _values_filechooser;\r
+ private final JFileChooser _sequences_filechooser;\r
+ private final JFileChooser _open_filechooser;\r
+ private final JFileChooser _msa_filechooser;\r
+ private final JFileChooser _seqs_pi_filechooser;\r
+ private final JFileChooser _open_filechooser_for_species_tree;\r
+ private final JFileChooser _save_filechooser;\r
+ private final JFileChooser _writetopdf_filechooser;\r
+ private final JFileChooser _writetographics_filechooser;\r
+ // Application-only print menu items\r
+ private JMenuItem _print_item;\r
+ private JMenuItem _write_to_pdf_item;\r
+ private JMenuItem _write_to_jpg_item;\r
+ private JMenuItem _write_to_gif_item;\r
+ private JMenuItem _write_to_tif_item;\r
+ private JMenuItem _write_to_png_item;\r
+ private JMenuItem _write_to_bmp_item;\r
+ private JMenuItem _collapse_below_threshold;\r
+ private JMenuItem _collapse_below_branch_length;\r
+ private File _current_dir;\r
+ private ButtonGroup _radio_group_1;\r
+ private ButtonGroup _radio_group_2;\r
+ // Others:\r
+ double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT;\r
+ double _min_not_collapse_bl = 0.001;\r
+ // Phylogeny Inference menu\r
+ private JMenu _inference_menu;\r
+ private JMenuItem _inference_from_msa_item;\r
+ private JMenuItem _inference_from_seqs_item;\r
+ // Phylogeny Inference\r
+ private PhylogeneticInferenceOptions _phylogenetic_inference_options = null;\r
+ private Msa _msa = null;\r
+ private File _msa_file = null;\r
+ private List<MolecularSequence> _seqs = null;\r
+ private File _seqs_file = null;\r
+ JMenuItem _read_values_jmi;\r
+ JMenuItem _read_seqs_jmi;\r
+\r
+ private MainFrameApplication( final Phylogeny[] phys, final Configuration config ) {\r
+ _configuration = config;\r
+ if ( _configuration == null ) {\r
+ throw new IllegalArgumentException( "configuration is null" );\r
+ }\r
+ setVisible( false );\r
+ setOptions( Options.createInstance( _configuration ) );\r
+ _mainpanel = new MainPanel( _configuration, this );\r
+ _open_filechooser = null;\r
+ _open_filechooser_for_species_tree = null;\r
+ _save_filechooser = null;\r
+ _writetopdf_filechooser = null;\r
+ _writetographics_filechooser = null;\r
+ _msa_filechooser = null;\r
+ _seqs_pi_filechooser = null;\r
+ _values_filechooser = null;\r
+ _sequences_filechooser = null;\r
+ _jmenubar = new JMenuBar();\r
+ buildFileMenu();\r
+ buildTypeMenu();\r
+ _contentpane = getContentPane();\r
+ _contentpane.setLayout( new BorderLayout() );\r
+ _contentpane.add( _mainpanel, BorderLayout.CENTER );\r
+ // App is this big\r
+ setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );\r
+ // The window listener\r
+ setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );\r
+ addWindowListener( new WindowAdapter() {\r
+\r
+ @Override\r
+ public void windowClosing( final WindowEvent e ) {\r
+ exit();\r
+ }\r
+ } );\r
+ // setVisible( true );\r
+ if ( ( phys != null ) && ( phys.length > 0 ) ) {\r
+ AptxUtil.addPhylogeniesToTabs( phys, "", null, _configuration, _mainpanel );\r
+ validate();\r
+ getMainPanel().getControlPanel().showWholeAll();\r
+ getMainPanel().getControlPanel().showWhole();\r
+ }\r
+ //activateSaveAllIfNeeded();\r
+ // ...and its children\r
+ _contentpane.repaint();\r
+ }\r
+\r
+ private MainFrameApplication( final Phylogeny[] phys, final Configuration config, final String title ) {\r
+ this( phys, config, title, null );\r
+ }\r
+\r
+ private MainFrameApplication( final Phylogeny[] phys,\r
+ final Configuration config,\r
+ final String title,\r
+ final File current_dir ) {\r
+ super();\r
+ _configuration = config;\r
+ if ( _configuration == null ) {\r
+ throw new IllegalArgumentException( "configuration is null" );\r
+ }\r
+ try {\r
+ boolean synth_exception = false;\r
+ if ( Constants.__SYNTH_LF ) {\r
+ try {\r
+ final SynthLookAndFeel synth = new SynthLookAndFeel();\r
+ synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),\r
+ MainFrameApplication.class );\r
+ UIManager.setLookAndFeel( synth );\r
+ }\r
+ catch ( final Exception ex ) {\r
+ synth_exception = true;\r
+ ForesterUtil.printWarningMessage( Constants.PRG_NAME,\r
+ "could not create synth look and feel: "\r
+ + ex.getLocalizedMessage() );\r
+ }\r
+ }\r
+ if ( !Constants.__SYNTH_LF || synth_exception ) {\r
+ if ( _configuration.isUseNativeUI() ) {\r
+ UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );\r
+ }\r
+ else {\r
+ UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );\r
+ }\r
+ }\r
+ //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );\r
+ }\r
+ catch ( final UnsupportedLookAndFeelException e ) {\r
+ AptxUtil.dieWithSystemError( "unsupported look and feel: " + e.toString() );\r
+ }\r
+ catch ( final ClassNotFoundException e ) {\r
+ AptxUtil.dieWithSystemError( "class not found exception: " + e.toString() );\r
+ }\r
+ catch ( final InstantiationException e ) {\r
+ AptxUtil.dieWithSystemError( "instantiation exception: " + e.toString() );\r
+ }\r
+ catch ( final IllegalAccessException e ) {\r
+ AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() );\r
+ }\r
+ if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) {\r
+ setCurrentDir( current_dir );\r
+ }\r
+ // hide until everything is ready\r
+ setVisible( false );\r
+ setOptions( Options.createInstance( _configuration ) );\r
+ setInferenceManager( InferenceManager.createInstance( _configuration ) );\r
+ setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );\r
+ // _textframe = null; #~~~~\r
+ // set title\r
+ setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );\r
+ _mainpanel = new MainPanel( _configuration, this );\r
+ // The file dialogs\r
+ _open_filechooser = new JFileChooser();\r
+ _open_filechooser.setCurrentDirectory( new File( "." ) );\r
+ _open_filechooser.setMultiSelectionEnabled( false );\r
+ _open_filechooser.addChoosableFileFilter( MainFrameApplication.xmlfilter );\r
+ _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhxfilter );\r
+ _open_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );\r
+ _open_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );\r
+ _open_filechooser.addChoosableFileFilter( MainFrameApplication.tolfilter );\r
+ _open_filechooser.addChoosableFileFilter( _open_filechooser.getAcceptAllFileFilter() );\r
+ _open_filechooser.setFileFilter( MainFrameApplication.defaultfilter );\r
+ _open_filechooser_for_species_tree = new JFileChooser();\r
+ _open_filechooser_for_species_tree.setCurrentDirectory( new File( "." ) );\r
+ _open_filechooser_for_species_tree.setMultiSelectionEnabled( false );\r
+ _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.xmlfilter );\r
+ _open_filechooser_for_species_tree.addChoosableFileFilter( MainFrameApplication.tolfilter );\r
+ _open_filechooser_for_species_tree.setFileFilter( MainFrameApplication.xmlfilter );\r
+ _save_filechooser = new JFileChooser();\r
+ _save_filechooser.setCurrentDirectory( new File( "." ) );\r
+ _save_filechooser.setMultiSelectionEnabled( false );\r
+ _save_filechooser.setFileFilter( MainFrameApplication.xmlfilter );\r
+ _save_filechooser.addChoosableFileFilter( MainFrameApplication.nhfilter );\r
+ _save_filechooser.addChoosableFileFilter( MainFrameApplication.nexusfilter );\r
+ _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );\r
+ _writetopdf_filechooser = new JFileChooser();\r
+ _writetopdf_filechooser.addChoosableFileFilter( MainFrameApplication.pdffilter );\r
+ _writetographics_filechooser = new JFileChooser();\r
+ _writetographics_filechooser.addChoosableFileFilter( MainFrameApplication.graphicsfilefilter );\r
+ // Msa:\r
+ _msa_filechooser = new JFileChooser();\r
+ _msa_filechooser.setName( "Read Multiple Sequence Alignment File" );\r
+ _msa_filechooser.setCurrentDirectory( new File( "." ) );\r
+ _msa_filechooser.setMultiSelectionEnabled( false );\r
+ _msa_filechooser.addChoosableFileFilter( _msa_filechooser.getAcceptAllFileFilter() );\r
+ _msa_filechooser.addChoosableFileFilter( MainFrameApplication.msafilter );\r
+ // Seqs:\r
+ _seqs_pi_filechooser = new JFileChooser();\r
+ _seqs_pi_filechooser.setName( "Read Sequences File" );\r
+ _seqs_pi_filechooser.setCurrentDirectory( new File( "." ) );\r
+ _seqs_pi_filechooser.setMultiSelectionEnabled( false );\r
+ _seqs_pi_filechooser.addChoosableFileFilter( _seqs_pi_filechooser.getAcceptAllFileFilter() );\r
+ _seqs_pi_filechooser.addChoosableFileFilter( MainFrameApplication.seqsfilter );\r
+ // Expression\r
+ _values_filechooser = new JFileChooser();\r
+ _values_filechooser.setCurrentDirectory( new File( "." ) );\r
+ _values_filechooser.setMultiSelectionEnabled( false );\r
+ // Sequences\r
+ _sequences_filechooser = new JFileChooser();\r
+ _sequences_filechooser.setCurrentDirectory( new File( "." ) );\r
+ _sequences_filechooser.setMultiSelectionEnabled( false );\r
+ // build the menu bar\r
+ _jmenubar = new JMenuBar();\r
+ if ( !_configuration.isUseNativeUI() ) {\r
+ _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );\r
+ }\r
+ buildFileMenu();\r
+ if ( Constants.__ALLOW_PHYLOGENETIC_INFERENCE ) {\r
+ buildPhylogeneticInferenceMenu();\r
+ }\r
+ buildAnalysisMenu();\r
+ buildToolsMenu();\r
+ buildViewMenu();\r
+ buildFontSizeMenu();\r
+ buildOptionsMenu();\r
+ buildTypeMenu();\r
+ buildHelpMenu();\r
+ setJMenuBar( _jmenubar );\r
+ _jmenubar.add( _help_jmenu );\r
+ _contentpane = getContentPane();\r
+ _contentpane.setLayout( new BorderLayout() );\r
+ _contentpane.add( _mainpanel, BorderLayout.CENTER );\r
+ // App is this big\r
+ setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE );\r
+ // addWindowFocusListener( new WindowAdapter() {\r
+ //\r
+ // @Override\r
+ // public void windowGainedFocus( WindowEvent e ) {\r
+ // requestFocusInWindow();\r
+ // }\r
+ // } );\r
+ // The window listener\r
+ setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );\r
+ addWindowListener( new WindowAdapter() {\r
+\r
+ @Override\r
+ public void windowClosing( final WindowEvent e ) {\r
+ if ( isUnsavedDataPresent() ) {\r
+ final int r = JOptionPane.showConfirmDialog( null,\r
+ "Exit despite potentially unsaved changes?",\r
+ "Exit?",\r
+ JOptionPane.YES_NO_OPTION );\r
+ if ( r != JOptionPane.YES_OPTION ) {\r
+ return;\r
+ }\r
+ }\r
+ else {\r
+ final int r = JOptionPane.showConfirmDialog( null,\r
+ "Exit Archaeopteryx?",\r
+ "Exit?",\r
+ JOptionPane.YES_NO_OPTION );\r
+ if ( r != JOptionPane.YES_OPTION ) {\r
+ return;\r
+ }\r
+ }\r
+ exit();\r
+ }\r
+ } );\r
+ // The component listener\r
+ addComponentListener( new ComponentAdapter() {\r
+\r
+ @Override\r
+ public void componentResized( final ComponentEvent e ) {\r
+ if ( _mainpanel.getCurrentTreePanel() != null ) {\r
+ _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel()\r
+ .getWidth(),\r
+ _mainpanel.getCurrentTreePanel()\r
+ .getHeight(),\r
+ getOptions().isAllowFontSizeChange() );\r
+ }\r
+ }\r
+ } );\r
+ requestFocusInWindow();\r
+ // addKeyListener( this );\r
+ setVisible( true );\r
+ if ( ( phys != null ) && ( phys.length > 0 ) ) {\r
+ AptxUtil.addPhylogeniesToTabs( phys, title, null, _configuration, _mainpanel );\r
+ validate();\r
+ getMainPanel().getControlPanel().showWholeAll();\r
+ getMainPanel().getControlPanel().showWhole();\r
+ }\r
+ activateSaveAllIfNeeded();\r
+ // ...and its children\r
+ _contentpane.repaint();\r
+ System.gc();\r
+ }\r
+\r
+ private MainFrameApplication( final Phylogeny[] phys, final String config_file, final String title ) {\r
+ // Reads the config file (false, false => not url, not applet):\r
+ this( phys, new Configuration( config_file, false, false, true ), title );\r
+ }\r
+\r
+ @Override\r
+ public void actionPerformed( final ActionEvent e ) {\r
+ try {\r
+ super.actionPerformed( e );\r
+ final Object o = e.getSource();\r
+ // Handle app-specific actions here:\r
+ if ( o == _open_item ) {\r
+ readPhylogeniesFromFile();\r
+ }\r
+ if ( o == _open_url_item ) {\r
+ readPhylogeniesFromURL();\r
+ }\r
+ else if ( o == _save_item ) {\r
+ writeToFile( _mainpanel.getCurrentPhylogeny() );\r
+ // If subtree currently displayed, save it, instead of complete\r
+ // tree.\r
+ }\r
+ else if ( o == _new_item ) {\r
+ newTree();\r
+ }\r
+ else if ( o == _save_all_item ) {\r
+ writeAllToFile();\r
+ }\r
+ else if ( o == _close_item ) {\r
+ closeCurrentPane();\r
+ }\r
+ else if ( o == _write_to_pdf_item ) {\r
+ writeToPdf( _mainpanel.getCurrentPhylogeny() );\r
+ }\r
+ else if ( o == _write_to_jpg_item ) {\r
+ writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );\r
+ }\r
+ else if ( o == _write_to_png_item ) {\r
+ writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );\r
+ }\r
+ else if ( o == _write_to_gif_item ) {\r
+ writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );\r
+ }\r
+ else if ( o == _write_to_tif_item ) {\r
+ writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );\r
+ }\r
+ else if ( o == _write_to_bmp_item ) {\r
+ writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );\r
+ }\r
+ else if ( o == _print_item ) {\r
+ print();\r
+ }\r
+ else if ( o == _load_species_tree_item ) {\r
+ readSpeciesTreeFromFile();\r
+ }\r
+ else if ( o == _lineage_inference ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Subtree is shown.",\r
+ "Cannot infer ancestral taxonomies",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ executeLineageInference();\r
+ }\r
+ else if ( o == _obtain_detailed_taxonomic_information_jmi ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ obtainDetailedTaxonomicInformation();\r
+ }\r
+ else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ obtainDetailedTaxonomicInformationDelete();\r
+ }\r
+ else if ( o == _obtain_seq_information_jmi ) {\r
+ obtainSequenceInformation();\r
+ }\r
+ else if ( o == _read_values_jmi ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ addExpressionValuesFromFile();\r
+ }\r
+ else if ( o == _read_seqs_jmi ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ addSequencesFromFile();\r
+ }\r
+ else if ( o == _move_node_names_to_tax_sn_jmi ) {\r
+ moveNodeNamesToTaxSn();\r
+ }\r
+ else if ( o == _move_node_names_to_seq_names_jmi ) {\r
+ moveNodeNamesToSeqNames();\r
+ }\r
+ else if ( o == _extract_tax_code_from_node_names_jmi ) {\r
+ extractTaxDataFromNodeNames();\r
+ }\r
+ else if ( o == _graphics_export_visible_only_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _antialias_print_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _print_black_and_white_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _print_using_actual_size_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _graphics_export_using_actual_size_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _print_size_mi ) {\r
+ choosePrintSize();\r
+ }\r
+ else if ( o == _choose_pdf_width_mi ) {\r
+ choosePdfWidth();\r
+ }\r
+ else if ( o == _internal_number_are_confidence_for_nh_parsing_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _replace_underscores_cbmi ) {\r
+ if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) {\r
+ _extract_taxonomy_no_rbmi.setSelected( true );\r
+ }\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _allow_errors_in_distance_to_parent_cbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _collapse_below_threshold ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ collapseBelowThreshold();\r
+ }\r
+ else if ( o == _collapse_below_branch_length ) {\r
+ if ( isSubtreeDisplayed() ) {\r
+ return;\r
+ }\r
+ collapseBelowBranchLengthThreshold();\r
+ }\r
+ else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi )\r
+ || ( o == _extract_taxonomy_agressive_rbmi ) ) {\r
+ if ( _replace_underscores_cbmi != null ) {\r
+ _replace_underscores_cbmi.setSelected( false );\r
+ }\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _extract_taxonomy_no_rbmi ) {\r
+ updateOptions( getOptions() );\r
+ }\r
+ else if ( o == _inference_from_msa_item ) {\r
+ executePhyleneticInference( false );\r
+ }\r
+ else if ( o == _inference_from_seqs_item ) {\r
+ executePhyleneticInference( true );\r
+ }\r
+ _contentpane.repaint();\r
+ }\r
+ catch ( final Exception ex ) {\r
+ AptxUtil.unexpectedException( ex );\r
+ }\r
+ catch ( final Error err ) {\r
+ AptxUtil.unexpectedError( err );\r
+ }\r
+ }\r
+\r
+ public void end() {\r
+ _mainpanel.terminate();\r
+ _contentpane.removeAll();\r
+ setVisible( false );\r
+ dispose();\r
+ }\r
+\r
+ @Override\r
+ public MainPanel getMainPanel() {\r
+ return _mainpanel;\r
+ }\r
+\r
+ public Msa getMsa() {\r
+ return _msa;\r
+ }\r
+\r
+ public File getMsaFile() {\r
+ return _msa_file;\r
+ }\r
+\r
+ public List<MolecularSequence> getSeqs() {\r
+ return _seqs;\r
+ }\r
+\r
+ public File getSeqsFile() {\r
+ return _seqs_file;\r
+ }\r
+\r
+ public void readMsaFromFile() {\r
+ // Set an initial directory if none set yet\r
+ final File my_dir = getCurrentDir();\r
+ _msa_filechooser.setMultiSelectionEnabled( false );\r
+ // Open file-open dialog and set current directory\r
+ if ( my_dir != null ) {\r
+ _msa_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _msa_filechooser.showOpenDialog( _contentpane );\r
+ // All done: get the msa\r
+ final File file = _msa_filechooser.getSelectedFile();\r
+ setCurrentDir( _msa_filechooser.getCurrentDirectory() );\r
+ if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ setMsaFile( null );\r
+ setMsa( null );\r
+ Msa msa = null;\r
+ try {\r
+ final InputStream is = new FileInputStream( file );\r
+ if ( FastaParser.isLikelyFasta( file ) ) {\r
+ msa = FastaParser.parseMsa( is );\r
+ }\r
+ else {\r
+ msa = GeneralMsaParser.parse( is );\r
+ }\r
+ }\r
+ catch ( final MsaFormatException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Multiple sequence alignment format error",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final IOException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Failed to read multiple sequence alignment",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final IllegalArgumentException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Unexpected error during reading of multiple sequence alignment",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final Exception e ) {\r
+ setArrowCursor();\r
+ e.printStackTrace();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Unexpected error during reading of multiple sequence alignment",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Multiple sequence alignment is empty",\r
+ "Illegal Multiple Sequence Alignment",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( msa.getNumberOfSequences() < 4 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Multiple sequence alignment needs to contain at least 3 sequences",\r
+ "Illegal multiple sequence alignment",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( msa.getLength() < 2 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Multiple sequence alignment needs to contain at least 2 residues",\r
+ "Illegal multiple sequence alignment",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ System.gc();\r
+ setMsaFile( _msa_filechooser.getSelectedFile() );\r
+ setMsa( msa );\r
+ }\r
+ }\r
+\r
+ public void readSeqsFromFileforPI() {\r
+ // Set an initial directory if none set yet\r
+ final File my_dir = getCurrentDir();\r
+ _seqs_pi_filechooser.setMultiSelectionEnabled( false );\r
+ // Open file-open dialog and set current directory\r
+ if ( my_dir != null ) {\r
+ _seqs_pi_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _seqs_pi_filechooser.showOpenDialog( _contentpane );\r
+ // All done: get the seqs\r
+ final File file = _seqs_pi_filechooser.getSelectedFile();\r
+ setCurrentDir( _seqs_pi_filechooser.getCurrentDirectory() );\r
+ if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ setSeqsFile( null );\r
+ setSeqs( null );\r
+ List<MolecularSequence> seqs = null;\r
+ try {\r
+ if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {\r
+ seqs = FastaParser.parse( new FileInputStream( file ) );\r
+ for( final MolecularSequence seq : seqs ) {\r
+ System.out.println( SequenceWriter.toFasta( seq, 60 ) );\r
+ }\r
+ }\r
+ else {\r
+ //TODO error\r
+ }\r
+ }\r
+ catch ( final MsaFormatException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Multiple sequence file format error",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final IOException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Failed to read multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final IllegalArgumentException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Unexpected error during reading of multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final Exception e ) {\r
+ setArrowCursor();\r
+ e.printStackTrace();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Unexpected error during reading of multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Multiple sequence file is empty",\r
+ "Illegal multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( seqs.size() < 4 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Multiple sequence file needs to contain at least 3 sequences",\r
+ "Illegal multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ // if ( msa.getLength() < 2 ) {\r
+ // JOptionPane.showMessageDialog( this,\r
+ // "Multiple sequence alignment needs to contain at least 2 residues",\r
+ // "Illegal multiple sequence file",\r
+ // JOptionPane.ERROR_MESSAGE );\r
+ // return;\r
+ // }\r
+ System.gc();\r
+ setSeqsFile( _seqs_pi_filechooser.getSelectedFile() );\r
+ setSeqs( seqs );\r
+ }\r
+ }\r
+\r
+ void buildAnalysisMenu() {\r
+ _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );\r
+ _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );\r
+ _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );\r
+ _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );\r
+ customizeJMenuItem( _gsdi_item );\r
+ customizeJMenuItem( _gsdir_item );\r
+ customizeJMenuItem( _load_species_tree_item );\r
+ _analysis_menu.addSeparator();\r
+ _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );\r
+ customizeJMenuItem( _lineage_inference );\r
+ _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );\r
+ _jmenubar.add( _analysis_menu );\r
+ }\r
+\r
+ @Override\r
+ void buildFileMenu() {\r
+ _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );\r
+ _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );\r
+ _file_jmenu.addSeparator();\r
+ final WebservicesManager webservices_manager = WebservicesManager.getInstance();\r
+ _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager\r
+ .getAvailablePhylogeniesWebserviceClients().size() ];\r
+ for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {\r
+ final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );\r
+ _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );\r
+ _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );\r
+ }\r
+ if ( getConfiguration().isEditable() ) {\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _new_item = new JMenuItem( "New" ) );\r
+ _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );\r
+ }\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );\r
+ _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );\r
+ _save_all_item.setToolTipText( "Write all phylogenies to one file." );\r
+ _save_all_item.setEnabled( false );\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );\r
+ if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {\r
+ _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );\r
+ }\r
+ _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );\r
+ _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );\r
+ if ( AptxUtil.canWriteFormat( "gif" ) ) {\r
+ _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );\r
+ }\r
+ if ( AptxUtil.canWriteFormat( "bmp" ) ) {\r
+ _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );\r
+ }\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _close_item = new JMenuItem( "Close Tab" ) );\r
+ _close_item.setToolTipText( "To close the current pane." );\r
+ _close_item.setEnabled( true );\r
+ _file_jmenu.addSeparator();\r
+ _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );\r
+ customizeJMenuItem( _open_item );\r
+ _open_item\r
+ .setFont( new Font( _open_item.getFont().getFontName(), Font.BOLD, _open_item.getFont().getSize() + 4 ) );\r
+ customizeJMenuItem( _open_url_item );\r
+ for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {\r
+ customizeJMenuItem( _load_phylogeny_from_webservice_menu_items[ i ] );\r
+ }\r
+ customizeJMenuItem( _save_item );\r
+ if ( getConfiguration().isEditable() ) {\r
+ customizeJMenuItem( _new_item );\r
+ }\r
+ customizeJMenuItem( _close_item );\r
+ customizeJMenuItem( _save_all_item );\r
+ customizeJMenuItem( _write_to_pdf_item );\r
+ customizeJMenuItem( _write_to_png_item );\r
+ customizeJMenuItem( _write_to_jpg_item );\r
+ customizeJMenuItem( _write_to_gif_item );\r
+ customizeJMenuItem( _write_to_tif_item );\r
+ customizeJMenuItem( _write_to_bmp_item );\r
+ customizeJMenuItem( _print_item );\r
+ customizeJMenuItem( _exit_item );\r
+ _jmenubar.add( _file_jmenu );\r
+ }\r
+\r
+ void buildOptionsMenu() {\r
+ _options_jmenu = MainFrame.createMenu( OPTIONS_HEADER, getConfiguration() );\r
+ _options_jmenu.addChangeListener( new ChangeListener() {\r
+\r
+ @Override\r
+ public void stateChanged( final ChangeEvent e ) {\r
+ MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );\r
+ MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );\r
+ MainFrame\r
+ .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );\r
+ MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame\r
+ .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );\r
+ setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );\r
+ setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );\r
+ MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );\r
+ MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );\r
+ MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );\r
+ try {\r
+ getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();\r
+ getMainPanel().getControlPanel().setVisibilityOfX();\r
+ }\r
+ catch ( final Exception ignore ) {\r
+ // do nothing, not important.\r
+ }\r
+ }\r
+ } );\r
+ _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );\r
+ _options_jmenu\r
+ .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );\r
+ _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );\r
+ _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) );\r
+ _radio_group_1 = new ButtonGroup();\r
+ _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );\r
+ _radio_group_1.add( _uniform_cladograms_rbmi );\r
+ _radio_group_1.add( _non_lined_up_cladograms_rbmi );\r
+ _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) );\r
+ _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );\r
+ _options_jmenu\r
+ .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) );\r
+ _options_jmenu\r
+ .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) );\r
+ _options_jmenu\r
+ .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) );\r
+ _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );\r
+ if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {\r
+ _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );\r
+ _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );\r
+ }\r
+ _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) );\r
+ _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) );\r
+ _options_jmenu.add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( COLOR_BY_TAXONOMIC_GROUP ) );\r
+ _options_jmenu.add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( COLOR_LABELS_LABEL ) );\r
+ _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );\r
+ _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( ABBREV_SN_LABEL ) );\r
+ _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( LABEL_DIRECTION_LABEL ) );\r
+ _label_direction_cbmi.setToolTipText( LABEL_DIRECTION_TIP );\r
+ _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( SCREEN_ANTIALIAS_LABEL ) );\r
+ _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( BG_GRAD_LABEL ) );\r
+ _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );\r
+ _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );\r
+ _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );\r
+ _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );\r
+ _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );\r
+ _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );\r
+ _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );\r
+ _options_jmenu.addSeparator();\r
+ _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) );\r
+ _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) );\r
+ _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) );\r
+ _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) );\r
+ _options_jmenu.addSeparator();\r
+ _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),\r
+ getConfiguration() ) );\r
+ _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );\r
+ _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );\r
+ _options_jmenu\r
+ .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );\r
+ _options_jmenu\r
+ .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );\r
+ _options_jmenu\r
+ .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );\r
+ _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );\r
+ _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );\r
+ _options_jmenu.addSeparator();\r
+ _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/NHX/Nexus Input:" ), getConfiguration() ) );\r
+ _options_jmenu\r
+ .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) );\r
+ _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) );\r
+ _options_jmenu\r
+ .add( _allow_errors_in_distance_to_parent_cbmi = new JCheckBoxMenuItem( "Ignore Distance Values Format Errors" ) );\r
+ _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) );\r
+ _options_jmenu\r
+ .add( _extract_taxonomy_pfam_strict_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style Node Names" ) );\r
+ _options_jmenu\r
+ .add( _extract_taxonomy_pfam_relaxed_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style like Node Names" ) );\r
+ _options_jmenu\r
+ .add( _extract_taxonomy_agressive_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids/Scientific Names from Node Names" ) );\r
+ _extract_taxonomy_pfam_strict_rbmi\r
+ .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"BCL2_MOUSE/123-304\" or \"BCL2_10090/123-304\"" );\r
+ _extract_taxonomy_pfam_relaxed_rbmi\r
+ .setToolTipText( "To extract taxonomy codes/ids from node names in the form of e.g. \"bax_MOUSE\" or \"bax_10090\"" );\r
+ _extract_taxonomy_agressive_rbmi\r
+ .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\"" );\r
+ _radio_group_2 = new ButtonGroup();\r
+ _radio_group_2.add( _extract_taxonomy_no_rbmi );\r
+ _radio_group_2.add( _extract_taxonomy_pfam_strict_rbmi );\r
+ _radio_group_2.add( _extract_taxonomy_pfam_relaxed_rbmi );\r
+ _radio_group_2.add( _extract_taxonomy_agressive_rbmi );\r
+ _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) );\r
+ _options_jmenu\r
+ .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) );\r
+ _use_brackets_for_conf_in_nh_export_cbmi\r
+ .setToolTipText( "e.g. \"0.1[90]\" for a branch with support 90 and a length of 0.1" );\r
+ _options_jmenu\r
+ .add( _use_internal_names_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL ) );\r
+ customizeJMenuItem( _choose_font_mi );\r
+ customizeJMenuItem( _choose_minimal_confidence_mi );\r
+ customizeJMenuItem( _switch_colors_mi );\r
+ customizeJMenuItem( _print_size_mi );\r
+ customizeJMenuItem( _choose_pdf_width_mi );\r
+ customizeJMenuItem( _overview_placment_mi );\r
+ customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()\r
+ .isShowDefaultNodeShapesExternal() );\r
+ customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()\r
+ .isShowDefaultNodeShapesInternal() );\r
+ customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()\r
+ .isShowDefaultNodeShapesForMarkedNodes() );\r
+ customizeJMenuItem( _cycle_node_shape_mi );\r
+ customizeJMenuItem( _cycle_node_fill_mi );\r
+ customizeJMenuItem( _choose_node_size_mi );\r
+ customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );\r
+ customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );\r
+ customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );\r
+ customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );\r
+ customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );\r
+ customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );\r
+ customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );\r
+ customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );\r
+ customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );\r
+ customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,\r
+ getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );\r
+ customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,\r
+ getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );\r
+ customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,\r
+ getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );\r
+ customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );\r
+ customizeCheckBoxMenuItem( _label_direction_cbmi,\r
+ getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );\r
+ customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );\r
+ customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );\r
+ customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions()\r
+ .isInternalNumberAreConfidenceForNhParsing() );\r
+ customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi,\r
+ getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO );\r
+ customizeRadioButtonMenuItem( _extract_taxonomy_pfam_strict_rbmi,\r
+ getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );\r
+ customizeRadioButtonMenuItem( _extract_taxonomy_pfam_relaxed_rbmi,\r
+ getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );\r
+ customizeRadioButtonMenuItem( _extract_taxonomy_agressive_rbmi,\r
+ getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.AGGRESSIVE );\r
+ customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() );\r
+ customizeCheckBoxMenuItem( _allow_errors_in_distance_to_parent_cbmi, getOptions()\r
+ .isReplaceUnderscoresInNhParsing() );\r
+ customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );\r
+ customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );\r
+ customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );\r
+ customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );\r
+ customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()\r
+ .isGraphicsExportUsingActualSize() );\r
+ customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );\r
+ customizeCheckBoxMenuItem( _use_brackets_for_conf_in_nh_export_cbmi, getOptions()\r
+ .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );\r
+ customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions()\r
+ .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );\r
+ customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );\r
+ customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );\r
+ _jmenubar.add( _options_jmenu );\r
+ }\r
+\r
+ void buildPhylogeneticInferenceMenu() {\r
+ final InferenceManager im = getInferenceManager();\r
+ _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );\r
+ _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );\r
+ customizeJMenuItem( _inference_from_msa_item );\r
+ _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );\r
+ if ( im.canDoMsa() ) {\r
+ _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );\r
+ customizeJMenuItem( _inference_from_seqs_item );\r
+ _inference_from_seqs_item\r
+ .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );\r
+ }\r
+ else {\r
+ _inference_menu\r
+ .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );\r
+ customizeJMenuItem( _inference_from_seqs_item );\r
+ _inference_from_seqs_item.setEnabled( false );\r
+ }\r
+ _jmenubar.add( _inference_menu );\r
+ }\r
+\r
+ void buildToolsMenu() {\r
+ _tools_menu = createMenu( "Tools", getConfiguration() );\r
+ _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );\r
+ customizeJMenuItem( _confcolor_item );\r
+ _tools_menu.add( _color_rank_jmi = new JMenuItem( "Colorize Subtrees via Taxonomic Rank" ) );\r
+ customizeJMenuItem( _color_rank_jmi );\r
+ _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" );\r
+ _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );\r
+ customizeJMenuItem( _taxcolor_item );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );\r
+ _remove_visual_styles_item\r
+ .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny" );\r
+ customizeJMenuItem( _remove_visual_styles_item );\r
+ _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );\r
+ _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny" );\r
+ customizeJMenuItem( _remove_branch_color_item );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) );\r
+ customizeJMenuItem( _annotate_item );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );\r
+ customizeJMenuItem( _midpoint_root_item );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _delete_selected_nodes_item = new JMenuItem( "Delete Selected Nodes" ) );\r
+ _delete_selected_nodes_item.setToolTipText( "To delete all selected external nodes" );\r
+ customizeJMenuItem( _delete_selected_nodes_item );\r
+ _tools_menu.add( _delete_not_selected_nodes_item = new JMenuItem( "Retain Selected Nodes" ) );\r
+ _delete_not_selected_nodes_item.setToolTipText( "To delete all not selected external nodes" );\r
+ customizeJMenuItem( _delete_not_selected_nodes_item );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );\r
+ customizeJMenuItem( _collapse_species_specific_subtrees );\r
+ _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse species-specific subtrees" );\r
+ _tools_menu\r
+ .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );\r
+ customizeJMenuItem( _collapse_below_threshold );\r
+ _collapse_below_threshold\r
+ .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)" );\r
+ //\r
+ _tools_menu\r
+ .add( _collapse_below_branch_length = new JMenuItem( "Collapse Branches with Branch Lengths Below Threshold into Multifurcations" ) );\r
+ customizeJMenuItem( _collapse_below_branch_length );\r
+ _collapse_below_branch_length\r
+ .setToolTipText( "To (permanently) collapse branches with branches with branch lengths below a threshold into multifurcations" );\r
+ //\r
+ _tools_menu.addSeparator();\r
+ _tools_menu\r
+ .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );\r
+ customizeJMenuItem( _extract_tax_code_from_node_names_jmi );\r
+ _extract_tax_code_from_node_names_jmi\r
+ .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'" );\r
+ _tools_menu\r
+ .add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );\r
+ customizeJMenuItem( _move_node_names_to_tax_sn_jmi );\r
+ _move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );\r
+ _tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );\r
+ customizeJMenuItem( _move_node_names_to_seq_names_jmi );\r
+ _move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) );\r
+ customizeJMenuItem( _obtain_seq_information_jmi );\r
+ _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" );\r
+ _tools_menu\r
+ .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );\r
+ customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );\r
+ _obtain_detailed_taxonomic_information_jmi\r
+ .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );\r
+ _tools_menu\r
+ .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );\r
+ customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );\r
+ _obtain_detailed_taxonomic_information_deleting_jmi\r
+ .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );\r
+ _tools_menu.addSeparator();\r
+ _tools_menu.add( _read_values_jmi = new JMenuItem( "Attach Vector/Expression Values" ) );\r
+ customizeJMenuItem( _read_values_jmi );\r
+ _read_values_jmi.setToolTipText( "To attach vector (e.g. gene expression) values to tree nodes (beta)" );\r
+ _jmenubar.add( _tools_menu );\r
+ _tools_menu.add( _read_seqs_jmi = new JMenuItem( "Attach Molecular Sequences" ) );\r
+ customizeJMenuItem( _read_seqs_jmi );\r
+ _read_seqs_jmi\r
+ .setToolTipText( "To attach molecular sequences to tree nodes (from Fasta-formatted file) (beta)" );\r
+ _jmenubar.add( _tools_menu );\r
+ }\r
+\r
+ @Override\r
+ void close() {\r
+ if ( isUnsavedDataPresent() ) {\r
+ final int r = JOptionPane.showConfirmDialog( this,\r
+ "Exit despite potentially unsaved changes?",\r
+ "Exit?",\r
+ JOptionPane.YES_NO_OPTION );\r
+ if ( r != JOptionPane.YES_OPTION ) {\r
+ return;\r
+ }\r
+ }\r
+ exit();\r
+ }\r
+\r
+ void executeLineageInference() {\r
+ if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {\r
+ return;\r
+ }\r
+ if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Phylogeny is not rooted.",\r
+ "Cannot infer ancestral taxonomies",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,\r
+ _mainpanel.getCurrentTreePanel(),\r
+ _mainpanel.getCurrentPhylogeny()\r
+ .copy() );\r
+ new Thread( inferrer ).start();\r
+ }\r
+\r
+ void exit() {\r
+ removeAllTextFrames();\r
+ _mainpanel.terminate();\r
+ _contentpane.removeAll();\r
+ setVisible( false );\r
+ dispose();\r
+ System.exit( 0 );\r
+ }\r
+\r
+ void readPhylogeniesFromURL() {\r
+ URL url = null;\r
+ Phylogeny[] phys = null;\r
+ final String message = "Please enter a complete URL, for example \"http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"";\r
+ final String url_string = JOptionPane.showInputDialog( this,\r
+ message,\r
+ "Use URL/webservice to obtain a phylogeny",\r
+ JOptionPane.QUESTION_MESSAGE );\r
+ boolean nhx_or_nexus = false;\r
+ if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {\r
+ try {\r
+ url = new URL( url_string );\r
+ PhylogenyParser parser = null;\r
+ if ( url.getHost().toLowerCase().indexOf( "tolweb" ) >= 0 ) {\r
+ parser = new TolParser();\r
+ }\r
+ else {\r
+ parser = ParserUtils.createParserDependingOnUrlContents( url, getConfiguration()\r
+ .isValidatePhyloXmlAgainstSchema() );\r
+ }\r
+ if ( parser instanceof NexusPhylogeniesParser ) {\r
+ nhx_or_nexus = true;\r
+ }\r
+ else if ( parser instanceof NHXParser ) {\r
+ nhx_or_nexus = true;\r
+ }\r
+ if ( _mainpanel.getCurrentTreePanel() != null ) {\r
+ _mainpanel.getCurrentTreePanel().setWaitCursor();\r
+ }\r
+ else {\r
+ _mainpanel.setWaitCursor();\r
+ }\r
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();\r
+ phys = factory.create( url.openStream(), parser );\r
+ }\r
+ catch ( final MalformedURLException e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),\r
+ "Malformed URL",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ catch ( final IOException e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Could not read from " + url + "\n"\r
+ + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),\r
+ "Failed to read URL",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ catch ( final Exception e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),\r
+ "Unexpected Exception",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ finally {\r
+ if ( _mainpanel.getCurrentTreePanel() != null ) {\r
+ _mainpanel.getCurrentTreePanel().setArrowCursor();\r
+ }\r
+ else {\r
+ _mainpanel.setArrowCursor();\r
+ }\r
+ }\r
+ if ( ( phys != null ) && ( phys.length > 0 ) ) {\r
+ if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) {\r
+ for( final Phylogeny phy : phys ) {\r
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );\r
+ }\r
+ }\r
+ AptxUtil.addPhylogeniesToTabs( phys,\r
+ new File( url.getFile() ).getName(),\r
+ new File( url.getFile() ).toString(),\r
+ getConfiguration(),\r
+ getMainPanel() );\r
+ _mainpanel.getControlPanel().showWhole();\r
+ }\r
+ }\r
+ activateSaveAllIfNeeded();\r
+ System.gc();\r
+ }\r
+\r
+ void setMsa( final Msa msa ) {\r
+ _msa = msa;\r
+ }\r
+\r
+ void setMsaFile( final File msa_file ) {\r
+ _msa_file = msa_file;\r
+ }\r
+\r
+ void setSeqs( final List<MolecularSequence> seqs ) {\r
+ _seqs = seqs;\r
+ }\r
+\r
+ void setSeqsFile( final File seqs_file ) {\r
+ _seqs_file = seqs_file;\r
+ }\r
+\r
+ void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {\r
+ _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),\r
+ _mainpanel.getCurrentTreePanel().getHeight(),\r
+ true );\r
+ String file_written_to = "";\r
+ boolean error = false;\r
+ try {\r
+ file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,\r
+ _mainpanel.getCurrentTreePanel().getWidth(),\r
+ _mainpanel.getCurrentTreePanel().getHeight(),\r
+ _mainpanel.getCurrentTreePanel(),\r
+ _mainpanel.getControlPanel(),\r
+ type,\r
+ getOptions() );\r
+ }\r
+ catch ( final IOException e ) {\r
+ error = true;\r
+ JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ if ( !error ) {\r
+ if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Wrote image to: " + file_written_to,\r
+ "Graphics Export",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "There was an unknown problem when attempting to write to an image file: \""\r
+ + file_name + "\"",\r
+ "Error",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ }\r
+ _contentpane.repaint();\r
+ }\r
+\r
+ private void addExpressionValuesFromFile() {\r
+ if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Need to load evolutionary tree first",\r
+ "Can Not Read Expression Values",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ return;\r
+ }\r
+ final File my_dir = getCurrentDir();\r
+ if ( my_dir != null ) {\r
+ _values_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _values_filechooser.showOpenDialog( _contentpane );\r
+ final File file = _values_filechooser.getSelectedFile();\r
+ if ( ( file != null ) && ( file.length() > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ BasicTable<String> t = null;\r
+ try {\r
+ t = BasicTableParser.parse( file, '\t' );\r
+ if ( t.getNumberOfColumns() < 2 ) {\r
+ t = BasicTableParser.parse( file, ',' );\r
+ }\r
+ if ( t.getNumberOfColumns() < 2 ) {\r
+ t = BasicTableParser.parse( file, ' ' );\r
+ }\r
+ }\r
+ catch ( final IOException e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getMessage(),\r
+ "Could Not Read Expression Value Table",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( t.getNumberOfColumns() < 2 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Table contains " + t.getNumberOfColumns() + " column(s)",\r
+ "Problem with Expression Value Table",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( t.getNumberOfRows() < 1 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Table contains zero rows",\r
+ "Problem with Expression Value Table",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( t.getNumberOfRows() != phy.getNumberOfExternalNodes() ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Table contains " + t.getNumberOfRows() + " rows, but tree contains "\r
+ + phy.getNumberOfExternalNodes() + " external nodes",\r
+ "Warning",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ final DescriptiveStatistics stats = new BasicDescriptiveStatistics();\r
+ int not_found = 0;\r
+ for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {\r
+ final PhylogenyNode node = iter.next();\r
+ final String node_name = node.getName();\r
+ if ( !ForesterUtil.isEmpty( node_name ) ) {\r
+ int row = -1;\r
+ try {\r
+ row = t.findRow( node_name );\r
+ }\r
+ catch ( final IllegalArgumentException e ) {\r
+ JOptionPane\r
+ .showMessageDialog( this,\r
+ e.getMessage(),\r
+ "Error Mapping Node Identifiers to Expression Value Identifiers",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( row < 0 ) {\r
+ if ( node.isExternal() ) {\r
+ not_found++;\r
+ }\r
+ continue;\r
+ }\r
+ final List<Double> l = new ArrayList<Double>();\r
+ for( int col = 1; col < t.getNumberOfColumns(); ++col ) {\r
+ double d = -100;\r
+ try {\r
+ d = Double.parseDouble( t.getValueAsString( col, row ) );\r
+ }\r
+ catch ( final NumberFormatException e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Could not parse \"" + t.getValueAsString( col, row )\r
+ + "\" into a decimal value",\r
+ "Issue with Expression Value Table",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ stats.addValue( d );\r
+ l.add( d );\r
+ }\r
+ if ( !l.isEmpty() ) {\r
+ if ( node.getNodeData().getProperties() != null ) {\r
+ node.getNodeData().getProperties()\r
+ .removePropertiesWithGivenReferencePrefix( PhyloXmlUtil.VECTOR_PROPERTY_REF );\r
+ }\r
+ node.getNodeData().setVector( l );\r
+ }\r
+ }\r
+ }\r
+ if ( not_found > 0 ) {\r
+ JOptionPane.showMessageDialog( this, "Could not fine expression values for " + not_found\r
+ + " external node(s)", "Warning", JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ getCurrentTreePanel().setStatisticsForExpressionValues( stats );\r
+ }\r
+ }\r
+\r
+ private void addSequencesFromFile() {\r
+ if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Need to load evolutionary tree first",\r
+ "Can Not Read Sequences",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ return;\r
+ }\r
+ final File my_dir = getCurrentDir();\r
+ if ( my_dir != null ) {\r
+ _sequences_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _sequences_filechooser.showOpenDialog( _contentpane );\r
+ final File file = _sequences_filechooser.getSelectedFile();\r
+ List<MolecularSequence> seqs = null;\r
+ if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ try {\r
+ if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) {\r
+ seqs = FastaParser.parse( new FileInputStream( file ) );\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Format does not appear to be Fasta",\r
+ "Multiple sequence file format error",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ }\r
+ catch ( final MsaFormatException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Multiple sequence file format error",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final IOException e ) {\r
+ setArrowCursor();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Failed to read multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ catch ( final Exception e ) {\r
+ setArrowCursor();\r
+ e.printStackTrace();\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "Unexpected error during reading of multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ return;\r
+ }\r
+ if ( ( seqs == null ) || ( seqs.size() < 1 ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Multiple sequence file is empty",\r
+ "Empty multiple sequence file",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ setArrowCursor();\r
+ return;\r
+ }\r
+ }\r
+ if ( seqs != null ) {\r
+ for( final MolecularSequence seq : seqs ) {\r
+ System.out.println( seq.getIdentifier() );\r
+ }\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ int total_counter = 0;\r
+ int attached_counter = 0;\r
+ for( final MolecularSequence seq : seqs ) {\r
+ ++total_counter;\r
+ final String seq_name = seq.getIdentifier();\r
+ if ( !ForesterUtil.isEmpty( seq_name ) ) {\r
+ List<PhylogenyNode> nodes = phy.getNodesViaSequenceName( seq_name );\r
+ if ( nodes.isEmpty() ) {\r
+ nodes = phy.getNodesViaSequenceSymbol( seq_name );\r
+ }\r
+ if ( nodes.isEmpty() ) {\r
+ nodes = phy.getNodesViaGeneName( seq_name );\r
+ }\r
+ if ( nodes.isEmpty() ) {\r
+ nodes = phy.getNodes( seq_name );\r
+ }\r
+ if ( nodes.size() > 1 ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Sequence name \"" + seq_name + "\" is not unique",\r
+ "Sequence name not unique",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ setArrowCursor();\r
+ return;\r
+ }\r
+ final String[] a = seq_name.split( "\\s" );\r
+ if ( nodes.isEmpty() && ( a.length > 1 ) ) {\r
+ final String seq_name_split = a[ 0 ];\r
+ nodes = phy.getNodesViaSequenceName( seq_name_split );\r
+ if ( nodes.isEmpty() ) {\r
+ nodes = phy.getNodesViaSequenceSymbol( seq_name_split );\r
+ }\r
+ if ( nodes.isEmpty() ) {\r
+ nodes = phy.getNodes( seq_name_split );\r
+ }\r
+ if ( nodes.size() > 1 ) {\r
+ JOptionPane.showMessageDialog( this, "Split sequence name \"" + seq_name_split\r
+ + "\" is not unique", "Sequence name not unique", JOptionPane.ERROR_MESSAGE );\r
+ setArrowCursor();\r
+ return;\r
+ }\r
+ }\r
+ if ( nodes.size() == 1 ) {\r
+ ++attached_counter;\r
+ final PhylogenyNode n = nodes.get( 0 );\r
+ if ( !n.getNodeData().isHasSequence() ) {\r
+ n.getNodeData().addSequence( new org.forester.phylogeny.data.Sequence() );\r
+ }\r
+ n.getNodeData().getSequence().setMolecularSequence( seq.getMolecularSequenceAsString() );\r
+ if ( ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {\r
+ n.getNodeData().getSequence().setName( seq_name );\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if ( attached_counter > 0 ) {\r
+ int ext_nodes = 0;\r
+ int ext_nodes_with_seq = 0;\r
+ for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) {\r
+ ++ext_nodes;\r
+ final PhylogenyNode n = iter.next();\r
+ if ( n.getNodeData().isHasSequence()\r
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {\r
+ ++ext_nodes_with_seq;\r
+ }\r
+ }\r
+ final String s;\r
+ if ( ext_nodes == ext_nodes_with_seq ) {\r
+ s = "All " + ext_nodes_with_seq + " external nodes now have a molecular sequence attached to them.";\r
+ }\r
+ else {\r
+ s = ext_nodes_with_seq + " out of " + ext_nodes\r
+ + " external nodes now have a molecular sequence attached to them.";\r
+ }\r
+ if ( ( attached_counter == total_counter ) && ( ext_nodes == ext_nodes_with_seq ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Attached all " + total_counter + " sequences to tree nodes.\n" + s,\r
+ "All sequences attached",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this, "Attached " + attached_counter\r
+ + " sequences out of a total of " + total_counter + " sequences.\n" + s, attached_counter\r
+ + " sequences attached", JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this, "No maching tree node for any of the " + total_counter\r
+ + " sequences", "Could not attach any sequences", JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+\r
+ private void choosePdfWidth() {\r
+ final String s = ( String ) JOptionPane.showInputDialog( this,\r
+ "Please enter the default line width for PDF export.\n"\r
+ + "[current value: "\r
+ + getOptions().getPrintLineWidth() + "]\n",\r
+ "Line Width for PDF Export",\r
+ JOptionPane.QUESTION_MESSAGE,\r
+ null,\r
+ null,\r
+ getOptions().getPrintLineWidth() );\r
+ if ( !ForesterUtil.isEmpty( s ) ) {\r
+ boolean success = true;\r
+ float f = 0.0f;\r
+ final String m_str = s.trim();\r
+ if ( !ForesterUtil.isEmpty( m_str ) ) {\r
+ try {\r
+ f = Float.parseFloat( m_str );\r
+ }\r
+ catch ( final Exception ex ) {\r
+ success = false;\r
+ }\r
+ }\r
+ else {\r
+ success = false;\r
+ }\r
+ if ( success && ( f > 0.0 ) ) {\r
+ getOptions().setPrintLineWidth( f );\r
+ }\r
+ }\r
+ }\r
+\r
+ private void choosePrintSize() {\r
+ final String s = ( String ) JOptionPane.showInputDialog( this,\r
+ "Please enter values for width and height,\nseparated by a comma.\n"\r
+ + "[current values: "\r
+ + getOptions().getPrintSizeX() + ", "\r
+ + getOptions().getPrintSizeY() + "]\n"\r
+ + "[A4: " + Constants.A4_SIZE_X + ", "\r
+ + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "\r
+ + Constants.US_LETTER_SIZE_X + ", "\r
+ + Constants.US_LETTER_SIZE_Y + "]",\r
+ "Default Size for Graphics Export",\r
+ JOptionPane.QUESTION_MESSAGE,\r
+ null,\r
+ null,\r
+ getOptions().getPrintSizeX() + ", "\r
+ + getOptions().getPrintSizeY() );\r
+ if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {\r
+ boolean success = true;\r
+ int x = 0;\r
+ int y = 0;\r
+ final String[] str_ary = s.split( "," );\r
+ if ( str_ary.length == 2 ) {\r
+ final String x_str = str_ary[ 0 ].trim();\r
+ final String y_str = str_ary[ 1 ].trim();\r
+ if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {\r
+ try {\r
+ x = Integer.parseInt( x_str );\r
+ y = Integer.parseInt( y_str );\r
+ }\r
+ catch ( final Exception ex ) {\r
+ success = false;\r
+ }\r
+ }\r
+ else {\r
+ success = false;\r
+ }\r
+ }\r
+ else {\r
+ success = false;\r
+ }\r
+ if ( success && ( x > 1 ) && ( y > 1 ) ) {\r
+ getOptions().setPrintSizeX( x );\r
+ getOptions().setPrintSizeY( y );\r
+ }\r
+ }\r
+ }\r
+\r
+ private void closeCurrentPane() {\r
+ if ( getMainPanel().getCurrentTreePanel() != null ) {\r
+ if ( getMainPanel().getCurrentTreePanel().isEdited() ) {\r
+ final int r = JOptionPane.showConfirmDialog( this,\r
+ "Close tab despite potentially unsaved changes?",\r
+ "Close Tab?",\r
+ JOptionPane.YES_NO_OPTION );\r
+ if ( r != JOptionPane.YES_OPTION ) {\r
+ return;\r
+ }\r
+ }\r
+ getMainPanel().closeCurrentPane();\r
+ activateSaveAllIfNeeded();\r
+ }\r
+ }\r
+\r
+ private void collapseBl( final Phylogeny phy ) {\r
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();\r
+ final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();\r
+ double min_bl = Double.MAX_VALUE;\r
+ boolean bl_present = false;\r
+ while ( it.hasNext() ) {\r
+ final PhylogenyNode n = it.next();\r
+ if ( !n.isExternal() && !n.isRoot() ) {\r
+ final double bl = n.getDistanceToParent();\r
+ if ( bl != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {\r
+ bl_present = true;\r
+ if ( bl < getMinNotCollapseBlValue() ) {\r
+ to_be_removed.add( n );\r
+ }\r
+ if ( bl < min_bl ) {\r
+ min_bl = bl;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if ( bl_present ) {\r
+ for( final PhylogenyNode node : to_be_removed ) {\r
+ PhylogenyMethods.removeNode( node, phy );\r
+ }\r
+ if ( to_be_removed.size() > 0 ) {\r
+ phy.externalNodesHaveChanged();\r
+ phy.clearHashIdToNodeMap();\r
+ phy.recalculateNumberOfExternalDescendants( true );\r
+ getCurrentTreePanel().resetNodeIdToDistToLeafMap();\r
+ getCurrentTreePanel().updateSetOfCollapsedExternalNodes();\r
+ getCurrentTreePanel().calculateLongestExtNodeInfo();\r
+ getCurrentTreePanel().setNodeInPreorderToNull();\r
+ getCurrentTreePanel().recalculateMaxDistanceToRoot();\r
+ getCurrentTreePanel().resetPreferredSize();\r
+ getCurrentTreePanel().setEdited( true );\r
+ getCurrentTreePanel().repaint();\r
+ repaint();\r
+ }\r
+ if ( to_be_removed.size() > 0 ) {\r
+ JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()\r
+ + " branches with\nbranch length values below " + getMinNotCollapseBlValue(), "Collapsed "\r
+ + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "No branch collapsed,\nminimum branch length is " + min_bl,\r
+ "No branch collapsed",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "No branch collapsed because no branch length values present",\r
+ "No branch length values present",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ }\r
+\r
+ private void collapse( final Phylogeny phy ) {\r
+ final PhylogenyNodeIterator it = phy.iteratorPostorder();\r
+ final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();\r
+ double min_support = Double.MAX_VALUE;\r
+ boolean conf_present = false;\r
+ while ( it.hasNext() ) {\r
+ final PhylogenyNode n = it.next();\r
+ if ( !n.isExternal() && !n.isRoot() ) {\r
+ final List<Confidence> c = n.getBranchData().getConfidences();\r
+ if ( ( c != null ) && ( c.size() > 0 ) ) {\r
+ conf_present = true;\r
+ double max = 0;\r
+ for( final Confidence confidence : c ) {\r
+ if ( confidence.getValue() > max ) {\r
+ max = confidence.getValue();\r
+ }\r
+ }\r
+ if ( max < getMinNotCollapseConfidenceValue() ) {\r
+ to_be_removed.add( n );\r
+ }\r
+ if ( max < min_support ) {\r
+ min_support = max;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if ( conf_present ) {\r
+ for( final PhylogenyNode node : to_be_removed ) {\r
+ PhylogenyMethods.removeNode( node, phy );\r
+ }\r
+ if ( to_be_removed.size() > 0 ) {\r
+ phy.externalNodesHaveChanged();\r
+ phy.clearHashIdToNodeMap();\r
+ phy.recalculateNumberOfExternalDescendants( true );\r
+ getCurrentTreePanel().resetNodeIdToDistToLeafMap();\r
+ getCurrentTreePanel().updateSetOfCollapsedExternalNodes();\r
+ getCurrentTreePanel().calculateLongestExtNodeInfo();\r
+ getCurrentTreePanel().setNodeInPreorderToNull();\r
+ getCurrentTreePanel().recalculateMaxDistanceToRoot();\r
+ getCurrentTreePanel().resetPreferredSize();\r
+ getCurrentTreePanel().setEdited( true );\r
+ getCurrentTreePanel().repaint();\r
+ repaint();\r
+ }\r
+ if ( to_be_removed.size() > 0 ) {\r
+ JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()\r
+ + " branches with\nconfidence values below " + getMinNotCollapseConfidenceValue(), "Collapsed "\r
+ + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this, "No branch collapsed,\nminimum confidence value per branch is "\r
+ + min_support, "No branch collapsed", JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "No branch collapsed because no confidence values present",\r
+ "No confidence values present",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ }\r
+\r
+ private void collapseBelowThreshold() {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ final String s = ( String ) JOptionPane.showInputDialog( this,\r
+ "Please enter the minimum confidence value\n",\r
+ "Minimal Confidence Value",\r
+ JOptionPane.QUESTION_MESSAGE,\r
+ null,\r
+ null,\r
+ getMinNotCollapseConfidenceValue() );\r
+ if ( !ForesterUtil.isEmpty( s ) ) {\r
+ boolean success = true;\r
+ double m = 0.0;\r
+ final String m_str = s.trim();\r
+ if ( !ForesterUtil.isEmpty( m_str ) ) {\r
+ try {\r
+ m = Double.parseDouble( m_str );\r
+ }\r
+ catch ( final Exception ex ) {\r
+ success = false;\r
+ }\r
+ }\r
+ else {\r
+ success = false;\r
+ }\r
+ if ( success && ( m >= 0.0 ) ) {\r
+ setMinNotCollapseConfidenceValue( m );\r
+ collapse( phy );\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void collapseBelowBranchLengthThreshold() {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ final String s = ( String ) JOptionPane\r
+ .showInputDialog( this,\r
+ "Please enter the minimum branch length value\n",\r
+ "Minimal Branch Length Value",\r
+ JOptionPane.QUESTION_MESSAGE,\r
+ null,\r
+ null,\r
+ getMinNotCollapseBlValue() );\r
+ if ( !ForesterUtil.isEmpty( s ) ) {\r
+ boolean success = true;\r
+ double m = 0.0;\r
+ final String m_str = s.trim();\r
+ if ( !ForesterUtil.isEmpty( m_str ) ) {\r
+ try {\r
+ m = Double.parseDouble( m_str );\r
+ }\r
+ catch ( final Exception ex ) {\r
+ success = false;\r
+ }\r
+ }\r
+ else {\r
+ success = false;\r
+ }\r
+ if ( success && ( m >= 0.0 ) ) {\r
+ setMinNotCollapseBlValue( m );\r
+ collapseBl( phy );\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private PhyloXmlParser createPhyloXmlParser() {\r
+ PhyloXmlParser xml_parser = null;\r
+ if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {\r
+ try {\r
+ xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();\r
+ }\r
+ catch ( final Exception e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ e.getLocalizedMessage(),\r
+ "failed to create validating XML parser",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ if ( xml_parser == null ) {\r
+ xml_parser = PhyloXmlParser.createPhyloXmlParser();\r
+ }\r
+ return xml_parser;\r
+ }\r
+\r
+ private void executePhyleneticInference( final boolean from_unaligned_seqs ) {\r
+ final PhyloInferenceDialog dialog = new PhyloInferenceDialog( this,\r
+ getPhylogeneticInferenceOptions(),\r
+ from_unaligned_seqs );\r
+ dialog.activate();\r
+ if ( dialog.getValue() == JOptionPane.OK_OPTION ) {\r
+ if ( !from_unaligned_seqs ) {\r
+ if ( getMsa() != null ) {\r
+ final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),\r
+ getPhylogeneticInferenceOptions()\r
+ .copy(), this );\r
+ new Thread( inferrer ).start();\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "No multiple sequence alignment selected",\r
+ "Phylogenetic Inference Not Launched",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ else {\r
+ if ( getSeqs() != null ) {\r
+ final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),\r
+ getPhylogeneticInferenceOptions()\r
+ .copy(), this );\r
+ new Thread( inferrer ).start();\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "No input sequences selected",\r
+ "Phylogenetic Inference Not Launched",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {\r
+ final StringBuilder sb = new StringBuilder();\r
+ final StringBuilder sb_failed = new StringBuilder();\r
+ int counter = 0;\r
+ int counter_failed = 0;\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ final PhylogenyNodeIterator it = phy.iteratorExternalForward();\r
+ while ( it.hasNext() ) {\r
+ final PhylogenyNode n = it.next();\r
+ final String name = n.getName().trim();\r
+ if ( !ForesterUtil.isEmpty( name ) ) {\r
+ final String nt = ParserUtils.extractTaxonomyDataFromNodeName( n,\r
+ TAXONOMY_EXTRACTION.AGGRESSIVE );\r
+ if ( !ForesterUtil.isEmpty( nt ) ) {\r
+ if ( counter < 15 ) {\r
+ sb.append( name + ": " + nt + "\n" );\r
+ }\r
+ else if ( counter == 15 ) {\r
+ sb.append( "...\n" );\r
+ }\r
+ counter++;\r
+ }\r
+ else {\r
+ if ( counter_failed < 15 ) {\r
+ sb_failed.append( name + "\n" );\r
+ }\r
+ else if ( counter_failed == 15 ) {\r
+ sb_failed.append( "...\n" );\r
+ }\r
+ counter_failed++;\r
+ }\r
+ }\r
+ }\r
+ if ( counter > 0 ) {\r
+ String failed = "";\r
+ String all = "all ";\r
+ if ( counter_failed > 0 ) {\r
+ all = "";\r
+ failed = "\nCould not extract taxonomic data for " + counter_failed\r
+ + " named external nodes:\n" + sb_failed;\r
+ }\r
+ JOptionPane.showMessageDialog( this,\r
+ "Extracted taxonomic data from " + all + counter\r
+ + " named external nodes:\n" + sb.toString() + failed,\r
+ "Taxonomic Data Extraction Completed",\r
+ counter_failed > 0 ? JOptionPane.WARNING_MESSAGE\r
+ : JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ else {\r
+ JOptionPane\r
+ .showMessageDialog( this,\r
+ "Could not extract any taxonomic data.\nMaybe node names are empty\n"\r
+ + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"\r
+ + "or nodes already have taxonomic data?\n",\r
+ "No Taxonomic Data Extracted",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private ControlPanel getControlPanel() {\r
+ return getMainPanel().getControlPanel();\r
+ }\r
+\r
+ private File getCurrentDir() {\r
+ if ( ( _current_dir == null ) || !_current_dir.canRead() ) {\r
+ if ( ForesterUtil.isWindows() ) {\r
+ try {\r
+ _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );\r
+ }\r
+ catch ( final Exception e ) {\r
+ _current_dir = null;\r
+ }\r
+ }\r
+ }\r
+ if ( ( _current_dir == null ) || !_current_dir.canRead() ) {\r
+ if ( System.getProperty( "user.home" ) != null ) {\r
+ _current_dir = new File( System.getProperty( "user.home" ) );\r
+ }\r
+ else if ( System.getProperty( "user.dir" ) != null ) {\r
+ _current_dir = new File( System.getProperty( "user.dir" ) );\r
+ }\r
+ }\r
+ return _current_dir;\r
+ }\r
+\r
+ private double getMinNotCollapseConfidenceValue() {\r
+ return _min_not_collapse;\r
+ }\r
+\r
+ private double getMinNotCollapseBlValue() {\r
+ return _min_not_collapse_bl;\r
+ }\r
+\r
+ private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {\r
+ if ( _phylogenetic_inference_options == null ) {\r
+ _phylogenetic_inference_options = new PhylogeneticInferenceOptions();\r
+ }\r
+ return _phylogenetic_inference_options;\r
+ }\r
+\r
+ private boolean isUnsavedDataPresent() {\r
+ final List<TreePanel> tps = getMainPanel().getTreePanels();\r
+ for( final TreePanel tp : tps ) {\r
+ if ( tp.isEdited() ) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ private void moveNodeNamesToSeqNames() throws PhyloXmlDataFormatException {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ PhylogenyMethods\r
+ .transferNodeNameToField( phy, PhylogenyMethods.PhylogenyNodeField.SEQUENCE_NAME, false );\r
+ }\r
+ }\r
+ }\r
+\r
+ private void moveNodeNamesToTaxSn() throws PhyloXmlDataFormatException {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ PhylogenyMethods.transferNodeNameToField( phy,\r
+ PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,\r
+ false );\r
+ }\r
+ }\r
+ }\r
+\r
+ private void newTree() {\r
+ final Phylogeny[] phys = new Phylogeny[ 1 ];\r
+ final Phylogeny phy = new Phylogeny();\r
+ final PhylogenyNode node = new PhylogenyNode();\r
+ phy.setRoot( node );\r
+ phy.setRooted( true );\r
+ phys[ 0 ] = phy;\r
+ AptxUtil.addPhylogeniesToTabs( phys, "", "", getConfiguration(), getMainPanel() );\r
+ _mainpanel.getControlPanel().showWhole();\r
+ _mainpanel.getCurrentTreePanel().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );\r
+ _mainpanel.getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );\r
+ if ( getMainPanel().getMainFrame() == null ) {\r
+ // Must be "E" applet version.\r
+ ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )\r
+ .setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );\r
+ }\r
+ else {\r
+ getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );\r
+ }\r
+ activateSaveAllIfNeeded();\r
+ System.gc();\r
+ }\r
+\r
+ private void obtainDetailedTaxonomicInformation() {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ final TaxonomyDataManager t = new TaxonomyDataManager( this,\r
+ _mainpanel.getCurrentTreePanel(),\r
+ phy.copy(),\r
+ false,\r
+ true );\r
+ new Thread( t ).start();\r
+ }\r
+ }\r
+ }\r
+\r
+ private void obtainDetailedTaxonomicInformationDelete() {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ final TaxonomyDataManager t = new TaxonomyDataManager( this,\r
+ _mainpanel.getCurrentTreePanel(),\r
+ phy.copy(),\r
+ true,\r
+ true );\r
+ new Thread( t ).start();\r
+ }\r
+ }\r
+ }\r
+\r
+ private void obtainSequenceInformation() {\r
+ if ( getCurrentTreePanel() != null ) {\r
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ final SequenceDataRetriver u = new SequenceDataRetriver( this,\r
+ _mainpanel.getCurrentTreePanel(),\r
+ phy.copy() );\r
+ new Thread( u ).start();\r
+ }\r
+ }\r
+ }\r
+\r
+ private void print() {\r
+ if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )\r
+ || getCurrentTreePanel().getPhylogeny().isEmpty() ) {\r
+ return;\r
+ }\r
+ if ( !getOptions().isPrintUsingActualSize() ) {\r
+ getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80,\r
+ getOptions().getPrintSizeY() - 140,\r
+ true );\r
+ getCurrentTreePanel().resetPreferredSize();\r
+ getCurrentTreePanel().repaint();\r
+ }\r
+ final String job_name = Constants.PRG_NAME;\r
+ boolean error = false;\r
+ String printer_name = null;\r
+ try {\r
+ printer_name = Printer.print( getCurrentTreePanel(), job_name );\r
+ }\r
+ catch ( final Exception e ) {\r
+ error = true;\r
+ JOptionPane.showMessageDialog( this, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ if ( !error && ( printer_name != null ) ) {\r
+ String msg = "Printing data sent to printer";\r
+ if ( printer_name.length() > 1 ) {\r
+ msg += " [" + printer_name + "]";\r
+ }\r
+ JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ if ( !getOptions().isPrintUsingActualSize() ) {\r
+ getControlPanel().showWhole();\r
+ }\r
+ }\r
+\r
+ private void printPhylogenyToPdf( final String file_name ) {\r
+ if ( !getOptions().isPrintUsingActualSize() ) {\r
+ getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(),\r
+ getOptions().getPrintSizeY(),\r
+ true );\r
+ getCurrentTreePanel().resetPreferredSize();\r
+ getCurrentTreePanel().repaint();\r
+ }\r
+ String pdf_written_to = "";\r
+ boolean error = false;\r
+ try {\r
+ if ( getOptions().isPrintUsingActualSize() ) {\r
+ pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name,\r
+ getCurrentTreePanel(),\r
+ getCurrentTreePanel().getWidth(),\r
+ getCurrentTreePanel().getHeight() );\r
+ }\r
+ else {\r
+ pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()\r
+ .getPrintSizeX(), getOptions().getPrintSizeY() );\r
+ }\r
+ }\r
+ catch ( final IOException e ) {\r
+ error = true;\r
+ JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ if ( !error ) {\r
+ if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Wrote PDF to: " + pdf_written_to,\r
+ "Information",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ else {\r
+ JOptionPane.showMessageDialog( this,\r
+ "There was an unknown problem when attempting to write to PDF file: \""\r
+ + file_name + "\"",\r
+ "Error",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ }\r
+ if ( !getOptions().isPrintUsingActualSize() ) {\r
+ getControlPanel().showWhole();\r
+ }\r
+ }\r
+\r
+ private void readPhylogeniesFromFile() {\r
+ boolean exception = false;\r
+ Phylogeny[] phys = null;\r
+ // Set an initial directory if none set yet\r
+ final File my_dir = getCurrentDir();\r
+ _open_filechooser.setMultiSelectionEnabled( true );\r
+ // Open file-open dialog and set current directory\r
+ if ( my_dir != null ) {\r
+ _open_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _open_filechooser.showOpenDialog( _contentpane );\r
+ // All done: get the file\r
+ final File[] files = _open_filechooser.getSelectedFiles();\r
+ setCurrentDir( _open_filechooser.getCurrentDirectory() );\r
+ boolean nhx_or_nexus = false;\r
+ if ( ( files != null ) && ( files.length > 0 ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ for( final File file : files ) {\r
+ if ( ( file != null ) && !file.isDirectory() ) {\r
+ if ( _mainpanel.getCurrentTreePanel() != null ) {\r
+ _mainpanel.getCurrentTreePanel().setWaitCursor();\r
+ }\r
+ else {\r
+ _mainpanel.setWaitCursor();\r
+ }\r
+ if ( ( _open_filechooser.getFileFilter() == MainFrameApplication.nhfilter )\r
+ || ( _open_filechooser.getFileFilter() == MainFrameApplication.nhxfilter ) ) {\r
+ try {\r
+ final NHXParser nhx = new NHXParser();\r
+ setSpecialOptionsForNhxParser( nhx );\r
+ phys = PhylogenyMethods.readPhylogenies( nhx, file );\r
+ nhx_or_nexus = true;\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ else if ( _open_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {\r
+ warnIfNotPhyloXmlValidation( getConfiguration() );\r
+ try {\r
+ final PhyloXmlParser xml_parser = createPhyloXmlParser();\r
+ phys = PhylogenyMethods.readPhylogenies( xml_parser, file );\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {\r
+ try {\r
+ phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ else if ( _open_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {\r
+ try {\r
+ final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();\r
+ setSpecialOptionsForNexParser( nex );\r
+ phys = PhylogenyMethods.readPhylogenies( nex, file );\r
+ nhx_or_nexus = true;\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ // "*.*":\r
+ else {\r
+ try {\r
+ final PhylogenyParser parser = ParserUtils\r
+ .createParserDependingOnFileType( file, getConfiguration()\r
+ .isValidatePhyloXmlAgainstSchema() );\r
+ if ( parser instanceof NexusPhylogeniesParser ) {\r
+ final NexusPhylogeniesParser nex = ( NexusPhylogeniesParser ) parser;\r
+ setSpecialOptionsForNexParser( nex );\r
+ nhx_or_nexus = true;\r
+ }\r
+ else if ( parser instanceof NHXParser ) {\r
+ final NHXParser nhx = ( NHXParser ) parser;\r
+ setSpecialOptionsForNhxParser( nhx );\r
+ nhx_or_nexus = true;\r
+ }\r
+ else if ( parser instanceof PhyloXmlParser ) {\r
+ warnIfNotPhyloXmlValidation( getConfiguration() );\r
+ }\r
+ phys = PhylogenyMethods.readPhylogenies( parser, file );\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ if ( _mainpanel.getCurrentTreePanel() != null ) {\r
+ _mainpanel.getCurrentTreePanel().setArrowCursor();\r
+ }\r
+ else {\r
+ _mainpanel.setArrowCursor();\r
+ }\r
+ if ( !exception && ( phys != null ) && ( phys.length > 0 ) ) {\r
+ boolean one_desc = false;\r
+ if ( nhx_or_nexus ) {\r
+ for( final Phylogeny phy : phys ) {\r
+ if ( getOptions().isInternalNumberAreConfidenceForNhParsing() ) {\r
+ PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" );\r
+ }\r
+ if ( PhylogenyMethods.getMinimumDescendentsPerInternalNodes( phy ) == 1 ) {\r
+ one_desc = true;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ if ( PREPROCESS_TREES ) {\r
+ preProcessTreesUponReading( phys );\r
+ }\r
+ AptxUtil.addPhylogeniesToTabs( phys,\r
+ file.getName(),\r
+ file.getAbsolutePath(),\r
+ getConfiguration(),\r
+ getMainPanel() );\r
+ _mainpanel.getControlPanel().showWhole();\r
+ if ( nhx_or_nexus && one_desc ) {\r
+ JOptionPane\r
+ .showMessageDialog( this,\r
+ "One or more trees contain (a) node(s) with one descendant, "\r
+ + ForesterUtil.LINE_SEPARATOR\r
+ + "possibly indicating illegal parentheses within node names.",\r
+ "Warning: Possible Error in New Hampshire Formatted Data",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ activateSaveAllIfNeeded();\r
+ System.gc();\r
+ }\r
+\r
+ private void preProcessTreesUponReading( final Phylogeny[] phys ) {\r
+ for( final Phylogeny phy : phys ) {\r
+ if ( ( phy != null ) && !phy.isEmpty() ) {\r
+ for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {\r
+ final PhylogenyNode n = it.next();\r
+ if ( n.isExternal() ) {\r
+ if ( n.getNodeData().isHasSequence() ) {\r
+ final Sequence s = n.getNodeData().getSequence();\r
+ if ( ForesterUtil.isEmpty( s.getGeneName() ) || s.getGeneName().startsWith( "LOC" ) ) {\r
+ if ( ( s.getAccession() != null )\r
+ && !ForesterUtil.isEmpty( s.getAccession().getValue() ) ) {\r
+ s.setGeneName( s.getAccession().getValue() );\r
+ }\r
+ else if ( !ForesterUtil.isEmpty( n.getName() ) ) {\r
+ s.setGeneName( n.getName() );\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ private void readSpeciesTreeFromFile() {\r
+ Phylogeny t = null;\r
+ boolean exception = false;\r
+ final File my_dir = getCurrentDir();\r
+ _open_filechooser_for_species_tree.setSelectedFile( new File( "" ) );\r
+ if ( my_dir != null ) {\r
+ _open_filechooser_for_species_tree.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _open_filechooser_for_species_tree.showOpenDialog( _contentpane );\r
+ final File file = _open_filechooser_for_species_tree.getSelectedFile();\r
+ if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {\r
+ try {\r
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser\r
+ .createPhyloXmlParserXsdValidating(), file );\r
+ t = trees[ 0 ];\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {\r
+ try {\r
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( new TolParser(), file );\r
+ t = trees[ 0 ];\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ // "*.*":\r
+ else {\r
+ try {\r
+ final Phylogeny[] trees = PhylogenyMethods.readPhylogenies( PhyloXmlParser\r
+ .createPhyloXmlParserXsdValidating(), file );\r
+ t = trees[ 0 ];\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringOpenFile( e );\r
+ }\r
+ }\r
+ if ( !exception && ( t != null ) && !t.isRooted() ) {\r
+ exception = true;\r
+ t = null;\r
+ JOptionPane.showMessageDialog( this,\r
+ "Species tree is not rooted",\r
+ "Species tree not loaded",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ }\r
+ if ( !exception && ( t != null ) ) {\r
+ final Set<Taxonomy> tax_set = new HashSet<Taxonomy>();\r
+ for( final PhylogenyNodeIterator it = t.iteratorExternalForward(); it.hasNext(); ) {\r
+ final PhylogenyNode node = it.next();\r
+ if ( !node.getNodeData().isHasTaxonomy() ) {\r
+ exception = true;\r
+ t = null;\r
+ JOptionPane\r
+ .showMessageDialog( this,\r
+ "Species tree contains external node(s) without taxonomy information",\r
+ "Species tree not loaded",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ break;\r
+ }\r
+ else {\r
+ if ( tax_set.contains( node.getNodeData().getTaxonomy() ) ) {\r
+ exception = true;\r
+ t = null;\r
+ JOptionPane.showMessageDialog( this,\r
+ "Taxonomy ["\r
+ + node.getNodeData().getTaxonomy().asSimpleText()\r
+ + "] is not unique in species tree",\r
+ "Species tree not loaded",\r
+ JOptionPane.ERROR_MESSAGE );\r
+ break;\r
+ }\r
+ else {\r
+ tax_set.add( node.getNodeData().getTaxonomy() );\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if ( !exception && ( t != null ) ) {\r
+ setSpeciesTree( t );\r
+ JOptionPane.showMessageDialog( this,\r
+ "Species tree successfully loaded",\r
+ "Species tree loaded",\r
+ JOptionPane.INFORMATION_MESSAGE );\r
+ }\r
+ _contentpane.repaint();\r
+ System.gc();\r
+ }\r
+ }\r
+\r
+ private void setArrowCursor() {\r
+ try {\r
+ _mainpanel.getCurrentTreePanel().setArrowCursor();\r
+ }\r
+ catch ( final Exception ex ) {\r
+ // Do nothing.\r
+ }\r
+ }\r
+\r
+ private void setCurrentDir( final File current_dir ) {\r
+ _current_dir = current_dir;\r
+ }\r
+\r
+ private void setMinNotCollapseConfidenceValue( final double min_not_collapse ) {\r
+ _min_not_collapse = min_not_collapse;\r
+ }\r
+\r
+ private void setMinNotCollapseBlValue( final double min_not_collapse_bl ) {\r
+ _min_not_collapse_bl = min_not_collapse_bl;\r
+ }\r
+\r
+ private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {\r
+ _phylogenetic_inference_options = phylogenetic_inference_options;\r
+ }\r
+\r
+ private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {\r
+ nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );\r
+ nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );\r
+ }\r
+\r
+ private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {\r
+ nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );\r
+ nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );\r
+ nhx.setAllowErrorsInDistanceToParent( getOptions().isAllowErrorsInDistanceToParent() );\r
+ }\r
+\r
+ private void writeAllToFile() {\r
+ if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {\r
+ return;\r
+ }\r
+ final File my_dir = getCurrentDir();\r
+ if ( my_dir != null ) {\r
+ _save_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ _save_filechooser.setSelectedFile( new File( "" ) );\r
+ final int result = _save_filechooser.showSaveDialog( _contentpane );\r
+ final File file = _save_filechooser.getSelectedFile();\r
+ setCurrentDir( _save_filechooser.getCurrentDirectory() );\r
+ if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ if ( file.exists() ) {\r
+ final int i = JOptionPane.showConfirmDialog( this,\r
+ file + " already exists. Overwrite?",\r
+ "Warning",\r
+ JOptionPane.OK_CANCEL_OPTION,\r
+ JOptionPane.WARNING_MESSAGE );\r
+ if ( i != JOptionPane.OK_OPTION ) {\r
+ return;\r
+ }\r
+ else {\r
+ try {\r
+ file.delete();\r
+ }\r
+ catch ( final Exception e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Failed to delete: " + file,\r
+ "Error",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+ final int count = getMainPanel().getTabbedPane().getTabCount();\r
+ final List<Phylogeny> trees = new ArrayList<Phylogeny>();\r
+ for( int i = 0; i < count; ++i ) {\r
+ final Phylogeny phy = getMainPanel().getPhylogeny( i );\r
+ if ( ForesterUtil.isEmpty( phy.getName() )\r
+ && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {\r
+ phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );\r
+ }\r
+ trees.add( phy );\r
+ getMainPanel().getTreePanels().get( i ).setEdited( false );\r
+ }\r
+ final PhylogenyWriter writer = new PhylogenyWriter();\r
+ try {\r
+ writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );\r
+ }\r
+ catch ( final IOException e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Failed to write to: " + file,\r
+ "Error",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+\r
+ private boolean writeAsNewHampshire( final Phylogeny t, boolean exception, final File file ) {\r
+ try {\r
+ final PhylogenyWriter writer = new PhylogenyWriter();\r
+ writer.toNewHampshire( t, true, getOptions().getNhConversionSupportValueStyle(), file );\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringSaveAs( e );\r
+ }\r
+ return exception;\r
+ }\r
+\r
+ private boolean writeAsNexus( final Phylogeny t, boolean exception, final File file ) {\r
+ try {\r
+ final PhylogenyWriter writer = new PhylogenyWriter();\r
+ writer.toNexus( file, t, getOptions().getNhConversionSupportValueStyle() );\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringSaveAs( e );\r
+ }\r
+ return exception;\r
+ }\r
+\r
+ private boolean writeAsPhyloXml( final Phylogeny t, boolean exception, final File file ) {\r
+ try {\r
+ final PhylogenyWriter writer = new PhylogenyWriter();\r
+ writer.toPhyloXML( file, t, 0 );\r
+ }\r
+ catch ( final Exception e ) {\r
+ exception = true;\r
+ exceptionOccuredDuringSaveAs( e );\r
+ }\r
+ return exception;\r
+ }\r
+\r
+ private void writeToFile( final Phylogeny t ) {\r
+ if ( t == null ) {\r
+ return;\r
+ }\r
+ String initial_filename = null;\r
+ if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {\r
+ try {\r
+ initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();\r
+ }\r
+ catch ( final IOException e ) {\r
+ initial_filename = null;\r
+ }\r
+ }\r
+ if ( !ForesterUtil.isEmpty( initial_filename ) ) {\r
+ _save_filechooser.setSelectedFile( new File( initial_filename ) );\r
+ }\r
+ else {\r
+ _save_filechooser.setSelectedFile( new File( "" ) );\r
+ }\r
+ final File my_dir = getCurrentDir();\r
+ if ( my_dir != null ) {\r
+ _save_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _save_filechooser.showSaveDialog( _contentpane );\r
+ final File file = _save_filechooser.getSelectedFile();\r
+ setCurrentDir( _save_filechooser.getCurrentDirectory() );\r
+ boolean exception = false;\r
+ if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ if ( file.exists() ) {\r
+ final int i = JOptionPane.showConfirmDialog( this,\r
+ file + " already exists.\nOverwrite?",\r
+ "Overwrite?",\r
+ JOptionPane.OK_CANCEL_OPTION,\r
+ JOptionPane.QUESTION_MESSAGE );\r
+ if ( i != JOptionPane.OK_OPTION ) {\r
+ return;\r
+ }\r
+ else {\r
+ final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );\r
+ try {\r
+ ForesterUtil.copyFile( file, to );\r
+ }\r
+ catch ( final Exception e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Failed to create backup copy " + to,\r
+ "Failed to Create Backup Copy",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ try {\r
+ file.delete();\r
+ }\r
+ catch ( final Exception e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Failed to delete: " + file,\r
+ "Failed to Delete",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+ if ( _save_filechooser.getFileFilter() == MainFrameApplication.nhfilter ) {\r
+ exception = writeAsNewHampshire( t, exception, file );\r
+ }\r
+ else if ( _save_filechooser.getFileFilter() == MainFrameApplication.xmlfilter ) {\r
+ exception = writeAsPhyloXml( t, exception, file );\r
+ }\r
+ else if ( _save_filechooser.getFileFilter() == MainFrameApplication.nexusfilter ) {\r
+ exception = writeAsNexus( t, exception, file );\r
+ }\r
+ // "*.*":\r
+ else {\r
+ final String file_name = file.getName().trim().toLowerCase();\r
+ if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )\r
+ || file_name.endsWith( ".tree" ) ) {\r
+ exception = writeAsNewHampshire( t, exception, file );\r
+ }\r
+ else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {\r
+ exception = writeAsNexus( t, exception, file );\r
+ }\r
+ // XML is default:\r
+ else {\r
+ exception = writeAsPhyloXml( t, exception, file );\r
+ }\r
+ }\r
+ if ( !exception ) {\r
+ getMainPanel().setTitleOfSelectedTab( file.getName() );\r
+ getMainPanel().getCurrentTreePanel().setTreeFile( file );\r
+ getMainPanel().getCurrentTreePanel().setEdited( false );\r
+ }\r
+ }\r
+ }\r
+\r
+ private void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {\r
+ if ( ( t == null ) || t.isEmpty() ) {\r
+ return;\r
+ }\r
+ String initial_filename = "";\r
+ if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {\r
+ initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();\r
+ }\r
+ if ( initial_filename.indexOf( '.' ) > 0 ) {\r
+ initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );\r
+ }\r
+ initial_filename = initial_filename + "." + type;\r
+ _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );\r
+ final File my_dir = getCurrentDir();\r
+ if ( my_dir != null ) {\r
+ _writetographics_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _writetographics_filechooser.showSaveDialog( _contentpane );\r
+ File file = _writetographics_filechooser.getSelectedFile();\r
+ setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );\r
+ if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {\r
+ file = new File( file.toString() + "." + type );\r
+ }\r
+ if ( file.exists() ) {\r
+ final int i = JOptionPane.showConfirmDialog( this,\r
+ file + " already exists. Overwrite?",\r
+ "Warning",\r
+ JOptionPane.OK_CANCEL_OPTION,\r
+ JOptionPane.WARNING_MESSAGE );\r
+ if ( i != JOptionPane.OK_OPTION ) {\r
+ return;\r
+ }\r
+ else {\r
+ try {\r
+ file.delete();\r
+ }\r
+ catch ( final Exception e ) {\r
+ JOptionPane.showMessageDialog( this,\r
+ "Failed to delete: " + file,\r
+ "Error",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+ }\r
+ writePhylogenyToGraphicsFile( file.toString(), type );\r
+ }\r
+ }\r
+\r
+ private void writeToPdf( final Phylogeny t ) {\r
+ if ( ( t == null ) || t.isEmpty() ) {\r
+ return;\r
+ }\r
+ String initial_filename = "";\r
+ if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {\r
+ initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();\r
+ }\r
+ if ( initial_filename.indexOf( '.' ) > 0 ) {\r
+ initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );\r
+ }\r
+ initial_filename = initial_filename + ".pdf";\r
+ _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );\r
+ final File my_dir = getCurrentDir();\r
+ if ( my_dir != null ) {\r
+ _writetopdf_filechooser.setCurrentDirectory( my_dir );\r
+ }\r
+ final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );\r
+ File file = _writetopdf_filechooser.getSelectedFile();\r
+ setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );\r
+ if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {\r
+ if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {\r
+ file = new File( file.toString() + ".pdf" );\r
+ }\r
+ if ( file.exists() ) {\r
+ final int i = JOptionPane.showConfirmDialog( this,\r
+ file + " already exists. Overwrite?",\r
+ "WARNING",\r
+ JOptionPane.OK_CANCEL_OPTION,\r
+ JOptionPane.WARNING_MESSAGE );\r
+ if ( i != JOptionPane.OK_OPTION ) {\r
+ return;\r
+ }\r
+ }\r
+ printPhylogenyToPdf( file.toString() );\r
+ }\r
+ }\r
+\r
+ public static MainFrameApplication createInstance( final Phylogeny[] phys, final Configuration config ) {\r
+ return new MainFrameApplication( phys, config );\r
+ }\r
+\r
+ public static MainFrame createInstance( final Phylogeny[] phys,\r
+ final Configuration config,\r
+ final String title,\r
+ final File current_dir ) {\r
+ return new MainFrameApplication( phys, config, title, current_dir );\r
+ }\r
+\r
+ static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {\r
+ return new MainFrameApplication( phys, config, title );\r
+ }\r
+\r
+ static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {\r
+ return new MainFrameApplication( phys, config_file_name, title );\r
+ }\r
+\r
+ static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {\r
+ mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "\r
+ + o.getPrintSizeY() + ")" );\r
+ }\r
+\r
+ static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {\r
+ mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );\r
+ }\r
+\r
+ static void warnIfNotPhyloXmlValidation( final Configuration c ) {\r
+ if ( !c.isValidatePhyloXmlAgainstSchema() ) {\r
+ JOptionPane\r
+ .showMessageDialog( null,\r
+ ForesterUtil\r
+ .wordWrap( "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",\r
+ 80 ),\r
+ "Warning",\r
+ JOptionPane.WARNING_MESSAGE );\r
+ }\r
+ }\r
+} // MainFrameApplication.\r
+\r
+class DefaultFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )\r
+ || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )\r
+ || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )\r
+ || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )\r
+ || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )\r
+ || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )\r
+ || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )\r
+ || file_name.endsWith( ".con" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";\r
+ }\r
+}\r
+\r
+class GraphicsFileFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )\r
+ || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";\r
+ }\r
+}\r
+\r
+class MsaFileFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )\r
+ || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";\r
+ }\r
+}\r
+\r
+class NexusFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )\r
+ || file_name.endsWith( ".tre" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";\r
+ }\r
+} // NexusFilter\r
+\r
+class NHFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )\r
+ || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )\r
+ || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )\r
+ || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";\r
+ }\r
+} // NHFilter\r
+\r
+class NHXFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".nhx" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "NHX files (*.nhx) [deprecated]";\r
+ }\r
+}\r
+\r
+class PdfFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "PDF files (*.pdf)";\r
+ }\r
+} // PdfFilter\r
+\r
+class SequencesFileFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )\r
+ || file_name.endsWith( ".seqs" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";\r
+ }\r
+}\r
+\r
+class TolFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f\r
+ .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "Tree of Life files (*.tol, *.tolxml)";\r
+ }\r
+} // TolFilter\r
+\r
+class XMLFilter extends FileFilter {\r
+\r
+ @Override\r
+ public boolean accept( final File f ) {\r
+ final String file_name = f.getName().trim().toLowerCase();\r
+ return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )\r
+ || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();\r
+ }\r
+\r
+ @Override\r
+ public String getDescription() {\r
+ return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";\r
+ }\r
+} // XMLFilter\r