+ 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..." ) );
+ 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() ) );