From: cmzmasek Date: Wed, 17 Aug 2016 19:20:49 +0000 (-0700) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4a71774e563925de62c37378a6c32c3275f2e287;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/archaeopteryx/AptxConstants.java b/forester/java/src/org/forester/archaeopteryx/AptxConstants.java index 19e0697..c322ccf 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxConstants.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxConstants.java @@ -79,7 +79,7 @@ public final class AptxConstants { final static short NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT = 3; final static short NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT = 2; public static final boolean NH_PARSING_IGNORE_QUOTES_DEFAULT = false; - static final CLADOGRAM_TYPE CLADOGRAM_TYPE_DEFAULT = CLADOGRAM_TYPE.EXT_NODE_SUM_DEP; + static final CLADOGRAM_TYPE CLADOGRAM_TYPE_DEFAULT = CLADOGRAM_TYPE.LINED_UP; final static boolean VALIDATE_AGAINST_PHYLOXML_XSD_SCJEMA_DEFAULT = true; final static String BACKUP_FILE_SUFFIX = ".BAK"; final static double MIN_NOT_COLLAPSE_DEFAULT = 50; diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index f946f23..41aac93 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -67,7 +67,6 @@ 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.PhyloXmlUtil; import org.forester.io.parsers.tol.TolParser; import org.forester.io.parsers.util.ParserUtils; import org.forester.phylogeny.Phylogeny; @@ -81,6 +80,7 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.util.AsciiHistogram; import org.forester.util.DescriptiveStatistics; import org.forester.util.ForesterUtil; +import org.forester.util.TaxonomyUtil; public final class AptxUtil { @@ -133,12 +133,15 @@ public final class AptxUtil { first = normalizeCharForRGB( first ); second = normalizeCharForRGB( second ); third = normalizeCharForRGB( third ); - if ( ( first > 235 ) && ( second > 235 ) && ( third > 235 ) ) { + if ( ( first > 200 ) && ( second > 200 ) && ( third > 200 ) ) { first = 0; } else if ( ( first < 60 ) && ( second < 60 ) && ( third < 60 ) ) { second = 255; } + else if ( Math.abs( first - second ) < 40 && Math.abs( second - third ) < 40 ) { + third = 255; + } return new Color( first, second, third ); } @@ -744,10 +747,10 @@ public final class AptxUtil { } final static String[] getAllPossibleRanks() { - final String[] str_array = new String[ PhyloXmlUtil.TAXONOMY_RANKS_LIST.size() - 2 ]; + final String[] str_array = new String[ TaxonomyUtil.TAXONOMY_RANKS_LIST.size() - 2 ]; int i = 0; - for( final String e : PhyloXmlUtil.TAXONOMY_RANKS_LIST ) { - if ( !e.equals( PhyloXmlUtil.UNKNOWN ) && !e.equals( PhyloXmlUtil.OTHER ) ) { + for( final String e : TaxonomyUtil.TAXONOMY_RANKS_LIST ) { + if ( !e.equals( TaxonomyUtil.UNKNOWN ) && !e.equals( TaxonomyUtil.OTHER ) ) { str_array[ i++ ] = e; } } @@ -755,10 +758,10 @@ public final class AptxUtil { } final static String[] getAllPossibleRanks(final Map present_ranks) { - final String[] str_array = new String[ PhyloXmlUtil.TAXONOMY_RANKS_LIST.size() - 2 ]; + final String[] str_array = new String[ TaxonomyUtil.TAXONOMY_RANKS_LIST.size() - 2 ]; int i = 0; - for( final String e : PhyloXmlUtil.TAXONOMY_RANKS_LIST ) { - if ( !e.equals( PhyloXmlUtil.UNKNOWN ) && !e.equals( PhyloXmlUtil.OTHER ) ) { + for( final String e : TaxonomyUtil.TAXONOMY_RANKS_LIST ) { + if ( !e.equals( TaxonomyUtil.UNKNOWN ) && !e.equals( TaxonomyUtil.OTHER ) ) { if ( present_ranks != null && present_ranks.containsKey( e ) ) { str_array[ i++ ] = e + " (" + present_ranks.get(e) + ")"; } diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index ff3ce2f..694036b 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -107,7 +107,6 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { private JCheckBoxMenuItem _background_gradient_cbmi; private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi; private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi; - private JRadioButtonMenuItem _uniform_cladograms_rbmi; private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi; private Options _options; private JMenuItem _choose_font_mi; @@ -258,10 +257,6 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { updateOptions( getOptions() ); _mainpanel.getControlPanel().showWhole(); } - else if ( o == _uniform_cladograms_rbmi ) { - updateOptions( getOptions() ); - _mainpanel.getControlPanel().showWhole(); - } else if ( o == _ext_node_dependent_cladogram_rbmi ) { updateOptions( getOptions() ); _mainpanel.getControlPanel().showWhole(); @@ -1063,12 +1058,10 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { getConfiguration() ) ); _options_jmenu .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) ); - _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) ); _options_jmenu .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) ); _radio_group_1 = new ButtonGroup(); _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( MainFrame.SHOW_OVERVIEW_LABEL ) ); _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) ); @@ -1153,10 +1146,8 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi, getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ); - customizeRadioButtonMenuItem( _uniform_cladograms_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); - customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); + customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, + getOptions().getCladogramType() == CLADOGRAM_TYPE.LINED_UP ); customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() ); customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() ); customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() ); @@ -1685,11 +1676,9 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) { options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP ); } - else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) { - options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); - } + else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) { - options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); + options.setCladogramType( CLADOGRAM_TYPE.LINED_UP ); } options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null ) && _search_case_senstive_cbmi.isSelected() ); diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index b4a4398..3418951 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -988,20 +988,6 @@ public final class Configuration { setMaxBaseFontSize( i ); } } - else if ( key.equals( "graphics_export_x" ) ) { - // final String str = ( ( String ) st.nextElement() ).trim(); - // final int i = parseInt( str ); - // if ( i > 0 ) { - // setGraphicsExportX( i ); - // } - } - else if ( key.equals( "graphics_export_y" ) ) { - //final String str = ( ( String ) st.nextElement() ).trim(); - // final int i = parseInt( str ); - //if ( i > 0 ) { - // setGraphicsExportY( i ); - //} - } else if ( key.equals( "pdf_export_line_width" ) ) { final String str = ( ( String ) st.nextElement() ).trim(); final float f = parseFloat( str ); @@ -1083,22 +1069,14 @@ public final class Configuration { if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.NON_LINED_UP.toString() ) ) { setCladogramType( Options.CLADOGRAM_TYPE.NON_LINED_UP ); } - else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP.toString() ) ) { - setCladogramType( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); - } - else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP.toString() ) ) { - setCladogramType( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); + else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.LINED_UP.toString() ) ) { + setCladogramType( Options.CLADOGRAM_TYPE.LINED_UP ); } else { ForesterUtil.printWarningMessage( AptxConstants.PRG_NAME, "unknown value [" + type_str + "] for [cladogram_type]" ); } } - else if ( key.equals( "non_lined_up_cladogram" ) ) { - ForesterUtil - .printWarningMessage( AptxConstants.PRG_NAME, - "configuration key [non_lined_up_cladogram] is deprecated, use [cladogram_type] instead" ); - } else if ( key.equals( "hide_controls_and_menus" ) ) { _hide_controls_and_menus = parseBoolean( ( String ) st.nextElement() ); } diff --git a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java index f9b53b6..6a45310 100644 --- a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java +++ b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java @@ -60,6 +60,7 @@ import javax.swing.ListCellRenderer; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE; +import org.forester.archaeopteryx.util.TypomaticJButton; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY; @@ -73,39 +74,36 @@ import org.forester.util.ForesterUtil; final class ControlPanel extends JPanel implements ActionListener { enum NodeClickAction { - ADD_NEW_NODE, - BLAST, - COLLAPSE, - COLOR_SUBTREE, - COPY_SUBTREE, - CUT_SUBTREE, - DELETE_NODE_OR_SUBTREE, - EDIT_NODE_DATA, - GET_EXT_DESC_DATA, - OPEN_PDB_WEB, - OPEN_SEQ_WEB, - OPEN_TAX_WEB, - PASTE_SUBTREE, - REROOT, - SELECT_NODES, - SHOW_DATA, - SORT_DESCENDENTS, - SUBTREE, - SWAP, - CHANGE_NODE_FONT, - COLOR_NODE_FONT, - UNCOLLAPSE_ALL, - ORDER_SUBTREE; - } - final static Font jcb_bold_font = new Font( Configuration.getDefaultFontFamilyName(), - Font.BOLD, - 9 ); - final static Font jcb_font = new Font( Configuration.getDefaultFontFamilyName(), - Font.PLAIN, - 9 ); - final static Font js_font = new Font( Configuration.getDefaultFontFamilyName(), - Font.PLAIN, - 9 ); + ADD_NEW_NODE, + BLAST, + COLLAPSE, + COLOR_SUBTREE, + COPY_SUBTREE, + CUT_SUBTREE, + DELETE_NODE_OR_SUBTREE, + EDIT_NODE_DATA, + GET_EXT_DESC_DATA, + OPEN_PDB_WEB, + OPEN_SEQ_WEB, + OPEN_TAX_WEB, + PASTE_SUBTREE, + REROOT, + SELECT_NODES, + SHOW_DATA, + SORT_DESCENDENTS, + SUBTREE, + SWAP, + CHANGE_NODE_FONT, + COLOR_NODE_FONT, + UNCOLLAPSE_ALL, + ORDER_SUBTREE; + } + final static Font jcb_bold_font = new Font( Configuration + .getDefaultFontFamilyName(), Font.BOLD, 9 ); + final static Font jcb_font = new Font( Configuration + .getDefaultFontFamilyName(), Font.PLAIN, 9 ); + final static Font js_font = new Font( Configuration + .getDefaultFontFamilyName(), Font.PLAIN, 9 ); private static final String RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree"; private static final String SEARCH_TIP_TEXT = "Enter text to search for. Use ',' for logical OR and '+' for logical AND (not used in this manner for regular expression searches)."; private static final long serialVersionUID = -8463483932821545633L; @@ -120,8 +118,6 @@ final class ControlPanel extends JPanel implements ActionListener { private int _collapse_cb_item; private int _uncollapse_all_cb_item; private int _order_subtree_cb_item; - - private JCheckBox _color_acc_species; private JCheckBox _color_acc_sequence; private JCheckBox _color_according_to_annotation; @@ -140,6 +136,8 @@ final class ControlPanel extends JPanel implements ActionListener { private JCheckBox _display_internal_data; private JLabel _domain_display_label; private JTextField _domain_structure_evalue_thr_tf; + private JTextField _depth_collapse_depth_tf; + private JTextField _rank_collapse_depth_tf; private List _draw_phylogram; private JCheckBox _dynamically_hide_data; private int _edit_node_data_item; @@ -204,6 +202,12 @@ final class ControlPanel extends JPanel implements ActionListener { private JButton _zoom_out_domain_structure; private JButton _zoom_out_x; private JButton _zoom_out_y; + private JButton _decr_depth_collapse_level; + private JButton _incr_depth_collapse_level; + private JLabel _depth_collapse_label; + private JButton _decr_rank_collapse_level; + private JButton _incr_rank_collapse_level; + private JLabel _rank_collapse_label; ControlPanel( final MainPanel ap, final Configuration configuration ) { init(); @@ -297,7 +301,6 @@ final class ControlPanel extends JPanel implements ActionListener { pri = DESCENDANT_SORT_PRIORITY.SEQUENCE; } PhylogenyMethods.orderAppearanceX( tp.getPhylogeny().getRoot(), true, pri ); - tp.setNodeInPreorderToNull(); tp.getPhylogeny().externalNodesHaveChanged(); tp.getPhylogeny().clearHashIdToNodeMap(); @@ -343,6 +346,50 @@ final class ControlPanel extends JPanel implements ActionListener { setDynamicHidingIsOn( false ); displayedPhylogenyMightHaveChanged( true ); } + else if ( ( e.getSource() == _decr_depth_collapse_level ) + || ( e.getSource() == _incr_depth_collapse_level ) ) { + if ( e.getSource() == _decr_depth_collapse_level ) { + _mainpanel.getCurrentTreePanel().decreaseDepthCollapseLevel(); + } + else { + _mainpanel.getCurrentTreePanel().increaseDepthCollapseLevel(); + } + search0(); + search1(); + _mainpanel.getCurrentTreePanel().updateSetOfCollapsedExternalNodes(); + _mainpanel.getCurrentTreePanel().getPhylogeny().recalculateNumberOfExternalDescendants( true ); + _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap(); + _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo(); + _mainpanel.getCurrentTreePanel().setNodeInPreorderToNull(); + displayedPhylogenyMightHaveChanged( true ); + _mainpanel.getCurrentTreePanel().resetPreferredSize(); + _mainpanel.getCurrentTreePanel().updateOvSizes(); + _mainpanel.adjustJScrollPane(); + showWhole(); + repaint(); + } + else if ( ( e.getSource() == _decr_rank_collapse_level ) + || ( e.getSource() == _incr_rank_collapse_level ) ) { + if ( e.getSource() == _decr_rank_collapse_level ) { + _mainpanel.getCurrentTreePanel().decreaseRankCollapseLevel(); + } + else { + _mainpanel.getCurrentTreePanel().increaseRankCollapseLevel(); + } + search0(); + search1(); + _mainpanel.getCurrentTreePanel().updateSetOfCollapsedExternalNodes(); + _mainpanel.getCurrentTreePanel().getPhylogeny().recalculateNumberOfExternalDescendants( true ); + _mainpanel.getCurrentTreePanel().resetNodeIdToDistToLeafMap(); + _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo(); + _mainpanel.getCurrentTreePanel().setNodeInPreorderToNull(); + displayedPhylogenyMightHaveChanged( true ); + _mainpanel.getCurrentTreePanel().resetPreferredSize(); + _mainpanel.getCurrentTreePanel().updateOvSizes(); + _mainpanel.adjustJScrollPane(); + showWhole(); + repaint(); + } else { displayedPhylogenyMightHaveChanged( true ); } @@ -403,7 +450,8 @@ final class ControlPanel extends JPanel implements ActionListener { public JComboBox getSequenceRelationTypeBox() { if ( _sequence_relation_type_box == null ) { _sequence_relation_type_box = new JComboBox(); - for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : SequenceRelation.SEQUENCE_RELATION_TYPE.values() ) { + for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : SequenceRelation.SEQUENCE_RELATION_TYPE + .values() ) { _sequence_relation_type_box.addItem( type ); } _sequence_relation_type_box.addActionListener( new ActionListener() { @@ -525,11 +573,8 @@ final class ControlPanel extends JPanel implements ActionListener { final int index, final boolean isSelected, final boolean cellHasFocus ) { - final Component component = new DefaultListCellRenderer().getListCellRendererComponent( list, - value, - index, - isSelected, - cellHasFocus ); + final Component component = new DefaultListCellRenderer() + .getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); if ( ( value != null ) && ( value instanceof SequenceRelation.SEQUENCE_RELATION_TYPE ) ) { ( ( DefaultListCellRenderer ) component ).setText( SequenceRelation .getPrintableNameByType( ( SequenceRelation.SEQUENCE_RELATION_TYPE ) value ) ); @@ -556,7 +601,6 @@ final class ControlPanel extends JPanel implements ActionListener { }// addSequenceRelationBlock /* GUILHEM_END */ - private List getIsDrawPhylogramList() { return _draw_phylogram; } @@ -614,19 +658,20 @@ final class ControlPanel extends JPanel implements ActionListener { getOptions().isSearchCaseSensitive(), !getOptions().isMatchWholeTermsOnly(), isShowDomainArchitectures(), - tp != null ? Math.pow( 10, - tp.getDomainStructureEvalueThresholdExp() ) - : 0 ) ); + tp != null + ? Math.pow( 10, + tp.getDomainStructureEvalueThresholdExp() ) + : 0 ) ); } else { - nodes.addAll( PhylogenyMethods.searchData( query, - tree, - getOptions().isSearchCaseSensitive(), - !getOptions().isMatchWholeTermsOnly(), - getOptions().isSearchWithRegex(), - isShowDomainArchitectures(), - tp != null ? Math.pow( 10, tp - .getDomainStructureEvalueThresholdExp() ) : 0 ) ); + nodes.addAll( PhylogenyMethods + .searchData( query, + tree, + getOptions().isSearchCaseSensitive(), + !getOptions().isMatchWholeTermsOnly(), + getOptions().isSearchWithRegex(), + isShowDomainArchitectures(), + tp != null ? Math.pow( 10, tp.getDomainStructureEvalueThresholdExp() ) : 0 ) ); } } if ( getOptions().isInverseSearchResult() ) { @@ -634,7 +679,7 @@ final class ControlPanel extends JPanel implements ActionListener { final Set temp_nodes = nodes; nodes = new HashSet(); for( final PhylogenyNode n : all ) { - if ( (!temp_nodes.contains( n.getId() )) && n.isHasNodeData() ) { + if ( ( !temp_nodes.contains( n.getId() ) ) && n.isHasNodeData() ) { nodes.add( n.getId() ); } } @@ -680,19 +725,20 @@ final class ControlPanel extends JPanel implements ActionListener { getOptions().isSearchCaseSensitive(), !getOptions().isMatchWholeTermsOnly(), isShowDomainArchitectures(), - tp != null ? Math.pow( 10, - tp.getDomainStructureEvalueThresholdExp() ) - : 0 ) ); + tp != null + ? Math.pow( 10, + tp.getDomainStructureEvalueThresholdExp() ) + : 0 ) ); } else { - nodes.addAll( PhylogenyMethods.searchData( query, - tree, - getOptions().isSearchCaseSensitive(), - !getOptions().isMatchWholeTermsOnly(), - getOptions().isSearchWithRegex(), - isShowDomainArchitectures(), - tp != null ? Math.pow( 10, tp - .getDomainStructureEvalueThresholdExp() ) : 0 ) ); + nodes.addAll( PhylogenyMethods + .searchData( query, + tree, + getOptions().isSearchCaseSensitive(), + !getOptions().isMatchWholeTermsOnly(), + getOptions().isSearchWithRegex(), + isShowDomainArchitectures(), + tp != null ? Math.pow( 10, tp.getDomainStructureEvalueThresholdExp() ) : 0 ) ); } } if ( getOptions().isInverseSearchResult() ) { @@ -700,7 +746,7 @@ final class ControlPanel extends JPanel implements ActionListener { final Set temp_nodes = nodes; nodes = new HashSet(); for( final PhylogenyNode n : all ) { - if ( (!temp_nodes.contains( n.getId() )) && n.isHasNodeData() ) { + if ( ( !temp_nodes.contains( n.getId() ) ) && n.isHasNodeData() ) { nodes.add( n.getId() ); } } @@ -718,7 +764,7 @@ final class ControlPanel extends JPanel implements ActionListener { searchReset1(); } } - + private void setDrawPhylogram( final int index, final boolean b ) { getIsDrawPhylogramList().set( index, b ); } @@ -745,7 +791,7 @@ final class ControlPanel extends JPanel implements ActionListener { } cb_index++; } -if ( _configuration.doDisplayClickToOption( Configuration.uncollapse_all ) ) { + if ( _configuration.doDisplayClickToOption( Configuration.uncollapse_all ) ) { _uncollapse_all_cb_item = cb_index; addClickToOption( Configuration.uncollapse_all, _configuration.getClickToTitle( Configuration.uncollapse_all ) ); @@ -753,7 +799,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.uncollapse_all ) ) { selected_index = cb_index; } cb_index++; -} + } if ( _configuration.doDisplayClickToOption( Configuration.reroot ) ) { _reroot_cb_item = cb_index; addClickToOption( Configuration.reroot, _configuration.getClickToTitle( Configuration.reroot ) ); @@ -778,7 +824,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.uncollapse_all ) ) { } cb_index++; } -if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { + if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _order_subtree_cb_item = cb_index; addClickToOption( Configuration.order_subtree, _configuration.getClickToTitle( Configuration.order_subtree ) ); @@ -786,8 +832,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { selected_index = cb_index; } cb_index++; -} - + } if ( _configuration.doDisplayClickToOption( Configuration.sort_descendents ) ) { _sort_descendents_item = cb_index; addClickToOption( Configuration.sort_descendents, @@ -817,7 +862,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) { _color_subtree_cb_item = cb_index; - addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) ); + addClickToOption( Configuration.color_subtree, + _configuration.getClickToTitle( Configuration.color_subtree ) ); if ( default_option == Configuration.color_subtree ) { selected_index = cb_index; } @@ -825,7 +871,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } if ( _configuration.doDisplayClickToOption( Configuration.open_seq_web ) ) { _open_seq_web_item = cb_index; - addClickToOption( Configuration.open_seq_web, _configuration.getClickToTitle( Configuration.open_seq_web ) ); + addClickToOption( Configuration.open_seq_web, + _configuration.getClickToTitle( Configuration.open_seq_web ) ); if ( default_option == Configuration.open_seq_web ) { selected_index = cb_index; } @@ -833,7 +880,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } if ( _configuration.doDisplayClickToOption( Configuration.open_pdb_web ) ) { _open_pdb_item = cb_index; - addClickToOption( Configuration.open_pdb_web, _configuration.getClickToTitle( Configuration.open_pdb_web ) ); + addClickToOption( Configuration.open_pdb_web, + _configuration.getClickToTitle( Configuration.open_pdb_web ) ); if ( default_option == Configuration.open_pdb_web ) { selected_index = cb_index; } @@ -841,7 +889,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } if ( _configuration.doDisplayClickToOption( Configuration.open_tax_web ) ) { _open_tax_web_item = cb_index; - addClickToOption( Configuration.open_tax_web, _configuration.getClickToTitle( Configuration.open_tax_web ) ); + addClickToOption( Configuration.open_tax_web, + _configuration.getClickToTitle( Configuration.open_tax_web ) ); if ( default_option == Configuration.open_tax_web ) { selected_index = cb_index; } @@ -857,7 +906,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } if ( _configuration.doDisplayClickToOption( Configuration.select_nodes ) ) { _select_nodes_item = cb_index; - addClickToOption( Configuration.select_nodes, _configuration.getClickToTitle( Configuration.select_nodes ) ); + addClickToOption( Configuration.select_nodes, + _configuration.getClickToTitle( Configuration.select_nodes ) ); if ( default_option == Configuration.select_nodes ) { selected_index = cb_index; } @@ -866,8 +916,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { if ( _configuration.doDisplayClickToOption( Configuration.get_ext_desc_data ) ) { _get_ext_desc_data = cb_index; if ( !ForesterUtil.isEmpty( getConfiguration().getLabelForGetExtDescendentsData() ) ) { - addClickToOption( Configuration.get_ext_desc_data, getConfiguration() - .getLabelForGetExtDescendentsData() ); + addClickToOption( Configuration.get_ext_desc_data, + getConfiguration().getLabelForGetExtDescendentsData() ); } else { addClickToOption( Configuration.get_ext_desc_data, @@ -881,7 +931,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { if ( getOptions().isEditable() ) { if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) { _cut_subtree_item = cb_index; - addClickToOption( Configuration.cut_subtree, _configuration.getClickToTitle( Configuration.cut_subtree ) ); + addClickToOption( Configuration.cut_subtree, + _configuration.getClickToTitle( Configuration.cut_subtree ) ); if ( default_option == Configuration.cut_subtree ) { selected_index = cb_index; } @@ -952,7 +1003,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _configuration.doCheckOption( Configuration.dynamically_hide_data ) ); } if ( _configuration.doDisplayOption( Configuration.node_data_popup ) ) { - addCheckbox( Configuration.node_data_popup, _configuration.getDisplayTitle( Configuration.node_data_popup ) ); + addCheckbox( Configuration.node_data_popup, + _configuration.getDisplayTitle( Configuration.node_data_popup ) ); setCheckbox( Configuration.node_data_popup, _configuration.doCheckOption( Configuration.node_data_popup ) ); } if ( _configuration.doDisplayOption( Configuration.display_internal_data ) ) { @@ -994,7 +1046,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } add( label ); if ( _configuration.doDisplayOption( Configuration.show_node_names ) ) { - addCheckbox( Configuration.show_node_names, _configuration.getDisplayTitle( Configuration.show_node_names ) ); + addCheckbox( Configuration.show_node_names, + _configuration.getDisplayTitle( Configuration.show_node_names ) ); setCheckbox( Configuration.show_node_names, _configuration.doCheckOption( Configuration.show_node_names ) ); } if ( _configuration.doDisplayOption( Configuration.show_tax_code ) ) { @@ -1022,13 +1075,15 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { setCheckbox( Configuration.show_seq_names, _configuration.doCheckOption( Configuration.show_seq_names ) ); } if ( _configuration.doDisplayOption( Configuration.show_gene_names ) ) { - addCheckbox( Configuration.show_gene_names, _configuration.getDisplayTitle( Configuration.show_gene_names ) ); + addCheckbox( Configuration.show_gene_names, + _configuration.getDisplayTitle( Configuration.show_gene_names ) ); setCheckbox( Configuration.show_gene_names, _configuration.doCheckOption( Configuration.show_gene_names ) ); } if ( _configuration.doDisplayOption( Configuration.show_seq_symbols ) ) { addCheckbox( Configuration.show_seq_symbols, _configuration.getDisplayTitle( Configuration.show_seq_symbols ) ); - setCheckbox( Configuration.show_seq_symbols, _configuration.doCheckOption( Configuration.show_seq_symbols ) ); + setCheckbox( Configuration.show_seq_symbols, + _configuration.doCheckOption( Configuration.show_seq_symbols ) ); } if ( _configuration.doDisplayOption( Configuration.show_sequence_acc ) ) { addCheckbox( Configuration.show_sequence_acc, @@ -1037,7 +1092,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _configuration.doCheckOption( Configuration.show_sequence_acc ) ); } if ( _configuration.doDisplayOption( Configuration.show_annotation ) ) { - addCheckbox( Configuration.show_annotation, _configuration.getDisplayTitle( Configuration.show_annotation ) ); + addCheckbox( Configuration.show_annotation, + _configuration.getDisplayTitle( Configuration.show_annotation ) ); setCheckbox( Configuration.show_annotation, _configuration.doCheckOption( Configuration.show_annotation ) ); } if ( _configuration.doDisplayOption( Configuration.write_confidence_values ) ) { @@ -1081,10 +1137,12 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { if ( _configuration.doDisplayOption( Configuration.show_vector_data ) ) { addCheckbox( Configuration.show_vector_data, _configuration.getDisplayTitle( Configuration.show_vector_data ) ); - setCheckbox( Configuration.show_vector_data, _configuration.doCheckOption( Configuration.show_vector_data ) ); + setCheckbox( Configuration.show_vector_data, + _configuration.doCheckOption( Configuration.show_vector_data ) ); } if ( _configuration.doDisplayOption( Configuration.show_properties ) ) { - addCheckbox( Configuration.show_properties, _configuration.getDisplayTitle( Configuration.show_properties ) ); + addCheckbox( Configuration.show_properties, + _configuration.getDisplayTitle( Configuration.show_properties ) ); setCheckbox( Configuration.show_properties, _configuration.doCheckOption( Configuration.show_properties ) ); } if ( _configuration.doDisplayOption( Configuration.show_taxonomy_images ) ) { @@ -1164,15 +1222,15 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { add( y_panel ); add( z_panel ); if ( getConfiguration().isUseNativeUI() ) { - _zoom_in_x = new JButton( "+" ); - _zoom_out_x = new JButton( "-" ); + _zoom_in_x = new TypomaticJButton( "+" ); + _zoom_out_x = new TypomaticJButton( "-" ); } else { - _zoom_in_x = new JButton( "X+" ); - _zoom_out_x = new JButton( "X-" ); + _zoom_in_x = new TypomaticJButton( "X+" ); + _zoom_out_x = new TypomaticJButton( "X-" ); } - _zoom_in_y = new JButton( "Y+" ); - _zoom_out_y = new JButton( "Y-" ); + _zoom_in_y = new TypomaticJButton( "Y+" ); + _zoom_out_y = new TypomaticJButton( "Y-" ); _show_whole = new JButton( "F" ); _show_whole.setToolTipText( "To fit the complete phylogeny to the current display size [F or Home]" ); _zoom_in_x.setToolTipText( "To zoom in horizontally [Shift+cursor-right]" ); @@ -1194,7 +1252,6 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _return_to_super_tree.setEnabled( false ); _order = new JButton( "Order Tree" ); _uncollapse_all = new JButton( "Uncollapse All" ); - addJButton( _zoom_in_y, x_panel ); addJButton( _zoom_out_x, y_panel ); addJButton( _show_whole, y_panel ); @@ -1203,6 +1260,12 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) { setUpControlsForDomainStrucures(); } + if ( true ) { + setUpControlsForDepthCollapse(); + } + if ( true ) { + setUpControlsForRankCollapse(); + } final JLabel spacer2 = new JLabel( "" ); add( spacer2 ); addJButton( _return_to_super_tree, this ); @@ -1271,7 +1334,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _show_taxo_rank = new JCheckBox( title ); addJCheckBox( _show_taxo_rank, ch_panel ); add( ch_panel ); - break; + break; case Configuration.show_taxonomy_images: _show_taxo_images_cb = new JCheckBox( title ); addJCheckBox( _show_taxo_images_cb, ch_panel ); @@ -1423,7 +1486,6 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) { if ( ( _mainpanel != null ) && ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) ) { - if ( recalc_longest_ext_node_info ) { _mainpanel.getCurrentTreePanel().initNodeData(); _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo(); @@ -1434,10 +1496,12 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _mainpanel.getCurrentTreePanel().recalculateMaxDistanceToRoot(); setVisibilityOfDomainStrucureControls(); updateDomainStructureEvaluethresholdDisplay(); + updateDepthCollapseDepthDisplay(); + updateRankCollapseRankDisplay(); + getMainPanel().getControlPanel(); _mainpanel.getCurrentTreePanel().calculateScaleDistance(); _mainpanel.getCurrentTreePanel().calcMaxDepth(); _mainpanel.adjustJScrollPane(); - _mainpanel.getCurrentTreePanel().repaint(); // _mainpanel.getCurrentTreePanel().setUpUrtFactor(); } @@ -1603,7 +1667,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { boolean isShowTaxonomyCode() { return ( ( _show_taxo_code != null ) && _show_taxo_code.isSelected() ); } - + boolean isShowTaxonomyRank() { return ( ( _show_taxo_rank != null ) && _show_taxo_rank.isSelected() ); } @@ -1617,7 +1681,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } boolean isUseVisualStyles() { - return ( ( ( getUseVisualStylesCb() != null ) && getUseVisualStylesCb().isSelected() ) || ( ( getUseVisualStylesCb() == null ) && _color_branches ) ); + return ( ( ( getUseVisualStylesCb() != null ) && getUseVisualStylesCb().isSelected() ) + || ( ( getUseVisualStylesCb() == null ) && _color_branches ) ); } boolean isWidthBranches() { @@ -2019,8 +2084,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { _domain_display_label = new JLabel( "Domain Architectures:" ); add( customizeLabel( _domain_display_label, getConfiguration() ) ); add( _domain_display_label ); - _zoom_in_domain_structure = new JButton( "d+" ); - _zoom_out_domain_structure = new JButton( "d-" ); + _zoom_in_domain_structure = new TypomaticJButton( "d+" ); + _zoom_out_domain_structure = new TypomaticJButton( "d-" ); _decr_domain_structure_evalue_thr = new JButton( "-" ); _incr_domain_structure_evalue_thr = new JButton( "+" ); _zoom_in_domain_structure.setPreferredSize( new Dimension( 10, 10 ) ); @@ -2051,6 +2116,66 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { addJButton( _incr_domain_structure_evalue_thr, d2_panel ); } + void setUpControlsForDepthCollapse() { + _depth_collapse_label = new JLabel( "Collapse by Node Depth:" ); + _depth_collapse_label + .setToolTipText( "to automaticall collapse nodes with a depth equal or larger than a threshold" ); + add( customizeLabel( _depth_collapse_label, getConfiguration() ) ); + add( _depth_collapse_label ); + _decr_depth_collapse_level = new TypomaticJButton( "-" ); + _incr_depth_collapse_level = new TypomaticJButton( "+" ); + _decr_depth_collapse_level.setPreferredSize( new Dimension( 10, 10 ) ); + _incr_depth_collapse_level.setPreferredSize( new Dimension( 10, 10 ) ); + _decr_depth_collapse_level.setToolTipText( "to decrease the depth threshold (wraps around)" ); + _incr_depth_collapse_level.setToolTipText( "to increase the depth threshold (wraps around)" ); + _depth_collapse_depth_tf = new JTextField( 3 ); + _depth_collapse_depth_tf.setToolTipText( "the current depth threshold" ); + _depth_collapse_depth_tf.setEditable( false ); + if ( !getConfiguration().isUseNativeUI() ) { + _depth_collapse_depth_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() ); + _depth_collapse_depth_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() ); + _depth_collapse_depth_tf.setBorder( null ); + } + final JPanel panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) ); + if ( !_configuration.isUseNativeUI() ) { + panel.setBackground( getBackground() ); + } + add( panel ); + addJButton( _decr_depth_collapse_level, panel ); + addJTextField( _depth_collapse_depth_tf, panel ); + addJButton( _incr_depth_collapse_level, panel ); + } + + void setUpControlsForRankCollapse() { + _rank_collapse_label = new JLabel( "Collapse by Node Rank:" ); + _rank_collapse_label + .setToolTipText( "to automatically collapse nodes with a taxonomic rank equal or lower than a threshold" ); + add( customizeLabel( _rank_collapse_label, getConfiguration() ) ); + add( _rank_collapse_label ); + _decr_rank_collapse_level = new TypomaticJButton( "-" ); + _incr_rank_collapse_level = new TypomaticJButton( "+" ); + _decr_rank_collapse_level.setPreferredSize( new Dimension( 10, 10 ) ); + _incr_rank_collapse_level.setPreferredSize( new Dimension( 10, 10 ) ); + _decr_rank_collapse_level.setToolTipText( "to decrease the taxonomic rank threshold (wraps around)" ); + _incr_rank_collapse_level.setToolTipText( "to increase the taxonomic rank threshold (wraps around)" ); + _rank_collapse_depth_tf = new JTextField( 3 ); + _rank_collapse_depth_tf.setToolTipText( "the current taxonomic rank threshold" ); + _rank_collapse_depth_tf.setEditable( false ); + if ( !getConfiguration().isUseNativeUI() ) { + _rank_collapse_depth_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() ); + _rank_collapse_depth_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() ); + _rank_collapse_depth_tf.setBorder( null ); + } + final JPanel panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) ); + if ( !_configuration.isUseNativeUI() ) { + panel.setBackground( getBackground() ); + } + add( panel ); + addJButton( _decr_rank_collapse_level, panel ); + addJTextField( _rank_collapse_depth_tf, panel ); + addJButton( _incr_rank_collapse_level, panel ); + } + void setupSearchTools0() { final JLabel search_label = new JLabel( "Search (A):" ); search_label.setFont( ControlPanel.jcb_bold_font ); @@ -2173,9 +2298,9 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { void setVisibilityOfDomainStrucureCB() { try { - if ( ( getCurrentTreePanel() != null ) - && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel() - .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) { + if ( ( getCurrentTreePanel() != null ) && ( ( getCurrentTreePanel() + .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) + || ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) { if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) { getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( false ); } @@ -2240,15 +2365,12 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } } } - if ( isDrawPhylogram() - || ( ( getCurrentTreePanel() != null ) && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel() - .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) ) { + if ( isDrawPhylogram() || ( ( getCurrentTreePanel() != null ) && ( ( getCurrentTreePanel() + .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) + || ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) ) { if ( mf._non_lined_up_cladograms_rbmi != null ) { mf._non_lined_up_cladograms_rbmi.setVisible( false ); } - if ( mf._uniform_cladograms_rbmi != null ) { - mf._uniform_cladograms_rbmi.setVisible( false ); - } if ( mf._ext_node_dependent_cladogram_rbmi != null ) { mf._ext_node_dependent_cladogram_rbmi.setVisible( false ); } @@ -2257,9 +2379,6 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { if ( mf._non_lined_up_cladograms_rbmi != null ) { mf._non_lined_up_cladograms_rbmi.setVisible( true ); } - if ( mf._uniform_cladograms_rbmi != null ) { - mf._uniform_cladograms_rbmi.setVisible( true ); - } if ( mf._ext_node_dependent_cladogram_rbmi != null ) { mf._ext_node_dependent_cladogram_rbmi.setVisible( true ); } @@ -2310,7 +2429,8 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { * Fit entire tree into window. */ void showWhole() { - if ( ( _mainpanel.getCurrentScrollPane() == null ) || _mainpanel.getCurrentTreePanel().getPhylogeny().isEmpty() ) { + if ( ( _mainpanel.getCurrentScrollPane() == null ) + || _mainpanel.getCurrentTreePanel().getPhylogeny().isEmpty() ) { return; } getCurrentTreePanel().updateSetOfCollapsedExternalNodes(); @@ -2385,13 +2505,15 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { e.setSelectedTypeInTypeMenu( e.getCurrentTreePanel().getPhylogenyGraphicsType() ); } else { - getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel() - .getPhylogenyGraphicsType() ); + getMainPanel().getMainFrame() + .setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel().getPhylogenyGraphicsType() ); } getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton(); getMainPanel().getControlPanel().search0(); getMainPanel().getControlPanel().search1(); getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay(); + getMainPanel().getControlPanel().updateDepthCollapseDepthDisplay(); + getMainPanel().getControlPanel().updateRankCollapseRankDisplay(); getSequenceRelationTypeBox().removeAllItems(); for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny() .getRelevantSequenceRelationTypes() ) { @@ -2406,7 +2528,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { /** * Uncollapse all nodes. */ - void uncollapseAll( final TreePanel tp ) { + final void uncollapseAll( final TreePanel tp ) { final Phylogeny t = tp.getPhylogeny(); if ( ( t != null ) && !t.isEmpty() ) { for( final PhylogenyNodeIterator iter = t.iteratorPreorder(); iter.hasNext(); ) { @@ -2418,18 +2540,88 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { t.recalculateNumberOfExternalDescendants( false ); tp.setNodeInPreorderToNull(); t.clearHashIdToNodeMap(); + tp.resetDepthCollapseDepthValue(); + tp.resetRankCollapseRankValue(); showWhole(); } } - void updateDomainStructureEvaluethresholdDisplay() { + final void updateDomainStructureEvaluethresholdDisplay() { if ( _domain_structure_evalue_thr_tf != null ) { - _domain_structure_evalue_thr_tf.setText( "10^" - + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThresholdExp() ); + _domain_structure_evalue_thr_tf + .setText( "10^" + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThresholdExp() ); + } + } + + private final String obtainDepthCollapseDepthValue() { + if ( getMainPanel().getCurrentTreePanel() == null ) { + return ""; + } + final TreePanel tp = getMainPanel().getCurrentTreePanel(); + final Phylogeny p = tp.getPhylogeny(); + if ( ( p == null ) || ( p.getNumberOfExternalNodes() < 3 ) ) { + return "off"; + } + else if ( tp.getDepthCollapseDepthValue() < 0 ) { + tp.setDepthCollapseDepthValue( PhylogenyMethods.calculateMaxDepth( p ) ); + return "off"; + } + else if ( tp.getDepthCollapseDepthValue() == PhylogenyMethods.calculateMaxDepth( p ) ) { + return "off"; + } + return String.valueOf( tp.getDepthCollapseDepthValue() ); + } + + private final String obtainRankCollapseDepthValue() { + if ( getMainPanel().getCurrentTreePanel() == null ) { + return ""; + } + final TreePanel tp = getMainPanel().getCurrentTreePanel(); + final Phylogeny p = tp.getPhylogeny(); + if ( ( p == null ) || ( p.getNumberOfExternalNodes() < 3 ) ) { + return "off"; + } + else { + final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( p ); + if ( ranks.length < 1 ) { + return "off"; + } + else if ( tp.getRankCollapseRankValue() < 0 ) { + tp.setRankCollapseRankValue( ranks.length - 1 ); + return "off"; + } + else if ( tp.getRankCollapseRankValue() == ( ranks.length - 1 ) ) { + return "off"; + } + } + return String.valueOf( tp.getRankCollapseRankValue() ); + } + + final void updateDepthCollapseDepthDisplay() { + if ( _depth_collapse_depth_tf != null ) { + _depth_collapse_depth_tf.setText( " " + obtainDepthCollapseDepthValue() ); + } + } + + final void updateRankCollapseRankDisplay() { + if ( _rank_collapse_depth_tf != null ) { + final String r = obtainRankCollapseDepthValue(); + if ( r.equals( "off" ) ) { + _rank_collapse_depth_tf.setText( " off" ); + _rank_collapse_depth_tf.setToolTipText( "the current taxonomic rank threshold" ); + } + else { + final String ranks[] = PhylogenyMethods + .obtainPresentRanksSorted( getMainPanel().getCurrentTreePanel().getPhylogeny() ); + final int rr = Integer.parseInt( r ); + _rank_collapse_depth_tf.setText( ranks[ rr ] ); + _rank_collapse_depth_tf.setToolTipText( ( rr + 1 ) + "/" + ( ranks.length - 1 ) + ": " + + ranks[ Integer.parseInt( r ) ] ); + } } } - void zoomInX( final float factor, final float x_correction_factor ) { + final void zoomInX( final float factor, final float x_correction_factor ) { final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar(); final TreePanel treepanel = getMainPanel().getCurrentTreePanel(); treepanel.multiplyUrtFactor( 1f ); @@ -2437,14 +2629,15 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) || isDrawPhylogram( getMainPanel().getCurrentTabIndex() ) || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) { - final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) ); + final double x = ( sb.getMaximum() - sb.getMinimum() ) + / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) ); treepanel.setXdistance( ( treepanel.getXdistance() * factor ) ); treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) ); getMainPanel().adjustJScrollPane(); treepanel.resetPreferredSize(); getMainPanel().getCurrentScrollPane().getViewport().validate(); - sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - - ( sb.getVisibleAmount() / 2.0 ) ) ); + sb.setValue( ForesterUtil + .roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - ( sb.getVisibleAmount() / 2.0 ) ) ); } else { final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue(); @@ -2459,7 +2652,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { treepanel.updateOvSizes(); } - void zoomInY( final float factor ) { + final void zoomInY( final float factor ) { final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar(); final TreePanel treepanel = getMainPanel().getCurrentTreePanel(); treepanel.multiplyUrtFactor( 1.1f ); @@ -2468,13 +2661,13 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { getMainPanel().adjustJScrollPane(); treepanel.resetPreferredSize(); getMainPanel().getCurrentScrollPane().getViewport().validate(); - sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - - ( sb.getVisibleAmount() / 2.0 ) ) ); + sb.setValue( ForesterUtil + .roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - ( sb.getVisibleAmount() / 2.0 ) ) ); treepanel.resetPreferredSize(); treepanel.updateOvSizes(); } - void zoomOutX( final float factor, final float x_correction_factor ) { + final void zoomOutX( final float factor, final float x_correction_factor ) { final TreePanel treepanel = getMainPanel().getCurrentTreePanel(); treepanel.multiplyUrtFactor( 1f ); if ( ( treepanel.getXdistance() * factor ) > 0.0 ) { @@ -2512,24 +2705,25 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { } } - void zoomOutY( final float factor ) { + final void zoomOutY( final float factor ) { final TreePanel treepanel = getMainPanel().getCurrentTreePanel(); treepanel.multiplyUrtFactor( 0.9f ); if ( ( treepanel.getYdistance() * factor ) > 0.0 ) { final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar(); - final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) ); + final double x = ( sb.getMaximum() - sb.getMinimum() ) + / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) ); treepanel.setYdistance( ( treepanel.getYdistance() * factor ) ); getMainPanel().adjustJScrollPane(); treepanel.resetPreferredSize(); getMainPanel().getCurrentScrollPane().getViewport().validate(); - sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - - ( sb.getVisibleAmount() / 2.0 ) ) ); + sb.setValue( ForesterUtil + .roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x ) - ( sb.getVisibleAmount() / 2.0 ) ) ); treepanel.resetPreferredSize(); treepanel.updateOvSizes(); } } - static JLabel customizeLabel( final JLabel label, final Configuration configuration ) { + final static JLabel customizeLabel( final JLabel label, final Configuration configuration ) { label.setFont( ControlPanel.jcb_bold_font ); if ( !configuration.isUseNativeUI() ) { label.setForeground( configuration.getGuiCheckboxTextColor() ); @@ -2538,7 +2732,7 @@ if ( _configuration.doDisplayClickToOption( Configuration.order_subtree ) ) { return label; } - public JCheckBox getUseBranchWidthsCb() { + final public JCheckBox getUseBranchWidthsCb() { return _width_branches; } } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 7411509..758f053 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -94,7 +94,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { final static MsaFileFilter msafilter = new MsaFileFilter(); final static SequencesFileFilter seqsfilter = new SequencesFileFilter(); final static DefaultFilter defaultfilter = new DefaultFilter(); - static final String USE_MOUSEWHEEL_SHIFT_TO_ROTATE = "In this display type, use mousewheel + Shift to rotate [or A and S]"; + static final String USE_MOUSEWHEEL_SHIFT_TO_ROTATE = "rotate with mousewheel + Shift (or A and S), D toggles between horizontal and radial labels"; static final String PHYLOXML_REF_TOOL_TIP = AptxConstants.PHYLOXML_REFERENCE; //TODO //FIXME static final String APTX_REF_TOOL_TIP = AptxConstants.APTX_REFERENCE; private static final long serialVersionUID = 3655000897845508358L; @@ -119,8 +119,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { static final String INVERSE_SEARCH_RESULT_LABEL = "Negate Result"; static final String COLOR_BY_TAXONOMIC_GROUP = "Colorize by Taxonomic Group"; static final String DISPLAY_SCALE_LABEL = "Scale"; - static final String NON_LINED_UP_CLADOGRAMS_LABEL = "Non-Lined Up Cladograms"; - static final String UNIFORM_CLADOGRAMS_LABEL = "Total Node Sum Dependent Cladograms"; + static final String NON_LINED_UP_CLADOGRAMS_LABEL = "Non-Lined Up Cladogram"; static final String LABEL_DIRECTION_LABEL = "Radial Labels"; static final String LABEL_DIRECTION_TIP = "To use radial node labels in radial and unrooted display types"; static final String SEARCH_WITH_REGEX_TIP = "To search using regular expressions (~Java/Perl syntax). For example, use \"^B.+\\d{2,}$\" to search for everything starting with a B and ending with at least two digits."; @@ -132,7 +131,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { static final String DISPLAY_NODE_BOXES_LABEL_MARKED = "Shapes for Nodes with Visual Data"; static final String SHOW_OVERVIEW_LABEL = "Overview"; static final String FONT_SIZE_MENU_LABEL = "Font Size"; - static final String NONUNIFORM_CLADOGRAMS_LABEL = "External Node Sum Dependent Cladograms"; + static final String NONUNIFORM_CLADOGRAMS_LABEL = "Lined Up Cladogram"; static final String SHOW_DOMAIN_LABELS_LABEL = "Domain Labels"; static final String SHOW_ANN_REF_SOURCE_LABEL = "Seq Annotation Ref Sources"; static final String COLOR_LABELS_TIP = "To use parent branch colors for node labels as well, need to turn off taxonomy dependent colorization and turn on branch colorization for this to become apparent"; @@ -211,7 +210,6 @@ public abstract class MainFrame extends JFrame implements ActionListener { JCheckBoxMenuItem _screen_antialias_cbmi; JCheckBoxMenuItem _background_gradient_cbmi; JRadioButtonMenuItem _non_lined_up_cladograms_rbmi; - JRadioButtonMenuItem _uniform_cladograms_rbmi; JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi; JCheckBoxMenuItem _color_by_taxonomic_group_cbmi; JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me @@ -232,6 +230,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { JCheckBoxMenuItem _show_confidence_stddev_cbmi; JCheckBoxMenuItem _right_line_up_domains_cbmi; JCheckBoxMenuItem _line_up_renderable_data_cbmi; + JCheckBoxMenuItem _collapsed_with_average_height_cbmi; // _ print JCheckBoxMenuItem _graphics_export_visible_only_cbmi; JCheckBoxMenuItem _antialias_print_cbmi; @@ -500,10 +499,6 @@ public abstract class MainFrame extends JFrame implements ActionListener { updateOptions( getOptions() ); showWhole(); } - else if ( o == _uniform_cladograms_rbmi ) { - updateOptions( getOptions() ); - showWhole(); - } else if ( o == _ext_node_dependent_cladogram_rbmi ) { updateOptions( getOptions() ); showWhole(); @@ -579,6 +574,13 @@ public abstract class MainFrame extends JFrame implements ActionListener { } updateOptions( getOptions() ); } + + else if ( o == _collapsed_with_average_height_cbmi ) { + if ( _collapsed_with_average_height_cbmi.isSelected() ) { + _collapsed_with_average_height_cbmi.setSelected( true ); + } + updateOptions( getOptions() ); + } else if ( o == _right_line_up_domains_cbmi ) { if ( _right_line_up_domains_cbmi.isSelected() ) { _line_up_renderable_data_cbmi.setSelected( true ); @@ -1212,6 +1214,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { customizeCheckBoxMenuItem( _convex_type_cbmi, false ); customizeCheckBoxMenuItem( _unrooted_type_cbmi, false ); customizeCheckBoxMenuItem( _circular_type_cbmi, false ); + _triangular_type_cbmi.setToolTipText( "not suitable for phylograms" ); + _curved_type_cbmi.setToolTipText( "not suitable for phylograms" ); _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE ); _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE ); initializeTypeMenu( getOptions() ); @@ -1838,11 +1842,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) { options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP ); } - else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) { - options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); - } else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) { - options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); + options.setCladogramType( CLADOGRAM_TYPE.LINED_UP ); } options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null ) && _search_case_senstive_cbmi.isSelected() ); @@ -1939,6 +1940,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { if ( ( _parse_beast_style_extended_nexus_tags_cbmi != null ) && _parse_beast_style_extended_nexus_tags_cbmi.isEnabled() ) { options.setParseBeastStyleExtendedNexusTags(_parse_beast_style_extended_nexus_tags_cbmi.isSelected() ); } + if ( ( _collapsed_with_average_height_cbmi != null ) && _collapsed_with_average_height_cbmi.isEnabled() ) { + options.setCollapsedWithAverageHeigh(_collapsed_with_average_height_cbmi.isSelected() ); + } + } void updateTypeCheckboxes( final Options options, final Object o ) { diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java index bc5b737..c44a75c 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java @@ -204,12 +204,10 @@ public final class MainFrameApplet extends MainFrame { getConfiguration() ) ); _options_jmenu .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) ); - _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) ); _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) ); _radio_group_1 = new ButtonGroup(); _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 ); + _radio_group_1.add( _non_lined_up_cladograms_rbmi ); _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) ); _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) ); _options_jmenu @@ -289,10 +287,8 @@ public final class MainFrameApplet extends MainFrame { customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi, getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ); - customizeRadioButtonMenuItem( _uniform_cladograms_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); - customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); + customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, + getOptions().getCladogramType() == CLADOGRAM_TYPE.LINED_UP ); customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() ); customizeCheckBoxMenuItem( _label_direction_cbmi, getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 40fc4bc..3baabd1 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -42,7 +42,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import javax.swing.ButtonGroup; @@ -118,7 +117,6 @@ public final class MainFrameApplication extends MainFrame { // Application-only print menu items private JMenuItem _collapse_below_threshold; private JMenuItem _collapse_below_branch_length; - private JMenuItem _collapse_by_taxonomic_rank; private ButtonGroup _radio_group_1; private ButtonGroup _radio_group_2; // Others: @@ -435,12 +433,7 @@ public final class MainFrameApplication extends MainFrame { } collapseBelowThreshold(); } - else if ( o == _collapse_by_taxonomic_rank ) { - if ( isSubtreeDisplayed() ) { - return; - } - collapseByTaxonomicRank(); - } + else if ( o == _collapse_below_branch_length ) { if ( isSubtreeDisplayed() ) { return; @@ -983,7 +976,7 @@ public final class MainFrameApplication extends MainFrame { } } - private void collapse( final Phylogeny phy ) { + private void collapseBelowThreshold( final Phylogeny phy ) { final PhylogenyNodeIterator it = phy.iteratorPostorder(); final List to_be_removed = new ArrayList(); double min_support = Double.MAX_VALUE; @@ -1051,27 +1044,6 @@ public final class MainFrameApplication extends MainFrame { } } - private void collapseByTaxonomicRank() { - if ( _mainpanel.getCurrentTreePanel() != null ) { - final Map present_ranks = AptxUtil.getRankCounts( _mainpanel.getCurrentTreePanel().getPhylogeny()); - final String[] ranks = AptxUtil.getAllPossibleRanks(present_ranks); - String rank = ( String ) JOptionPane - .showInputDialog( this, - "What rank should the collapsing be based on", - "Rank Selection", - JOptionPane.QUESTION_MESSAGE, - null, - ranks, - null ); - if ( !ForesterUtil.isEmpty( rank ) ) { - if ( rank.indexOf( '(' ) > 0 ) { - rank = rank.substring( 0, rank.indexOf( '(' ) ).trim(); - } - _mainpanel.getCurrentTreePanel().collapseByTaxonomicRank( rank ); - } - } - } - private void collapseBelowBranchLengthThreshold() { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); @@ -1135,7 +1107,7 @@ public final class MainFrameApplication extends MainFrame { } if ( success && ( m >= 0.0 ) ) { setMinNotCollapseConfidenceValue( m ); - collapse( phy ); + collapseBelowThreshold( phy ); } } } @@ -1844,12 +1816,10 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) ); _options_jmenu .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) ); - _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) ); _options_jmenu.add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( NON_LINED_UP_CLADOGRAMS_LABEL ) ); _radio_group_1 = new ButtonGroup(); _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 ); + _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 @@ -1858,8 +1828,16 @@ public final class MainFrameApplication extends MainFrame { .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( _collapsed_with_average_height_cbmi = new JCheckBoxMenuItem( "Proportional Height of Collapsed Subtrees" ) ); + + _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( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) ); @@ -1962,12 +1940,11 @@ public final class MainFrameApplication extends MainFrame { customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() ); customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() ); customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); + customizeCheckBoxMenuItem( _collapsed_with_average_height_cbmi, getOptions().isCollapsedWithAverageHeigh() ); customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi, getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ); - customizeRadioButtonMenuItem( _uniform_cladograms_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, - getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); + getOptions().getCladogramType() == CLADOGRAM_TYPE.LINED_UP ); customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() ); customizeCheckBoxMenuItem( _label_direction_cbmi, getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL ); @@ -2058,12 +2035,9 @@ public final class MainFrameApplication extends MainFrame { _delete_not_selected_nodes_item.setToolTipText( "To delete all not selected external nodes" ); customizeJMenuItem( _delete_not_selected_nodes_item ); _tools_menu.addSeparator(); - _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) ); + _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Single Taxonomy-Subtrees" ) ); customizeJMenuItem( _collapse_species_specific_subtrees ); - _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse species-specific subtrees" ); - _tools_menu.add( _collapse_by_taxonomic_rank = new JMenuItem( "Collapse By Taxonomic Rank" ) ); - customizeJMenuItem( _collapse_by_taxonomic_rank ); - _collapse_by_taxonomic_rank.setToolTipText( "To (reversibly) collapse subtrees by taxonomic rank" ); + _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse subtrees associated with only one taxonomy (such as species specific subtrees)" ); _tools_menu .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) ); customizeJMenuItem( _collapse_below_threshold ); diff --git a/forester/java/src/org/forester/archaeopteryx/Options.java b/forester/java/src/org/forester/archaeopteryx/Options.java index 8494510..4241797 100644 --- a/forester/java/src/org/forester/archaeopteryx/Options.java +++ b/forester/java/src/org/forester/archaeopteryx/Options.java @@ -41,7 +41,7 @@ import org.forester.util.ForesterUtil; final public class Options { public static enum CLADOGRAM_TYPE { - EXT_NODE_SUM_DEP, NON_LINED_UP, TOTAL_NODE_SUM_DEP; + LINED_UP, NON_LINED_UP; } public static enum NODE_LABEL_DIRECTION { @@ -120,7 +120,8 @@ final public class Options { private boolean _right_align_domains; private boolean _color_all_found_nodes_when_coloring_subtree; private boolean _parse_beast_style_extended_nexus_tags; - + private boolean _collapsed_with_average_height; + private Options() { init(); } @@ -224,6 +225,7 @@ final public class Options { _ext_desc_data_to_return = NodeDataField.UNKNOWN; _line_up_renderable_node_data = true; _right_align_domains = false; + _collapsed_with_average_height= true; } final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) { @@ -598,7 +600,17 @@ final public class Options { return _parse_beast_style_extended_nexus_tags; } - final void setParseBeastStyleExtendedNexusTags( boolean parse_beast_style_extended_nexus_tags ) { + final void setParseBeastStyleExtendedNexusTags( final boolean parse_beast_style_extended_nexus_tags ) { _parse_beast_style_extended_nexus_tags = parse_beast_style_extended_nexus_tags; } + + final boolean isCollapsedWithAverageHeigh() { + return _collapsed_with_average_height; + } + + final void setCollapsedWithAverageHeigh( final boolean collapsed_with_average_height ) { + _collapsed_with_average_height = collapsed_with_average_height; + } + + } diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index c60d06a..ef650bc 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -195,128 +195,138 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } } - public final static boolean SPECIAL_DOMAIN_COLORING = true; - final static Cursor ARROW_CURSOR = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ); - final static Cursor CUT_CURSOR = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR ); - final static Cursor HAND_CURSOR = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ); - final static Cursor MOVE_CURSOR = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR ); - final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ); - final private static double _180_OVER_PI = 180.0 / Math.PI; - private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI / 32 ); - private final static int CONFIDENCE_LEFT_MARGIN = 4; - private final static int EURO_D = 10; - private final static NumberFormat FORMATTER_BRANCH_LENGTH; - private final static NumberFormat FORMATTER_CONFIDENCE; - private static final float HALF_PI = ( float ) ( Math.PI / 2.0 ); - private final static int LIMIT_FOR_HQ_RENDERING = 2000; - private final static int MAX_NODE_FRAMES = 10; - private final static int MAX_SUBTREES = 100; - private final static int MIN_ROOT_LENGTH = 3; - private final static int MOVE = 20; - private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node"; - private static final float ONEHALF_PI = ( float ) ( 1.5 * Math.PI ); - private static final short OV_BORDER = 10; - private final static double OVERVIEW_FOUND_NODE_BOX_SIZE = 2; - private final static double OVERVIEW_FOUND_NODE_BOX_SIZE_HALF = 1; - private static final float PI = ( float ) ( Math.PI ); - final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(), - Font.PLAIN, - 12 ); - private static final float ROUNDED_D = 8; - private final static long serialVersionUID = -978349745916505029L; - private static final BasicStroke STROKE_0025 = new BasicStroke( 0.025f ); - private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f ); - private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f ); - private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f ); - private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f ); - private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f ); - private static final BasicStroke STROKE_1 = new BasicStroke( 1f ); - private static final BasicStroke STROKE_2 = new BasicStroke( 2f ); - private static final double TWO_PI = 2 * Math.PI; - private final static int WIGGLE = 2; - private static final String SHOW_ONLY_THIS_CONF_TYPE = null; //TODO remove me - HashMap _nodeid_dist_to_leaf = new HashMap(); - final private Arc2D _arc = new Arc2D.Double(); - private AffineTransform _at; - private int _circ_max_depth; - final private Set _collapsed_external_nodeid_set = new HashSet(); - private JColorChooser _color_chooser = null; - private Configuration _configuration = null; - private ControlPanel _control_panel = null; - private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float(); - private Set _current_external_nodes = null; - private StringBuilder _current_external_nodes_data_buffer = new StringBuilder(); - private int _current_external_nodes_data_buffer_change_counter = 0; - private int _domain_structure_e_value_thr_exp = AptxConstants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP; - private double _domain_structure_width = AptxConstants.DOMAIN_STRUCTURE_DEFAULT_WIDTH; - private int _dynamic_hiding_factor = 0; - private boolean _edited = false; - private final Ellipse2D _ellipse = new Ellipse2D.Float(); - private int _external_node_index = 0; - private Set _found_nodes_0 = null; - private Set _found_nodes_1 = null; - private final FontRenderContext _frc = new FontRenderContext( null, - false, - false ); - private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR; - private PhylogenyNode _highlight_node = null; - private boolean _in_ov = false; - private boolean _in_ov_rect = false; - private float _last_drag_point_x = 0; - private float _last_drag_point_y = 0; - private final Line2D _line = new Line2D.Float(); - private int _longest_ext_node_info = 0; - private PhylogenyNode _ext_node_with_longest_txt_info = null; - private MainPanel _main_panel = null; - private double _max_distance_to_root = -1; - private Popup _node_desc_popup; - private int _node_frame_index = 0; - private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ]; - private JPopupMenu _node_popup_menu = null; - private JMenuItem _node_popup_menu_items[] = null; - private PhylogenyNode[] _nodes_in_preorder = null; - private Options _options = null; - private float _ov_max_height = 0; - private float _ov_max_width = 0; - private boolean _ov_on = false; - private final Rectangle2D _ov_rectangle = new Rectangle2D.Float(); - private final Rectangle _ov_virtual_rectangle = new Rectangle(); - private float _ov_x_correction_factor = 0.0f; - private float _ov_x_distance = 0; - private int _ov_x_position = 0; - private float _ov_y_distance = 0; - private int _ov_y_position = 0; - private int _ov_y_start = 0; - private final boolean _phy_has_branch_lengths; - private Phylogeny _phylogeny = null; - private final Path2D.Float _polygon = new Path2D.Float(); - private final StringBuffer _popup_buffer = new StringBuffer(); - private final QuadCurve2D _quad_curve = new QuadCurve2D.Float(); - private Sequence _query_sequence = null; - private final Rectangle2D _rectangle = new Rectangle2D.Float(); - private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING, - RenderingHints.VALUE_RENDER_DEFAULT ); - private JTextArea _rollover_popup; - private PhylogenyNode _root; - private final StringBuilder _sb = new StringBuilder(); - private double _scale_distance = 0.0; - private String _scale_label = null; - private DescriptiveStatistics _statistics_for_vector_data; - private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ]; - private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ]; - private int _subtree_index = 0; - private File _treefile = null; - private float _urt_factor = 1; - private float _urt_factor_ov = 1; - final private HashMap _urt_nodeid_angle_map = new HashMap(); - final private HashMap _urt_nodeid_index_map = new HashMap(); - private double _urt_starting_angle = ( float ) ( Math.PI / 2 ); - private float _x_correction_factor = 0.0f; - private float _x_distance = 0.0f; - private float _y_distance = 0.0f; - private int _length_of_longest_text; - private int _longest_domain; - private Map _attributed_string_map = null; + public final static boolean SPECIAL_DOMAIN_COLORING = true; + final static Cursor ARROW_CURSOR = Cursor + .getPredefinedCursor( Cursor.DEFAULT_CURSOR ); + final static Cursor CUT_CURSOR = Cursor + .getPredefinedCursor( Cursor.CROSSHAIR_CURSOR ); + final static Cursor HAND_CURSOR = Cursor + .getPredefinedCursor( Cursor.HAND_CURSOR ); + final static Cursor MOVE_CURSOR = Cursor + .getPredefinedCursor( Cursor.MOVE_CURSOR ); + final static Cursor WAIT_CURSOR = Cursor + .getPredefinedCursor( Cursor.WAIT_CURSOR ); + final private static double _180_OVER_PI = 180.0 / Math.PI; + private static final float ANGLE_ROTATION_UNIT = ( float ) ( Math.PI + / 32 ); + private final static int CONFIDENCE_LEFT_MARGIN = 4; + private final static int EURO_D = 10; + private final static NumberFormat FORMATTER_BRANCH_LENGTH; + private final static NumberFormat FORMATTER_CONFIDENCE; + private static final float HALF_PI = ( float ) ( Math.PI + / 2.0 ); + private final static int LIMIT_FOR_HQ_RENDERING = 2000; + private final static int MAX_NODE_FRAMES = 10; + private final static int MAX_SUBTREES = 100; + private final static int MIN_ROOT_LENGTH = 3; + private final static int MOVE = 20; + private final static String NODE_POPMENU_NODE_CLIENT_PROPERTY = "node"; + private static final float ONEHALF_PI = ( float ) ( 1.5 + * Math.PI ); + private static final short OV_BORDER = 10; + private final static double OVERVIEW_FOUND_NODE_BOX_SIZE = 2; + private final static double OVERVIEW_FOUND_NODE_BOX_SIZE_HALF = 1; + private static final float PI = ( float ) ( Math.PI ); + final private static Font POPUP_FONT = new Font( Configuration + .getDefaultFontFamilyName(), Font.PLAIN, 12 ); + private static final float ROUNDED_D = 8; + private final static long serialVersionUID = -978349745916505029L; + private static final BasicStroke STROKE_0025 = new BasicStroke( 0.025f ); + private static final BasicStroke STROKE_005 = new BasicStroke( 0.05f ); + private static final BasicStroke STROKE_01 = new BasicStroke( 0.1f ); + private static final BasicStroke STROKE_025 = new BasicStroke( 0.25f ); + private static final BasicStroke STROKE_05 = new BasicStroke( 0.5f ); + private static final BasicStroke STROKE_075 = new BasicStroke( 0.75f ); + private static final BasicStroke STROKE_1 = new BasicStroke( 1f ); + private static final BasicStroke STROKE_2 = new BasicStroke( 2f ); + private static final double TWO_PI = 2 * Math.PI; + private final static int WIGGLE = 2; + private static final String SHOW_ONLY_THIS_CONF_TYPE = null; //TODO remove me + HashMap _nodeid_dist_to_leaf = new HashMap(); + final private Arc2D _arc = new Arc2D.Double(); + private AffineTransform _at; + private int _circ_max_depth; + final private Set _collapsed_external_nodeid_set = new HashSet(); + private JColorChooser _color_chooser = null; + private Configuration _configuration = null; + private ControlPanel _control_panel = null; + private final CubicCurve2D _cubic_curve = new CubicCurve2D.Float(); + private Set _current_external_nodes = null; + private StringBuilder _current_external_nodes_data_buffer = new StringBuilder(); + private int _current_external_nodes_data_buffer_change_counter = 0; + private int _domain_structure_e_value_thr_exp = AptxConstants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP; + private double _domain_structure_width = AptxConstants.DOMAIN_STRUCTURE_DEFAULT_WIDTH; + private int _dynamic_hiding_factor = 0; + private boolean _edited = false; + private final Ellipse2D _ellipse = new Ellipse2D.Float(); + private int _external_node_index = 0; + private Set _found_nodes_0 = null; + private Set _found_nodes_1 = null; + private final FontRenderContext _frc = new FontRenderContext( null, + false, + false ); + private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR; + private PhylogenyNode _highlight_node = null; + private boolean _in_ov = false; + private boolean _in_ov_rect = false; + private float _last_drag_point_x = 0; + private float _last_drag_point_y = 0; + private final Line2D _line = new Line2D.Float(); + private int _longest_ext_node_info = 0; + private PhylogenyNode _ext_node_with_longest_txt_info = null; + private MainPanel _main_panel = null; + private double _max_distance_to_root = -1; + private Popup _node_desc_popup; + private int _node_frame_index = 0; + private final NodeFrame[] _node_frames = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ]; + private JPopupMenu _node_popup_menu = null; + private JMenuItem _node_popup_menu_items[] = null; + private PhylogenyNode[] _nodes_in_preorder = null; + private Options _options = null; + private float _ov_max_height = 0; + private float _ov_max_width = 0; + private boolean _ov_on = false; + private final Rectangle2D _ov_rectangle = new Rectangle2D.Float(); + private final Rectangle _ov_virtual_rectangle = new Rectangle(); + private float _ov_x_correction_factor = 0.0f; + private float _ov_x_distance = 0; + private int _ov_x_position = 0; + private float _ov_y_distance = 0; + private int _ov_y_position = 0; + private int _ov_y_start = 0; + private final boolean _phy_has_branch_lengths; + private Phylogeny _phylogeny = null; + private final Path2D.Float _polygon = new Path2D.Float(); + private final StringBuffer _popup_buffer = new StringBuffer(); + private final QuadCurve2D _quad_curve = new QuadCurve2D.Float(); + private Sequence _query_sequence = null; + private final Rectangle2D _rectangle = new Rectangle2D.Float(); + private final RenderingHints _rendering_hints = new RenderingHints( RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_DEFAULT ); + private JTextArea _rollover_popup; + private PhylogenyNode _root; + private final StringBuilder _sb = new StringBuilder(); + private double _scale_distance = 0.0; + private String _scale_label = null; + private DescriptiveStatistics _statistics_for_vector_data; + private final Phylogeny[] _sub_phylogenies = new Phylogeny[ TreePanel.MAX_SUBTREES ]; + private final PhylogenyNode[] _sub_phylogenies_temp_roots = new PhylogenyNode[ TreePanel.MAX_SUBTREES ]; + private int _subtree_index = 0; + private File _treefile = null; + private float _urt_factor = 1; + private float _urt_factor_ov = 1; + final private HashMap _urt_nodeid_angle_map = new HashMap(); + final private HashMap _urt_nodeid_index_map = new HashMap(); + private double _urt_starting_angle = ( float ) ( Math.PI + / 2 ); + private float _x_correction_factor = 0.0f; + private float _x_distance = 0.0f; + private float _y_distance = 0.0f; + private int _length_of_longest_text; + private int _longest_domain; + private Map _attributed_string_map = null; + private int _depth_collapse_level = -1; + private int _rank_collapse_level = -1; static { final DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator( '.' ); @@ -361,8 +371,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee addMouseWheelListener( this ); calculateScaleDistance(); FORMATTER_CONFIDENCE.setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() ); - FORMATTER_BRANCH_LENGTH.setMaximumFractionDigits( configuration - .getNumberOfDigitsAfterCommaForBranchLengthValues() ); + FORMATTER_BRANCH_LENGTH + .setMaximumFractionDigits( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() ); } @Override @@ -636,11 +646,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.setColor( Color.BLACK ); } else if ( ( ( action == NodeClickAction.COPY_SUBTREE ) || ( action == NodeClickAction.CUT_SUBTREE ) - || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) || ( action == NodeClickAction.ADD_NEW_NODE ) ) - && ( getCutOrCopiedTree() != null ) - && ( getCopiedAndPastedNodes() != null ) - && !to_pdf - && !to_graphics_file && getCopiedAndPastedNodes().contains( node.getId() ) ) { + || ( action == NodeClickAction.DELETE_NODE_OR_SUBTREE ) || ( action == NodeClickAction.PASTE_SUBTREE ) + || ( action == NodeClickAction.ADD_NEW_NODE ) ) && ( getCutOrCopiedTree() != null ) + && ( getCopiedAndPastedNodes() != null ) && !to_pdf && !to_graphics_file + && getCopiedAndPastedNodes().contains( node.getId() ) ) { g.setColor( getTreeColorSet().getFoundColor0() ); } else if ( getControlPanel().isUseVisualStyles() && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) { @@ -678,7 +687,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) { - if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) { + if ( ForesterUtil + .seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) { type = 'p'; } else { @@ -720,7 +730,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee nodeTaxonomyDataAsSB( _ext_node_with_longest_txt_info.getNodeData().getTaxonomy(), sb ); } } - return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() ); } @@ -931,8 +940,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { al = new SubtreeColorizationActionListener( _color_chooser, node ); } - final JDialog dialog = JColorChooser - .createDialog( this, "Subtree colorization", true, _color_chooser, al, null ); + final JDialog dialog = JColorChooser.createDialog( this, + "Subtree colorization", + true, + _color_chooser, + al, + null ); setEdited( true ); dialog.setVisible( true ); } @@ -1080,7 +1093,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.draw( _arc ); } - final private void drawLine( final double x1, final double y1, final double x2, final double y2, final Graphics2D g ) { + final private void drawLine( final double x1, + final double y1, + final double x2, + final double y2, + final Graphics2D g ) { if ( ( x1 == x2 ) && ( y1 == y2 ) ) { return; } @@ -1123,7 +1140,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } - final private void drawRect( final float x, final float y, final float width, final float heigth, final Graphics2D g ) { + final private void drawRect( final float x, + final float y, + final float width, + final float heigth, + final Graphics2D g ) { _rectangle.setFrame( x, y, width, heigth ); g.draw( _rectangle ); } @@ -1416,7 +1437,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private void increaseOvSize() { - if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) ) + if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() + / 2 ) ) && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect() .getHeight() / 2 ) ) ) { setOvMaxWidth( getOvMaxWidth() + 5 ); @@ -1435,6 +1457,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee setTreeFile( null ); setEdited( false ); initializeOvSettings(); + resetDepthCollapseDepthValue(); + resetRankCollapseRankValue(); setStartingAngle( ( TWO_PI * 3 ) / 4 ); final ImageLoader il = new ImageLoader( this ); new Thread( il ).start(); @@ -1448,8 +1472,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final private boolean inOvVirtualRectangle( final int x, final int y ) { return ( ( x >= ( getOvVirtualRectangle().x - 1 ) ) && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) ) - && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y - + getOvVirtualRectangle().height + 1 ) ) ); + && ( y >= ( getOvVirtualRectangle().y - 1 ) ) + && ( y <= ( getOvVirtualRectangle().y + getOvVirtualRectangle().height + 1 ) ) ); } final private boolean inOvVirtualRectangle( final MouseEvent e ) { @@ -1472,12 +1496,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) { - if ( node.getNodeData().isHasTaxonomy() - && ( ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) - || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) - || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) || ( ( node - .getNodeData().getTaxonomy().getIdentifier() != null ) && !ForesterUtil.isEmpty( node - .getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) { + if ( node.getNodeData().isHasTaxonomy() && ( ( !ForesterUtil + .isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) + || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) + || ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) + || ( ( node.getNodeData().getTaxonomy().getIdentifier() != null ) + && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getIdentifier().getValue() ) ) ) ) { return true; } else { @@ -1511,25 +1535,21 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee y_dist = 40 + ( int ) getYdistance(); } return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) ) - || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) || ( ( node.getParent() != null ) && ( node - .getParent().getXcoord() > getVisibleRect().getMaxX() ) ) ); + || ( node.getYcoord() > ( getVisibleRect().getMaxY() + y_dist ) ) + || ( ( node.getParent() != null ) && ( node.getParent().getXcoord() > getVisibleRect().getMaxX() ) ) ); } final private boolean isNodeDataInvisibleUnrootedCirc( final PhylogenyNode node ) { return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) ) || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) ) - || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect() - .getMaxX() + 20 ) ) ); + || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) + || ( node.getXcoord() > ( getVisibleRect().getMaxX() + 20 ) ) ); } final private boolean isNonLinedUpCladogram() { return getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP; } - final private boolean isUniformBranchLengthsForCladogram() { - return getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP; - } - final private void keyPressedCalls( final KeyEvent e ) { if ( isOvOn() && ( getMousePosition() != null ) && ( getMousePosition().getLocation() != null ) ) { if ( inOvVirtualRectangle( getMousePosition().x, getMousePosition().y ) ) { @@ -1842,7 +1862,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } sb.append( node.getNodeData().getSequence().getGeneName() ); } - if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) { + if ( getControlPanel().isShowSeqNames() + && ( node.getNodeData().getSequence().getName().length() > 0 ) ) { if ( sb.length() > 0 ) { sb.append( " " ); } @@ -1945,7 +1966,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), isApplet() ? obtainApplet() : null, - "_aptx_seq" ); + "_aptx_seq" ); } catch ( final IOException e ) { AptxUtil.showErrorMessage( this, e.toString() ); @@ -1973,7 +1994,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), isApplet() ? obtainApplet() : null, - "_aptx_seq" ); + "_aptx_seq" ); } catch ( final IOException e ) { AptxUtil.showErrorMessage( this, e.toString() ); @@ -2007,11 +2028,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee e.printStackTrace(); } } - else if ( ( tax.getIdentifier() != null ) - && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) + else if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) && !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) - && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" ) || tax.getIdentifier().getProvider() - .equalsIgnoreCase( "uniprot" ) ) ) { + && ( tax.getIdentifier().getProvider().equalsIgnoreCase( "ncbi" ) + || tax.getIdentifier().getProvider().equalsIgnoreCase( "uniprot" ) ) ) { try { uri_str = "http://www.uniprot.org/taxonomy/" + URLEncoder.encode( tax.getIdentifier().getValue(), ForesterConstants.UTF_8 ); @@ -2056,7 +2076,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), isApplet() ? obtainApplet() : null, - "_aptx_tax" ); + "_aptx_tax" ); } catch ( final IOException e ) { AptxUtil.showErrorMessage( this, e.toString() ); @@ -2085,21 +2105,29 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } if ( !node.isRoot() ) { if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) { - TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent() - .getXcoord() + EURO_D, node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), g ); + TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), + node.getParent().getXcoord() + EURO_D, + node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), + g ); } else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) { - TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent() - .getXcoord() + ROUNDED_D, node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), g ); + TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), + node.getParent().getXcoord() + ROUNDED_D, + node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), + g ); } else { - TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), node.getParent() - .getXcoord() + 3, node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), g ); + TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), + node.getParent().getXcoord() + 3, + node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), + g ); } } else { - TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), 3, node.getYcoord() - - getTreeFontSet().getSmallMaxDescent(), g ); + TreePanel.drawString( FORMATTER_BRANCH_LENGTH.format( node.getDistanceToParent() ), + 3, + node.getYcoord() - getTreeFontSet().getSmallMaxDescent(), + g ); } } @@ -2120,8 +2148,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) { final float dx = x2 - x1; final float dy = y2 - y1; - _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1 - + ( dy * 0.8f ), x2, y2 ); + _cubic_curve.setCurve( x1, + y1, + x1 + ( dx * 0.4f ), + y1 + ( dy * 0.2f ), + x1 + ( dx * 0.6f ), + y1 + ( dy * 0.8f ), + x2, + y2 ); ( g ).draw( _cubic_curve ); } else { @@ -2159,8 +2193,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CURVED ) { final float dx = x2 - x1; final float dy = y2 - y1; - _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1 - + ( dy * 0.8f ), x2, y2 ); + _cubic_curve.setCurve( x1, + y1, + x1 + ( dx * 0.4f ), + y1 + ( dy * 0.2f ), + x1 + ( dx * 0.6f ), + y1 + ( dy * 0.8f ), + x2, + y2 ); g.draw( _cubic_curve ); } else { @@ -2170,10 +2210,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( node.isFirstChildNode() || node.isLastChildNode() || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) { - if ( !to_graphics_file - && !to_pdf - && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect() - .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) { + if ( !to_graphics_file && !to_pdf + && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) + && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) + || ( ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) + && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) { // Do nothing. } else { @@ -2206,8 +2247,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } // draw the horizontal line - if ( !to_graphics_file && !to_pdf - && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) { + if ( !to_graphics_file && !to_pdf && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) + || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) { return; } float x1_r = 0; @@ -2362,23 +2403,49 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee c = getTreeColorSet().getCollapseFillColor(); } double d = node.getAllExternalDescendants().size(); - if ( d > 1000 ) { - d = ( 3 * _y_distance ) / 3; + float xxx; + double s = 0; + if ( getControlPanel().isDrawPhylogram() ) { + if ( d > 1000 ) { + d = 0.75 * _y_distance; + } + else { + d = 0.25 * Math.log10( d ) * _y_distance; + } + final float half_box_size = 0.5f * getOptions().getDefaultNodeShapeSize(); + if ( d < half_box_size ) { + d = half_box_size; + } + _polygon.reset(); + final float xx = node.getXcoord() - ( getOptions().getDefaultNodeShapeSize() ); + xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1; + _polygon.moveTo( xxx, node.getYcoord() + 0.5 ); + _polygon.lineTo( xxx, node.getYcoord() - 0.5 ); + s = _options.isCollapsedWithAverageHeigh() + ? PhylogenyMethods.calculateAverageTreeHeight( node ) * _x_correction_factor : 1; + _polygon.lineTo( node.getXcoord() + s, node.getYcoord() - d ); + _polygon.lineTo( node.getXcoord() + s, node.getYcoord() + d ); + _polygon.closePath(); } else { - d = ( Math.log10( d ) * _y_distance ) / 2.5; - } - final int box_size = getOptions().getDefaultNodeShapeSize() + 1; - if ( d < box_size ) { - d = box_size; - } - final float xx = node.getXcoord() - ( 2 * box_size ); - final float xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1; - _polygon.reset(); - _polygon.moveTo( xxx, node.getYcoord() ); - _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d ); - _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d ); - _polygon.closePath(); + if ( d > 1000 ) { + d = _y_distance; + } + else { + d = ( Math.log10( d ) * _y_distance ) / 2.5; + } + final int box_size = getOptions().getDefaultNodeShapeSize() + 1; + if ( d < box_size ) { + d = box_size; + } + final float xx = node.getXcoord() - ( 2 * box_size ); + xxx = xx > ( node.getParent().getXcoord() + 1 ) ? xx : node.getParent().getXcoord() + 1; + _polygon.reset(); + _polygon.moveTo( xxx, node.getYcoord() ); + _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d ); + _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d ); + _polygon.closePath(); + } if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) { g.setColor( c ); g.fill( _polygon ); @@ -2390,13 +2457,18 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.draw( _polygon ); } else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { - g.setPaint( new GradientPaint( xxx, node.getYcoord(), getBackground(), node.getXcoord(), ( float ) ( node - .getYcoord() - d ), c, false ) ); + g.setPaint( new GradientPaint( xxx, + node.getYcoord(), + getBackground(), + node.getXcoord(), + ( float ) ( node.getYcoord() - d ), + c, + false ) ); g.fill( _polygon ); g.setPaint( c ); g.draw( _polygon ); } - paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes ); + paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, s ); } final private void paintConfidenceValues( final Graphics2D g, @@ -2408,9 +2480,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee Collections.sort( confidences ); final StringBuilder sb = new StringBuilder(); for( final Confidence confidence : confidences ) { - if ( ForesterUtil.isEmpty( SHOW_ONLY_THIS_CONF_TYPE ) - || ( !ForesterUtil.isEmpty( confidence.getType() ) && confidence.getType() - .equalsIgnoreCase( SHOW_ONLY_THIS_CONF_TYPE ) ) ) { + if ( ForesterUtil.isEmpty( SHOW_ONLY_THIS_CONF_TYPE ) || ( !ForesterUtil.isEmpty( confidence.getType() ) + && confidence.getType().equalsIgnoreCase( SHOW_ONLY_THIS_CONF_TYPE ) ) ) { final double value = confidence.getValue(); if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) { if ( value < getOptions().getMinConfidenceValue() ) { @@ -2422,14 +2493,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { not_first = true; } - sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions() - .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); + sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil + .round( value, getOptions().getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); if ( getOptions().isShowConfidenceStddev() ) { if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) { sb.append( "(" ); - sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence - .getStandardDeviation(), getOptions() - .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); + sb.append( FORMATTER_CONFIDENCE + .format( ForesterUtil.round( confidence.getStandardDeviation(), + getOptions() + .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); sb.append( ")" ); } } @@ -2454,11 +2526,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final String conf_str = sb.toString(); TreePanel.drawString( conf_str, - parent_x - + ( ( x - parent_x - getTreeFontSet().getFontMetricsSmall() - .stringWidth( conf_str ) ) / 2 ), - ( node.getYcoord() + getTreeFontSet().getSmallMaxAscent() ) - 1, - g ); + parent_x + ( ( x - parent_x + - getTreeFontSet().getFontMetricsSmall().stringWidth( conf_str ) ) / 2 ), + ( node.getYcoord() + getTreeFontSet().getSmallMaxAscent() ) - 1, + g ); } } @@ -2474,25 +2545,25 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( AptxConstants.SPECIAL_CUSTOM ) { g.setColor( Color.BLUE ); } - TreePanel - .drawString( gained, - parent_x - + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( gained ) ) / 2 ), - ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ), - g ); + TreePanel.drawString( gained, + parent_x + ( ( x - parent_x + - getFontMetricsForLargeDefaultFont().stringWidth( gained ) ) / 2 ), + ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ), + g ); g.setColor( getTreeColorSet().getLostCharactersColor() ); - TreePanel - .drawString( lost, - parent_x - + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( lost ) ) / 2 ), - ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ), - g ); + TreePanel.drawString( lost, + parent_x + ( ( x - parent_x + - getFontMetricsForLargeDefaultFont().stringWidth( lost ) ) / 2 ), + ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ), + g ); } } private void paintMolecularSequences( final Graphics2D g, final PhylogenyNode node, final boolean to_pdf ) { - final RenderableMsaSequence rs = RenderableMsaSequence.createInstance( node.getNodeData().getSequence() - .getMolecularSequence(), node.getNodeData().getSequence().getType(), getConfiguration() ); + final RenderableMsaSequence rs = RenderableMsaSequence + .createInstance( node.getNodeData().getSequence().getMolecularSequence(), + node.getNodeData().getSequence().getType(), + getConfiguration() ); if ( rs != null ) { final int default_height = 8; final float y = getYdistance(); @@ -2543,17 +2614,20 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() ) || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() ) || ( getOptions().isShowDefaultNodeShapesForMarkedNodes() - && ( node.getNodeData().getNodeVisualData() != null ) && ( !node.getNodeData() - .getNodeVisualData().isEmpty() ) ) - || ( getControlPanel().isUseVisualStyles() && ( ( node.getNodeData().getNodeVisualData() != null ) && ( ( node - .getNodeData().getNodeVisualData().getNodeColor() != null ) - || ( node.getNodeData().getNodeVisualData().getSize() != NodeVisualData.DEFAULT_SIZE ) - || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT ) || ( node - .getNodeData().getNodeVisualData().getShape() != NodeShape.DEFAULT ) ) ) ) - || ( getControlPanel().isEvents() && node.isHasAssignedEvent() && ( node.getNodeData().getEvent() - .isDuplication() - || node.getNodeData().getEvent().isSpeciation() || node.getNodeData().getEvent() - .isSpeciationOrDuplication() ) ) ) { + && ( node.getNodeData().getNodeVisualData() != null ) + && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) + || ( getControlPanel().isUseVisualStyles() + && ( ( node.getNodeData().getNodeVisualData() != null ) + && ( ( node.getNodeData().getNodeVisualData().getNodeColor() != null ) + || ( node.getNodeData().getNodeVisualData() + .getSize() != NodeVisualData.DEFAULT_SIZE ) + || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT ) + || ( node.getNodeData().getNodeVisualData() + .getShape() != NodeShape.DEFAULT ) ) ) ) + || ( getControlPanel().isEvents() && node.isHasAssignedEvent() + && ( node.getNodeData().getEvent().isDuplication() + || node.getNodeData().getEvent().isSpeciation() + || node.getNodeData().getEvent().isSpeciationOrDuplication() ) ) ) { NodeVisualData vis = null; if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) { @@ -2643,8 +2717,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } if ( shape == NodeShape.CIRCLE ) { if ( fill == NodeFill.GRADIENT ) { - drawOvalGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE - : outline_color, to_pdf ? outline_color : getBackground(), outline_color ); + drawOvalGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, + g, + to_pdf ? Color.WHITE : outline_color, + to_pdf ? outline_color : getBackground(), + outline_color ); } else if ( fill == NodeFill.NONE ) { Color background = getBackground(); @@ -2672,8 +2752,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) { if ( fill == NodeVisualData.NodeFill.GRADIENT ) { - drawRectGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE - : outline_color, to_pdf ? outline_color : getBackground(), outline_color ); + drawRectGradient( x - half_box_size, + y - half_box_size, + box_size, + box_size, + g, + to_pdf ? Color.WHITE : outline_color, + to_pdf ? outline_color : getBackground(), + outline_color ); } else if ( fill == NodeVisualData.NodeFill.NONE ) { Color background = getBackground(); @@ -2706,14 +2792,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final PhylogenyNode node, final boolean to_graphics_file, final boolean to_pdf, - final boolean is_in_found_nodes ) { + final boolean is_in_found_nodes, + final double add ) { if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) { return 0; } if ( getControlPanel().isWriteBranchLengthValues() && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) - || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) ) - && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) { + || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) + || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) ) + && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) { paintBranchLength( g, node, to_pdf, to_graphics_file ); } if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) { @@ -2721,17 +2809,18 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } _sb.setLength( 0 ); int x = 0; + if ( add > 0 ) { + x += add; + } final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2; - if ( getControlPanel().isShowTaxonomyImages() - && ( getImageMap() != null ) - && !getImageMap().isEmpty() - && node.getNodeData().isHasTaxonomy() - && ( ( node.getNodeData().getTaxonomy().getUris() != null ) && !node.getNodeData().getTaxonomy() - .getUris().isEmpty() ) ) { + if ( getControlPanel().isShowTaxonomyImages() && ( getImageMap() != null ) && !getImageMap().isEmpty() + && node.getNodeData().isHasTaxonomy() && ( ( node.getNodeData().getTaxonomy().getUris() != null ) + && !node.getNodeData().getTaxonomy().getUris().isEmpty() ) ) { x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g ); } - if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel() - .isShowTaxonomyCommonNames() || getControlPanel().isShowTaxonomyRank() ) && node.getNodeData().isHasTaxonomy() ) { + if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() + || getControlPanel().isShowTaxonomyCommonNames() || getControlPanel().isShowTaxonomyRank() ) + && node.getNodeData().isHasTaxonomy() ) { x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x ); } setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() ); @@ -2778,15 +2867,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { final List seqRelations = node.getNodeData().getSequence().getSequenceRelations(); for( final SequenceRelation seqRelation : seqRelations ) { - final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) || seqRelation - .getRef1().isEqual( _query_sequence ) ) - && seqRelation.getType().equals( getControlPanel().getSequenceRelationTypeBox() - .getSelectedItem() ); + final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence ) + || seqRelation.getRef1().isEqual( _query_sequence ) ) + && seqRelation.getType() + .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() ); if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query final double linePosX = node.getXcoord() + 2 + half_box_size; - final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() || ( seqRelation - .getConfidence() == null ) ) ? null : " (" + seqRelation.getConfidence().getValue() - + ")"; + final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence() + || ( seqRelation.getConfidence() == null ) ) ? null + : " (" + seqRelation.getConfidence().getValue() + ")"; if ( sConfidence != null ) { float confidenceX = pos_x; if ( sb_str.length() > 0 ) { @@ -2795,7 +2884,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc ) - .getBounds().getWidth(); + .getBounds().getWidth(); TreePanel.drawString( sConfidence, confidenceX, pos_y, g ); x += CONFIDENCE_LEFT_MARGIN + confidenceWidth; } @@ -2808,8 +2897,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { nodeTextBoundsWidth += 2; } - g.drawLine( ( int ) linePosX + 1, 3 + ( int ) pos_y, ( int ) linePosX + x - + nodeTextBoundsWidth, 3 + ( int ) pos_y ); + g.drawLine( ( int ) linePosX + 1, + 3 + ( int ) pos_y, + ( int ) linePosX + x + nodeTextBoundsWidth, + 3 + ( int ) pos_y ); break; } } @@ -2843,9 +2934,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else if ( getControlPanel().isColorAccordingToAnnotation() ) { g.setColor( calculateColorForAnnotation( ann ) ); } - final String ann_str = TreePanelUtil.createAnnotationString( ann, getOptions().isShowAnnotationRefSource() ); - TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord() - + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ), g ); + final String ann_str = TreePanelUtil.createAnnotationString( ann, + getOptions().isShowAnnotationRefSource() ); + TreePanel.drawString( ann_str, + node.getXcoord() + x + 3 + half_box_size, + node.getYcoord() + + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ), + g ); _sb.setLength( 0 ); _sb.append( ann_str ); if ( _sb.length() > 0 ) { @@ -2870,22 +2965,28 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } if ( getControlPanel().isShowBinaryCharacters() ) { TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer() - .toString(), node.getXcoord() + x + 1 + half_box_size, node.getYcoord() - + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ), g ); - paintGainedAndLostCharacters( g, node, node.getNodeData().getBinaryCharacters() - .getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters() - .getLostCharactersAsStringBuffer().toString() ); + .toString(), + node.getXcoord() + x + 1 + half_box_size, + node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() + / down_shift_factor ), + g ); + paintGainedAndLostCharacters( g, + node, + node.getNodeData().getBinaryCharacters() + .getGainedCharactersAsStringBuffer().toString(), + node.getNodeData().getBinaryCharacters() + .getLostCharactersAsStringBuffer().toString() ); } else { - TreePanel - .drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(), - node.getXcoord() + x + 4 + half_box_size, - node.getYcoord() - + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ), - g ); - paintGainedAndLostCharacters( g, node, "+" - + node.getNodeData().getBinaryCharacters().getGainedCount(), "-" - + node.getNodeData().getBinaryCharacters().getLostCount() ); + TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(), + node.getXcoord() + x + 4 + half_box_size, + node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() + / down_shift_factor ), + g ); + paintGainedAndLostCharacters( g, + node, + "+" + node.getNodeData().getBinaryCharacters().getGainedCount(), + "-" + node.getNodeData().getBinaryCharacters().getLostCount() ); } } } @@ -2909,8 +3010,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _sb.setLength( 0 ); _sb.append( " " ); if ( node.getNodeData().isHasTaxonomy() - && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel() - .isShowTaxonomyCommonNames() ) ) { + && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() + || getControlPanel().isShowTaxonomyCommonNames() ) ) { final Taxonomy taxonomy = node.getNodeData().getTaxonomy(); if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) { _sb.append( taxonomy.getTaxonomyCode() ); @@ -2958,7 +3059,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _sb.append( node.getName() ); } if ( node.getNodeData().isHasSequence() ) { - if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) { + if ( getControlPanel().isShowSequenceAcc() + && ( node.getNodeData().getSequence().getAccession() != null ) ) { if ( _sb.length() > 0 ) { _sb.append( " " ); } @@ -3038,15 +3140,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final private void paintNodeLite( final Graphics2D g, final PhylogenyNode node ) { if ( node.isCollapse() ) { - if ( !node.isRoot() && !node.getParent().isCollapse() ) { - paintCollapsedNode( g, node, false, false, false ); - } return; } if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) { g.setColor( getColorForFoundNode( node ) ); - drawRectFilled( node.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, node.getYSecondary() - - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, OVERVIEW_FOUND_NODE_BOX_SIZE, OVERVIEW_FOUND_NODE_BOX_SIZE, g ); + drawRectFilled( node.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, + node.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, + OVERVIEW_FOUND_NODE_BOX_SIZE, + OVERVIEW_FOUND_NODE_BOX_SIZE, + g ); } float new_x = 0; if ( !node.isExternal() && !node.isCollapse() ) { @@ -3055,18 +3157,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node ); for( int i = 0; i < node.getNumberOfDescendants(); ++i ) { final PhylogenyNode child_node = node.getChildNode( i ); - int factor_x; - if ( !isUniformBranchLengthsForCladogram() ) { - factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes(); - } - else { - factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node ); - } + final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes(); if ( first_child ) { first_child = false; - y2 = node.getYSecondary() - - ( getOvYDistance() * ( node.getNumberOfExternalNodes() - child_node - .getNumberOfExternalNodes() ) ); + y2 = node.getYSecondary() - ( getOvYDistance() + * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) ); } else { y2 += getOvYDistance() * child_node.getNumberOfExternalNodes(); @@ -3103,12 +3198,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee ++_external_node_index; } // Confidence values - if ( getControlPanel().isShowConfidenceValues() - && !node.isExternal() - && !node.isRoot() + if ( getControlPanel().isShowConfidenceValues() && !node.isExternal() && !node.isRoot() && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) - || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) ) - && node.getBranchData().isHasConfidences() ) { + || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) + || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) ) + && node.getBranchData().isHasConfidences() ) { paintConfidenceValues( g, node, to_pdf, to_graphics_file ); } // Draw a line to root: @@ -3132,20 +3226,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( !node.isExternal() && !node.isCollapse() ) { boolean first_child = true; float y2 = 0.0f; - final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node ); for( int i = 0; i < node.getNumberOfDescendants(); ++i ) { final PhylogenyNode child_node = node.getChildNode( i ); - int factor_x; - if ( !isUniformBranchLengthsForCladogram() ) { - factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes(); - } - else { - factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf( child_node ); - } + final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes(); if ( first_child ) { first_child = false; - y2 = node.getYcoord() - - ( _y_distance * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) ); + y2 = node.getYcoord() - ( _y_distance + * ( node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes() ) ); } else { y2 += _y_distance * child_node.getNumberOfExternalNodes(); @@ -3179,14 +3266,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) { paintMolecularSequences( g, node, to_pdf ); } - if ( dynamically_hide - && !is_in_found_nodes - && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node - .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont() + if ( dynamically_hide && !is_in_found_nodes && ( ( node.isExternal() + && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) + || ( !node.isExternal() && ( ( new_x_min < 20 ) + || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont() .getHeight() ) ) ) ) ) { return; } - final int x = paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes ); + final int x = paintNodeData( g, node, to_graphics_file, to_pdf, is_in_found_nodes, 0 ); paintNodeWithRenderableData( x, g, node, to_graphics_file, to_pdf ); } @@ -3202,8 +3289,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return; } if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence() - && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) - && ( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) { + && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) && ( node.getNodeData() + .getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) { RenderableDomainArchitecture rds = null; try { rds = ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture(); @@ -3223,16 +3310,17 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( getOptions().isLineUpRendarableNodeData() ) { if ( getOptions().isRightLineUpDomains() ) { rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() ) - + _length_of_longest_text + ( ( _longest_domain - rds.getTotalLength() ) * rds - .getRenderingFactorWidth() ) ), node.getYcoord() - ( h / 2.0f ), g, this, to_pdf ); - } - else { - rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() ) + _length_of_longest_text ), + + _length_of_longest_text + + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ) ), node.getYcoord() - ( h / 2.0f ), g, this, to_pdf ); } + else { + rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() ) + + _length_of_longest_text ), node.getYcoord() - ( h / 2.0f ), g, this, to_pdf ); + } } else { rds.render( node.getXcoord() + x, node.getYcoord() - ( h / 2.0f ), g, this, to_pdf ); @@ -3240,13 +3328,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else { if ( getOptions().isRightLineUpDomains() ) { - rds.render( ( ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text ) - 20 ) - + ( ( _longest_domain - rds.getTotalLength() ) * rds - .getRenderingFactorWidth() ), - node.getYcoord() - ( h / 2.0f ), - g, - this, - to_pdf ); + rds.render( ( ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text ) + - 20 ) + ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ), + node.getYcoord() - ( h / 2.0f ), + g, + this, + to_pdf ); } else { rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text, @@ -3273,11 +3360,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee rv.render( ( float ) ( node.getXcoord() + x + domain_add ), node.getYcoord() - 3, g, this, to_pdf ); } else { - rv.render( ( float ) ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text + domain_add ), - node.getYcoord() - 3, - g, - this, - to_pdf ); + rv.render( ( float ) ( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text + + domain_add ), node.getYcoord() - 3, g, this, to_pdf ); } } } @@ -3324,10 +3408,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private void paintPhylogenyLite( final Graphics2D g ) { - _phylogeny - .getRoot() - .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle() - .getWidth() ) ) ) ); + _phylogeny.getRoot().setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + + ( MOVE / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ) ); _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) ); final Stroke s = g.getStroke(); g.setStroke( STROKE_05 ); @@ -3409,9 +3491,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift; float start_y; if ( !using_visual_font ) { - start_y = node.getYcoord() - + ( getFontMetricsForLargeDefaultFont().getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 - : 3.0f ) ); + start_y = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() + / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) ); } else { start_y = node.getYcoord() @@ -3422,12 +3503,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final String label = _sb.toString(); /* GUILHEM_BEG */ if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 ) - && ( node.getNodeData().isHasSequence() ) && node.getNodeData().getSequence().equals( _query_sequence ) ) { + && ( node.getNodeData().isHasSequence() ) + && node.getNodeData().getSequence().equals( _query_sequence ) ) { // invert font color and background color to show that this is the query sequence - final Rectangle2D nodeTextBounds = new TextLayout( label, g.getFont(), new FontRenderContext( null, - false, - false ) ) - .getBounds(); + final Rectangle2D nodeTextBounds = new TextLayout( label, + g.getFont(), + new FontRenderContext( null, false, false ) ) + .getBounds(); g.fillRect( ( int ) start_x - 1, ( int ) start_y - 8, ( int ) nodeTextBounds.getWidth() + 4, 11 ); g.setColor( getTreeColorSet().getBackgroundColor() ); } @@ -3686,8 +3768,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.setColor( getTaxonomyBasedColor( node ) ); } else if ( getControlPanel().isColorAccordingToAnnotation() - && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node - .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) { + && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) + && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) { g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) ); } else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles() @@ -3905,8 +3987,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { ann_str = ann.toString(); } - sb.append( SequenceWriter.toFasta( ann_str, n.getNodeData().getSequence() - .getMolecularSequence(), 60 ) ); + sb.append( SequenceWriter.toFasta( ann_str, + n.getNodeData().getSequence().getMolecularSequence(), + 60 ) ); data.add( sb.toString() ); } break; @@ -3940,7 +4023,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final String name = d.getName(); if ( !( s.contains( name ) ) ) { data.add( name ); - if ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN ) { + if ( getOptions() + .getExtDescNodeDataToReturn() == NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN ) { s.add( name ); } } @@ -3998,8 +4082,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) { if ( sb.length() < 1 ) { - TreePanelUtil.showInformationMessage( this, "No Appropriate Data (" + obtainTitleForExtDescNodeData() - + ")", "Descendants of selected node do not contain selected data" ); + TreePanelUtil.showInformationMessage( this, + "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")", + "Descendants of selected node do not contain selected data" ); clearCurrentExternalNodesDataBuffer(); } else { @@ -4007,21 +4092,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee String title; if ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() ) { title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data" - : obtainTitleForExtDescNodeData() ) - + " for " - + data.size() - + " nodes, unique entries: " + : obtainTitleForExtDescNodeData() ) + " for " + data.size() + " nodes, unique entries: " + size; } else { title = ( getOptions().getExtDescNodeDataToReturn() == NodeDataField.UNKNOWN ? "Data" - : obtainTitleForExtDescNodeData() ) - + " for " - + data.size() - + "/" - + node.getNumberOfExternalNodes() - + " external descendats of node " - + node + : obtainTitleForExtDescNodeData() ) + " for " + data.size() + "/" + + node.getNumberOfExternalNodes() + " external descendats of node " + node + ", unique entries: " + size; } final String s = sb.toString().trim(); @@ -4040,11 +4117,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) { try { if ( ( node.getName().length() > 0 ) - || ( node.getNodeData().isHasTaxonomy() && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData() - .getTaxonomy() ) ) - || ( node.getNodeData().isHasSequence() && !TreePanelUtil.isSequenceEmpty( node.getNodeData() - .getSequence() ) ) || ( node.getNodeData().isHasDate() ) - || ( node.getNodeData().isHasDistribution() ) || node.getBranchData().isHasConfidences() ) { + || ( node.getNodeData().isHasTaxonomy() + && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) + || ( node.getNodeData().isHasSequence() + && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) + || ( node.getNodeData().isHasDate() ) || ( node.getNodeData().isHasDistribution() ) + || node.getBranchData().isHasConfidences() ) { _popup_buffer.setLength( 0 ); short lines = 0; if ( node.getName().length() > 0 ) { @@ -4124,7 +4202,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _popup_buffer.append( "]" ); } if ( !enc_data ) { - if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) { + if ( ( tax.getIdentifier() != null ) + && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) { if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) { _popup_buffer.append( "[" ); _popup_buffer.append( tax.getIdentifier().getProvider() ); @@ -4207,15 +4286,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _popup_buffer.append( confidence.getType() ); _popup_buffer.append( "] " ); } - _popup_buffer - .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(), - getOptions() - .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); + _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(), + getOptions() + .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) { _popup_buffer.append( " (sd=" ); - _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence - .getStandardDeviation(), getOptions() - .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); + _popup_buffer.append( FORMATTER_CONFIDENCE + .format( ForesterUtil.round( confidence.getStandardDeviation(), + getOptions() + .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); _popup_buffer.append( ")" ); } } @@ -4236,7 +4315,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( _popup_buffer.length() > 0 ) { if ( !getConfiguration().isUseNativeUI() ) { _rollover_popup - .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) ); + .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) ); _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() ); if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) { _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() ); @@ -4255,11 +4334,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) ); } _rollover_popup.setText( _popup_buffer.toString() ); - _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null, - _rollover_popup, - e.getLocationOnScreen().x + 10, - e.getLocationOnScreen().y - - ( lines * 20 ) ); + _node_desc_popup = PopupFactory.getSharedInstance() + .getPopup( null, + _rollover_popup, + e.getLocationOnScreen().x + 10, + e.getLocationOnScreen().y - ( lines * 20 ) ); _node_desc_popup.show(); } } @@ -4345,7 +4424,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( getMainPanel().getMainFrame() == null ) { // Must be "E" applet version. ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() ) - .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() ); + .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() ); } else { getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() ); @@ -4369,22 +4448,23 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee calculateLongestExtNodeInfo(); if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) ) && ( getTreeFontSet().getLargeFont().getSize() > ( 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) { - while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) ) && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) { + while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) ) + && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) { getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(), true ); calculateLongestExtNodeInfo(); } } else { - while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) ) - && ( getTreeFontSet().getLargeFont().getSize() <= ( getTreeFontSet().getLargeFontMemory() - .getSize() - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) { + while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) ) && ( getTreeFontSet().getLargeFont() + .getSize() <= ( getTreeFontSet().getLargeFontMemory().getSize() + - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) { getMainPanel().getTreeFontSet().increaseFontSize(); calculateLongestExtNodeInfo(); } } //_length_of_longest_text = calcLengthOfLongestText(); int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes(); - final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny ); + final int max_depth = PhylogenyMethods.calculateMaxDepthConsiderCollapsed( _phylogeny ) + 1; if ( ext_nodes == 1 ) { ext_nodes = max_depth; if ( ext_nodes < 1 ) { @@ -4394,7 +4474,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee updateOvSizes(); float xdist = 0; float ov_xdist = 0; - if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) { + if ( !isNonLinedUpCladogram() ) { xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) ); ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) ); } @@ -4415,9 +4495,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee setXdistance( xdist ); setYdistance( ydist ); setOvXDistance( ov_xdist ); - final double height = _phylogeny.getHeight(); + final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() ); if ( height > 0 ) { - final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo() - getXdistance() ) / height ); + final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo() + - getXdistance() ) / height ); setXcorrectionFactor( corr > 0 ? corr : 0 ); final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height ); setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 ); @@ -4454,11 +4535,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) { return; } - int max_possible_length = ForesterUtil.roundToInt( ( getSize().getWidth() - 2 * MOVE ) - * AptxConstants.EXT_NODE_INFO_LENGTH_MAX_RATIO ); + int max_possible_length = ForesterUtil + .roundToInt( ( getSize().getWidth() - ( 2 * MOVE ) ) * AptxConstants.EXT_NODE_INFO_LENGTH_MAX_RATIO ); if ( max_possible_length < 20 ) { - max_possible_length = 20; - } + max_possible_length = 20; + } int longest = 30; int longest_txt = 0; _longest_domain = 0; @@ -4491,7 +4572,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) { sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters() - .getGainedCharactersAsStringBuffer().toString() ); + .getGainedCharactersAsStringBuffer().toString() ); } if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null ) && ( node.getNodeData().getVector().size() > 0 ) ) { @@ -4507,8 +4588,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee // FIXME // TODO this might need some clean up final DomainArchitecture d = node.getNodeData().getSequence().getDomainArchitecture(); - sum += ( ( _domain_structure_width / ( ( RenderableDomainArchitecture ) d ).getOriginalSize() - .getWidth() ) * d.getTotalLength() ) + 10; + sum += ( ( _domain_structure_width + / ( ( RenderableDomainArchitecture ) d ).getOriginalSize().getWidth() ) * d.getTotalLength() ) + + 10; if ( d.getTotalLength() > _longest_domain ) { _longest_domain = d.getTotalLength(); } @@ -4528,12 +4610,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } _ext_node_with_longest_txt_info = longest_txt_node; - if ( longest >= max_possible_length ) { + if ( longest >= max_possible_length ) { _longest_ext_node_info = max_possible_length; - } - else { - _longest_ext_node_info = longest; - } + } + else { + _longest_ext_node_info = longest; + } _length_of_longest_text = calcLengthOfLongestText(); } @@ -4640,15 +4722,17 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) { final Property p = pm.getProperty( ref ); final String value_str = p.getValue(); - final String index_str = ref - .substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), ref.length() ); + final String index_str = ref.substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(), + ref.length() ); double d = -100; try { d = Double.parseDouble( value_str ); } catch ( final NumberFormatException e ) { - JOptionPane.showMessageDialog( this, "Could not parse \"" + value_str - + "\" into a decimal value", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE ); + JOptionPane.showMessageDialog( this, + "Could not parse \"" + value_str + "\" into a decimal value", + "Problem with Vector Data", + JOptionPane.ERROR_MESSAGE ); return; } int i = -1; @@ -4658,7 +4742,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee catch ( final NumberFormatException e ) { JOptionPane.showMessageDialog( this, "Could not parse \"" + index_str - + "\" into index for vector data", + + "\" into index for vector data", "Problem with Vector Data", JOptionPane.ERROR_MESSAGE ); return; @@ -4720,7 +4804,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee repaint(); } } - + final void uncollapseAll( final PhylogenyNode node ) { if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) { JOptionPane.showMessageDialog( this, @@ -4730,7 +4814,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return; } if ( !node.isExternal() ) { - TreePanelUtil.uncollapseSubtree( node); + TreePanelUtil.uncollapseSubtree( node ); updateSetOfCollapsedExternalNodes(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); @@ -4756,49 +4840,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee calculateLongestExtNodeInfo(); setNodeInPreorderToNull(); resetPreferredSize(); + resetDepthCollapseDepthValue(); + resetRankCollapseRankValue(); _main_panel.adjustJScrollPane(); + getControlPanel().showWhole(); setArrowCursor(); - repaint(); } - final void collapseByTaxonomicRank( final String rank ) { - if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) { - return; - } - setWaitCursor(); - - final int collapsed = TreePanelUtil.collapseByTaxonomicRank( _phylogeny, rank, this ); - - setArrowCursor(); - repaint(); - if ( collapsed > 0 ) { - String msg = "Collapsing via " + rank + " completed:\n"; - if ( collapsed > 1 ) { - msg += "collapsed " + collapsed + " subtrees"; - } - else { - msg += "collapsed one subtree"; - } - setEdited( true ); - JOptionPane.showMessageDialog( this, - msg, - "Taxonomy Rank-Collapsing Completed (" + rank + ")", - JOptionPane.INFORMATION_MESSAGE ); - } - else { - String msg = "Could not taxonomy rank-collapse any subtree via " + rank + ".\n"; - msg += "Possible solutions (given that suitable taxonomic information is present):\n"; - msg += "select a different rank (e.g. phylum, genus, ...)\n"; - msg += " and/or\n"; - msg += "execute:\n"; - msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n"; - msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)"; - JOptionPane.showMessageDialog( this, msg, "Taxonomy Rank-Collapsing Failed", JOptionPane.WARNING_MESSAGE ); - } - } - - - + + final void colorRank( final String rank ) { if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) { return; @@ -4842,9 +4892,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee msg += "select a different rank (e.g. phylum, genus, ...)\n"; msg += " and/or\n"; msg += "execute:\n"; - msg += "1. \"" + MainFrameApplication.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n"; - msg += "2. \"" + MainFrameApplication.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)"; - JOptionPane.showMessageDialog( this, msg, "Taxonomy Rank-Colorization Failed", JOptionPane.WARNING_MESSAGE ); + msg += "1. \"" + MainFrame.OBTAIN_DETAILED_TAXONOMIC_INFORMATION + "\" (Tools)\n"; + msg += "2. \"" + MainFrame.INFER_ANCESTOR_TAXONOMIES + "\" (Analysis)"; + JOptionPane.showMessageDialog( this, + msg, + "Taxonomy Rank-Colorization Failed", + JOptionPane.WARNING_MESSAGE ); } } @@ -5032,14 +5085,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) { RenderableDomainArchitecture rds = null; - if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) { + if ( !( node.getNodeData().getSequence() + .getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) { if ( SPECIAL_DOMAIN_COLORING ) { rds = new RenderableDomainArchitecture( node.getNodeData().getSequence() - .getDomainArchitecture(), node.getName() ); + .getDomainArchitecture(), node.getName() ); } else { rds = new RenderableDomainArchitecture( node.getNodeData().getSequence() - .getDomainArchitecture() ); + .getDomainArchitecture() ); } node.getNodeData().getSequence().setDomainArchitecture( rds ); } @@ -5071,15 +5125,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final boolean inOv( final MouseEvent e ) { return ( ( e.getX() > ( getVisibleRect().x + getOvXPosition() + 1 ) ) && ( e.getX() < ( ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() ) - 1 ) ) - && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) && ( e.getY() < ( ( getVisibleRect().y - + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) ); + && ( e.getY() > ( getVisibleRect().y + getOvYPosition() + 1 ) ) + && ( e.getY() < ( ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() ) - 1 ) ) ); } final boolean inOvRectangle( final MouseEvent e ) { return ( ( e.getX() >= ( getOvRectangle().getX() - 1 ) ) && ( e.getX() <= ( getOvRectangle().getX() + getOvRectangle().getWidth() + 1 ) ) - && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) && ( e.getY() <= ( getOvRectangle().getY() - + getOvRectangle().getHeight() + 1 ) ) ); + && ( e.getY() >= ( getOvRectangle().getY() - 1 ) ) + && ( e.getY() <= ( getOvRectangle().getY() + getOvRectangle().getHeight() + 1 ) ) ); } final boolean isApplet() { @@ -5089,9 +5143,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final boolean isCanCollapse() { return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ); } - + final boolean isCanUncollapseAll( final PhylogenyNode node ) { - if ( node.isExternal() || getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) { + if ( node.isExternal() || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) { return false; } if ( node.isCollapse() ) { @@ -5105,7 +5159,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } return false; } - + final boolean isCanColorSubtree() { return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ); } @@ -5115,8 +5169,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final boolean isCanCut( final PhylogenyNode node ) { - return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() && !node - .isRoot() ); + return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && getOptions().isEditable() + && !node.isRoot() ); } final boolean isCanDelete() { @@ -5133,8 +5187,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final boolean isCanSubtree( final PhylogenyNode node ) { - return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() && ( !node - .isRoot() || ( _subtree_index > 0 ) ) ); + return ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && !node.isExternal() + && ( !node.isRoot() || ( _subtree_index > 0 ) ) ); } final boolean isCurrentTreeIsSubtree() { @@ -5200,7 +5254,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee y = max_y; } getMainPanel().getCurrentScrollPane().getViewport() - .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) ); + .setViewPosition( new Point( ForesterUtil.roundToInt( x ), ForesterUtil.roundToInt( y ) ) ); setInOvRect( true ); repaint(); } @@ -5447,8 +5501,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g ); if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) { g.setColor( getColorForFoundNode( c ) ); - drawRectFilled( c.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, c.getYSecondary() - - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, OVERVIEW_FOUND_NODE_BOX_SIZE, OVERVIEW_FOUND_NODE_BOX_SIZE, g ); + drawRectFilled( c.getXSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, + c.getYSecondary() - OVERVIEW_FOUND_NODE_BOX_SIZE_HALF, + OVERVIEW_FOUND_NODE_BOX_SIZE, + OVERVIEW_FOUND_NODE_BOX_SIZE, + g ); } } @@ -5537,8 +5594,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } else { if ( !to_graphics_file ) { - g.setPaint( new GradientPaint( r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y - + r.height, getTreeColorSet().getBackgroundColorGradientBottom() ) ); + g.setPaint( new GradientPaint( r.x, + r.y, + getTreeColorSet().getBackgroundColor(), + r.x, + r.y + r.height, + getTreeColorSet().getBackgroundColorGradientBottom() ) ); g.fill( r ); } else { @@ -5560,19 +5621,19 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) { _external_node_index = 0; // Position starting X of tree - if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/) { + if ( !_phylogeny.isRooted() /*|| ( _subtree_index > 0 )*/ ) { _phylogeny.getRoot().setXcoord( TreePanel.MOVE ); } else if ( ( _phylogeny.getRoot().getDistanceToParent() > 0.0 ) && getControlPanel().isDrawPhylogram() ) { - _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + ( _phylogeny.getRoot() - .getDistanceToParent() * getXcorrectionFactor() ) ) ); + _phylogeny.getRoot().setXcoord( ( float ) ( TreePanel.MOVE + + ( _phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor() ) ) ); } else { _phylogeny.getRoot().setXcoord( TreePanel.MOVE + getXdistance() ); } // Position starting Y of tree _phylogeny.getRoot().setYcoord( ( getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes() ) - + ( TreePanel.MOVE / 2.0f ) ); + + ( TreePanel.MOVE / 2.0f ) ); final int dynamic_hiding_factor = calcDynamicHidingFactor(); if ( getControlPanel().isDynamicallyHideData() ) { if ( dynamic_hiding_factor > 1 ) { @@ -5628,8 +5689,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL; _dynamic_hiding_factor = 0; if ( getControlPanel().isDynamicallyHideData() ) { - _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5 * getPhylogeny() - .getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) ); + _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5 + * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * 10 ) ); } if ( getControlPanel().getDynamicallyHideData() != null ) { if ( _dynamic_hiding_factor > 1 ) { @@ -5669,12 +5730,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) { - final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) / 2 ) - ( MOVE + getLongestExtNodeInfo() ) ); + final int radius = ( int ) ( ( Math.min( getPreferredSize().getWidth(), getPreferredSize().getHeight() ) + / 2 ) - ( MOVE + getLongestExtNodeInfo() ) ); final int d = radius + MOVE + getLongestExtNodeInfo(); _dynamic_hiding_factor = 0; if ( getControlPanel().isDynamicallyHideData() && ( radius > 0 ) ) { - _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5 * getPhylogeny() - .getNumberOfExternalNodes() ) / ( TWO_PI * radius ) ); + _dynamic_hiding_factor = ( int ) ( ( getFontMetricsForLargeDefaultFont().getHeight() * 1.5 + * getPhylogeny().getNumberOfExternalNodes() ) / ( TWO_PI * radius ) ); } if ( getControlPanel().getDynamicallyHideData() != null ) { if ( _dynamic_hiding_factor > 1 ) { @@ -5706,9 +5768,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee getStartingAngle(), x_pos + radius_ov, y_pos + radius_ov, - ( int ) ( radius_ov - ( getLongestExtNodeInfo() / ( getVisibleRect().width / getOvRectangle() - .getWidth() ) ) ), - g ); + ( int ) ( radius_ov - ( getLongestExtNodeInfo() + / ( getVisibleRect().width / getOvRectangle().getWidth() ) ) ), + g ); g.setTransform( _at ); paintOvRectangle( g ); } @@ -5787,24 +5849,19 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee y = TreePanel.MOVE + ForesterUtil.roundToInt( getYdistance() * getPhylogeny().getRoot().getNumberOfExternalNodes() * 2 ); if ( getControlPanel().isDrawPhylogram() ) { - x = TreePanel.MOVE - + getLongestExtNodeInfo() - + ForesterUtil - .roundToInt( ( getXcorrectionFactor() * getPhylogeny().getHeight() ) + getXdistance() ); - + x = TreePanel.MOVE + getLongestExtNodeInfo() + + ForesterUtil.roundToInt( ( getXcorrectionFactor() + * getPhylogeny().calculateHeight( !_options.isCollapsedWithAverageHeigh() ) ) + + getXdistance() ); } else { - if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) { - x = TreePanel.MOVE - + getLongestExtNodeInfo() - + ForesterUtil.roundToInt( getXdistance() - * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) ); + if ( !isNonLinedUpCladogram() ) { + x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil + .roundToInt( getXdistance() * ( getPhylogeny().getRoot().getNumberOfExternalNodes() + 2 ) ); } else { - x = TreePanel.MOVE - + getLongestExtNodeInfo() - + ForesterUtil.roundToInt( getXdistance() - * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) ); + x = TreePanel.MOVE + getLongestExtNodeInfo() + ForesterUtil + .roundToInt( getXdistance() * ( PhylogenyMethods.calculateMaxDepth( getPhylogeny() ) + 1 ) ); } } setPreferredSize( new Dimension( x, y ) ); @@ -6023,11 +6080,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( getControlPanel().isShowTaxonomyScientificNames() || getControlPanel().isShowTaxonomyCode() ) { pri = DESCENDANT_SORT_PRIORITY.TAXONOMY; } - else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols() || getControlPanel().isShowGeneNames() ) { + else if ( getControlPanel().isShowSeqNames() || getControlPanel().isShowSeqSymbols() + || getControlPanel().isShowGeneNames() ) { pri = DESCENDANT_SORT_PRIORITY.SEQUENCE; } PhylogenyMethods.orderAppearanceX( node, true, pri ); - setNodeInPreorderToNull(); getPhylogeny().externalNodesHaveChanged(); getPhylogeny().clearHashIdToNodeMap(); @@ -6037,7 +6094,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee getControlPanel().displayedPhylogenyMightHaveChanged( true ); repaint(); } - + final void swap( final PhylogenyNode node ) { if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) { return; @@ -6102,7 +6159,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final void updateOvSizes() { - if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) { + if ( ( getWidth() > ( 1.05 * getVisibleRect().width ) ) + || ( getHeight() > ( 1.05 * getVisibleRect().height ) ) ) { setOvOn( true ); float l = getLongestExtNodeInfo(); final float w_ratio = getOvMaxWidth() / getWidth(); @@ -6110,7 +6168,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes(); setOvYDistance( getOvMaxHeight() / ( 2 * ext_nodes ) ); float ov_xdist = 0; - if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) { + if ( !isNonLinedUpCladogram() ) { ov_xdist = ( ( getOvMaxWidth() - l ) / ( ext_nodes ) ); } else { @@ -6124,7 +6182,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee ydist = 0.0f; } setOvXDistance( ov_xdist ); - final double height = _phylogeny.getHeight(); + final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() ); if ( height > 0 ) { final float ov_corr = ( float ) ( ( ( getOvMaxWidth() - l ) - getOvXDistance() ) / height ); setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 ); @@ -6188,41 +6246,142 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final private static void drawString( final String str, final float x, final float y, final Graphics2D g ) { g.drawString( str, x, y ); } - - + final private void drawStringX( final String str, final float x, final float y, final Graphics2D g ) { //TODO //FIXME if ( getAttributedStringMap() == null /*&& getAttributedStringMap().containsKey(str) */ ) { - final AttributedString as = new AttributedString(str); + final AttributedString as = new AttributedString( str ); //Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); - - as.addAttribute(TextAttribute.FONT, g.getFont()); - as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 3); - as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 3, 4); - - as.addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 1, 2); - as.addAttribute(TextAttribute.FOREGROUND, Color.PINK, 3, 5); - as.addAttribute(TextAttribute.STRIKETHROUGH, - TextAttribute.STRIKETHROUGH_ON, 2, 4); - g.drawString(as.getIterator(), x, y); + as.addAttribute( TextAttribute.FONT, g.getFont() ); + as.addAttribute( TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 3 ); + as.addAttribute( TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 3, 4 ); + as.addAttribute( TextAttribute.FOREGROUND, Color.BLUE, 1, 2 ); + as.addAttribute( TextAttribute.FOREGROUND, Color.PINK, 3, 5 ); + as.addAttribute( TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 4 ); + g.drawString( as.getIterator(), x, y ); } else { g.drawString( str, x, y ); } } - private final Map getAttributedStringMap() { - return _attributed_string_map ; + return _attributed_string_map; } - + private final void setAttributedStringMap( final Map attributed_string_map ) { _attributed_string_map = attributed_string_map; } final private static boolean plusPressed( final int key_code ) { return ( ( key_code == KeyEvent.VK_ADD ) || ( key_code == KeyEvent.VK_PLUS ) - || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) || ( key_code == KeyEvent.VK_1 ) ); + || ( key_code == KeyEvent.VK_EQUALS ) || ( key_code == KeyEvent.VK_SEMICOLON ) + || ( key_code == KeyEvent.VK_1 ) ); + } + + public void decreaseDepthCollapseLevel() { + if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) { + if ( _depth_collapse_level <= 1 ) { + _depth_collapse_level = PhylogenyMethods.calculateMaxDepth( _phylogeny ); + uncollapseAll(); + } + else { + --_depth_collapse_level; + PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level ); + } + + } + } + + public void increaseDepthCollapseLevel() { + if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) { + final int max = PhylogenyMethods.calculateMaxDepth( _phylogeny ); + if ( _depth_collapse_level >= max ) { + _depth_collapse_level = 1; + } + else { + ++_depth_collapse_level; + } + PhylogenyMethods.collapseToDepth( _phylogeny, _depth_collapse_level ); + } + } + + public void decreaseRankCollapseLevel() { + if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) { + final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny ); + if ( ranks.length > 1 ) { + if ( _rank_collapse_level <= 0 ) { + _rank_collapse_level = ranks.length - 1; + uncollapseAll(); + } + else { + --_rank_collapse_level; + PhylogenyMethods.collapseToRank( _phylogeny, mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); + } + } + } + } + + + public void increaseRankCollapseLevel() { + if ( ( _phylogeny != null ) && ( _phylogeny.getNumberOfExternalNodes() > 2 ) ) { + final String ranks[] = PhylogenyMethods.obtainPresentRanksSorted( _phylogeny ); + if ( ranks.length > 1 ) { + if ( _rank_collapse_level >= (ranks.length - 1 ) ) { + _rank_collapse_level = 0; + PhylogenyMethods.collapseToRank( _phylogeny,mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); + } + else if ( _rank_collapse_level == (ranks.length - 2 ) ) { + ++_rank_collapse_level; + uncollapseAll(); + } + else { + ++_rank_collapse_level; + PhylogenyMethods.collapseToRank( _phylogeny,mapToAbsoluteRankLevel( ranks, _rank_collapse_level ) ); + } + } + } + } + + + private final static int mapToAbsoluteRankLevel( final String present_ranks_sorted[], + final int rank_collapse_level ) { + final String rank_str = present_ranks_sorted[ rank_collapse_level ]; + if ( !TaxonomyUtil.RANK_TO_INT.containsKey( rank_str ) ) { + throw new IllegalStateException( "unexpected exception: cannot find rank " + rank_str ); + } + return TaxonomyUtil.RANK_TO_INT.get( rank_str ); + } + + private final void uncollapseAll() { + final PhylogenyNodeIterator it = new PreorderTreeIterator(_phylogeny ); + while ( it.hasNext() ) { + it.next().setCollapse( false ); + } + } + + final int resetDepthCollapseDepthValue() { + return _depth_collapse_level = -1; + } + + final int getDepthCollapseDepthValue() { + return _depth_collapse_level; + } + + final void setDepthCollapseDepthValue( final int depth_collapse_level ) { + _depth_collapse_level = depth_collapse_level; + } + + final int resetRankCollapseRankValue() { + return _rank_collapse_level = -1; + } + + final int getRankCollapseRankValue() { + return _rank_collapse_level; + } + + final void setRankCollapseRankValue( final int rank_collapse_level ) { + _rank_collapse_level = rank_collapse_level; } } diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java b/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java index a7d8d87..9aeec3b 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java @@ -205,6 +205,9 @@ public class TreePanelUtil { final static void collapseSpeciesSpecificSubtrees( final Phylogeny phy ) { boolean inferred = false; + for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) { + iter.next().setCollapse( false ); + } for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) { final PhylogenyNode n = it.next(); if ( !n.isExternal() && !n.isCollapse() && ( n.getNumberOfDescendants() > 1 ) ) { @@ -318,7 +321,6 @@ public class TreePanelUtil { ++collapsed; if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { true_lineage_set.add( n.getNodeData().getTaxonomy().getScientificName() ); - System.out.println( "1 true_lineage_set added " + n.getNodeData().getTaxonomy().getScientificName() ); } } } @@ -330,8 +332,6 @@ public class TreePanelUtil { if ( !true_lineage_set.isEmpty() ) { for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { if ( true_lineage_set.contains( lin ) ) { - //TreePanelUtil - // .colorizeSubtree( node, new BranchColor( true_lineage_to_color_map.get( lin ) ) ); TreePanelUtil.collapseSubtree( node, true ); ++collapsed; success = true; @@ -347,12 +347,9 @@ public class TreePanelUtil { if ( lineage_to_rank_map.containsKey( lin ) && !ForesterUtil.isEmpty( lineage_to_rank_map.get( lin ) ) && lineage_to_rank_map.get( lin ).equalsIgnoreCase( rank ) ) { - //final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) ); - //TreePanelUtil.colorizeSubtree( node, c ); - TreePanelUtil.collapseSubtree( node, true ); + TreePanelUtil.collapseSubtree( node, true ); ++collapsed; true_lineage_set.add( lin ); - System.out.println( "2 true_lineage_set added " + lin ); break; } else { @@ -367,12 +364,9 @@ public class TreePanelUtil { lineage_to_rank_map.put( lin, up.getRank() ); System.out.println( lin + "->" + up.getRank() ); if ( up.getRank().equalsIgnoreCase( rank ) ) { - // final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) ); - // TreePanelUtil.colorizeSubtree( node, c ); TreePanelUtil.collapseSubtree( node, true ); ++collapsed; true_lineage_set.add( lin ); - System.out.println( "3 true_lineage_set added " + lin ); break; } } diff --git a/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlUtil.java b/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlUtil.java index ba80282..bedfc3d 100644 --- a/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlUtil.java +++ b/forester/java/src/org/forester/io/parsers/phyloxml/PhyloXmlUtil.java @@ -25,9 +25,7 @@ package org.forester.io.parsers.phyloxml; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.regex.Pattern; @@ -35,16 +33,12 @@ import org.forester.io.parsers.util.ParserUtils; public final class PhyloXmlUtil { - public static final String OTHER = "other"; - public static final String UNKNOWN = "unknown"; public final static Pattern SEQUENCE_SYMBOL_PATTERN = Pattern.compile( "\\S{1,20}" ); public final static Pattern TAXOMONY_CODE_PATTERN = Pattern .compile( ParserUtils.TAX_CODE ); public final static Pattern LIT_REF_DOI_PATTERN = Pattern .compile( "[a-zA-Z0-9_\\.]+\\S+" ); public final static Set SEQUENCE_TYPES = new HashSet(); - public final static List TAXONOMY_RANKS_LIST = new ArrayList(); - public final static Set TAXONOMY_RANKS_SET = new HashSet(); public static final int ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT = 9; public static final String VECTOR_PROPERTY_REF = "vector:index="; public static final String VECTOR_PROPERTY_TYPE = "xsd:decimal"; @@ -56,114 +50,6 @@ public final class PhyloXmlUtil { SEQUENCE_TYPES.add( SEQ_TYPE_RNA ); SEQUENCE_TYPES.add( SEQ_TYPE_PROTEIN ); SEQUENCE_TYPES.add( SEQ_TYPE_DNA ); - TAXONOMY_RANKS_LIST.add( "domain" ); - TAXONOMY_RANKS_LIST.add( "superkingdom" ); - TAXONOMY_RANKS_LIST.add( "kingdom" ); - TAXONOMY_RANKS_LIST.add( "subkingdom" ); - TAXONOMY_RANKS_LIST.add( "branch" ); - TAXONOMY_RANKS_LIST.add( "infrakingdom" ); - TAXONOMY_RANKS_LIST.add( "superphylum" ); - TAXONOMY_RANKS_LIST.add( "phylum" ); - TAXONOMY_RANKS_LIST.add( "subphylum" ); - TAXONOMY_RANKS_LIST.add( "infraphylum" ); - TAXONOMY_RANKS_LIST.add( "microphylum" ); - TAXONOMY_RANKS_LIST.add( "superdivision" ); - TAXONOMY_RANKS_LIST.add( "division" ); - TAXONOMY_RANKS_LIST.add( "subdivision" ); - TAXONOMY_RANKS_LIST.add( "infradivision" ); - TAXONOMY_RANKS_LIST.add( "superclass" ); - TAXONOMY_RANKS_LIST.add( "class" ); - TAXONOMY_RANKS_LIST.add( "subclass" ); - TAXONOMY_RANKS_LIST.add( "infraclass" ); - TAXONOMY_RANKS_LIST.add( "superlegion" ); - TAXONOMY_RANKS_LIST.add( "legion" ); - TAXONOMY_RANKS_LIST.add( "sublegion" ); - TAXONOMY_RANKS_LIST.add( "infralegion" ); - TAXONOMY_RANKS_LIST.add( "supercohort" ); - TAXONOMY_RANKS_LIST.add( "cohort" ); - TAXONOMY_RANKS_LIST.add( "subcohort" ); - TAXONOMY_RANKS_LIST.add( "infracohort" ); - TAXONOMY_RANKS_LIST.add( "superorder" ); - TAXONOMY_RANKS_LIST.add( "order" ); - TAXONOMY_RANKS_LIST.add( "suborder" ); - TAXONOMY_RANKS_LIST.add( "infraorder" ); - TAXONOMY_RANKS_LIST.add( "superfamily" ); - TAXONOMY_RANKS_LIST.add( "family" ); - TAXONOMY_RANKS_LIST.add( "subfamily" ); - TAXONOMY_RANKS_LIST.add( "supertribe" ); - TAXONOMY_RANKS_LIST.add( "tribe" ); - TAXONOMY_RANKS_LIST.add( "subtribe" ); - TAXONOMY_RANKS_LIST.add( "infratribe" ); - TAXONOMY_RANKS_LIST.add( "genus" ); - TAXONOMY_RANKS_LIST.add( "subgenus" ); - TAXONOMY_RANKS_LIST.add( "superspecies" ); - TAXONOMY_RANKS_LIST.add( "species" ); - TAXONOMY_RANKS_LIST.add( "subspecies" ); - TAXONOMY_RANKS_LIST.add( "variety" ); - TAXONOMY_RANKS_LIST.add( "varietas" ); - TAXONOMY_RANKS_LIST.add( "subvariety" ); - TAXONOMY_RANKS_LIST.add( "form" ); - TAXONOMY_RANKS_LIST.add( "subform" ); - TAXONOMY_RANKS_LIST.add( "cultivar" ); - TAXONOMY_RANKS_LIST.add( "strain" ); - TAXONOMY_RANKS_LIST.add( "section" ); - TAXONOMY_RANKS_LIST.add( "subsection" ); - TAXONOMY_RANKS_LIST.add( UNKNOWN ); - TAXONOMY_RANKS_LIST.add( OTHER ); - // same thing as set: - TAXONOMY_RANKS_SET.add( "domain" ); - TAXONOMY_RANKS_SET.add( "superkingdom" ); - TAXONOMY_RANKS_SET.add( "kingdom" ); - TAXONOMY_RANKS_SET.add( "subkingdom" ); - TAXONOMY_RANKS_SET.add( "branch" ); - TAXONOMY_RANKS_SET.add( "infrakingdom" ); - TAXONOMY_RANKS_SET.add( "superphylum" ); - TAXONOMY_RANKS_SET.add( "phylum" ); - TAXONOMY_RANKS_SET.add( "subphylum" ); - TAXONOMY_RANKS_SET.add( "infraphylum" ); - TAXONOMY_RANKS_SET.add( "microphylum" ); - TAXONOMY_RANKS_SET.add( "superdivision" ); - TAXONOMY_RANKS_SET.add( "division" ); - TAXONOMY_RANKS_SET.add( "subdivision" ); - TAXONOMY_RANKS_SET.add( "infradivision" ); - TAXONOMY_RANKS_SET.add( "superclass" ); - TAXONOMY_RANKS_SET.add( "class" ); - TAXONOMY_RANKS_SET.add( "subclass" ); - TAXONOMY_RANKS_SET.add( "infraclass" ); - TAXONOMY_RANKS_SET.add( "superlegion" ); - TAXONOMY_RANKS_SET.add( "legion" ); - TAXONOMY_RANKS_SET.add( "sublegion" ); - TAXONOMY_RANKS_SET.add( "infralegion" ); - TAXONOMY_RANKS_SET.add( "supercohort" ); - TAXONOMY_RANKS_SET.add( "cohort" ); - TAXONOMY_RANKS_SET.add( "subcohort" ); - TAXONOMY_RANKS_SET.add( "infracohort" ); - TAXONOMY_RANKS_SET.add( "superorder" ); - TAXONOMY_RANKS_SET.add( "order" ); - TAXONOMY_RANKS_SET.add( "suborder" ); - TAXONOMY_RANKS_SET.add( "infraorder" ); - TAXONOMY_RANKS_SET.add( "superfamily" ); - TAXONOMY_RANKS_SET.add( "family" ); - TAXONOMY_RANKS_SET.add( "subfamily" ); - TAXONOMY_RANKS_SET.add( "supertribe" ); - TAXONOMY_RANKS_SET.add( "tribe" ); - TAXONOMY_RANKS_SET.add( "subtribe" ); - TAXONOMY_RANKS_SET.add( "infratribe" ); - TAXONOMY_RANKS_SET.add( "genus" ); - TAXONOMY_RANKS_SET.add( "subgenus" ); - TAXONOMY_RANKS_SET.add( "superspecies" ); - TAXONOMY_RANKS_SET.add( "species" ); - TAXONOMY_RANKS_SET.add( "subspecies" ); - TAXONOMY_RANKS_SET.add( "variety" ); - TAXONOMY_RANKS_SET.add( "varietas" ); - TAXONOMY_RANKS_SET.add( "subvariety" ); - TAXONOMY_RANKS_SET.add( "form" ); - TAXONOMY_RANKS_SET.add( "subform" ); - TAXONOMY_RANKS_SET.add( "cultivar" ); - TAXONOMY_RANKS_SET.add( "strain" ); - TAXONOMY_RANKS_SET.add( "section" ); - TAXONOMY_RANKS_SET.add( "subsection" ); - TAXONOMY_RANKS_SET.add( UNKNOWN ); - TAXONOMY_RANKS_SET.add( OTHER ); + }; } diff --git a/forester/java/src/org/forester/phylogeny/Phylogeny.java b/forester/java/src/org/forester/phylogeny/Phylogeny.java index 3d94dd7..0990171 100644 --- a/forester/java/src/org/forester/phylogeny/Phylogeny.java +++ b/forester/java/src/org/forester/phylogeny/Phylogeny.java @@ -131,19 +131,19 @@ public class Phylogeny { * the root-node of a subtree * @return the height of the subtree emanating at n */ - public double calculateSubtreeHeight( final PhylogenyNode n ) { - if ( n.isExternal() || n.isCollapse() ) { - return ForesterUtil.isLargerOrEqualToZero( n.getDistanceToParent() ); + public double calculateSubtreeHeight( final PhylogenyNode n, final boolean take_collapse_into_account ) { + if ( n.isExternal() || ( take_collapse_into_account && n.isCollapse() ) ) { + return n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0; } else { double max = -Double.MAX_VALUE; for( int i = 0; i < n.getNumberOfDescendants(); ++i ) { - final double l = calculateSubtreeHeight( n.getChildNode( i ) ); + final double l = calculateSubtreeHeight( n.getChildNode( i ), take_collapse_into_account ); if ( l > max ) { max = l; } } - return max + ForesterUtil.isLargerOrEqualToZero( n.getDistanceToParent() ); + return max + ( n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0) ; } } @@ -370,17 +370,15 @@ public class Phylogeny { /** * This calculates the height for rooted, tree-shaped phylogenies. The - * height is the longest distance from the root to an external node. Please - * note. Child nodes of collapsed nodes are ignored -- which is useful for - * display purposes but might be misleading for other applications. + * height is the longest distance from the root to an external node. * * @return the height for rooted, tree-shaped phylogenies */ - public double getHeight() { + public double calculateHeight(final boolean take_collapse_into_account) { if ( isEmpty() ) { return 0.0; } - return calculateSubtreeHeight( getRoot() ); + return calculateSubtreeHeight( getRoot(), take_collapse_into_account ); } public Identifier getIdentifier() { diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java index 09f9955..dfe3341 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java @@ -42,6 +42,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.forester.archaeopteryx.TreePanelUtil; import org.forester.io.parsers.FastaParser; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; @@ -62,9 +63,11 @@ 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.phylogeny.iterators.PreorderTreeIterator; import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.DescriptiveStatistics; import org.forester.util.ForesterUtil; +import org.forester.util.TaxonomyUtil; public class PhylogenyMethods { @@ -269,6 +272,47 @@ public class PhylogenyMethods { } return max; } + + public static String[] obtainPresentRanksSorted( final Phylogeny phy ) { + final Set present_ranks = new HashSet(); + for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) { + final PhylogenyNode node = iter.next(); + if ( !node.isExternal() && !node.isRoot() && ( node.getNodeData().getTaxonomy() != null ) + && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getRank() ) ) { + final String current_rank = node.getNodeData().getTaxonomy().getRank(); + if ( TaxonomyUtil.RANK_TO_INT.containsKey( current_rank ) ) { + present_ranks.add( current_rank ); + } + } + } + final String ordered_ranks[] = new String[present_ranks.size() + 1]; + int c = 0; + for( final String rank : TaxonomyUtil.RANKS ) { + if ( present_ranks.contains( rank ) ) { + ordered_ranks[ c++ ] = rank; + } + } + ordered_ranks[ c ] = "off"; + return ordered_ranks; + } + + public static int calculateMaxDepthConsiderCollapsed( final Phylogeny phy ) { + int max = 0; + for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) { + PhylogenyNode n = iter.next(); + int steps = 0; + while ( n.getParent() != null ) { + if ( !n.isCollapse() ) { + steps++; + } + n = n.getParent(); + } + if ( steps > max ) { + max = steps; + } + } + return max; + } public static double calculateMaxDistanceToRoot( final Phylogeny phy ) { double max = 0.0; @@ -412,7 +456,8 @@ public class PhylogenyMethods { return deleted; } - public static void deleteExternalNodesPositiveSelectionT( final List species_to_keep, final Phylogeny phy ) { + public static void deleteExternalNodesPositiveSelectionT( final List species_to_keep, + final Phylogeny phy ) { final Set to_delete = new HashSet(); for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) { final PhylogenyNode n = it.next(); @@ -818,7 +863,8 @@ public class PhylogenyMethods { else { if ( ( n.getNumberOfDescendants() == 2 ) && ( n.getChildNode1().getNumberOfExternalNodes() != n.getChildNode2().getNumberOfExternalNodes() ) - && ( ( n.getChildNode1().getNumberOfExternalNodes() < n.getChildNode2().getNumberOfExternalNodes() ) == order ) ) { + && ( ( n.getChildNode1().getNumberOfExternalNodes() < n.getChildNode2() + .getNumberOfExternalNodes() ) == order ) ) { final PhylogenyNode temp = n.getChildNode1(); n.setChild1( n.getChildNode2() ); n.setChild2( temp ); @@ -841,7 +887,7 @@ public class PhylogenyMethods { } } } - + public synchronized static void orderAppearanceX( final PhylogenyNode n, final boolean order_ext_alphabetically, final DESCENDANT_SORT_PRIORITY pri ) { @@ -849,17 +895,11 @@ public class PhylogenyMethods { return; } else { - _order_changed = false; - orderAppearance( n, - true, - order_ext_alphabetically, - pri ); - if (!_order_changed ) { - orderAppearance( n, - false, - order_ext_alphabetically, - pri ); - } + _order_changed = false; + orderAppearance( n, true, order_ext_alphabetically, pri ); + if ( !_order_changed ) { + orderAppearance( n, false, order_ext_alphabetically, pri ); + } } } @@ -902,7 +942,8 @@ public class PhylogenyMethods { PhylogenyNode.setNodeCount( i ); } - public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) throws IOException { + public final static Phylogeny[] readPhylogenies( final PhylogenyParser parser, final File file ) + throws IOException { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny[] trees = factory.create( file, parser ); if ( ( trees == null ) || ( trees.length == 0 ) ) { @@ -960,21 +1001,21 @@ public class PhylogenyMethods { } private static enum NDF { - NodeName( "NN" ), - TaxonomyCode( "TC" ), - TaxonomyCommonName( "CN" ), - TaxonomyScientificName( "TS" ), - TaxonomyIdentifier( "TI" ), - TaxonomySynonym( "SY" ), - SequenceName( "SN" ), - GeneName( "GN" ), - SequenceSymbol( "SS" ), - SequenceAccession( "SA" ), - Domain( "DO" ), - Annotation( "AN" ), - CrossRef( "XR" ), - BinaryCharacter( "BC" ), - MolecularSequence( "MS" ); + NodeName( "NN" ), + TaxonomyCode( "TC" ), + TaxonomyCommonName( "CN" ), + TaxonomyScientificName( "TS" ), + TaxonomyIdentifier( "TI" ), + TaxonomySynonym( "SY" ), + SequenceName( "SN" ), + GeneName( "GN" ), + SequenceSymbol( "SS" ), + SequenceAccession( "SA" ), + Domain( "DO" ), + Annotation( "AN" ), + CrossRef( "XR" ), + BinaryCharacter( "BC" ), + MolecularSequence( "MS" ); private final String _text; @@ -993,12 +1034,12 @@ public class PhylogenyMethods { } public static List searchData( final String query, - final Phylogeny phy, - final boolean case_sensitive, - final boolean partial, - final boolean regex, - final boolean search_domains, - final double domains_confidence_threshold ) { + final Phylogeny phy, + final boolean case_sensitive, + final boolean partial, + final boolean regex, + final boolean search_domains, + final double domains_confidence_threshold ) { final List nodes = new ArrayList(); if ( phy.isEmpty() || ( query == null ) ) { return nodes; @@ -1021,8 +1062,7 @@ public class PhylogenyMethods { && match( node.getName(), my_query, case_sensitive, partial, regex ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCode ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCode ) ) && node.getNodeData().isHasTaxonomy() && match( node.getNodeData().getTaxonomy().getTaxonomyCode(), my_query, case_sensitive, @@ -1030,8 +1070,7 @@ public class PhylogenyMethods { regex ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCommonName ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCommonName ) ) && node.getNodeData().isHasTaxonomy() && match( node.getNodeData().getTaxonomy().getCommonName(), my_query, case_sensitive, @@ -1039,8 +1078,7 @@ public class PhylogenyMethods { regex ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyScientificName ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyScientificName ) ) && node.getNodeData().isHasTaxonomy() && match( node.getNodeData().getTaxonomy().getScientificName(), my_query, case_sensitive, @@ -1048,8 +1086,7 @@ public class PhylogenyMethods { regex ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyIdentifier ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyIdentifier ) ) && node.getNodeData().isHasTaxonomy() && ( node.getNodeData().getTaxonomy().getIdentifier() != null ) && match( node.getNodeData().getTaxonomy().getIdentifier().getValue(), my_query, @@ -1073,16 +1110,22 @@ public class PhylogenyMethods { match = true; } if ( !match && ( ( ndf == null ) || ( ndf == NDF.GeneName ) ) && node.getNodeData().isHasSequence() - && match( node.getNodeData().getSequence().getGeneName(), my_query, case_sensitive, partial, regex ) ) { + && match( node.getNodeData().getSequence().getGeneName(), + my_query, + case_sensitive, + partial, + regex ) ) { match = true; } if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceSymbol ) ) && node.getNodeData().isHasSequence() - && match( node.getNodeData().getSequence().getSymbol(), my_query, case_sensitive, partial, regex ) ) { + && match( node.getNodeData().getSequence().getSymbol(), + my_query, + case_sensitive, + partial, + regex ) ) { match = true; } - if ( !match - && ( ( ndf == null ) || ( ndf == NDF.SequenceAccession ) ) - && node.getNodeData().isHasSequence() + if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceAccession ) ) && node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAccession() != null ) && match( node.getNodeData().getSequence().getAccession().getValue(), my_query, @@ -1150,9 +1193,7 @@ public class PhylogenyMethods { } } } - if ( !match - && ( ndf == NDF.MolecularSequence ) - && node.getNodeData().isHasSequence() + if ( !match && ( ndf == NDF.MolecularSequence ) && node.getNodeData().isHasSequence() && match( node.getNodeData().getSequence().getMolecularSequence(), my_query, case_sensitive, @@ -1168,11 +1209,11 @@ public class PhylogenyMethods { } public static List searchDataLogicalAnd( final String[] queries, - final Phylogeny phy, - final boolean case_sensitive, - final boolean partial, - final boolean search_domains, - final double domains_confidence_threshold ) { + final Phylogeny phy, + final boolean case_sensitive, + final boolean partial, + final boolean search_domains, + final double domains_confidence_threshold ) { final List nodes = new ArrayList(); if ( phy.isEmpty() || ( queries == null ) || ( queries.length < 1 ) ) { return nodes; @@ -1200,8 +1241,7 @@ public class PhylogenyMethods { && match( node.getName(), query, case_sensitive, partial, false ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCode ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCode ) ) && node.getNodeData().isHasTaxonomy() && match( node.getNodeData().getTaxonomy().getTaxonomyCode(), query, case_sensitive, @@ -1209,8 +1249,7 @@ public class PhylogenyMethods { false ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCommonName ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCommonName ) ) && node.getNodeData().isHasTaxonomy() && match( node.getNodeData().getTaxonomy().getCommonName(), query, case_sensitive, @@ -1227,8 +1266,7 @@ public class PhylogenyMethods { false ) ) { match = true; } - else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyIdentifier ) ) - && node.getNodeData().isHasTaxonomy() + else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyIdentifier ) ) && node.getNodeData().isHasTaxonomy() && ( node.getNodeData().getTaxonomy().getIdentifier() != null ) && match( node.getNodeData().getTaxonomy().getIdentifier().getValue(), query, @@ -1248,22 +1286,30 @@ public class PhylogenyMethods { } } if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceName ) ) && node.getNodeData().isHasSequence() - && match( node.getNodeData().getSequence().getName(), query, case_sensitive, partial, false ) ) { + && match( node.getNodeData().getSequence().getName(), + query, + case_sensitive, + partial, + false ) ) { match = true; } - if ( !match - && ( ( ndf == null ) || ( ndf == NDF.GeneName ) ) - && node.getNodeData().isHasSequence() - && match( node.getNodeData().getSequence().getGeneName(), query, case_sensitive, partial, false ) ) { + if ( !match && ( ( ndf == null ) || ( ndf == NDF.GeneName ) ) && node.getNodeData().isHasSequence() + && match( node.getNodeData().getSequence().getGeneName(), + query, + case_sensitive, + partial, + false ) ) { match = true; } if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceSymbol ) ) - && node.getNodeData().isHasSequence() - && match( node.getNodeData().getSequence().getSymbol(), query, case_sensitive, partial, false ) ) { + && node.getNodeData().isHasSequence() && match( node.getNodeData().getSequence().getSymbol(), + query, + case_sensitive, + partial, + false ) ) { match = true; } - if ( !match - && ( ( ndf == null ) || ( ndf == NDF.SequenceAccession ) ) + if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceAccession ) ) && node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAccession() != null ) && match( node.getNodeData().getSequence().getAccession().getValue(), @@ -1332,9 +1378,7 @@ public class PhylogenyMethods { } } } - if ( !match - && ( ndf == NDF.MolecularSequence ) - && node.getNodeData().isHasSequence() + if ( !match && ( ndf == NDF.MolecularSequence ) && node.getNodeData().isHasSequence() && match( node.getNodeData().getSequence().getMolecularSequence(), query, case_sensitive, @@ -1487,8 +1531,8 @@ public class PhylogenyMethods { } else if ( !( ref_ext_taxo.contains( n.getNodeData().getTaxonomy().getScientificName() ) ) && !( ref_ext_taxo.contains( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) - && !( ( n.getNodeData().getTaxonomy().getIdentifier() != null ) && ref_ext_taxo.contains( n - .getNodeData().getTaxonomy().getIdentifier().getValuePlusProvider() ) ) ) { + && !( ( n.getNodeData().getTaxonomy().getIdentifier() != null ) && ref_ext_taxo + .contains( n.getNodeData().getTaxonomy().getIdentifier().getValuePlusProvider() ) ) ) { nodes_to_delete.add( n ); } } @@ -1543,7 +1587,8 @@ public class PhylogenyMethods { return true; } - final static public void transferInternalNodeNamesToConfidence( final Phylogeny phy, final String confidence_type ) { + final static public void transferInternalNodeNamesToConfidence( final Phylogeny phy, + final String confidence_type ) { final PhylogenyNodeIterator it = phy.iteratorPostorder(); while ( it.hasNext() ) { transferInternalNodeNameToConfidence( confidence_type, it.next() ); @@ -1570,7 +1615,8 @@ public class PhylogenyMethods { final static public void transferNodeNameToField( final Phylogeny phy, final PhylogenyNodeField field, - final boolean external_only ) throws PhyloXmlDataFormatException { + final boolean external_only ) + throws PhyloXmlDataFormatException { final PhylogenyNodeIterator it = phy.iteratorPostorder(); while ( it.hasNext() ) { final PhylogenyNode n = it.next(); @@ -1690,6 +1736,20 @@ public class PhylogenyMethods { return d; } + public static double calculateAverageTreeHeight( final PhylogenyNode node ) { + final List ext = node.getAllExternalDescendants(); + double s = 0; + for( PhylogenyNode n : ext ) { + while ( n != node ) { + if ( n.getDistanceToParent() > 0 ) { + s += n.getDistanceToParent(); + } + n = n.getParent(); + } + } + return s / ext.size(); + } + /** * Deep copies the phylogeny originating from this node. */ @@ -1825,19 +1885,21 @@ public class PhylogenyMethods { } public static enum DESCENDANT_SORT_PRIORITY { - NODE_NAME, SEQUENCE, TAXONOMY; + NODE_NAME, + SEQUENCE, + TAXONOMY; } public static enum PhylogenyNodeField { - CLADE_NAME, - SEQUENCE_NAME, - SEQUENCE_SYMBOL, - TAXONOMY_CODE, - TAXONOMY_COMMON_NAME, - TAXONOMY_ID, - TAXONOMY_ID_UNIPROT_1, - TAXONOMY_ID_UNIPROT_2, - TAXONOMY_SCIENTIFIC_NAME; + CLADE_NAME, + SEQUENCE_NAME, + SEQUENCE_SYMBOL, + TAXONOMY_CODE, + TAXONOMY_COMMON_NAME, + TAXONOMY_ID, + TAXONOMY_ID_UNIPROT_1, + TAXONOMY_ID_UNIPROT_2, + TAXONOMY_SCIENTIFIC_NAME; } public static void addMolecularSeqsToTree( final Phylogeny phy, final Msa msa ) { @@ -1977,4 +2039,93 @@ public class PhylogenyMethods { return 0; } } + + public final static Map calculateDepths( final Phylogeny phy ) { + final Map depths = new HashMap(); + calculateDepthsHelper( phy.getRoot(), 0, depths ); + return depths; + } + + private final static void calculateDepthsHelper( final PhylogenyNode n, int d, final Map depths ) { + depths.put( n.getId(), d ); + ++d; + final List descs = n.getDescendants(); + for( final PhylogenyNode desc : descs ) { + calculateDepthsHelper( desc, d, depths ); + } + } + + public final static void collapseToDepth( final Phylogeny phy, final int depth ) { + if ( phy.getNumberOfExternalNodes() < 3 ) { + return; + } + collapseToDepthHelper( phy.getRoot(), 0, depth ); + } + + private final static void collapseToDepthHelper( final PhylogenyNode n, int d, final int depth ) { + if ( n.isExternal() ) { + n.setCollapse( false ); + return; + } + if ( d >= depth ) { + n.setCollapse( true ); + final PhylogenyNodeIterator it = new PreorderTreeIterator( n ); + while ( it.hasNext() ) { + it.next().setCollapse( true ); + } + } + else { + n.setCollapse( false ); + ++d; + final List descs = n.getDescendants(); + for( final PhylogenyNode desc : descs ) { + collapseToDepthHelper( desc, d, depth ); + } + } + } + + + + public final static void collapseToRank( final Phylogeny phy, final int rank ) { + if ( phy.getNumberOfExternalNodes() < 3 ) { + return; + } + if ( rank < 0 || rank >= TaxonomyUtil.RANKS.length ) { + throw new IllegalArgumentException( "Rank " + rank + " is out of range" ); + } + collapseToRankHelper( phy.getRoot(), rank ); + } + + private final static void collapseToRankHelper( final PhylogenyNode n, final int target_rank ) { + if ( n.isExternal() ) { + n.setCollapse( false ); + return; + } + if ( ( n.getNodeData().getTaxonomy() != null ) + && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() ) ) { + final String current_rank = n.getNodeData().getTaxonomy().getRank(); + if ( !TaxonomyUtil.RANK_TO_INT.containsKey( current_rank ) ) { + System.out.println( "Don't know rank \"" + current_rank + "\", ignoring." ); + } + else { + if ( TaxonomyUtil.RANK_TO_INT.get( current_rank ) >= target_rank ) { + n.setCollapse( true ); + + final PhylogenyNodeIterator it = new PreorderTreeIterator( n ); + while ( it.hasNext() ) { + it.next().setCollapse( true ); + } + return; + } + } + } + n.setCollapse( false ); + final List descs = n.getDescendants(); + for( final PhylogenyNode desc : descs ) { + collapseToRankHelper( desc, target_rank ); + } + } + + + } diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index 6aa0fff..9e71765 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -789,14 +789,14 @@ public final class PhylogenyNode implements Comparable { } /** - * Inserts PhylogenyNode n at the specified position i into the list of + * Inserts PhylogenyNode node at the specified position i into the list of * child nodes. This does not allow null slots in the list of child nodes: - * If i is larger than the number of child nodes, n is just added to the - * list, not place at index i. + * If i is larger than the number of child nodes, node is just added to the + * list, not placed at index i. * * @param i * the index of position where to add the child - * @param n + * @param node * the PhylogenyNode to add */ final public void setChildNode( final int i, final PhylogenyNode node ) { diff --git a/forester/java/src/org/forester/phylogeny/data/Taxonomy.java b/forester/java/src/org/forester/phylogeny/data/Taxonomy.java index 8a2dc33..117f831 100644 --- a/forester/java/src/org/forester/phylogeny/data/Taxonomy.java +++ b/forester/java/src/org/forester/phylogeny/data/Taxonomy.java @@ -35,6 +35,7 @@ import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException; import org.forester.io.parsers.phyloxml.PhyloXmlMapping; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.util.ForesterUtil; +import org.forester.util.TaxonomyUtil; public class Taxonomy implements PhylogenyData, MultipleUris, Comparable { @@ -304,7 +305,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable 0.0 ) { if ( ( 2 * d ) > Math.abs( diff ) ) { child0.setDistanceToParent( d - ( diff / 2.0 ) ); diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 5d8854d..de8ec6e 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -3352,7 +3352,7 @@ public final class Test { if ( t2.getNumberOfExternalNodes() != 4 ) { return false; } - if ( t2.getHeight() != 8.5 ) { + if ( t2.calculateHeight(false) != 8.5 ) { return false; } if ( !t2.isCompletelyBinary() ) { @@ -3365,7 +3365,7 @@ public final class Test { if ( t3.getNumberOfExternalNodes() != 5 ) { return false; } - if ( t3.getHeight() != 11 ) { + if ( t3.calculateHeight(true) != 11 ) { return false; } if ( t3.isCompletelyBinary() ) { @@ -3376,7 +3376,7 @@ public final class Test { if ( t4.getNumberOfExternalNodes() != 9 ) { return false; } - if ( t4.getHeight() != 11 ) { + if ( t4.calculateHeight(false) != 11 ) { return false; } if ( t4.isCompletelyBinary() ) { @@ -3387,17 +3387,17 @@ public final class Test { if ( t5.getNumberOfExternalNodes() != 8 ) { return false; } - if ( t5.getHeight() != 15 ) { + if ( t5.calculateHeight(false) != 15 ) { return false; } final StringBuffer sb6 = new StringBuffer( "(X,Y,Z,(((A111)A11:2)A1:2,(X,Y,Z,A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" ); final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ]; - if ( t6.getHeight() != 15 ) { + if ( t6.calculateHeight(true) != 15 ) { return false; } final StringBuffer sb7 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:15,D:8)" ); final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ]; - if ( t7.getHeight() != 15 ) { + if ( t7.calculateHeight(true) != 15 ) { return false; } final StringBuffer sb8 = new StringBuffer( "(((A11:11)A1:2,(A21:2,A22:2,A23,A24,AA:)A2:11,A3:2)A:2,B:15,C:15,D:15)" ); @@ -3405,17 +3405,17 @@ public final class Test { if ( t8.getNumberOfExternalNodes() != 10 ) { return false; } - if ( t8.getHeight() != 15 ) { + if ( t8.calculateHeight(true) != 15 ) { return false; } final char[] a9 = new char[] { 'a' }; final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ]; - if ( t9.getHeight() != 0 ) { + if ( t9.calculateHeight(true) != 0 ) { return false; } final char[] a10 = new char[] { 'a', ':', '6' }; final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ]; - if ( t10.getHeight() != 6 ) { + if ( t10.calculateHeight(true) != 6 ) { return false; } } diff --git a/forester/java/src/org/forester/util/TaxonomyUtil.java b/forester/java/src/org/forester/util/TaxonomyUtil.java index ef38563..a5beeac 100644 --- a/forester/java/src/org/forester/util/TaxonomyUtil.java +++ b/forester/java/src/org/forester/util/TaxonomyUtil.java @@ -1,8 +1,12 @@ package org.forester.util; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; public final class TaxonomyUtil { @@ -24,7 +28,7 @@ public final class TaxonomyUtil { } _default_taxcode_taxgroup_map.put( code, group ); } - private final static Map _default_taxcode_taxgroup_map = new HashMap(); + private final static Map _default_taxcode_taxgroup_map = new HashMap(); static { put( "BUFBU", "deuterostomia" ); put( "NOTVI", "deuterostomia" ); @@ -574,7 +578,7 @@ public final class TaxonomyUtil { put( "HELPH", "bacteria" ); put( "AQUAE", "bacteria" ); } - private final static Map FAKE_CODE_TO_ID_MAP = new HashMap(); + private final static Map FAKE_CODE_TO_ID_MAP = new HashMap(); static { FAKE_CODE_TO_ID_MAP.put( "CTEXX", 283909 ); FAKE_CODE_TO_ID_MAP.put( "HMAXX", 6085 ); @@ -605,4 +609,79 @@ public final class TaxonomyUtil { FAKE_CODE_TO_ID_MAP.put( "ALIXX", 87102 ); FAKE_CODE_TO_ID_MAP.put( "TTRXX", 529818 ); } + public final static List TAXONOMY_RANKS_LIST = new ArrayList(); + public final static Set TAXONOMY_RANKS_SET = new HashSet(); + public static final String OTHER = "other"; + public static final String UNKNOWN = "unknown";; + final public static HashMap RANK_TO_INT = new HashMap(); + static { + TAXONOMY_RANKS_LIST.add( "domain" ); + TAXONOMY_RANKS_LIST.add( "superkingdom" ); + TAXONOMY_RANKS_LIST.add( "kingdom" ); + TAXONOMY_RANKS_LIST.add( "subkingdom" ); + TAXONOMY_RANKS_LIST.add( "branch" ); + TAXONOMY_RANKS_LIST.add( "infrakingdom" ); + TAXONOMY_RANKS_LIST.add( "superphylum" ); + TAXONOMY_RANKS_LIST.add( "phylum" ); + TAXONOMY_RANKS_LIST.add( "subphylum" ); + TAXONOMY_RANKS_LIST.add( "infraphylum" ); + TAXONOMY_RANKS_LIST.add( "microphylum" ); + TAXONOMY_RANKS_LIST.add( "superdivision" ); + TAXONOMY_RANKS_LIST.add( "division" ); + TAXONOMY_RANKS_LIST.add( "subdivision" ); + TAXONOMY_RANKS_LIST.add( "infradivision" ); + TAXONOMY_RANKS_LIST.add( "superclass" ); + TAXONOMY_RANKS_LIST.add( "class" ); + TAXONOMY_RANKS_LIST.add( "subclass" ); + TAXONOMY_RANKS_LIST.add( "infraclass" ); + TAXONOMY_RANKS_LIST.add( "superlegion" ); + TAXONOMY_RANKS_LIST.add( "legion" ); + TAXONOMY_RANKS_LIST.add( "sublegion" ); + TAXONOMY_RANKS_LIST.add( "infralegion" ); + TAXONOMY_RANKS_LIST.add( "supercohort" ); + TAXONOMY_RANKS_LIST.add( "cohort" ); + TAXONOMY_RANKS_LIST.add( "subcohort" ); + TAXONOMY_RANKS_LIST.add( "infracohort" ); + TAXONOMY_RANKS_LIST.add( "superorder" ); + TAXONOMY_RANKS_LIST.add( "order" ); + TAXONOMY_RANKS_LIST.add( "suborder" ); + TAXONOMY_RANKS_LIST.add( "infraorder" ); + TAXONOMY_RANKS_LIST.add( "superfamily" ); + TAXONOMY_RANKS_LIST.add( "family" ); + TAXONOMY_RANKS_LIST.add( "subfamily" ); + TAXONOMY_RANKS_LIST.add( "supertribe" ); + TAXONOMY_RANKS_LIST.add( "tribe" ); + TAXONOMY_RANKS_LIST.add( "subtribe" ); + TAXONOMY_RANKS_LIST.add( "infratribe" ); + TAXONOMY_RANKS_LIST.add( "genus" ); + TAXONOMY_RANKS_LIST.add( "subgenus" ); + TAXONOMY_RANKS_LIST.add( "superspecies" ); + TAXONOMY_RANKS_LIST.add( "species" ); + TAXONOMY_RANKS_LIST.add( "subspecies" ); + TAXONOMY_RANKS_LIST.add( "variety" ); + TAXONOMY_RANKS_LIST.add( "varietas" ); + TAXONOMY_RANKS_LIST.add( "subvariety" ); + TAXONOMY_RANKS_LIST.add( "form" ); + TAXONOMY_RANKS_LIST.add( "subform" ); + TAXONOMY_RANKS_LIST.add( "cultivar" ); + TAXONOMY_RANKS_LIST.add( "strain" ); + TAXONOMY_RANKS_LIST.add( "section" ); + TAXONOMY_RANKS_LIST.add( "subsection" ); + TAXONOMY_RANKS_LIST.add( UNKNOWN ); + TAXONOMY_RANKS_LIST.add( OTHER ); + } + final public static String RANKS[] = new String[ TAXONOMY_RANKS_LIST.size() - 2 ]; + static { + // same thing as set: + for( final String rank : TAXONOMY_RANKS_LIST ) { + System.out.println( "=" + rank ); + TAXONOMY_RANKS_SET.add( rank ); + } + final int l = RANKS.length; + for( int i = 0; i < l; ++i ) { + System.out.println( "i=" + i ); + RANKS[ i ] = TAXONOMY_RANKS_LIST.get( i ); + RANK_TO_INT.put( RANKS[ i ], i ); + } + } }