+ 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 ) {
+ setArrowCursor();
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Multiple sequence alignment format error",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ catch ( final IOException e ) {
+ setArrowCursor();
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Failed to read multiple sequence alignment",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ catch ( final IllegalArgumentException e ) {
+ setArrowCursor();
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Unexpected error during reading of multiple sequence alignment",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ catch ( final Exception e ) {
+ setArrowCursor();
+ 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 readSeqsFromFileforPI() {
+ // Set an initial directory if none set yet
+ final File my_dir = getCurrentDir();
+ _seqs_pi_filechooser.setMultiSelectionEnabled( false );
+ // Open file-open dialog and set current directory
+ if ( my_dir != null ) {
+ _seqs_pi_filechooser.setCurrentDirectory( my_dir );
+ }
+ final int result = _seqs_pi_filechooser.showOpenDialog( _contentpane );
+ // All done: get the seqs
+ final File file = _seqs_pi_filechooser.getSelectedFile();
+ setCurrentDir( _seqs_pi_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 ) {
+ setArrowCursor();
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Multiple sequence file format error",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ catch ( final IOException e ) {
+ setArrowCursor();
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Failed to read multiple sequence file",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ catch ( final IllegalArgumentException e ) {
+ setArrowCursor();
+ JOptionPane.showMessageDialog( this,
+ e.getLocalizedMessage(),
+ "Unexpected error during reading of multiple sequence file",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ catch ( final Exception e ) {
+ setArrowCursor();
+ 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_pi_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 (GSDI with re-rooting)" ) );
+ _analysis_menu.add( _load_species_tree_item = new JMenuItem( "Load Species Tree..." ) );
+ customizeJMenuItem( _gsdi_item );
+ customizeJMenuItem( _gsdir_item );
+ customizeJMenuItem( _load_species_tree_item );
+ _analysis_menu.addSeparator();
+ _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
+ customizeJMenuItem( _lineage_inference );
+ _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
+ _jmenubar.add( _analysis_menu );
+ }
+
+ @Override
+ void buildFileMenu() {
+ _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
+ _file_jmenu.add( _open_item = new JMenuItem( "Read Tree from File..." ) );
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _open_url_item = new JMenuItem( "Read Tree from URL/Webservice..." ) );
+ _file_jmenu.addSeparator();
+ final WebservicesManager webservices_manager = WebservicesManager.getInstance();
+ _load_phylogeny_from_webservice_menu_items = new JMenuItem[ webservices_manager
+ .getAvailablePhylogeniesWebserviceClients().size() ];
+ for( int i = 0; i < webservices_manager.getAvailablePhylogeniesWebserviceClients().size(); ++i ) {
+ final PhylogeniesWebserviceClient client = webservices_manager.getAvailablePhylogeniesWebserviceClient( i );
+ _load_phylogeny_from_webservice_menu_items[ i ] = new JMenuItem( client.getMenuName() );
+ _file_jmenu.add( _load_phylogeny_from_webservice_menu_items[ i ] );
+ }
+ if ( getConfiguration().isEditable() ) {
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _new_item = new JMenuItem( "New" ) );
+ _new_item.setToolTipText( "to create a new tree with one node, as source for manual tree construction" );
+ }
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
+ _file_jmenu.add( _save_all_item = new JMenuItem( "Save All Trees As..." ) );
+ _save_all_item.setToolTipText( "Write all phylogenies to one file." );
+ _save_all_item.setEnabled( false );
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
+ if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {