X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FTreePanel.java;h=924eae9e4c8a408a2ea05d44cbcf670b9ba6388f;hb=9c1299acd081df2bd8c6c7320ce7f102f0fa5440;hp=f33c31d643c00aa81f6f27221ea11a22579e3932;hpb=b94510dea3a694b982079cae77805f1a47986b9b;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index f33c31d..924eae9 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -89,6 +89,7 @@ import javax.swing.JTextArea; import javax.swing.Popup; import javax.swing.PopupFactory; +import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON; import org.forester.archaeopteryx.ControlPanel.NodeClickAction; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; @@ -100,15 +101,18 @@ import org.forester.archaeopteryx.tools.ImageLoader; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; +import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.data.Annotation; import org.forester.phylogeny.data.BranchColor; import org.forester.phylogeny.data.Confidence; import org.forester.phylogeny.data.Event; +import org.forester.phylogeny.data.NodeData.NODE_DATA; import org.forester.phylogeny.data.NodeVisualization; import org.forester.phylogeny.data.NodeVisualization.NodeFill; import org.forester.phylogeny.data.NodeVisualization.NodeShape; import org.forester.phylogeny.data.PhylogenyData; +import org.forester.phylogeny.data.PhylogenyDataUtil; import org.forester.phylogeny.data.PropertiesMap; import org.forester.phylogeny.data.Property; import org.forester.phylogeny.data.Sequence; @@ -121,6 +125,7 @@ import org.forester.util.BasicDescriptiveStatistics; import org.forester.util.DescriptiveStatistics; import org.forester.util.ForesterConstants; import org.forester.util.ForesterUtil; +import org.forester.util.SequenceIdParser; public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable { @@ -216,7 +221,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee private double _max_distance_to_root = -1; private int _dynamic_hiding_factor = 0; private boolean _edited = false; - private Popup _node_desc_popup; + private Popup _node_desc_popup; private JTextArea _rollover_popup; // private final int _box_size; // private final int _half_box_size; @@ -225,7 +230,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final private static Font POPUP_FONT = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 12 ); - private static final boolean DRAW_MEAN_COUNTS = true; //TODO remove me later private Sequence _query_sequence = null; private final FontRenderContext _frc = new FontRenderContext( null, false, @@ -343,11 +347,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } + @Override final public void actionPerformed( final ActionEvent e ) { - int index; boolean done = false; final JMenuItem node_popup_menu_item = ( JMenuItem ) e.getSource(); - for( index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) { + for( int index = 0; ( index < _node_popup_menu_items.length ) && !done; index++ ) { // NOTE: index corresponds to the indices of click-to options // in the control panel. if ( node_popup_menu_item == _node_popup_menu_items[ index ] ) { @@ -368,7 +372,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee errorMessageNoCutCopyPasteInUnrootedDisplay(); return; } - final String label = getASimpleTextRepresentationOfANode( node ); + final String label = createASimpleTextRepresentationOfANode( node ); String msg = ""; if ( ForesterUtil.isEmpty( label ) ) { msg = "How to add the new, empty node?"; @@ -408,9 +412,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { phy.addAsChild( node ); } - _nodes_in_preorder = null; + setNodeInPreorderToNull(); _phylogeny.externalNodesHaveChanged(); - _phylogeny.hashIDs(); + _phylogeny.clearHashIdToNodeMap(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); setEdited( true ); @@ -457,31 +461,63 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final private void blast( final PhylogenyNode node ) { if ( !isCanBlast( node ) ) { JOptionPane.showMessageDialog( this, - "No sequence information present", + "Insufficient information present", "Cannot Blast", - JOptionPane.WARNING_MESSAGE ); + JOptionPane.INFORMATION_MESSAGE ); return; } - if ( node.getNodeData().isHasSequence() ) { - String name = ""; - if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) { - name = node.getNodeData().getSequence().getName(); - } - else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) { - name = node.getNodeData().getSequence().getSymbol(); - } - else if ( node.getNodeData().getSequence().getAccession() != null ) { - name = node.getNodeData().getSequence().getAccession().getValue(); - } - if ( !ForesterUtil.isEmpty( name ) ) { + else { + final String query = Blast.obtainQueryForBlast( node ); + System.out.println( "query for BLAST is: " + query ); + char type = '?'; + if ( !ForesterUtil.isEmpty( query ) ) { + if ( node.getNodeData().isHasSequence() ) { + if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getType() ) ) { + if ( node.getNodeData().getSequence().getType().toLowerCase() + .equals( PhyloXmlUtil.SEQ_TYPE_PROTEIN ) ) { + type = 'p'; + } + else { + type = 'n'; + } + } + else if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) { + if ( ForesterUtil.seqIsLikelyToBeAa( node.getNodeData().getSequence().getMolecularSequence() ) ) { + type = 'p'; + } + else { + type = 'n'; + } + } + } + if ( type == '?' ) { + if ( SequenceIdParser.isProtein( query ) ) { + type = 'p'; + } + else { + type = 'n'; + } + } + JApplet applet = null; + if ( isApplet() ) { + applet = obtainApplet(); + } try { - System.out.println( "trying: " + name ); - final Blast s = new Blast(); - s.go( name ); + Blast.openNcbiBlastWeb( query, type == 'n', applet, this ); } catch ( final Exception e ) { e.printStackTrace(); } + if ( Constants.ALLOW_DDBJ_BLAST ) { + try { + System.out.println( "trying: " + query ); + final Blast s = new Blast(); + s.ddbjBlast( query ); + } + catch ( final Exception e ) { + e.printStackTrace(); + } + } } } } @@ -531,7 +567,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) { return; } - int longest = 20; + int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE ) + * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO ); + if ( max_length < 40 ) { + max_length = 40; + } + int longest = 30; for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) { int sum = 0; if ( node.isCollapse() ) { @@ -561,6 +602,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee .asSimpleText() + " " ); } + if ( getControlPanel().isShowDomainArchitectures() + && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) { + sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() ) + .getRenderingSize().getWidth(); + } } if ( node.getNodeData().isHasTaxonomy() ) { final Taxonomy tax = node.getNodeData().getTaxonomy(); @@ -582,21 +628,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee sum += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getBinaryCharacters() .getGainedCharactersAsStringBuffer().toString() ); } - if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence() - && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) { - sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() ) - .getRenderingSize().getWidth(); - } - if ( sum >= Constants.EXT_NODE_INFO_LENGTH_MAX ) { - setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX ); + if ( sum >= max_length ) { + setLongestExtNodeInfo( max_length ); return; } if ( sum > longest ) { longest = sum; } } - if ( longest >= Constants.EXT_NODE_INFO_LENGTH_MAX ) { - setLongestExtNodeInfo( Constants.EXT_NODE_INFO_LENGTH_MAX ); + if ( longest >= max_length ) { + setLongestExtNodeInfo( max_length ); } else { setLongestExtNodeInfo( longest ); @@ -694,11 +735,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( !node.isExternal() && !node.isRoot() ) { final boolean collapse = !node.isCollapse(); AptxUtil.collapseSubtree( node, collapse ); - updateSetOfCollapsedExternalNodes( _phylogeny ); + updateSetOfCollapsedExternalNodes(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); calculateLongestExtNodeInfo(); - _nodes_in_preorder = null; + setNodeInPreorderToNull(); + _control_panel.displayedPhylogenyMightHaveChanged( true ); resetPreferredSize(); updateOvSizes(); _main_panel.adjustJScrollPane(); @@ -712,11 +754,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } setWaitCursor(); AptxUtil.collapseSpeciesSpecificSubtrees( _phylogeny ); - updateSetOfCollapsedExternalNodes( _phylogeny ); + updateSetOfCollapsedExternalNodes(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); calculateLongestExtNodeInfo(); - _nodes_in_preorder = null; + setNodeInPreorderToNull(); resetPreferredSize(); _main_panel.adjustJScrollPane(); setArrowCursor(); @@ -827,7 +869,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee errorMessageNoCutCopyPasteInUnrootedDisplay(); return; } - _nodes_in_preorder = null; + setNodeInPreorderToNull(); setCutOrCopiedTree( _phylogeny.copy( node ) ); final List nodes = PhylogenyMethods.getAllDescendants( node ); final Set node_ids = new HashSet( nodes.size() ); @@ -851,7 +893,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee JOptionPane.ERROR_MESSAGE ); return; } - final String label = getASimpleTextRepresentationOfANode( node ); + final String label = createASimpleTextRepresentationOfANode( node ); final int r = JOptionPane.showConfirmDialog( null, "Cut subtree" + label + "?", "Confirm Cutting of Subtree", @@ -859,11 +901,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( r != JOptionPane.OK_OPTION ) { return; } - _nodes_in_preorder = null; + setNodeInPreorderToNull(); setCopiedAndPastedNodes( null ); setCutOrCopiedTree( _phylogeny.copy( node ) ); _phylogeny.deleteSubtree( node, true ); - _phylogeny.hashIDs(); + _phylogeny.clearHashIdToNodeMap(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); setEdited( true ); @@ -904,7 +946,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee JOptionPane.ERROR_MESSAGE ); return; } - final String label = getASimpleTextRepresentationOfANode( node ); + final String label = createASimpleTextRepresentationOfANode( node ); final Object[] options = { "Node only", "Entire subtree", "Cancel" }; final int r = JOptionPane.showOptionDialog( this, "Delete" + label + "?", @@ -914,7 +956,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee null, options, options[ 2 ] ); - _nodes_in_preorder = null; + setNodeInPreorderToNull(); boolean node_only = true; if ( r == 1 ) { node_only = false; @@ -929,7 +971,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _phylogeny.deleteSubtree( node, true ); } _phylogeny.externalNodesHaveChanged(); - _phylogeny.hashIDs(); + _phylogeny.clearHashIdToNodeMap(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); setEdited( true ); @@ -1057,7 +1099,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) { return null; } - final int half_box_size_plus_wiggle = getOptions().getDefaultNodeShapeSize() / 2 + WIGGLE; + final int half_box_size_plus_wiggle = ( getOptions().getDefaultNodeShapeSize() / 2 ) + WIGGLE; for( final PhylogenyNodeIterator iter = _phylogeny.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); if ( ( _phylogeny.isRooted() || !node.isRoot() || ( node.getNumberOfDescendants() > 2 ) ) @@ -1071,7 +1113,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return null; } - final private String getASimpleTextRepresentationOfANode( final PhylogenyNode node ) { + final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) { final String tax = PhylogenyMethods.getSpecies( node ); String label = node.getName(); if ( !ForesterUtil.isEmpty( label ) && !ForesterUtil.isEmpty( tax ) ) { @@ -1315,11 +1357,133 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee case EDIT_NODE_DATA: showNodeEditFrame( node ); break; + case SORT_DESCENDENTS: + sortDescendants( node ); + break; + case GET_EXT_DESC_DATA: + showExtDescNodeData( node ); + break; default: throw new IllegalArgumentException( "unknown action: " + action ); } } + private void showExtDescNodeData( final PhylogenyNode node ) { + final List data = new ArrayList(); + for( final PhylogenyNode n : node.getAllExternalDescendants() ) { + switch ( getOptions().getExtDescNodeDataToReturn() ) { + case NODE_NAME: + if ( !ForesterUtil.isEmpty( n.getName() ) ) { + data.add( n.getName() ); + } + break; + case SEQUENCE_NAME: + if ( n.getNodeData().isHasSequence() + && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) { + data.add( n.getNodeData().getSequence().getName() ); + } + break; + case SEQUENCE_SYMBOL: + if ( n.getNodeData().isHasSequence() + && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) { + data.add( n.getNodeData().getSequence().getSymbol() ); + } + break; + case SEQUENCE_MOL_SEQ: + if ( n.getNodeData().isHasSequence() + && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) { + data.add( n.getNodeData().getSequence().getMolecularSequence() ); + } + break; + case SEQUENCE_ACC: + if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null ) + && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) { + data.add( n.getNodeData().getSequence().getAccession().toString() ); + } + break; + case TAXONOMY_SCIENTIFIC_NAME: + if ( n.getNodeData().isHasTaxonomy() + && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { + data.add( n.getNodeData().getTaxonomy().getScientificName() ); + } + break; + case TAXONOMY_CODE: + if ( n.getNodeData().isHasTaxonomy() + && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) { + data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() ); + } + break; + case UNKNOWN: + AptxUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data ); + break; + default: + throw new IllegalArgumentException( "unknown data element: " + + getOptions().getExtDescNodeDataToReturn() ); + } + } // for loop + if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) { + for( final String d : data ) { + if ( !ForesterUtil.isEmpty( d ) ) { + System.out.println( d ); + } + } + } + else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) { + final StringBuilder sb = new StringBuilder(); + for( final String d : data ) { + if ( !ForesterUtil.isEmpty( d ) ) { + sb.append( d ); + sb.append( "\n" ); + } + } + if ( sb.length() < 1 ) { + AptxUtil.showInformationMessage( this, + "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")", + "Descendants of selected node do not contain selected data" ); + } + else { + final String title = "External Descendants " + + ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data" + : obtainTitleForExtDescNodeData() ) + " (" + data.size() + "/" + + node.getNumberOfExternalNodes() + ") For Node " + node; + if ( getMainPanel().getMainFrame() == null ) { + // Must be "E" applet version. + final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet(); + final String s = sb.toString().trim(); + ae.showTextFrame( s, title ); + ae.setCurrentExternalNodesDataBuffer( s ); + } + else { + getMainPanel().getMainFrame().showTextFrame( sb.toString(), title ); + } + } + } + } + + private final String obtainTitleForExtDescNodeData() { + switch ( getOptions().getExtDescNodeDataToReturn() ) { + case NODE_NAME: + return "Node Names"; + case SEQUENCE_NAME: + return "Sequence Names"; + case SEQUENCE_SYMBOL: + return "Sequence Symbols"; + case SEQUENCE_MOL_SEQ: + return "Molecular Sequences"; + case SEQUENCE_ACC: + return "Sequence Accessors"; + case TAXONOMY_SCIENTIFIC_NAME: + return "Scientific Names"; + case TAXONOMY_CODE: + return "Taxonomy Codes"; + case UNKNOWN: + return "User Selected Data"; + default: + throw new IllegalArgumentException( "unknown data element: " + + getOptions().getExtDescNodeDataToReturn() ); + } + } + final void increaseDomainStructureEvalueThreshold() { if ( _domain_structure_e_value_thr_exp < 3 ) { _domain_structure_e_value_thr_exp += 1; @@ -1327,9 +1491,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private void increaseOvSize() { - if ( ( getOvMaxWidth() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) - && ( getOvMaxHeight() < getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect() - .getHeight() / 2 ) ) { + if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) ) + && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect() + .getHeight() / 2 ) ) ) { setOvMaxWidth( getOvMaxWidth() + 5 ); setOvMaxHeight( getOvMaxHeight() + 5 ); updateOvSettings(); @@ -1356,7 +1520,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee setTreeFile( null ); setEdited( false ); initializeOvSettings(); - setStartingAngle( TWO_PI * 3 / 4 ); + setStartingAngle( ( TWO_PI * 3 ) / 4 ); final ImageLoader il = new ImageLoader( this ); new Thread( il ).start(); } @@ -1406,24 +1570,24 @@ 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 ) ); + 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 ) ) ); } 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 ) ); + 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 ) ) ); } 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 ) ); + return ( ( x >= ( getOvVirtualRectangle().x - 1 ) ) + && ( x <= ( getOvVirtualRectangle().x + getOvVirtualRectangle().width + 1 ) ) + && ( y >= ( getOvVirtualRectangle().y - 1 ) ) && ( y <= ( getOvVirtualRectangle().y + + getOvVirtualRectangle().height + 1 ) ) ); } final private boolean inOvVirtualRectangle( final MouseEvent e ) { @@ -1435,10 +1599,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private boolean isCanBlast( final PhylogenyNode node ) { - return ( node.getNodeData().isHasSequence() && ( ( ( node.getNodeData().getSequence().getAccession() != null ) && !ForesterUtil - .isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) ) - || !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) || !ForesterUtil.isEmpty( node - .getNodeData().getSequence().getSymbol() ) ) ); + if ( !node.getNodeData().isHasSequence() && ForesterUtil.isEmpty( node.getName() ) ) { + return false; + } + return Blast.isContainsQueryForBlast( node ); } final boolean isCanCollapse() { @@ -1528,16 +1692,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( getControlPanel().isShowTaxonomyImages() ) { y_dist = 40 + ( int ) getYdistance(); } - return ( ( node.getYcoord() < getVisibleRect().getMinY() - y_dist ) - || ( node.getYcoord() > getVisibleRect().getMaxY() + y_dist ) || ( ( node.getParent() != null ) && ( node + return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - y_dist ) ) + || ( 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 ) ); + return ( ( node.getYcoord() < ( getVisibleRect().getMinY() - 20 ) ) + || ( node.getYcoord() > ( getVisibleRect().getMaxY() + 20 ) ) + || ( node.getXcoord() < ( getVisibleRect().getMinX() - 20 ) ) || ( node.getXcoord() > ( getVisibleRect() + .getMaxX() + 20 ) ) ); } final private boolean isNonLinedUpCladogram() { @@ -1737,9 +1901,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) ); } else if ( title.equals( Configuration.clickto_options[ Configuration.blast ][ 0 ] ) ) { - if ( Constants.__RELEASE || Constants.__SNAPSHOT_RELEASE ) { - continue; - } _node_popup_menu_items[ i ].setEnabled( isCanBlast( node ) ); } else if ( title.equals( Configuration.clickto_options[ Configuration.delete_subtree_or_node ][ 0 ] ) ) { @@ -1780,7 +1941,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _node_popup_menu_items[ i ].setEnabled( isCanReroot() ); } else if ( title.equals( Configuration.clickto_options[ Configuration.collapse_uncollapse ][ 0 ] ) ) { - _node_popup_menu_items[ i ].setEnabled( isCanCollapse() ); + _node_popup_menu_items[ i ].setEnabled( ( isCanCollapse() && !node.isExternal() ) ); } else if ( title.equals( Configuration.clickto_options[ Configuration.color_subtree ][ 0 ] ) ) { _node_popup_menu_items[ i ].setEnabled( isCanColorSubtree() ); @@ -1788,6 +1949,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else if ( title.equals( Configuration.clickto_options[ Configuration.subtree ][ 0 ] ) ) { _node_popup_menu_items[ i ].setEnabled( isCanSubtree( node ) ); } + else if ( title.equals( Configuration.clickto_options[ Configuration.swap ][ 0 ] ) ) { + _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() == 2 ); + } + else if ( title.equals( Configuration.clickto_options[ Configuration.sort_descendents ][ 0 ] ) ) { + _node_popup_menu_items[ i ].setEnabled( node.getNumberOfDescendants() > 1 ); + } _node_popup_menu_items[ i ].addActionListener( this ); _node_popup_menu.add( _node_popup_menu_items[ i ] ); } @@ -1804,7 +1971,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee JOptionPane.WARNING_MESSAGE ); return; } - _nodes_in_preorder = null; + setNodeInPreorderToNull(); setWaitCursor(); PhylogenyMethods.midpointRoot( _phylogeny ); resetNodeIdToDistToLeafMap(); @@ -1816,9 +1983,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( getOptions().isShowOverview() && isOvOn() && isInOv() ) { final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth(); final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight(); - double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - getOvRectangle().getWidth() / 2.0 ) + double x = ( e.getX() - getVisibleRect().x - getOvXPosition() - ( getOvRectangle().getWidth() / 2.0 ) ) * w_ratio; - double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - getOvRectangle().getHeight() / 2.0 ) + double y = ( e.getY() - getVisibleRect().y - getOvYPosition() - ( getOvRectangle().getHeight() / 2.0 ) ) * h_ratio; if ( x < 0 ) { x = 0; @@ -1915,8 +2082,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth(); final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight(); final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport().getViewPosition(); - double dx = ( w_ratio * e.getX() - w_ratio * getLastDragPointX() ); - double dy = ( h_ratio * e.getY() - h_ratio * getLastDragPointY() ); + double dx = ( ( w_ratio * e.getX() ) - ( w_ratio * getLastDragPointX() ) ); + double dy = ( ( h_ratio * e.getY() ) - ( h_ratio * getLastDragPointY() ) ); scroll_position.x = ForesterUtil.roundToInt( scroll_position.x + dx ); scroll_position.y = ForesterUtil.roundToInt( scroll_position.y + dy ); if ( scroll_position.x <= 0 ) { @@ -2008,6 +2175,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee setCursor( ARROW_CURSOR ); } + @Override final public void mouseWheelMoved( final MouseWheelEvent e ) { final int notches = e.getWheelRotation(); if ( inOvVirtualRectangle( e ) ) { @@ -2235,7 +2403,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final double root_y = _root.getYcoord(); final double dx = root_x - p.getXcoord(); final double dy = root_y - p.getYcoord(); - final double parent_radius = Math.sqrt( dx * dx + dy * dy ); + final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) ); final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle; assignGraphicsForBranchWithColorForParentBranch( c, false, g, to_pdf, to_graphics_file ); if ( ( c.isFirstChildNode() || c.isLastChildNode() ) @@ -2252,7 +2420,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( c.isExternal() ) { final boolean is_in_found_nodes = isInFoundNodes( c ); if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes - && ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor != 1 ) ) { + && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) { return; } paintNodeDataUnrootedCirc( g, c, to_pdf, to_graphics_file, radial_labels, 0, is_in_found_nodes ); @@ -2266,7 +2434,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final double dx = root_x - p.getXSecondary(); final double dy = root_y - p.getYSecondary(); final double arc = ( _urt_nodeid_angle_map.get( p.getId() ) ) - angle; - final double parent_radius = Math.sqrt( dx * dx + dy * dy ); + final double parent_radius = Math.sqrt( ( dx * dx ) + ( dy * dy ) ); g.setColor( getTreeColorSet().getOvColor() ); if ( ( c.isFirstChildNode() || c.isLastChildNode() ) && ( Math.abs( arc ) > 0.02 ) ) { final double r2 = 2.0 * parent_radius; @@ -2383,8 +2551,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee || ( 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 ) ) ) ) { + && ( ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) && ( y1 < ( getVisibleRect().getMinY() - 20 ) ) ) || ( ( y2 > ( getVisibleRect() + .getMaxY() + 20 ) ) && ( y1 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) ) { // Do nothing. } else { @@ -2418,7 +2586,7 @@ 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 ) ) ) { + && ( ( y2 < ( getVisibleRect().getMinY() - 20 ) ) || ( y2 > ( getVisibleRect().getMaxY() + 20 ) ) ) ) { return; } float x1_r = 0; @@ -2510,17 +2678,21 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee paintNodeBox( _root.getXcoord(), _root.getYcoord(), _root, g, to_pdf, to_graphics_file, isInFoundNodes( _root ) ); } - private void updateSetOfCollapsedExternalNodes( final Phylogeny phy ) { + void updateSetOfCollapsedExternalNodes() { + final Phylogeny phy = getPhylogeny(); _collapsed_external_nodeid_set.clear(); - E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) { - final PhylogenyNode ext_node = it.next(); - PhylogenyNode n = ext_node; - while ( !n.isRoot() ) { - if ( n.isCollapse() ) { - _collapsed_external_nodeid_set.add( ext_node.getId() ); - continue E; + if ( phy != null ) { + E: for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) { + final PhylogenyNode ext_node = it.next(); + PhylogenyNode n = ext_node; + while ( !n.isRoot() ) { + if ( n.isCollapse() ) { + _collapsed_external_nodeid_set.add( ext_node.getId() ); + ext_node.setCollapse( true ); + continue E; + } + n = n.getParent(); } - n = n.getParent(); } } } @@ -2538,8 +2710,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee double current_angle = starting_angle; for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) { final PhylogenyNode n = it.next(); - n.setXSecondary( ( float ) ( center_x + radius * Math.cos( current_angle ) ) ); - n.setYSecondary( ( float ) ( center_y + radius * Math.sin( current_angle ) ) ); + n.setXSecondary( ( float ) ( center_x + ( radius * Math.cos( current_angle ) ) ) ); + n.setYSecondary( ( float ) ( center_y + ( radius * Math.sin( current_angle ) ) ) ); _urt_nodeid_angle_map.put( n.getId(), current_angle ); current_angle += ( TWO_PI / circ_num_ext_nodes ); } @@ -2577,11 +2749,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } double r = 0; if ( !n.isRoot() ) { - r = 1 - ( ( ( double ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth ); + r = 1 - ( ( ( double ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth ); } final double theta = sum / descs.size(); - n.setXcoord( ( float ) ( center_x + r * radius * Math.cos( theta ) ) ); - n.setYcoord( ( float ) ( center_y + r * radius * Math.sin( theta ) ) ); + n.setXcoord( ( float ) ( center_x + ( r * radius * Math.cos( theta ) ) ) ); + n.setYcoord( ( float ) ( center_y + ( r * radius * Math.sin( theta ) ) ) ); _urt_nodeid_angle_map.put( n.getId(), theta ); for( final PhylogenyNode desc : descs ) { paintBranchCircular( n, desc, g, radial_labels, to_pdf, to_graphics_file ); @@ -2606,11 +2778,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } float r = 0; if ( !n.isRoot() ) { - r = 1 - ( ( ( float ) _circ_max_depth - PhylogenyMethods.calculateDepth( n ) ) / _circ_max_depth ); + r = 1 - ( ( ( float ) _circ_max_depth - n.calculateDepth() ) / _circ_max_depth ); } final double theta = _urt_nodeid_angle_map.get( n.getId() ); - n.setXSecondary( ( float ) ( center_x + radius * r * Math.cos( theta ) ) ); - n.setYSecondary( ( float ) ( center_y + radius * r * Math.sin( theta ) ) ); + n.setXSecondary( ( float ) ( center_x + ( radius * r * Math.cos( theta ) ) ) ); + n.setYSecondary( ( float ) ( center_y + ( radius * r * Math.sin( theta ) ) ) ); for( final PhylogenyNode desc : descs ) { paintBranchCircularLite( n, desc, g ); } @@ -2704,36 +2876,45 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final PhylogenyNode node, final boolean to_pdf, final boolean to_graphics_file ) { - String conf_str = ""; final List confidences = node.getBranchData().getConfidences(); - if ( confidences.size() == 1 ) { - final double value = node.getBranchData().getConfidence( 0 ).getValue(); - if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) { - return; - } - conf_str = FORMATTER_CONFIDENCE.format( value ); - } - else if ( confidences.size() > 1 ) { - boolean one_ok = false; - boolean not_first = false; - Collections.sort( confidences ); - final StringBuilder sb = new StringBuilder(); - for( final Confidence confidence : confidences ) { - final double value = confidence.getValue(); - if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) { - if ( value >= getOptions().getMinConfidenceValue() ) { - one_ok = true; - } - if ( not_first ) { - sb.append( "/" ); - } - else { - not_first = true; + // if ( confidences.size() == 1 ) { + // final double value = node.getBranchData().getConfidence( 0 ).getValue(); + // if ( ( value == Confidence.CONFIDENCE_DEFAULT_VALUE ) || ( value < getOptions().getMinConfidenceValue() ) ) { + // return; + // } + // conf_str = FORMATTER_CONFIDENCE.format( value ); + // } + // else if ( confidences.size() > 1 ) { + boolean one_ok = false; + boolean not_first = false; + Collections.sort( confidences ); + final StringBuilder sb = new StringBuilder(); + String conf_str = ""; + for( final Confidence confidence : confidences ) { + final double value = confidence.getValue(); + if ( value != Confidence.CONFIDENCE_DEFAULT_VALUE ) { + if ( value >= getOptions().getMinConfidenceValue() ) { + one_ok = true; + } + if ( not_first ) { + sb.append( "/" ); + } + else { + not_first = true; + } + 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( ")" ); } - sb.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( value, getOptions() - .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) ); } } + //} if ( one_ok ) { conf_str = sb.toString(); } @@ -2927,7 +3108,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( getOptions().isShowBranchLengthValues() && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) ) - && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) ) { + && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) { paintBranchLength( g, node, to_pdf, to_graphics_file ); } if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) { @@ -3058,7 +3239,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee x += CONFIDENCE_LEFT_MARGIN + confidenceWidth; } } - if ( x + nodeTextBoundsWidth > 0 ) /* we only underline if there is something displayed */ + if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */ { if ( nodeTextBoundsWidth == 0 ) { nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */ @@ -3127,28 +3308,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee .getLostCharactersAsStringBuffer().toString() ); } else { - if ( DRAW_MEAN_COUNTS && node.isInternal() ) { - final List ec = node.getAllExternalDescendants(); - double sum = 0; - int count = 0; - for( final PhylogenyNode phylogenyNode : ec ) { - count++; - if ( phylogenyNode.getNodeData().getBinaryCharacters() != null ) { - sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount(); - } - } - final double mean = ForesterUtil.round( sum / count, 1 ); - TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount() + " [" - + mean + "]", node.getXcoord() + x + 4 + half_box_size, node.getYcoord() - + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); - } - else { - TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(), - node.getXcoord() + x + 4 + half_box_size, - node.getYcoord() - + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), - g ); - } + TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(), + node.getXcoord() + x + 4 + half_box_size, + node.getYcoord() + + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), + g ); paintGainedAndLostCharacters( g, node, "+" + node.getNodeData().getBinaryCharacters().getGainedCount(), "-" + node.getNodeData().getBinaryCharacters().getLostCount() ); @@ -3168,10 +3332,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { sb.append( " " ); } - - final Property p = properties.getProperty( ref ); - sb.append( getPartAfterColon( p.getRef() ) ); sb.append( "=" ); sb.append( p.getValue() ); @@ -3181,10 +3342,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } return sb; } - + final private static String getPartAfterColon( final String s ) { final int i = s.indexOf( ':' ); - if ( (i < 1) ||( i == ( s.length()-1)) ) { + if ( ( i < 1 ) || ( i == ( s.length() - 1 ) ) ) { return s; } return s.substring( i + 1, s.length() ); @@ -3211,11 +3372,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } // y = y - ( 0.9 * getYdistance() ); final double hs = bi.getHeight() * scaling_factor; - double ws = bi.getWidth() * scaling_factor + offset; + double ws = ( bi.getWidth() * scaling_factor ) + offset; final double my_y = y - ( 0.5 * hs ); final int x_w = ( int ) ( x + ws + 0.5 ); final int y_h = ( int ) ( my_y + hs + 0.5 ); - if ( ( x_w - x > 7 ) && ( y_h - my_y > 7 ) ) { + if ( ( ( x_w - x ) > 7 ) && ( ( y_h - my_y ) > 7 ) ) { g.drawImage( bi, ( int ) ( x + 0.5 + offset ), ( int ) ( my_y + 0.5 ), @@ -3437,7 +3598,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee ++_external_node_index; } // Confidence values - if ( getControlPanel().isShowBootstrapValues() + if ( getControlPanel().isShowConfidenceValues() && !node.isExternal() && !node.isRoot() && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) @@ -3512,8 +3673,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } 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() < getTreeFontSet()._fm_large + && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) ) || ( !node + .isExternal() && ( ( new_x_min < 20 ) || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getTreeFontSet()._fm_large .getHeight() ) ) ) ) ) { return; } @@ -3540,28 +3701,53 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } catch ( final ClassCastException cce ) { cce.printStackTrace(); - return; - } - rds.setRenderingHeight( 6 ); - int x = 0; - if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( node ).length() > 0 ) ) { - x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " ); - } - if ( getControlPanel().isShowGeneNames() ) { - x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " ); } - if ( getControlPanel().isShowGeneSymbols() ) { - x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " ); - } - if ( getControlPanel().isShowSequenceAcc() ) { - x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession() - .toString() - + " " ); - } - if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) { - x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " ); + if ( rds != null ) { + rds.setRenderingHeight( 6 ); + int x = 0; + if ( node.getNodeData().isHasTaxonomy() ) { + if ( getControlPanel().isShowTaxonomyCode() + && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) { + x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy() + .getTaxonomyCode() + + " " ); + } + if ( getControlPanel().isShowTaxonomyScientificNames() + && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) ) { + x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy() + .getScientificName() + + " " ); + } + if ( getControlPanel().isShowTaxonomyCommonNames() + && ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getCommonName() ) ) ) { + x += getTreeFontSet()._fm_large_italic.stringWidth( node.getNodeData().getTaxonomy() + .getCommonName() + + " " ); + } + } + if ( node.getNodeData().isHasSequence() ) { + if ( getControlPanel().isShowGeneNames() + && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) ) { + x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + + " " ); + } + if ( getControlPanel().isShowGeneSymbols() + && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) ) { + x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + + " " ); + } + if ( getControlPanel().isShowSequenceAcc() + && ( node.getNodeData().getSequence().getAccession() != null ) ) { + x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence() + .getAccession().toString() + + " " ); + } + } + if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( node.getName() ) ) { + x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " ); + } + rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf ); } - rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf ); } } ////////////// @@ -3570,18 +3756,20 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(), getStatisticsForExpressionValues(), getConfiguration() ); - int x = 0; - PhylogenyNode my_node = node; - if ( !getControlPanel().isDrawPhylogram() ) { - my_node = getPhylogeny().getFirstExternalNode(); - } - if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) { - x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " ); - } - if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) { - x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " ); + if ( rv != null ) { + int x = 0; + PhylogenyNode my_node = node; + if ( !getControlPanel().isDrawPhylogram() ) { + my_node = getPhylogeny().getFirstExternalNode(); + } + if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( my_node ).length() > 0 ) ) { + x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( my_node ) + " " ); + } + if ( getControlPanel().isShowNodeNames() && ( my_node.getName().length() > 0 ) ) { + x += getTreeFontSet()._fm_large.stringWidth( my_node.getName() + " " ); + } + rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf ); } - rv.render( my_node.getXcoord() + x, node.getYcoord() - 5, g, this, to_pdf ); } ////////////// } @@ -3593,8 +3781,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final float y_ratio = ( float ) getHeight() / getVisibleRect().y; final float width = getOvMaxWidth() / w_ratio; final float height = getOvMaxHeight() / h_ratio; - final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio; - final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio; + final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio ); + final float y = getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / y_ratio ); g.setColor( getTreeColorSet().getFoundColor() ); getOvRectangle().setRect( x, y, width, height ); if ( ( width < 6 ) && ( height < 6 ) ) { @@ -3625,6 +3813,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final int graphics_file_height, final int graphics_file_x, final int graphics_file_y ) { + if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) { + return; + } if ( _control_panel.isShowSequenceRelations() ) { _query_sequence = _control_panel.getSelectedQuerySequence(); } @@ -3702,8 +3893,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee // paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData() // && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file ); //} - for( int i = 0; i < _nodes_in_preorder.length; ++i ) { - paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData() + for( final PhylogenyNode element : _nodes_in_preorder ) { + paintNodeRectangular( g, element, to_pdf, getControlPanel().isDynamicallyHideData() && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file ); } if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) { @@ -3743,7 +3934,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } paintUnrooted( _phylogeny.getRoot(), angle, - ( float ) ( angle + 2 * Math.PI ), + ( float ) ( angle + ( 2 * Math.PI ) ), radial_labels, g, to_pdf, @@ -3764,7 +3955,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.setColor( getTreeColorSet().getOvColor() ); paintUnrootedLite( _phylogeny.getRoot(), angle, - angle + 2 * Math.PI, + angle + ( 2 * Math.PI ), g, ( getUrtFactorOv() / ( getVisibleRect().width / getOvMaxWidth() ) ) ); paintOvRectangle( g ); @@ -3828,8 +4019,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) { // paintNodeLite( g, it.next() ); //} - for( int i = 0; i < _nodes_in_preorder.length; ++i ) { - paintNodeLite( g, _nodes_in_preorder[ i ] ); + for( final PhylogenyNode element : _nodes_in_preorder ) { + paintNodeLite( g, element ); } paintOvRectangle( g ); } @@ -4064,9 +4255,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { length = getUrtFactor(); } - final double mid_angle = current_angle + arc_size / 2; - final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length ); - final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length ); + final double mid_angle = current_angle + ( arc_size / 2 ); + final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) ); + final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) ); desc.setXcoord( new_x ); desc.setYcoord( new_y ); paintUnrooted( desc, current_angle, current_angle + arc_size, radial_labels, g, to_pdf, to_graphics_file ); @@ -4086,8 +4277,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee final Graphics2D g, final float urt_ov_factor ) { if ( n.isRoot() ) { - final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / 2 ); - final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / 2 ); + final int x_pos = ( int ) ( getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / 2 ) ); + final int y_pos = ( int ) ( getVisibleRect().y + getOvYPosition() + ( getOvMaxHeight() / 2 ) ); n.setXSecondary( x_pos ); n.setYSecondary( y_pos ); } @@ -4114,9 +4305,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { length = urt_ov_factor; } - final double mid_angle = current_angle + arc_size / 2; - final float new_x = ( float ) ( x + Math.cos( mid_angle ) * length ); - final float new_y = ( float ) ( y + Math.sin( mid_angle ) * length ); + final double mid_angle = current_angle + ( arc_size / 2 ); + final float new_x = ( float ) ( x + ( Math.cos( mid_angle ) * length ) ); + final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) ); desc.setXSecondary( new_x ); desc.setYSecondary( new_y ); if ( isInFoundNodes( desc ) ) { @@ -4142,7 +4333,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee JOptionPane.ERROR_MESSAGE ); return; } - final String label = getASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() ); + final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() ); final Object[] options = { "As sibling", "As descendant", "Cancel" }; final int r = JOptionPane.showOptionDialog( this, "How to paste subtree" + label + "?", @@ -4161,7 +4352,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final Phylogeny buffer_phy = getCutOrCopiedTree().copy(); buffer_phy.setAllNodesToNotCollapse(); - buffer_phy.preOrderReId(); + PhylogenyMethods.preOrderReId( buffer_phy ); buffer_phy.setRooted( true ); boolean need_to_show_whole = false; if ( paste_as_sibling ) { @@ -4193,9 +4384,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } node_ids.add( node.getId() ); getCopiedAndPastedNodes().addAll( node_ids ); - _nodes_in_preorder = null; + setNodeInPreorderToNull(); _phylogeny.externalNodesHaveChanged(); - _phylogeny.hashIDs(); + _phylogeny.clearHashIdToNodeMap(); _phylogeny.recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); setEdited( true ); @@ -4205,6 +4396,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee repaint(); } + @Override final public int print( final Graphics g, final PageFormat page_format, final int page_index ) throws PrinterException { if ( page_index > 0 ) { @@ -4244,7 +4436,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _node_frame_index--; _node_frames[ i ] = null; if ( i < _node_frame_index ) { - for( int j = 0; j < _node_frame_index - 1; j++ ) { + for( int j = 0; j < ( _node_frame_index - 1 ); j++ ) { _node_frames[ j ] = _node_frames[ j + 1 ]; } _node_frames[ _node_frame_index ] = null; @@ -4269,7 +4461,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee getPhylogeny().reRoot( node ); getPhylogeny().recalculateNumberOfExternalDescendants( true ); resetNodeIdToDistToLeafMap(); - _nodes_in_preorder = null; + setNodeInPreorderToNull(); resetPreferredSize(); getMainPanel().adjustJScrollPane(); repaint(); @@ -4498,7 +4690,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } if ( getMainPanel().getOptions().isAntialiasScreen() ) { - if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) { + if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) + && !getMainPanel().getOptions().isShowDefaultNodeShapes() + && ( ( getControlPanel() != null ) && !getControlPanel().isShowDomainArchitectures() ) ) { _rendering_hints.put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF ); } else { @@ -4529,10 +4723,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee * an instance of a Phylogeny */ public final void setTree( final Phylogeny t ) { - _nodes_in_preorder = null; + setNodeInPreorderToNull(); _phylogeny = t; } + final void setNodeInPreorderToNull() { + _nodes_in_preorder = null; + } + final void setTreeFile( final File treefile ) { _treefile = treefile; } @@ -4740,6 +4938,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee .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( ")" ); + } } } if ( node.getNodeData().isHasProperties() ) { @@ -4755,7 +4960,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } } - if ( _popup_buffer.length() > 0 ) { if ( !getConfiguration().isUseNativeUI() ) { _rollover_popup @@ -4833,7 +5037,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee JOptionPane.WARNING_MESSAGE ); return; } - _nodes_in_preorder = null; + setNodeInPreorderToNull(); if ( !node.isExternal() && !node.isRoot() && ( _subtree_index <= ( TreePanel.MAX_SUBTREES - 1 ) ) ) { _sub_phylogenies[ _subtree_index ] = _phylogeny; _sub_phylogenies_temp_roots[ _subtree_index ] = node; @@ -4870,7 +5074,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final void superTree() { - _nodes_in_preorder = null; + setNodeInPreorderToNull(); final PhylogenyNode temp_root = _sub_phylogenies_temp_roots[ _subtree_index - 1 ]; for( final PhylogenyNode n : temp_root.getDescendants() ) { n.setParent( temp_root ); @@ -4882,9 +5086,48 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final void swap( final PhylogenyNode node ) { + if ( node.isExternal() || ( node.getNumberOfDescendants() < 2 ) ) { + return; + } + if ( node.getNumberOfDescendants() > 2 ) { + JOptionPane.showMessageDialog( this, + "Cannot swap descendants of nodes with more than 2 descendants", + "Cannot swap descendants", + JOptionPane.ERROR_MESSAGE ); + return; + } + if ( !node.isExternal() ) { + node.swapChildren(); + setNodeInPreorderToNull(); + _phylogeny.externalNodesHaveChanged(); + _phylogeny.clearHashIdToNodeMap(); + _phylogeny.recalculateNumberOfExternalDescendants( true ); + resetNodeIdToDistToLeafMap(); + setEdited( true ); + } + repaint(); + } + + final void sortDescendants( final PhylogenyNode node ) { if ( !node.isExternal() ) { - _phylogeny.swapChildren( node ); - _nodes_in_preorder = null; + DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY; + if ( ( !getControlPanel().isShowTaxonomyScientificNames() && !getControlPanel().isShowTaxonomyCode() && !getControlPanel() + .isShowTaxonomyCommonNames() ) ) { + if ( ( getControlPanel().isShowSequenceAcc() || getControlPanel().isShowGeneNames() || getControlPanel() + .isShowGeneSymbols() ) ) { + pri = DESCENDANT_SORT_PRIORITY.SEQUENCE; + } + else if ( getControlPanel().isShowNodeNames() ) { + pri = DESCENDANT_SORT_PRIORITY.NODE_NAME; + } + } + PhylogenyMethods.sortNodeDescendents( node, pri ); + setNodeInPreorderToNull(); + _phylogeny.externalNodesHaveChanged(); + _phylogeny.clearHashIdToNodeMap(); + _phylogeny.recalculateNumberOfExternalDescendants( true ); + resetNodeIdToDistToLeafMap(); + setEdited( true ); } repaint(); } @@ -4990,7 +5233,7 @@ 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();