// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
//
// Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
package org.forester.archaeopteryx;
import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
import org.forester.sdi.GSDI;
import org.forester.sdi.GSDIR;
+import org.forester.sdi.SDIException;
import org.forester.sdi.SDIR;
import org.forester.sequence.Sequence;
import org.forester.util.BasicDescriptiveStatistics;
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";
// expression values menu:
JMenuItem _read_values_jmi;
+ 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 Configuration config, final String title ) {
this( phys, config, title, null );
}
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 );
}
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 );
moveNodeNamesToSeqNames();
}
else if ( o == _extract_tax_code_from_node_names_jmi ) {
- extractTaxCodeFromNodeNames();
+ extractTaxDataFromNodeNames();
}
else if ( o == _gsdi_item ) {
if ( isSubtreeDisplayed() ) {
}
}
- void buildAnalysisMenu() {
- _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
- _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
- _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (re-rooting)" ) );
- _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( _gsdir_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 );
+ public void end() {
+ _mainpanel.terminate();
+ _contentpane.removeAll();
+ setVisible( false );
+ dispose();
}
- 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
+ public MainPanel getMainPanel() {
+ return _mainpanel;
}
- @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..." ) );
+ public Msa getMsa() {
+ return _msa;
+ }
+
+ public File getMsaFile() {
+ return _msa_file;
+ }
+
+ public List<Sequence> getSeqs() {
+ return _seqs;
+ }
+
+ public File getSeqsFile() {
+ return _seqs_file;
+ }
+
+ 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 );
+ }
+ }
+
+ 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 );
+ }
+ }
+
+ void buildAnalysisMenu() {
+ _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
+ _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
+ _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (re-rooting)" ) );
+ _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( _gsdir_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 );
+ }
+
+ @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..." ) );
_jmenubar.add( _options_jmenu );
}
- void buildToolsMenu() {
+ void buildPhylogeneticInferenceMenu() {
+ final InferenceManager im = getInferenceManager();
+ _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() );
+ _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) );
+ customizeJMenuItem( _inference_from_msa_item );
+ _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" );
+ if ( im.canDoMsa() ) {
+ _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) );
+ customizeJMenuItem( _inference_from_seqs_item );
+ _inference_from_seqs_item
+ .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" );
+ }
+ else {
+ _inference_menu
+ .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) );
+ customizeJMenuItem( _inference_from_seqs_item );
+ _inference_from_seqs_item.setEnabled( false );
+ }
+ _jmenubar.add( _inference_menu );
+ }
+
+ void buildToolsMenu() {
_tools_menu = createMenu( "Tools", getConfiguration() );
_tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
customizeJMenuItem( _confcolor_item );
.setToolTipText( "To collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );
_tools_menu.addSeparator();
_tools_menu
+ .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );
+ customizeJMenuItem( _extract_tax_code_from_node_names_jmi );
+ _extract_tax_code_from_node_names_jmi
+ .setToolTipText( "To extract SwissProt/Uniprot taxonomic codes (mnemonics) from nodes names in the form of 'xyz_CAEEL', Uniprot/NCBI identifiers form of 'xyz_6239', or scientific names form of 'xyz_Caenorhabditis_elegans'" );
+ _tools_menu
.add( _move_node_names_to_tax_sn_jmi = new JMenuItem( "Transfer Node Names to Taxonomic Scientific Names" ) );
customizeJMenuItem( _move_node_names_to_tax_sn_jmi );
_move_node_names_to_tax_sn_jmi.setToolTipText( "To interpret node names as taxonomic scientific names" );
_tools_menu.add( _move_node_names_to_seq_names_jmi = new JMenuItem( "Transfer Node Names to Sequence Names" ) );
customizeJMenuItem( _move_node_names_to_seq_names_jmi );
_move_node_names_to_seq_names_jmi.setToolTipText( "To interpret node names as sequence (protein, gene) names" );
- _tools_menu
- .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 ) );
_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() ) {
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();
+ void executeFunctionAnalysis() {
+ if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
+ return;
}
- return xml_parser;
+ final GoAnnotation a = new GoAnnotation( this,
+ _mainpanel.getCurrentTreePanel(),
+ _mainpanel.getCurrentPhylogeny() );
+ new Thread( a ).start();
}
void executeGSDI() {
gene_tree.setAllNodesToNotCollapse();
gene_tree.recalculateNumberOfExternalDescendants( false );
GSDI gsdi = null;
- Phylogeny species_tree = _species_tree.copy();
+ final Phylogeny species_tree = _species_tree.copy();
try {
gsdi = new GSDI( gene_tree, species_tree, false, true, true );
}
+ catch ( final SDIException e ) {
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Error during GSDI",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE );
+ AptxUtil.unexpectedException( e );
return;
}
gene_tree.setRerootable( false );
gene_tree.setAllNodesToNotCollapse();
gene_tree.recalculateNumberOfExternalDescendants( false );
GSDIR gsdir = null;
- Phylogeny species_tree = _species_tree.copy();
+ final Phylogeny species_tree = _species_tree.copy();
try {
gsdir = new GSDIR( gene_tree, species_tree, true, true );
}
+ catch ( final SDIException e ) {
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Error during GSDIR",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
catch ( final Exception e ) {
- JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE );
+ AptxUtil.unexpectedException( e );
return;
}
- final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTrees().get( 0 );
+ final List<Phylogeny> assigned_trees = gsdir.getMinDuplicationsSumGeneTrees();
+ final List<Integer> shortests = GSDIR.getIndexesOfShortestTree( assigned_trees );
+ final Phylogeny result_gene_tree = assigned_trees.get( shortests.get( 0 ) );
result_gene_tree.setRerootable( false );
result_gene_tree.clearHashIdToNodeMap();
result_gene_tree.recalculateNumberOfExternalDescendants( true );
_mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
- //_mainpanel.getCurrentTreePanel().setTree( gene_tree );
- // _mainpanel.getCurrentTreePanel().setEdited( true );
getControlPanel().setShowEvents( true );
showWhole();
final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
showWhole();
_mainpanel.getCurrentTreePanel().setEdited( true );
JOptionPane.showMessageDialog( this,
- "Duplications: " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: "
+ "Duplications (min): " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: "
+ gsdir.getSpeciationsSum() + "\n"
+ "Number of root positions minimizing duplications sum: "
- + gsdir.getMinDuplicationsSumGeneTrees().size(),
+ + gsdir.getMinDuplicationsSumGeneTrees().size() + "\n"
+ + "Number of shortest trees: " + shortests.size(),
"GSDIR 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() {
+ void executeLineageInference() {
if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
return;
}
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;
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, NHXParser.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;
}
}
- private boolean isUnsavedDataPresent() {
- final List<TreePanel> tps = getMainPanel().getTreePanels();
- for( final TreePanel tp : tps ) {
- if ( tp.isEdited() ) {
- return true;
+ @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 );
}
- }
- 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 );
+ 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 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 );
- }
- }
+ void setMsa( final Msa msa ) {
+ _msa = msa;
}
- 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();
+ void setMsaFile( final File msa_file ) {
+ _msa_file = msa_file;
}
- 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();
- }
- }
+ void setSeqs( final List<Sequence> seqs ) {
+ _seqs = seqs;
}
- 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();
- }
- }
+ void setSeqsFile( final File seqs_file ) {
+ _seqs_file = seqs_file;
}
- 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 = "";
+ 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 {
- 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() );
- }
+ 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 ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
+ if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
JOptionPane.showMessageDialog( this,
- "Wrote PDF to: " + pdf_written_to,
- "Information",
+ "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 PDF file: \""
+ "There was an unknown problem when attempting to write to an image file: \""
+ file_name + "\"",
"Error",
JOptionPane.ERROR_MESSAGE );
}
}
- if ( !getOptions().isPrintUsingActualSize() ) {
- getControlPanel().showWhole();
- }
+ _contentpane.repaint();
}
private void addExpressionValuesFromFile() {
}
}
- 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 );
+ 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 );
+ }
}
- 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();
+ }
+
+ 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 );
}
- else {
- _mainpanel.setWaitCursor();
+ catch ( final Exception ex ) {
+ success = false;
}
- 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 {
+ success = false;
+ }
+ }
+ else {
+ success = false;
+ }
+ if ( success && ( x > 1 ) && ( y > 1 ) ) {
+ getOptions().setPrintSizeX( x );
+ getOptions().setPrintSizeY( y );
+ }
+ }
+ }
+
+ 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();
}
}
- 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 );
- }
+ if ( max < getMinNotCollapseConfidenceValue() ) {
+ to_be_removed.add( n );
}
- else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
- try {
- phys = PhylogenyMethods.readPhylogenies( new TolParser(), file );
- }
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
- }
+ if ( max < min_support ) {
+ min_support = max;
}
- 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 {
+ }
+ }
+ }
+ 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 {
- 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 );
+ m = Double.parseDouble( m_str );
}
- catch ( final Exception e ) {
- exception = true;
- exceptionOccuredDuringOpenFile( e );
+ catch ( final Exception ex ) {
+ success = false;
}
}
- if ( _mainpanel.getCurrentTreePanel() != null ) {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
- }
else {
- _mainpanel.setArrowCursor();
+ success = false;
}
- 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 );
- }
+ if ( success && ( m >= 0.0 ) ) {
+ setMinNotCollapseConfidenceValue( m );
+ collapse( phy, m );
}
}
}
}
- 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;
+ private PhyloXmlParser createPhyloXmlParser() {
+ PhyloXmlParser xml_parser = null;
+ if ( getConfiguration().isValidatePhyloXmlAgainstSchema() ) {
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 ) );
- }
+ 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;
+ }
+
+ 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 {
- //TODO error
+ JOptionPane.showMessageDialog( this,
+ "No multiple sequence alignment selected",
+ "Phylogenetic Inference Not Launched",
+ JOptionPane.WARNING_MESSAGE );
}
}
- catch ( final MsaFormatException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
+ else {
+ if ( getSeqs() != null ) {
+ final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
+ getPhylogeneticInferenceOptions()
+ .copy(), this );
+ new Thread( inferrer ).start();
}
- catch ( final Exception ex ) {
- // Do nothing.
+ else {
+ JOptionPane.showMessageDialog( this,
+ "No input sequences selected",
+ "Phylogenetic Inference Not Launched",
+ JOptionPane.WARNING_MESSAGE );
}
- 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.
+ }
+ }
+
+ private void extractTaxDataFromNodeNames() throws PhyloXmlDataFormatException {
+ final StringBuilder sb = new StringBuilder();
+ final StringBuilder sb_failed = new StringBuilder();
+ int counter = 0;
+ int counter_failed = 0;
+ if ( getCurrentTreePanel() != null ) {
+ final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final PhylogenyNodeIterator it = phy.iteratorExternalForward();
+ while ( it.hasNext() ) {
+ final PhylogenyNode n = it.next();
+ final String name = n.getName().trim();
+ if ( !ForesterUtil.isEmpty( name ) ) {
+ final String nt = ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.YES );
+ if ( !ForesterUtil.isEmpty( nt ) ) {
+ if ( counter < 15 ) {
+ sb.append( name + ": " + nt + "\n" );
+ }
+ else if ( counter == 15 ) {
+ sb.append( "...\n" );
+ }
+ counter++;
+ }
+ else {
+ if ( counter_failed < 15 ) {
+ sb_failed.append( name + "\n" );
+ }
+ else if ( counter_failed == 15 ) {
+ sb_failed.append( "...\n" );
+ }
+ counter_failed++;
+ }
+ }
}
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Failed to read multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- catch ( final IllegalArgumentException e ) {
- try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
+ if ( counter > 0 ) {
+ String failed = "";
+ String all = "all ";
+ if ( counter_failed > 0 ) {
+ all = "";
+ failed = "\nCould not extract taxonomic data for " + counter_failed
+ + " named external nodes:\n" + sb_failed;
+ }
+ JOptionPane.showMessageDialog( this,
+ "Extracted taxonomic data from " + all + counter
+ + " named external nodes:\n" + sb.toString() + failed,
+ "Taxonomic Data Extraction Completed",
+ counter_failed > 0 ? JOptionPane.WARNING_MESSAGE
+ : JOptionPane.INFORMATION_MESSAGE );
}
- catch ( final Exception ex ) {
- // Do nothing.
+ else {
+ JOptionPane
+ .showMessageDialog( this,
+ "Could not extract any taxonomic data.\nMaybe node names are empty\n"
+ + "or not in the forms \"XYZ_CAEEL\", \"XYZ_6239\", or \"XYZ_Caenorhabditis_elegans\"\n"
+ + "or nodes already have taxonomic data?\n",
+ "No Taxonomic Data Extracted",
+ JOptionPane.ERROR_MESSAGE );
}
- JOptionPane.showMessageDialog( this,
- e.getLocalizedMessage(),
- "Unexpected error during reading of multiple sequence file",
- JOptionPane.ERROR_MESSAGE );
- return;
}
- catch ( final Exception e ) {
+ }
+ }
+
+ private ControlPanel getControlPanel() {
+ return getMainPanel().getControlPanel();
+ }
+
+ private File getCurrentDir() {
+ if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
+ if ( ForesterUtil.isWindowns() ) {
try {
- _mainpanel.getCurrentTreePanel().setArrowCursor();
+ _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
}
- catch ( final Exception ex ) {
- // Do nothing.
+ catch ( final Exception e ) {
+ _current_dir = null;
}
- 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 ( ( _current_dir == null ) || !_current_dir.canRead() ) {
+ if ( System.getProperty( "user.home" ) != null ) {
+ _current_dir = new File( System.getProperty( "user.home" ) );
}
- 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;
+ else if ( System.getProperty( "user.dir" ) != null ) {
+ _current_dir = new File( System.getProperty( "user.dir" ) );
}
- // 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 );
}
+ return _current_dir;
}
- 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 );
+ private double getMinNotCollapseConfidenceValue() {
+ return _min_not_collapse;
+ }
+
+ private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {
+ if ( _phylogenetic_inference_options == null ) {
+ _phylogenetic_inference_options = new PhylogeneticInferenceOptions();
}
- 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;
+ return _phylogenetic_inference_options;
+ }
+
+ private boolean isUnsavedDataPresent() {
+ final List<TreePanel> tps = getMainPanel().getTreePanels();
+ for( final TreePanel tp : tps ) {
+ if ( tp.isEdited() ) {
+ return true;
}
- 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;
+ }
+ 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 );
}
- 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;
+ }
+ }
+
+ 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 );
}
- 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;
+ }
+ }
+
+ 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();
}
- if ( ( msa == null ) || ( msa.getNumberOfSequences() < 1 ) ) {
- JOptionPane.showMessageDialog( this,
- "Multiple sequence alignment is empty",
- "Illegal Multiple Sequence Alignment",
- JOptionPane.ERROR_MESSAGE );
- return;
+ }
+ }
+
+ 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();
}
- 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;
+ }
+ }
+
+ 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();
}
- 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;
+ }
+ }
+
+ 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 + "]";
}
- System.gc();
- setMsaFile( _msa_filechooser.getSelectedFile() );
- setMsa( msa );
+ JOptionPane.showMessageDialog( this, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
+ }
+ if ( !getOptions().isPrintUsingActualSize() ) {
+ getControlPanel().showWhole();
}
}
- @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 );
+ 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() );
}
- catch ( final MalformedURLException e ) {
- JOptionPane.showMessageDialog( this,
- "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
- "Malformed URL",
- JOptionPane.ERROR_MESSAGE );
+ else {
+ pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, getCurrentTreePanel(), getOptions()
+ .getPrintSizeX(), getOptions().getPrintSizeY() );
}
- catch ( final IOException e ) {
+ }
+ 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,
- "Could not read from " + url + "\n"
- + ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
- "Failed to read URL",
- JOptionPane.ERROR_MESSAGE );
+ "Wrote PDF to: " + pdf_written_to,
+ "Information",
+ JOptionPane.INFORMATION_MESSAGE );
}
- catch ( final Exception e ) {
+ else {
JOptionPane.showMessageDialog( this,
- ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
- "Unexpected Exception",
+ "There was an unknown problem when attempting to write to PDF file: \""
+ + file_name + "\"",
+ "Error",
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 );
+ }
+ if ( !getOptions().isPrintUsingActualSize() ) {
+ getControlPanel().showWhole();
+ }
+ }
+
+ 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 );
+ }
}
}
- AptxUtil.addPhylogeniesToTabs( phys,
- new File( url.getFile() ).getName(),
- new File( url.getFile() ).toString(),
- getConfiguration(),
- getMainPanel() );
- _mainpanel.getControlPanel().showWhole();
}
}
activateSaveAllIfNeeded();
_min_not_collapse = min_not_collapse;
}
+ private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {
+ _phylogenetic_inference_options = phylogenetic_inference_options;
+ }
+
private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) {
nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() );
+ nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() );
}
private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {
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;
}
}
- 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,
return new MainFrameApplication( phys, config, title, current_dir );
}
+ static MainFrame createInstance( final Phylogeny[] phys, final Configuration config, final String title ) {
+ return new MainFrameApplication( phys, config, title );
+ }
+
+ static MainFrame createInstance( final Phylogeny[] phys, final String config_file_name, final String title ) {
+ return new MainFrameApplication( phys, config_file_name, title );
+ }
+
static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
+ o.getPrintSizeY() + ")" );
JOptionPane.WARNING_MESSAGE );
}
}
+} // MainFrameApplication.
- 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;
- }
+class DefaultFilter extends FileFilter {
- public Msa getMsa() {
- return _msa;
+ @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();
}
- void setMsa( final Msa msa ) {
- _msa = msa;
+ @Override
+ public String getDescription() {
+ return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
}
+}
- void setMsaFile( final File msa_file ) {
- _msa_file = msa_file;
- }
+class GraphicsFileFilter extends FileFilter {
- public File getMsaFile() {
- return _msa_file;
+ @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();
}
- public List<Sequence> getSeqs() {
- return _seqs;
+ @Override
+ public String getDescription() {
+ return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
}
+}
- void setSeqs( final List<Sequence> seqs ) {
- _seqs = seqs;
- }
+class MsaFileFilter extends FileFilter {
- void setSeqsFile( final File seqs_file ) {
- _seqs_file = seqs_file;
+ @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();
}
- public File getSeqsFile() {
- return _seqs_file;
+ @Override
+ public String getDescription() {
+ return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
}
-} // MainFrameApplication.
+}
class NexusFilter extends FileFilter {
}
} // PdfFilter
+class SequencesFileFilter extends FileFilter {
+
+ @Override
+ public boolean accept( final File f ) {
+ final String file_name = f.getName().trim().toLowerCase();
+ return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
+ || file_name.endsWith( ".seqs" ) || f.isDirectory();
+ }
+
+ @Override
+ public String getDescription() {
+ return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
+ }
+}
+
class TolFilter extends FileFilter {
@Override