X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrameApplication.java;h=57c2cb4eb3d2e54532d6b64e119b07a1555c067f;hb=a59710c5067970e8c5b20c9de492088844210c57;hp=40d958162909b91cc77a763a89aa6ce0ea33bc43;hpb=bdf2d2a11d720d6457f52866af7ff909afe98db4;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 40d9581..57c2cb4 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -93,11 +93,13 @@ import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.Confidence; +import org.forester.phylogeny.data.PhylogenyDataUtil; +import org.forester.phylogeny.data.Sequence; 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.sequence.Sequence; +import org.forester.sequence.MolecularSequence; import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.BasicTable; import org.forester.util.BasicTableParser; @@ -123,6 +125,7 @@ public final class MainFrameApplication extends MainFrame { private final static SequencesFileFilter seqsfilter = new SequencesFileFilter(); private final static DefaultFilter defaultfilter = new DefaultFilter(); private static final long serialVersionUID = -799735726778865234L; + private static final boolean PREPROCESS_TREES = false; private final JFileChooser _values_filechooser; private final JFileChooser _sequences_filechooser; private final JFileChooser _open_filechooser; @@ -140,11 +143,14 @@ public final class MainFrameApplication extends MainFrame { private JMenuItem _write_to_tif_item; private JMenuItem _write_to_png_item; private JMenuItem _write_to_bmp_item; + private JMenuItem _collapse_below_threshold; + private JMenuItem _collapse_below_branch_length; private File _current_dir; private ButtonGroup _radio_group_1; private ButtonGroup _radio_group_2; // Others: double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT; + double _min_not_collapse_bl = 0.001; // Phylogeny Inference menu private JMenu _inference_menu; private JMenuItem _inference_from_msa_item; @@ -153,7 +159,7 @@ public final class MainFrameApplication extends MainFrame { private PhylogeneticInferenceOptions _phylogenetic_inference_options = null; private Msa _msa = null; private File _msa_file = null; - private List _seqs = null; + private List _seqs = null; private File _seqs_file = null; JMenuItem _read_values_jmi; JMenuItem _read_seqs_jmi; @@ -383,8 +389,7 @@ public final class MainFrameApplication extends MainFrame { _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel() .getWidth(), _mainpanel.getCurrentTreePanel() - .getHeight(), - getOptions().isAllowFontSizeChange() ); + .getHeight() ); } } } ); @@ -543,6 +548,12 @@ public final class MainFrameApplication extends MainFrame { } collapseBelowThreshold(); } + else if ( o == _collapse_below_branch_length ) { + if ( isSubtreeDisplayed() ) { + return; + } + collapseBelowBranchLengthThreshold(); + } else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi ) || ( o == _extract_taxonomy_agressive_rbmi ) ) { if ( _replace_underscores_cbmi != null ) { @@ -589,7 +600,7 @@ public final class MainFrameApplication extends MainFrame { return _msa_file; } - public List getSeqs() { + public List getSeqs() { return _seqs; } @@ -697,11 +708,11 @@ public final class MainFrameApplication extends MainFrame { if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { setSeqsFile( null ); setSeqs( null ); - List seqs = null; + List seqs = null; try { if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { seqs = FastaParser.parse( new FileInputStream( file ) ); - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { System.out.println( SequenceWriter.toFasta( seq, 60 ) ); } } @@ -889,18 +900,19 @@ public final class MainFrameApplication extends MainFrame { _radio_group_1.add( _ext_node_dependent_cladogram_rbmi ); _radio_group_1.add( _uniform_cladograms_rbmi ); _radio_group_1.add( _non_lined_up_cladograms_rbmi ); - /////// _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) ); _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) ); _options_jmenu .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) ); _options_jmenu .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) ); + _options_jmenu + .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) ); + _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) ); if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) { - _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) ); _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) ); + _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) ); } - _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) ); _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) ); _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) ); _options_jmenu.add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( COLOR_BY_TAXONOMIC_GROUP ) ); @@ -918,11 +930,12 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) ); _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) ); _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) ); - /////// _options_jmenu.addSeparator(); _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( SEARCH_SUBHEADER ), getConfiguration() ) ); _options_jmenu.add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( SEARCH_CASE_SENSITIVE_LABEL ) ); _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( SEARCH_TERMS_ONLY_LABEL ) ); + _options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) ); + _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP ); _options_jmenu.add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( INVERSE_SEARCH_RESULT_LABEL ) ); _options_jmenu.addSeparator(); _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ), @@ -944,7 +957,6 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu.add( _replace_underscores_cbmi = new JCheckBoxMenuItem( "Replace Underscores with Spaces" ) ); _options_jmenu .add( _allow_errors_in_distance_to_parent_cbmi = new JCheckBoxMenuItem( "Ignore Distance Values Format Errors" ) ); - // _options_jmenu.add( _extract_taxonomy_no_rbmi = new JRadioButtonMenuItem( "No Taxonomy Extraction" ) ); _options_jmenu .add( _extract_taxonomy_pfam_strict_rbmi = new JRadioButtonMenuItem( "Extract Taxonomy Codes/Ids from Pfam-style Node Names" ) ); @@ -963,7 +975,6 @@ public final class MainFrameApplication extends MainFrame { _radio_group_2.add( _extract_taxonomy_pfam_strict_rbmi ); _radio_group_2.add( _extract_taxonomy_pfam_relaxed_rbmi ); _radio_group_2.add( _extract_taxonomy_agressive_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 ) ); @@ -981,6 +992,8 @@ public final class MainFrameApplication extends MainFrame { .isShowDefaultNodeShapesExternal() ); customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions() .isShowDefaultNodeShapesInternal() ); + customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions() + .isShowDefaultNodeShapesForMarkedNodes() ); customizeJMenuItem( _cycle_node_shape_mi ); customizeJMenuItem( _cycle_node_fill_mi ); customizeJMenuItem( _choose_node_size_mi ); @@ -1017,6 +1030,7 @@ public final class MainFrameApplication extends MainFrame { customizeCheckBoxMenuItem( _replace_underscores_cbmi, getOptions().isReplaceUnderscoresInNhParsing() ); customizeCheckBoxMenuItem( _allow_errors_in_distance_to_parent_cbmi, getOptions() .isReplaceUnderscoresInNhParsing() ); + customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() ); customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() ); customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() ); customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() ); @@ -1087,11 +1101,19 @@ public final class MainFrameApplication extends MainFrame { _tools_menu.addSeparator(); _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) ); customizeJMenuItem( _collapse_species_specific_subtrees ); + _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse species-specific subtrees" ); _tools_menu .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) ); customizeJMenuItem( _collapse_below_threshold ); _collapse_below_threshold - .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)" ); + .setToolTipText( "To (permanently) 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 + .add( _collapse_below_branch_length = new JMenuItem( "Collapse Branches with Branch Lengths Below Threshold into Multifurcations" ) ); + customizeJMenuItem( _collapse_below_branch_length ); + _collapse_below_branch_length + .setToolTipText( "To (permanently) collapse branches with branches with branch lengths below a threshold into multifurcations" ); + // _tools_menu.addSeparator(); _tools_menu .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) ); @@ -1260,7 +1282,7 @@ public final class MainFrameApplication extends MainFrame { _msa_file = msa_file; } - void setSeqs( final List seqs ) { + void setSeqs( final List seqs ) { _seqs = seqs; } @@ -1270,8 +1292,7 @@ public final class MainFrameApplication extends MainFrame { void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) { _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(), - _mainpanel.getCurrentTreePanel().getHeight(), - true ); + _mainpanel.getCurrentTreePanel().getHeight() ); String file_written_to = ""; boolean error = false; try { @@ -1431,7 +1452,7 @@ public final class MainFrameApplication extends MainFrame { } final int result = _sequences_filechooser.showOpenDialog( _contentpane ); final File file = _sequences_filechooser.getSelectedFile(); - List seqs = null; + List seqs = null; if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { try { if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { @@ -1480,13 +1501,13 @@ public final class MainFrameApplication extends MainFrame { } } if ( seqs != null ) { - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { System.out.println( seq.getIdentifier() ); } final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); int total_counter = 0; int attached_counter = 0; - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { ++total_counter; final String seq_name = seq.getIdentifier(); if ( !ForesterUtil.isEmpty( seq_name ) ) { @@ -1670,7 +1691,65 @@ public final class MainFrameApplication extends MainFrame { } } - private void collapse( final Phylogeny phy, final double m ) { + private void collapseBl( final Phylogeny phy ) { + final PhylogenyNodeIterator it = phy.iteratorPostorder(); + final List to_be_removed = new ArrayList(); + double min_bl = Double.MAX_VALUE; + boolean bl_present = false; + while ( it.hasNext() ) { + final PhylogenyNode n = it.next(); + if ( !n.isExternal() && !n.isRoot() ) { + final double bl = n.getDistanceToParent(); + if ( bl != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { + bl_present = true; + if ( bl < getMinNotCollapseBlValue() ) { + to_be_removed.add( n ); + } + if ( bl < min_bl ) { + min_bl = bl; + } + } + } + } + if ( bl_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\nbranch length values below " + getMinNotCollapseBlValue(), "Collapsed " + + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE ); + } + else { + JOptionPane.showMessageDialog( this, + "No branch collapsed,\nminimum branch length is " + min_bl, + "No branch collapsed", + JOptionPane.INFORMATION_MESSAGE ); + } + } + else { + JOptionPane.showMessageDialog( this, + "No branch collapsed because no branch length values present", + "No branch length values present", + JOptionPane.INFORMATION_MESSAGE ); + } + } + + private void collapse( final Phylogeny phy ) { final PhylogenyNodeIterator it = phy.iteratorPostorder(); final List to_be_removed = new ArrayList(); double min_support = Double.MAX_VALUE; @@ -1760,7 +1839,43 @@ public final class MainFrameApplication extends MainFrame { } if ( success && ( m >= 0.0 ) ) { setMinNotCollapseConfidenceValue( m ); - collapse( phy, m ); + collapse( phy ); + } + } + } + } + } + + private void collapseBelowBranchLengthThreshold() { + if ( getCurrentTreePanel() != null ) { + final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); + if ( ( phy != null ) && !phy.isEmpty() ) { + final String s = ( String ) JOptionPane + .showInputDialog( this, + "Please enter the minimum branch length value\n", + "Minimal Branch Length Value", + JOptionPane.QUESTION_MESSAGE, + null, + null, + getMinNotCollapseBlValue() ); + 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 ) ) { + setMinNotCollapseBlValue( m ); + collapseBl( phy ); } } } @@ -1916,6 +2031,10 @@ public final class MainFrameApplication extends MainFrame { return _min_not_collapse; } + private double getMinNotCollapseBlValue() { + return _min_not_collapse_bl; + } + private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() { if ( _phylogenetic_inference_options == null ) { _phylogenetic_inference_options = new PhylogeneticInferenceOptions(); @@ -2024,8 +2143,7 @@ public final class MainFrameApplication extends MainFrame { } if ( !getOptions().isPrintUsingActualSize() ) { getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX() - 80, - getOptions().getPrintSizeY() - 140, - true ); + getOptions().getPrintSizeY() - 140 ); getCurrentTreePanel().resetPreferredSize(); getCurrentTreePanel().repaint(); } @@ -2053,9 +2171,8 @@ public final class MainFrameApplication extends MainFrame { private void printPhylogenyToPdf( final String file_name ) { if ( !getOptions().isPrintUsingActualSize() ) { - getCurrentTreePanel().calcParametersForPainting( getOptions().getPrintSizeX(), - getOptions().getPrintSizeY(), - true ); + getCurrentTreePanel() + .calcParametersForPainting( getOptions().getPrintSizeX(), getOptions().getPrintSizeY() ); getCurrentTreePanel().resetPreferredSize(); getCurrentTreePanel().repaint(); } @@ -2211,6 +2328,9 @@ public final class MainFrameApplication extends MainFrame { } } } + if ( PREPROCESS_TREES ) { + preProcessTreesUponReading( phys ); + } AptxUtil.addPhylogeniesToTabs( phys, file.getName(), file.getAbsolutePath(), @@ -2234,6 +2354,30 @@ public final class MainFrameApplication extends MainFrame { System.gc(); } + private void preProcessTreesUponReading( final Phylogeny[] phys ) { + for( final Phylogeny phy : phys ) { + if ( ( phy != null ) && !phy.isEmpty() ) { + for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) { + final PhylogenyNode n = it.next(); + if ( n.isExternal() ) { + if ( n.getNodeData().isHasSequence() ) { + final Sequence s = n.getNodeData().getSequence(); + if ( ForesterUtil.isEmpty( s.getGeneName() ) || s.getGeneName().startsWith( "LOC" ) ) { + if ( ( s.getAccession() != null ) + && !ForesterUtil.isEmpty( s.getAccession().getValue() ) ) { + s.setGeneName( s.getAccession().getValue() ); + } + else if ( !ForesterUtil.isEmpty( n.getName() ) ) { + s.setGeneName( n.getName() ); + } + } + } + } + } + } + } + } + private void readSpeciesTreeFromFile() { Phylogeny t = null; boolean exception = false; @@ -2347,6 +2491,10 @@ public final class MainFrameApplication extends MainFrame { _min_not_collapse = min_not_collapse; } + private void setMinNotCollapseBlValue( final double min_not_collapse_bl ) { + _min_not_collapse_bl = min_not_collapse_bl; + } + private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) { _phylogenetic_inference_options = phylogenetic_inference_options; }