X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrameApplication.java;h=14b480f39281b139bedfaf4207deac961e3c3f7f;hb=bfd17a215d89bce322b5d77163f0d1d6cedb390c;hp=efdc9829ec7de75c83c93ff51738d87cba19b5a1;hpb=de8fbefc959f11af246340c4f903fb2983a95d4d;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index efdc982..14b480f 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -36,6 +36,7 @@ import java.awt.event.WindowEvent; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -78,6 +79,7 @@ import org.forester.io.parsers.GeneralMsaParser; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.nexus.NexusPhylogeniesParser; import org.forester.io.parsers.nhx.NHXParser; +import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; @@ -90,13 +92,15 @@ import org.forester.msa.MsaFormatException; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; -import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE; +import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.Confidence; import org.forester.phylogeny.data.Taxonomy; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.sdi.GSDI; +import org.forester.sdi.GSDIR; +import org.forester.sdi.SDIException; import org.forester.sdi.SDIR; import org.forester.sequence.Sequence; import org.forester.util.BasicDescriptiveStatistics; @@ -202,6 +206,7 @@ public final class MainFrameApplication extends MainFrame { private JMenu _analysis_menu; private JMenuItem _load_species_tree_item; private JMenuItem _gsdi_item; + private JMenuItem _gsdir_item; private JMenuItem _root_min_dups_item; private JMenuItem _root_min_cost_l_item; private JMenuItem _lineage_inference; @@ -217,6 +222,7 @@ public final class MainFrameApplication extends MainFrame { private Phylogeny _species_tree; private File _current_dir; private ButtonGroup _radio_group_1; + private ButtonGroup _radio_group_2; // Others: double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT; // Phylogeny Inference menu @@ -294,7 +300,7 @@ public final class MainFrameApplication extends MainFrame { setOptions( Options.createInstance( _configuration ) ); setInferenceManager( InferenceManager.createInstance( _configuration ) ); setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) ); - _textframe = null; + // _textframe = null; #~~~~ _species_tree = null; // set title setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" ); @@ -554,8 +560,8 @@ public final class MainFrameApplication extends MainFrame { } obtainDetailedTaxonomicInformationDelete(); } - else if ( o == _obtain_uniprot_seq_information_jmi ) { - obtainUniProtSequenceInformation(); + else if ( o == _obtain_seq_information_jmi ) { + obtainSequenceInformation(); } else if ( o == _read_values_jmi ) { if ( isSubtreeDisplayed() ) { @@ -578,6 +584,12 @@ public final class MainFrameApplication extends MainFrame { } executeGSDI(); } + else if ( o == _gsdir_item ) { + if ( isSubtreeDisplayed() ) { + return; + } + executeGSDIR(); + } else if ( o == _root_min_dups_item ) { if ( isSubtreeDisplayed() ) { return; @@ -615,8 +627,8 @@ public final class MainFrameApplication extends MainFrame { updateOptions( getOptions() ); } else if ( o == _replace_underscores_cbmi ) { - if ( ( _extract_pfam_style_tax_codes_cbmi != null ) && _replace_underscores_cbmi.isSelected() ) { - _extract_pfam_style_tax_codes_cbmi.setSelected( false ); + if ( ( _extract_taxonomy_no_rbmi != null ) && !_extract_taxonomy_no_rbmi.isSelected() ) { + _extract_taxonomy_no_rbmi.setSelected( true ); } updateOptions( getOptions() ); } @@ -626,8 +638,8 @@ public final class MainFrameApplication extends MainFrame { } collapseBelowThreshold(); } - else if ( o == _extract_pfam_style_tax_codes_cbmi ) { - if ( ( _replace_underscores_cbmi != null ) && _extract_pfam_style_tax_codes_cbmi.isSelected() ) { + else if ( ( o == _extract_taxonomy_pfam_rbmi ) || ( o == _extract_taxonomy_yes_rbmi ) ) { + if ( _replace_underscores_cbmi != null ) { _replace_underscores_cbmi.setSelected( false ); } updateOptions( getOptions() ); @@ -651,12 +663,14 @@ public final class MainFrameApplication extends MainFrame { 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 ); @@ -680,7 +694,8 @@ public final class MainFrameApplication extends MainFrame { .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" ); } else { - _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) ); + _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 ); } @@ -841,8 +856,21 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu .add( _internal_number_are_confidence_for_nh_parsing_cbmi = new JCheckBoxMenuItem( "Internal Node Names are Confidence Values" ) ); _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) ); + // + _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) ); + _options_jmenu + .add( _extract_taxonomy_pfam_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Pfam-style Node Names" ) ); + _extract_taxonomy_pfam_rbmi + .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE/134-298\"" ); _options_jmenu - .add( _extract_pfam_style_tax_codes_cbmi = new JCheckBoxMenuItem( "Extract Taxonomy Codes from Pfam-style Labels" ) ); + .add( _extract_taxonomy_yes_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes from Node Names" ) ); + _extract_taxonomy_yes_rbmi + .setToolTipText( "To extract 5-letter taxonomy codes from node names in the form of \"BCL2_MOUSE\" or \"BCL2_MOUSE B-cell lymphoma 2...\"" ); + _radio_group_2 = new ButtonGroup(); + _radio_group_2.add( _extract_taxonomy_no_rbmi ); + _radio_group_2.add( _extract_taxonomy_pfam_rbmi ); + _radio_group_2.add( _extract_taxonomy_yes_rbmi ); + // _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Newick/Nexus Output:" ), getConfiguration() ) ); _options_jmenu .add( _use_brackets_for_conf_in_nh_export_cbmi = new JCheckBoxMenuItem( USE_BRACKETS_FOR_CONF_IN_NH_LABEL ) ); @@ -882,8 +910,12 @@ public final class MainFrameApplication extends MainFrame { customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() ); customizeCheckBoxMenuItem( _internal_number_are_confidence_for_nh_parsing_cbmi, getOptions() .isInternalNumberAreConfidenceForNhParsing() ); - customizeCheckBoxMenuItem( _extract_pfam_style_tax_codes_cbmi, getOptions() - .isExtractPfamTaxonomyCodesInNhParsing() ); + customizeRadioButtonMenuItem( _extract_taxonomy_no_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.NO ); + customizeRadioButtonMenuItem( _extract_taxonomy_yes_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.YES ); + customizeRadioButtonMenuItem( _extract_taxonomy_pfam_rbmi, + getOptions().getTaxonomyExtraction() == TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() ); customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() ); customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() ); @@ -912,6 +944,9 @@ public final class MainFrameApplication extends MainFrame { _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" ); customizeJMenuItem( _remove_branch_color_item ); _tools_menu.addSeparator(); + _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) ); + customizeJMenuItem( _annotate_item ); + _tools_menu.addSeparator(); _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) ); customizeJMenuItem( _midpoint_root_item ); _tools_menu.addSeparator(); @@ -937,10 +972,6 @@ public final class MainFrameApplication extends MainFrame { .setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" ); _tools_menu.addSeparator(); _tools_menu - .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) ); - customizeJMenuItem( _infer_common_sn_names_item ); - _tools_menu.addSeparator(); - _tools_menu .add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) ); customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi ); _obtain_detailed_taxonomic_information_jmi @@ -950,9 +981,9 @@ public final class MainFrameApplication extends MainFrame { customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi ); _obtain_detailed_taxonomic_information_deleting_jmi .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" ); - _tools_menu.add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) ); - customizeJMenuItem( _obtain_uniprot_seq_information_jmi ); - _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information" ); + _tools_menu.add( _obtain_seq_information_jmi = new JMenuItem( "Obtain Sequence Information" ) ); + customizeJMenuItem( _obtain_seq_information_jmi ); + _obtain_seq_information_jmi.setToolTipText( "To add additional sequence information" ); _tools_menu.addSeparator(); if ( !Constants.__RELEASE ) { _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) ); @@ -1206,11 +1237,20 @@ public final class MainFrameApplication extends MainFrame { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDI gsdi = null; + final Phylogeny species_tree = _species_tree.copy(); try { - gsdi = new GSDI( gene_tree, _species_tree.copy(), false, true, true ); + 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 ); _mainpanel.getCurrentTreePanel().setTree( gene_tree ); @@ -1221,7 +1261,7 @@ public final class MainFrameApplication extends MainFrame { getControlPanel().setShowEvents( true ); showWhole(); final int selected = _mainpanel.getTabbedPane().getSelectedIndex(); - _mainpanel.addPhylogenyInNewTab( gsdi.getSpeciesTree(), getConfiguration(), "species tree", null ); + _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null ); showWhole(); _mainpanel.getTabbedPane().setSelectedIndex( selected ); showWhole(); @@ -1231,6 +1271,54 @@ public final class MainFrameApplication extends MainFrame { + gsdi.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE ); } + void executeGSDIR() { + if ( !isOKforSDI( false, true ) ) { + return; + } + final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy(); + gene_tree.setAllNodesToNotCollapse(); + gene_tree.recalculateNumberOfExternalDescendants( false ); + GSDIR gsdir = null; + 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 ) { + AptxUtil.unexpectedException( e ); + return; + } + final List assigned_trees = gsdir.getMinDuplicationsSumGeneTrees(); + final List 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 ); + getControlPanel().setShowEvents( true ); + showWhole(); + final int selected = _mainpanel.getTabbedPane().getSelectedIndex(); + _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null ); + showWhole(); + _mainpanel.getTabbedPane().setSelectedIndex( selected ); + showWhole(); + _mainpanel.getCurrentTreePanel().setEdited( true ); + JOptionPane.showMessageDialog( this, + "Duplications (min): " + gsdir.getMinDuplicationsSum() + "\n" + "Speciations: " + + gsdir.getSpeciationsSum() + "\n" + + "Number of root positions minimizing duplications sum: " + + 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; @@ -1328,7 +1416,7 @@ public final class MainFrameApplication extends MainFrame { } void exit() { - removeTextFrame(); + removeAllTextFrames(); _mainpanel.terminate(); _contentpane.removeAll(); setVisible( false ); @@ -1353,7 +1441,7 @@ public final class MainFrameApplication extends MainFrame { final String name = n.getName().trim(); if ( !ForesterUtil.isEmpty( name ) ) { final String code = ParserUtils - .extractTaxonomyCodeFromNodeName( name, PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + .extractTaxonomyCodeFromNodeName( name, NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !ForesterUtil.isEmpty( code ) ) { PhylogenyMethods.setTaxonomyCode( n, code ); } @@ -1510,7 +1598,7 @@ public final class MainFrameApplication extends MainFrame { } } - private void obtainUniProtSequenceInformation() { + private void obtainSequenceInformation() { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); if ( ( phy != null ) && !phy.isEmpty() ) { @@ -1975,12 +2063,12 @@ public final class MainFrameApplication extends MainFrame { setMsa( null ); Msa msa = null; try { - if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { - msa = FastaParser.parseMsa( new FileInputStream( file ) ); - System.out.println( msa.toString() ); + final InputStream is = new FileInputStream( file ); + if ( FastaParser.isLikelyFasta( file ) ) { + msa = FastaParser.parseMsa( is ); } else { - msa = GeneralMsaParser.parse( new FileInputStream( file ) ); + msa = GeneralMsaParser.parse( is ); } } catch ( final MsaFormatException e ) { @@ -2252,11 +2340,7 @@ public final class MainFrameApplication extends MainFrame { private void setSpecialOptionsForNhxParser( final NHXParser nhx ) { nhx.setReplaceUnderscores( getOptions().isReplaceUnderscoresInNhParsing() ); - PhylogenyMethods.TAXONOMY_EXTRACTION te = PhylogenyMethods.TAXONOMY_EXTRACTION.NO; - if ( getOptions().isExtractPfamTaxonomyCodesInNhParsing() ) { - te = PhylogenyMethods.TAXONOMY_EXTRACTION.YES; - } - nhx.setTaxonomyExtraction( te ); + nhx.setTaxonomyExtraction( getOptions().getTaxonomyExtraction() ); } private void writeAllToFile() {