X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrameApplication.java;h=7c136947dfcf8d1370fb2bcc6c8d5406f7b4702c;hb=713d694ab9ab4e0701fd756af1ea2a892f96ade9;hp=7b3f4113c564857e3aeb6f1c675616b8aeb9c1c6;hpb=89f36e42fb462f8d7b59def3ead995fb16a87b59;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 7b3f411..7c13694 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -22,7 +22,7 @@ // 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; @@ -268,9 +268,6 @@ public final class MainFrameApplication extends MainFrame { 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 ); } @@ -353,7 +350,9 @@ public final class MainFrameApplication extends MainFrame { _contentpane.setLayout( new BorderLayout() ); _contentpane.add( _mainpanel, BorderLayout.CENTER ); // App is this big - setSize( MainFrameApplication.FRAME_X_SIZE, MainFrameApplication.FRAME_Y_SIZE ); + setSize( getConfiguration().getFrameXSize() > 40 ? getConfiguration().getFrameXSize() : FRAME_X_SIZE, + getConfiguration().getFrameYSize() > 40 ? getConfiguration().getFrameYSize() : FRAME_Y_SIZE ); + // addWindowFocusListener( new WindowAdapter() { // // @Override @@ -510,7 +509,7 @@ public final class MainFrameApplication extends MainFrame { moveNodeNamesToSeqNames(); } else if ( o == _extract_tax_code_from_node_names_jmi ) { - extractTaxCodeFromNodeNames(); + extractTaxDataFromNodeNames(); } else if ( o == _gsdi_item ) { if ( isSubtreeDisplayed() ) { @@ -1133,17 +1132,17 @@ public final class MainFrameApplication extends MainFrame { .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 ) ); @@ -1874,22 +1873,64 @@ public final class MainFrameApplication extends MainFrame { } } - private void extractTaxCodeFromNodeNames() throws PhyloXmlDataFormatException { + 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.iteratorPostorder(); + 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 code = ParserUtils - .extractTaxonomyCodeFromNodeName( name, NHXParser.TAXONOMY_EXTRACTION.YES ); - if ( !ForesterUtil.isEmpty( code ) ) { - PhylogenyMethods.setTaxonomyCode( n, code ); + 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++; } } } + 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 ); + } + 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 ); + } } } } @@ -2350,6 +2391,7 @@ public final class MainFrameApplication extends MainFrame { private void setSpecialOptionsForNexParser( final NexusPhylogeniesParser nex ) { nex.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() ); + nex.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() ); } private void setSpecialOptionsForNhxParser( final NHXParser nhx ) {