X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrameApplication.java;h=125471d2cb2ed4a62a77948532f670cb363423a2;hb=362bd0a813f302f28631d9c9447dd8aa9ee0ceda;hp=b688722af21136aec7111f3f654272cc0c13544b;hpb=6ebad4e2283f33540c6ed4a9b1c8efc839d62637;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index b688722..125471d 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -93,11 +93,13 @@ import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.Confidence; +import org.forester.phylogeny.data.PhylogenyDataUtil; +import org.forester.phylogeny.data.Sequence; import org.forester.phylogeny.data.Taxonomy; import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; -import org.forester.sequence.Sequence; +import org.forester.sequence.MolecularSequence; import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.BasicTable; import org.forester.util.BasicTableParser; @@ -123,6 +125,7 @@ public final class MainFrameApplication extends MainFrame { private final static SequencesFileFilter seqsfilter = new SequencesFileFilter(); private final static DefaultFilter defaultfilter = new DefaultFilter(); private static final long serialVersionUID = -799735726778865234L; + private static final boolean PREPROCESS_TREES = false; private final JFileChooser _values_filechooser; private final JFileChooser _sequences_filechooser; private final JFileChooser _open_filechooser; @@ -140,11 +143,14 @@ public final class MainFrameApplication extends MainFrame { private JMenuItem _write_to_tif_item; private JMenuItem _write_to_png_item; private JMenuItem _write_to_bmp_item; + private JMenuItem _collapse_below_threshold; + private JMenuItem _collapse_below_branch_length; private File _current_dir; private ButtonGroup _radio_group_1; private ButtonGroup _radio_group_2; // Others: double _min_not_collapse = Constants.MIN_NOT_COLLAPSE_DEFAULT; + double _min_not_collapse_bl = 0.001; // Phylogeny Inference menu private JMenu _inference_menu; private JMenuItem _inference_from_msa_item; @@ -153,7 +159,7 @@ public final class MainFrameApplication extends MainFrame { private PhylogeneticInferenceOptions _phylogenetic_inference_options = null; private Msa _msa = null; private File _msa_file = null; - private List _seqs = null; + private List _seqs = null; private File _seqs_file = null; JMenuItem _read_values_jmi; JMenuItem _read_seqs_jmi; @@ -543,6 +549,12 @@ public final class MainFrameApplication extends MainFrame { } collapseBelowThreshold(); } + else if ( o == _collapse_below_branch_length ) { + if ( isSubtreeDisplayed() ) { + return; + } + collapseBelowBranchLengthThreshold(); + } else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi ) || ( o == _extract_taxonomy_agressive_rbmi ) ) { if ( _replace_underscores_cbmi != null ) { @@ -589,7 +601,7 @@ public final class MainFrameApplication extends MainFrame { return _msa_file; } - public List getSeqs() { + public List getSeqs() { return _seqs; } @@ -697,11 +709,11 @@ public final class MainFrameApplication extends MainFrame { if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { setSeqsFile( null ); setSeqs( null ); - List seqs = null; + List seqs = null; try { if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { seqs = FastaParser.parse( new FileInputStream( file ) ); - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { System.out.println( SequenceWriter.toFasta( seq, 60 ) ); } } @@ -868,16 +880,16 @@ public final class MainFrameApplication extends MainFrame { .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) ); setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() ); setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() ); - MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(), - _show_scale_cbmi, - _show_branch_length_values_cbmi, - _non_lined_up_cladograms_rbmi, - _uniform_cladograms_rbmi, - _ext_node_dependent_cladogram_rbmi, - _label_direction_cbmi ); MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() ); MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() ); MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() ); + try { + getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB(); + getMainPanel().getControlPanel().setVisibilityOfX(); + } + catch ( final Exception ignore ) { + // do nothing, not important. + } } } ); _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) ); @@ -893,13 +905,13 @@ public final class MainFrameApplication extends MainFrame { _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( SHOW_OVERVIEW_LABEL ) ); _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) ); _options_jmenu - .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) ); - _options_jmenu .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_INT ) ); _options_jmenu .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL_EXT ) ); + _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) ); if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) { - _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) ); + _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) ); + _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) ); } _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) ); _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( SHOW_CONF_STDDEV_LABEL ) ); @@ -999,7 +1011,6 @@ public final class MainFrameApplication extends MainFrame { getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP ); customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi, getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP ); - customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() ); customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() ); customizeCheckBoxMenuItem( _label_direction_cbmi, getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL ); @@ -1029,6 +1040,8 @@ public final class MainFrameApplication extends MainFrame { .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ); customizeCheckBoxMenuItem( _use_internal_names_for_conf_in_nh_export_cbmi, getOptions() .getNhConversionSupportValueStyle() == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ); + customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() ); + customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() ); _jmenubar.add( _options_jmenu ); } @@ -1065,10 +1078,10 @@ public final class MainFrameApplication extends MainFrame { _tools_menu.addSeparator(); _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) ); _remove_visual_styles_item - .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." ); + .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny" ); customizeJMenuItem( _remove_visual_styles_item ); _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) ); - _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." ); + _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny" ); customizeJMenuItem( _remove_branch_color_item ); _tools_menu.addSeparator(); _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) ); @@ -1077,18 +1090,28 @@ public final class MainFrameApplication extends MainFrame { _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) ); customizeJMenuItem( _midpoint_root_item ); _tools_menu.addSeparator(); - _tools_menu.add( _deleted_selected_nodes_item = new JMenuItem( "Delete Selected Nodes" ) ); - customizeJMenuItem( _deleted_selected_nodes_item ); - _tools_menu.add( _deleted_not_selected_nodes_item = new JMenuItem( "Retain Selected Nodes" ) ); - customizeJMenuItem( _deleted_not_selected_nodes_item ); + _tools_menu.add( _delete_selected_nodes_item = new JMenuItem( "Delete Selected Nodes" ) ); + _delete_selected_nodes_item.setToolTipText( "To delete all selected external nodes" ); + customizeJMenuItem( _delete_selected_nodes_item ); + _tools_menu.add( _delete_not_selected_nodes_item = new JMenuItem( "Retain Selected Nodes" ) ); + _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" ) ); customizeJMenuItem( _collapse_species_specific_subtrees ); + _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse species-specific subtrees" ); _tools_menu .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) ); customizeJMenuItem( _collapse_below_threshold ); _collapse_below_threshold - .setToolTipText( "To collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" ); + .setToolTipText( "To (permanently) collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" ); + // + _tools_menu + .add( _collapse_below_branch_length = new JMenuItem( "Collapse Branches with Branch Lengths Below Threshold into Multifurcations" ) ); + customizeJMenuItem( _collapse_below_branch_length ); + _collapse_below_branch_length + .setToolTipText( "To (permanently) collapse branches with branches with branch lengths below a threshold into multifurcations" ); + // _tools_menu.addSeparator(); _tools_menu .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) ); @@ -1234,7 +1257,6 @@ public final class MainFrameApplication extends MainFrame { if ( ( phys != null ) && ( phys.length > 0 ) ) { if ( nhx_or_nexus && getOptions().isInternalNumberAreConfidenceForNhParsing() ) { for( final Phylogeny phy : phys ) { - PhylogenyMethods.transferInternalNodeNamesToConfidence( phy, "" ); } } @@ -1258,7 +1280,7 @@ public final class MainFrameApplication extends MainFrame { _msa_file = msa_file; } - void setSeqs( final List seqs ) { + void setSeqs( final List seqs ) { _seqs = seqs; } @@ -1429,7 +1451,7 @@ public final class MainFrameApplication extends MainFrame { } final int result = _sequences_filechooser.showOpenDialog( _contentpane ); final File file = _sequences_filechooser.getSelectedFile(); - List seqs = null; + List seqs = null; if ( ( file != null ) && !file.isDirectory() && ( result == JFileChooser.APPROVE_OPTION ) ) { try { if ( FastaParser.isLikelyFasta( new FileInputStream( file ) ) ) { @@ -1478,13 +1500,13 @@ public final class MainFrameApplication extends MainFrame { } } if ( seqs != null ) { - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { System.out.println( seq.getIdentifier() ); } final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); int total_counter = 0; int attached_counter = 0; - for( final Sequence seq : seqs ) { + for( final MolecularSequence seq : seqs ) { ++total_counter; final String seq_name = seq.getIdentifier(); if ( !ForesterUtil.isEmpty( seq_name ) ) { @@ -1668,7 +1690,65 @@ public final class MainFrameApplication extends MainFrame { } } - private void collapse( final Phylogeny phy, final double m ) { + private void collapseBl( final Phylogeny phy ) { + final PhylogenyNodeIterator it = phy.iteratorPostorder(); + final List to_be_removed = new ArrayList(); + double min_bl = Double.MAX_VALUE; + boolean bl_present = false; + while ( it.hasNext() ) { + final PhylogenyNode n = it.next(); + if ( !n.isExternal() && !n.isRoot() ) { + final double bl = n.getDistanceToParent(); + if ( bl != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { + bl_present = true; + if ( bl < getMinNotCollapseBlValue() ) { + to_be_removed.add( n ); + } + if ( bl < min_bl ) { + min_bl = bl; + } + } + } + } + if ( bl_present ) { + for( final PhylogenyNode node : to_be_removed ) { + PhylogenyMethods.removeNode( node, phy ); + } + if ( to_be_removed.size() > 0 ) { + phy.externalNodesHaveChanged(); + phy.clearHashIdToNodeMap(); + phy.recalculateNumberOfExternalDescendants( true ); + getCurrentTreePanel().resetNodeIdToDistToLeafMap(); + getCurrentTreePanel().updateSetOfCollapsedExternalNodes(); + getCurrentTreePanel().calculateLongestExtNodeInfo(); + getCurrentTreePanel().setNodeInPreorderToNull(); + getCurrentTreePanel().recalculateMaxDistanceToRoot(); + getCurrentTreePanel().resetPreferredSize(); + getCurrentTreePanel().setEdited( true ); + getCurrentTreePanel().repaint(); + repaint(); + } + if ( to_be_removed.size() > 0 ) { + JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size() + + " branches with\nbranch length values below " + getMinNotCollapseBlValue(), "Collapsed " + + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE ); + } + else { + JOptionPane.showMessageDialog( this, + "No branch collapsed,\nminimum branch length is " + min_bl, + "No branch collapsed", + JOptionPane.INFORMATION_MESSAGE ); + } + } + else { + JOptionPane.showMessageDialog( this, + "No branch collapsed because no branch length values present", + "No branch length values present", + JOptionPane.INFORMATION_MESSAGE ); + } + } + + private void collapse( final Phylogeny phy ) { final PhylogenyNodeIterator it = phy.iteratorPostorder(); final List to_be_removed = new ArrayList(); double min_support = Double.MAX_VALUE; @@ -1758,7 +1838,43 @@ public final class MainFrameApplication extends MainFrame { } if ( success && ( m >= 0.0 ) ) { setMinNotCollapseConfidenceValue( m ); - collapse( phy, m ); + collapse( phy ); + } + } + } + } + } + + private void collapseBelowBranchLengthThreshold() { + if ( getCurrentTreePanel() != null ) { + final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); + if ( ( phy != null ) && !phy.isEmpty() ) { + final String s = ( String ) JOptionPane + .showInputDialog( this, + "Please enter the minimum branch length value\n", + "Minimal Branch Length Value", + JOptionPane.QUESTION_MESSAGE, + null, + null, + getMinNotCollapseBlValue() ); + if ( !ForesterUtil.isEmpty( s ) ) { + boolean success = true; + double m = 0.0; + final String m_str = s.trim(); + if ( !ForesterUtil.isEmpty( m_str ) ) { + try { + m = Double.parseDouble( m_str ); + } + catch ( final Exception ex ) { + success = false; + } + } + else { + success = false; + } + if ( success && ( m >= 0.0 ) ) { + setMinNotCollapseBlValue( m ); + collapseBl( phy ); } } } @@ -1914,6 +2030,10 @@ public final class MainFrameApplication extends MainFrame { return _min_not_collapse; } + private double getMinNotCollapseBlValue() { + return _min_not_collapse_bl; + } + private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() { if ( _phylogenetic_inference_options == null ) { _phylogenetic_inference_options = new PhylogeneticInferenceOptions(); @@ -2209,6 +2329,9 @@ public final class MainFrameApplication extends MainFrame { } } } + if ( PREPROCESS_TREES ) { + preProcessTreesUponReading( phys ); + } AptxUtil.addPhylogeniesToTabs( phys, file.getName(), file.getAbsolutePath(), @@ -2232,6 +2355,30 @@ public final class MainFrameApplication extends MainFrame { System.gc(); } + private void preProcessTreesUponReading( final Phylogeny[] phys ) { + for( final Phylogeny phy : phys ) { + if ( ( phy != null ) && !phy.isEmpty() ) { + for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) { + final PhylogenyNode n = it.next(); + if ( n.isExternal() ) { + if ( n.getNodeData().isHasSequence() ) { + final Sequence s = n.getNodeData().getSequence(); + if ( ForesterUtil.isEmpty( s.getGeneName() ) || s.getGeneName().startsWith( "LOC" ) ) { + if ( ( s.getAccession() != null ) + && !ForesterUtil.isEmpty( s.getAccession().getValue() ) ) { + s.setGeneName( s.getAccession().getValue() ); + } + else if ( !ForesterUtil.isEmpty( n.getName() ) ) { + s.setGeneName( n.getName() ); + } + } + } + } + } + } + } + } + private void readSpeciesTreeFromFile() { Phylogeny t = null; boolean exception = false; @@ -2345,6 +2492,10 @@ public final class MainFrameApplication extends MainFrame { _min_not_collapse = min_not_collapse; } + private void setMinNotCollapseBlValue( final double min_not_collapse_bl ) { + _min_not_collapse_bl = min_not_collapse_bl; + } + private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) { _phylogenetic_inference_options = phylogenetic_inference_options; }