import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
2.0f },
0f );
private static final double TWO_PI = 2 * Math.PI;
- private final static int WIGGLE = 2;
+ private final static int WIGGLE = 3;
private static final String SHOW_ONLY_THIS_CONF_TYPE = null; //TODO remove me
HashMap<Long, Short> _nodeid_dist_to_leaf = new HashMap<Long, Short>();
final private Arc2D _arc = new Arc2D.Double();
private AffineTransform _at;
+ private int _clicked_x;
private int _circ_max_depth;
final private Set<Long> _collapsed_external_nodeid_set = new HashSet<Long>();
private JColorChooser _color_chooser = null;
private final FontRenderContext _frc = new FontRenderContext( null,
false,
false );
+ private float _furthest_node_x;
private PHYLOGENY_GRAPHICS_TYPE _graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
private PhylogenyNode _highlight_node = null;
private boolean _in_ov = false;
private float _ov_y_distance = 0;
private int _ov_y_position = 0;
private int _ov_y_start = 0;
+ private boolean _partition_tree = false;
+ private float _partition_threshold = 0;
private final boolean _phy_has_branch_lengths;
private Phylogeny _phylogeny = null;
private final Path2D.Float _polygon = new Path2D.Float();
RenderingHints.VALUE_RENDER_DEFAULT );
private JTextArea _rollover_popup;
private PhylogenyNode _root;
+ private float _root_x;
private final StringBuilder _sb = new StringBuilder();
private double _scale_distance = 0.0;
private String _scale_label = null;
private Map<String, AttributedString> _attributed_string_map = null;
private int _depth_collapse_level = -1;
private int _rank_collapse_level = -1;
+
+
+
static {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator( '.' );
@Override
final public void paintComponent( final Graphics g ) {
- // Dimension currentSize = getSize();
- // if ( offscreenImage == null || !currentSize.equals( offscreenDimension ) ) {
- // call the 'java.awt.Component.createImage(...)' method to get an
- // image
- // offscreenImage = createImage( currentSize.width, currentSize.height );
- // offscreenGraphics = offscreenImage.getGraphics();
- // offscreenDimension = currentSize;
- // }
- // super.paintComponent( g ); //why?
- //final Graphics2D g2d = ( Graphics2D ) offscreenGraphics;
final Graphics2D g2d = ( Graphics2D ) g;
g2d.setRenderingHints( _rendering_hints );
paintPhylogeny( g2d, false, false, 0, 0, 0, 0 );
- //g.drawImage( offscreenImage, 0, 0, this );
}
@Override
return _last_drag_point_y;
}
- final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
- if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
- final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
- _nodeid_dist_to_leaf.put( node.getId(), m );
- return m;
- }
- else {
- return _nodeid_dist_to_leaf.get( node.getId() );
- }
- }
-
final private double getMaxDistanceToRoot() {
if ( _max_distance_to_root < 0 ) {
recalculateMaxDistanceToRoot();
final private TreeFontSet getTreeFontSet() {
return getMainPanel().getTreeFontSet();
}
+
+ final public float getThreshold() {
+ return _partition_threshold;
+ }
final private float getUrtFactor() {
return _urt_factor;
sortDescendants( node );
break;
case GET_EXT_DESC_DATA:
- showExtDescNodeData( node );
+ showExtDescNodeData( node, '_' );
break;
case UNCOLLAPSE_ALL:
uncollapseAll( node );
final boolean to_pdf,
final boolean to_graphics_file ) {
g.setFont( getTreeFontSet().getSmallFont() );
- if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
+ if ( to_pdf || ( to_graphics_file && getOptions().isPrintBlackAndWhite() ) ) {
g.setColor( Color.BLACK );
}
else {
final boolean to_graphics_file,
final boolean to_pdf,
final boolean is_in_found_nodes ) {
+ ////
+ //// TODO
+ ////
Color c = null;
+ int res[] = null;
+ if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
+ res = calcFoundNodesInSubtree( node );
+ }
if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
c = Color.BLACK;
}
- else if ( is_in_found_nodes ) {
- c = getColorForFoundNode( node );
- }
- else if ( getControlPanel().isColorAccordingToSequence() ) {
- c = getSequenceBasedColor( node );
- }
- else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
- c = getTaxonomyBasedColor( node );
- }
+ //TODO
+ //FIXME
+ // else if ( is_in_found_nodes ) {
+ // c = getColorForFoundNode( node );
+ // }
+ // else if ( getControlPanel().isColorAccordingToSequence() ) {
+ // c = getSequenceBasedColor( node );
+ // }
+ // else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
+ // c = getTaxonomyBasedColor( node );
+ // }
else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
&& ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
c = PhylogenyMethods.getBranchColorValue( node );
else if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) {
x += ROUNDED_D;
}
- if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
+ if ( to_pdf || ( to_graphics_file && getOptions().isPrintBlackAndWhite() ) ) {
g.setColor( Color.BLACK );
}
else {
&& !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
addLabelForCollapsed( first.getNodeData().getTaxonomy().getTaxonomyCode(),
last.getNodeData().getTaxonomy().getTaxonomyCode(),
- node.getAllExternalDescendants().size() );
+ node.getAllExternalDescendants().size(),
+ node );
}
else if ( getControlPanel().isShowTaxonomyScientificNames() && first.getNodeData().isHasTaxonomy()
&& last.getNodeData().isHasTaxonomy()
&& !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) {
addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
last.getNodeData().getTaxonomy().getScientificName(),
- node.getAllExternalDescendants().size() );
+ node.getAllExternalDescendants().size(),
+ node );
}
else if ( getControlPanel().isShowSeqNames() && first.getNodeData().isHasSequence()
&& last.getNodeData().isHasSequence()
&& !ForesterUtil.isEmpty( last.getNodeData().getSequence().getName() ) ) {
addLabelForCollapsed( first.getNodeData().getSequence().getName(),
last.getNodeData().getSequence().getName(),
- node.getAllExternalDescendants().size() );
+ node.getAllExternalDescendants().size(),
+ node );
}
else if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( first.getName() )
&& !ForesterUtil.isEmpty( last.getName() ) ) {
addLabelForCollapsed( first.getName(),
last.getName(),
- node.getAllExternalDescendants().size() );
+ node.getAllExternalDescendants().size(),
+ node );
}
}
}
_sb.append( " [" );
_sb.append( node.getAllExternalDescendants().size() );
_sb.append( "]" );
+ if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
+ int[] res = calcFoundNodesInSubtree( node );
+ if ( res[ 0 ] > 0 ) {
+ _sb.append( " [" );
+ _sb.append( res[ 0 ] );
+ _sb.append( "/" );
+ _sb.append( res[ 1 ] );
+ _sb.append( "]" );
+ }
+ }
}
}
else {
}
}
- private final void addLabelForCollapsed( final String first, final String last, final int size ) {
+ private final void addLabelForCollapsed( final String first,
+ final String last,
+ final int size,
+ final PhylogenyNode node ) {
_sb.append( first.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? first
: first.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
_sb.append( " ... " );
_sb.append( last.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? last
: last.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
_sb.append( " (" + size + ")" );
+ if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
+ /////
+ /////
+ int[] res = calcFoundNodesInSubtree( node );
+ if ( res[ 0 ] > 0 ) {
+ _sb.append( " [" );
+ _sb.append( res[ 0 ] );
+ _sb.append( "/" );
+ _sb.append( res[ 1 ] );
+ _sb.append( "]" );
+ }
+ }
+ }
+
+ private final int[] calcFoundNodesInSubtree( final PhylogenyNode node ) {
+ final List<PhylogenyNode> all_descs = PhylogenyMethods.getAllDescendants( node );
+ int res[] = new int[ 2 ];
+ int found = 0;
+ int total = 0;
+ for( final PhylogenyNode desc : all_descs ) {
+ if ( desc.isHasNodeData() ) {
+ if ( ( _found_nodes_0 != null && _found_nodes_0.contains( desc.getId() ) )
+ || ( _found_nodes_1 != null && _found_nodes_1.contains( desc.getId() ) ) ) {
+ ++found;
+ }
+ ++total;
+ }
+ }
+ res[ 0 ] = found;
+ res[ 1 ] = total;
+ return res;
}
private final boolean isAllowAttributedStrings() {
if ( getOptions().isLineUpRendarableNodeData() ) {
if ( getOptions().isRightLineUpDomains() ) {
rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
- + _length_of_longest_text
+ + _length_of_longest_text + 50 //TODO why plus 50?
+ ( ( _longest_domain - rds.getTotalLength() ) * rds.getRenderingFactorWidth() ) ),
node.getYcoord() - ( h / 2.0f ),
g,
}
else {
rds.render( ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
- + _length_of_longest_text ), node.getYcoord() - ( h / 2.0f ), g, this, to_pdf );
+ + _length_of_longest_text + 50 ),
+ node.getYcoord() - ( h / 2.0f ),
+ g,
+ this,
+ to_pdf );
}
}
else {
//if ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
// && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
// && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
- // paintMolecularSequences( g, node, to_pdf );
+ // paintMolecularSequences( g, node, to_pdf );
//}
}
_urt_factor_ov = urt_factor_ov;
}
- private void showExtDescNodeData( final PhylogenyNode node ) {
+ private void showExtDescNodeData( final PhylogenyNode node, final char separator ) {
final List<String> data = new ArrayList<String>();
final List<PhylogenyNode> nodes = node.getAllExternalDescendants();
if ( ( getFoundNodes0() != null ) || ( getFoundNodes1() != null ) ) {
if ( n.getNodeData().isHasSequence()
&& !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
final StringBuilder ann = new StringBuilder();
- if ( !ForesterUtil.isEmpty( n.getName() ) ) {
+ if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( n.getName() ) ) {
ann.append( n.getName() );
- ann.append( "|" );
+ ann.append( separator );
+ }
+ if ( n.getNodeData().isHasTaxonomy() ) {
+ if ( getControlPanel().isShowTaxonomyCode()
+ && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
+ ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
+ ann.append( separator );
+ }
+ if ( getControlPanel().isShowTaxonomyScientificNames()
+ && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+ ann.append( n.getNodeData().getTaxonomy().getScientificName() );
+ ann.append( separator );
+ }
+ if ( getControlPanel().isShowTaxonomyCommonNames()
+ && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) ) {
+ ann.append( n.getNodeData().getTaxonomy().getCommonName() );
+ ann.append( separator );
+ }
}
- if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
- ann.append( "SYM=" );
+ if ( getControlPanel().isShowSeqSymbols()
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
ann.append( n.getNodeData().getSequence().getSymbol() );
- ann.append( "|" );
+ ann.append( separator );
}
- if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
- ann.append( "NAME=" );
+ if ( getControlPanel().isShowSeqNames()
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
ann.append( n.getNodeData().getSequence().getName() );
- ann.append( "|" );
+ ann.append( separator );
}
- if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
- ann.append( "GN=" );
+ if ( getControlPanel().isShowGeneNames()
+ && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getGeneName() ) ) {
ann.append( n.getNodeData().getSequence().getGeneName() );
- ann.append( "|" );
+ ann.append( separator );
}
- if ( n.getNodeData().getSequence().getAccession() != null ) {
- ann.append( "ACC=" );
+ if ( getControlPanel().isShowSequenceAcc()
+ && n.getNodeData().getSequence().getAccession() != null ) {
ann.append( n.getNodeData().getSequence().getAccession().asText() );
- ann.append( "|" );
- }
- if ( n.getNodeData().isHasTaxonomy() ) {
- if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
- ann.append( "TAXID=" );
- ann.append( n.getNodeData().getTaxonomy().getTaxonomyCode() );
- ann.append( "|" );
- }
- if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
- ann.append( "SN=" );
- ann.append( n.getNodeData().getTaxonomy().getScientificName() );
- ann.append( "|" );
- }
+ ann.append( separator );
}
- String ann_str;
- if ( ann.charAt( ann.length() - 1 ) == '|' ) {
+
+ final String ann_str;
+ if ( ann.length() > 0 && ann.charAt( ann.length() - 1 ) == separator ) {
ann_str = ann.substring( 0, ann.length() - 1 );
}
else {
}
boolean use_vis = false;
final Graphics2D g = ( Graphics2D ) getGraphics();
- if ( getControlPanel().isUseVisualStyles() ) {
+ if ( g != null && getControlPanel().isUseVisualStyles() ) {
use_vis = setFont( g, node, false );
}
if ( !use_vis ) {
* @param y
* @return pointer to the node at x,y, null if not found
*/
- final PhylogenyNode findNode( final int x, final int y ) {
+ public final PhylogenyNode findNode( final int x, final int y ) {
if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
return null;
}
return _domain_structure_e_value_thr_exp;
}
- final Set<Long> getFoundNodes0() {
+ public final Set<Long> getFoundNodes0() {
return _found_nodes_0;
}
- final Set<Long> getFoundNodes1() {
+ public final Set<Long> getFoundNodes1() {
return _found_nodes_1;
}
- List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
+ public List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
if ( getFoundNodes0() != null ) {
for( final Long id : getFoundNodes0() ) {
return getTreeColorSet().getTaxonomyColor();
}
- final File getTreeFile() {
+ public final File getTreeFile() {
return _treefile;
}
&& ( !node.isRoot() || ( _subtree_index > 0 ) ) );
}
- final boolean isCurrentTreeIsSubtree() {
+ public final boolean isCurrentTreeIsSubtree() {
return ( _subtree_index > 0 );
}
}
}
else {
- // no node was clicked
+ // no node was clicked so partition tree instead
_highlight_node = null;
- }
+
+ _clicked_x = e.getX();
+ if (!getPhylogeny().isEmpty()) {
+
+ PhylogenyNode furthestNode = PhylogenyMethods.calculateNodeWithMaxDistanceToRoot( _phylogeny );
+ _furthest_node_x = furthestNode.getXcoord();
+ _root_x = _phylogeny.getRoot().getXcoord();
+
+ // don't bother if 0 distance tree or clicked x lies outside of tree
+ if (_furthest_node_x != _root_x && !(_clicked_x < _root_x || _clicked_x > _furthest_node_x))
+ {
+ _partition_tree = true;
+
+ }
+
+
}
+ }
+ }
repaint();
}
paintCircularsLite( phy.getRoot(), phy, center_x, center_y, radius, g );
}
+ public final void paintFile( final Graphics2D g,
+ final boolean to_pdf,
+ final int graphics_file_width,
+ final int graphics_file_height,
+ final int graphics_file_x,
+ final int graphics_file_y ) {
+ paintPhylogeny(g,to_pdf,true,graphics_file_width,graphics_file_height,graphics_file_x,graphics_file_y);
+ }
final void paintPhylogeny( final Graphics2D g,
final boolean to_pdf,
final boolean to_graphics_file,
final int graphics_file_height,
final int graphics_file_x,
final int graphics_file_y ) {
+
if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
return;
}
g.setTransform( _at );
paintOvRectangle( g );
}
- }
+
+
+ }
+ if (_partition_tree) {
+ g.setColor( Color.BLACK );
+ _partition_threshold = (_clicked_x - _root_x) / (_furthest_node_x - _root_x);
+ drawLine( _clicked_x, 0, _clicked_x, getHeight(),g);
+ _partition_tree = false;
+ }
}
+
final void recalculateMaxDistanceToRoot() {
_max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
_current_external_nodes_data_buffer = sb;
}
- final void setFoundNodes0( final Set<Long> found_nodes ) {
+ public final void setFoundNodes0( final Set<Long> found_nodes ) {
_found_nodes_0 = found_nodes;
}
- final void setFoundNodes1( final Set<Long> found_nodes ) {
+ public final void setFoundNodes1( final Set<Long> found_nodes ) {
_found_nodes_1 = found_nodes;
}
getTreeFontSet().tinyFonts();
}
- final void setTreeFile( final File treefile ) {
+ public final void setTreeFile( final File treefile ) {
_treefile = treefile;
}