return AVAILABLE_FONT_FAMILIES_SORTED;
}
- final static void inferCommonPartOfScientificNames( final Phylogeny tree ) {
- boolean inferred = false;
- for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
- final PhylogenyNode n = it.next();
- if ( !n.getNodeData().isHasTaxonomy() && !n.isExternal() ) {
- final String sn = PhylogenyMethods.inferCommonPartOfScientificNameOfDescendants( n );
- if ( !ForesterUtil.isEmpty( sn ) ) {
- n.getNodeData().setTaxonomy( new Taxonomy() );
- n.getNodeData().getTaxonomy().setScientificName( sn );
- inferred = true;
- }
- }
- }
- if ( inferred ) {
- tree.setRerootable( false );
- }
- }
-
final static boolean isHasAssignedEvent( final PhylogenyNode node ) {
if ( !node.getNodeData().isHasEvent() ) {
return false;
else if ( o == _confcolor_item ) {
getMainPanel().getCurrentTreePanel().confColor();
}
- else if ( o == _infer_common_sn_names_item ) {
- if ( getCurrentTreePanel() != null ) {
- getCurrentTreePanel().inferCommonPartOfScientificNames();
- }
- }
else if ( o == _collapse_species_specific_subtrees ) {
if ( getCurrentTreePanel() != null ) {
getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
_return_to_super_tree.setEnabled( true );
}
+ void showAnnotations() {
+ _show_annotation.setSelected( true );
+ _color_according_to_annotation.setSelected( true );
+ _color_acc_species.setSelected( false );
+ _mainpanel.getCurrentTreePanel().repaint();
+ }
+
/**
* Add zoom and quick edit buttons. (Last modified 8/9/04)
*/
JMenuItem _taxcolor_item;
JMenuItem _confcolor_item;
JMenuItem _color_rank_jmi;
- JMenuItem _infer_common_sn_names_item;
JMenuItem _collapse_species_specific_subtrees;
JMenuItem _collapse_below_threshold; //TODO implememt me
JMenuItem _obtain_detailed_taxonomic_information_jmi;
else if ( o == _color_rank_jmi ) {
colorRank();
}
- else if ( o == _infer_common_sn_names_item ) {
- if ( isSubtreeDisplayed() ) {
- return;
- }
- if ( getCurrentTreePanel() != null ) {
- getCurrentTreePanel().inferCommonPartOfScientificNames();
- }
- }
else if ( o == _collapse_species_specific_subtrees ) {
if ( isSubtreeDisplayed() ) {
return;
}
final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
if ( ( phy != null ) && !phy.isEmpty() ) {
- final JTextField xField = new JTextField( 10 );
- final JTextField yField = new JTextField( 20 );
- xField.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
+ final JTextField ref_field = new JTextField( 10 );
+ final JTextField desc_filed = new JTextField( 20 );
+ ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
: getPreviousNodeAnnotationReference() );
- final JPanel myPanel = new JPanel();
- myPanel.add( new JLabel( "Reference " ) );
- myPanel.add( xField );
- myPanel.add( Box.createHorizontalStrut( 15 ) );
- myPanel.add( new JLabel( "Description " ) );
- myPanel.add( yField );
+ final JPanel my_panel = new JPanel();
+ my_panel.add( new JLabel( "Reference " ) );
+ my_panel.add( ref_field );
+ my_panel.add( Box.createHorizontalStrut( 15 ) );
+ my_panel.add( new JLabel( "Description " ) );
+ my_panel.add( desc_filed );
final int result = JOptionPane.showConfirmDialog( null,
- myPanel,
+ my_panel,
"Enter the sequence annotation(s) for the "
+ nodes.size() + " selected nodes",
JOptionPane.OK_CANCEL_OPTION );
if ( result == JOptionPane.OK_OPTION ) {
- String ref = xField.getText();
- String desc = yField.getText();
- if ( ref != null ) {
+ String ref = ref_field.getText();
+ String desc = desc_filed.getText();
+ if ( !ForesterUtil.isEmpty( ref ) ) {
ref = ref.trim();
ref = ref.replaceAll( "\\s+", " " );
+ if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
+ || ( ref.length() < 3 ) ) {
+ JOptionPane.showMessageDialog( this,
+ "Reference needs to be in the form of \"GO:1234567\"",
+ "Illegal Format for Annotation Reference",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ }
+ if ( ref != null ) {
+ setPreviousNodeAnnotationReference( ref );
}
if ( desc != null ) {
desc = desc.trim();
desc = desc.replaceAll( "\\s+", " " );
}
- if ( ref != null ) {
- setPreviousNodeAnnotationReference( ref );
- }
if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
for( final Integer id : nodes ) {
final PhylogenyNode n = phy.getNode( id );
n.getNodeData().getSequence().addAnnotation( ann );
}
}
+ getMainPanel().getControlPanel().showAnnotations();
}
}
}
_tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
customizeJMenuItem( _midpoint_root_item );
_tools_menu.addSeparator();
- _tools_menu
- .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
- customizeJMenuItem( _infer_common_sn_names_item );
_tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
customizeJMenuItem( _collapse_species_specific_subtrees );
_jmenubar.add( _tools_menu );
.setToolTipText( "To extract taxonomic codes (mnemonics) from nodes names in the form of 'xyz_ECOLI'" );
_tools_menu.addSeparator();
_tools_menu
- .add( _infer_common_sn_names_item = new JMenuItem( "Infer Common Parts of Internal Scientific Names" ) );
- customizeJMenuItem( _infer_common_sn_names_item );
- _tools_menu.addSeparator();
- _tools_menu
.add( _obtain_detailed_taxonomic_information_jmi = new JMenuItem( OBTAIN_DETAILED_TAXONOMIC_INFORMATION ) );
customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
_obtain_detailed_taxonomic_information_jmi
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
+import java.util.SortedSet;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
}
}
- final void inferCommonPartOfScientificNames() {
- if ( ( _phylogeny == null ) || ( _phylogeny.getNumberOfExternalNodes() < 2 ) ) {
- return;
- }
- setWaitCursor();
- AptxUtil.inferCommonPartOfScientificNames( _phylogeny );
- setArrowCursor();
- repaint();
- }
-
final void initNodeData() {
if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
return;
}
}
- final private Color calculateColorForAnnotation( final Annotation ann ) {
+ final private Color calculateColorForAnnotation( final SortedSet<Annotation> ann ) {
Color c = getTreeColorSet().getAnnotationColor();
if ( getControlPanel().isColorAccordingToAnnotation() && ( getControlPanel().getAnnotationColors() != null ) ) {
- final String ann_str = !ForesterUtil.isEmpty( ann.getRef() ) ? ann.getRef() : ann.getDesc();
+ final StringBuilder sb = new StringBuilder();
+ for( Annotation a : ann ) {
+ sb.append( !ForesterUtil.isEmpty( a.getRef() ) ? a.getRef() : a.getDesc() );
+ }
+ final String ann_str = sb.toString();
if ( !ForesterUtil.isEmpty( ann_str ) ) {
c = getControlPanel().getAnnotationColors().get( ann_str );
if ( c == null ) {
else if ( getControlPanel().isColorAccordingToAnnotation()
&& ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
.getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
- g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotation( 0 ) ) );
+ g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
}
else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isColorBranches()
&& ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
if ( _sb.length() > 0 ) {
x += getTreeFontSet()._fm_large.stringWidth( _sb.toString() ) + 5;
}
- final Annotation ann = node.getNodeData().getSequence().getAnnotation( 0 );
+ final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
g.setColor( Color.BLACK );
}
else if ( getControlPanel().isColorAccordingToAnnotation() ) {
g.setColor( calculateColorForAnnotation( ann ) );
}
- final String ann_str = ann.asSimpleText().toString();
+ final String ann_str = createAnnotationString( ann );
TreePanel.drawString( ann_str, node.getXcoord() + x + 3 + half_box_size, node.getYcoord()
+ ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g );
_sb.setLength( 0 );
}
}
+ private String createAnnotationString( final SortedSet<Annotation> ann ) {
+ final StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for( Annotation a : ann ) {
+ if ( !first ) {
+ sb.append( "|" );
+ }
+ else {
+ first = false;
+ }
+ sb.append( a.asSimpleText() );
+ }
+ final String ann_str = sb.toString();
+ return ann_str;
+ }
+
final private void paintNodeDataUnrootedCirc( final Graphics2D g,
final PhylogenyNode node,
final boolean to_pdf,
else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
g.setColor( getTaxonomyBasedColor( node ) );
}
+ else if ( getControlPanel().isColorAccordingToAnnotation()
+ && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
+ .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
+ g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
+ }
else {
g.setColor( getTreeColorSet().getSequenceColor() );
}
return nodes;
}
- public static String inferCommonPartOfScientificNameOfDescendants( final PhylogenyNode node ) {
- final List<PhylogenyNode> descs = node.getDescendants();
- String sn = null;
- for( final PhylogenyNode n : descs ) {
- if ( !n.getNodeData().isHasTaxonomy()
- || ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
- return null;
- }
- else if ( sn == null ) {
- sn = n.getNodeData().getTaxonomy().getScientificName().trim();
- }
- else {
- String sn_current = n.getNodeData().getTaxonomy().getScientificName().trim();
- if ( !sn.equals( sn_current ) ) {
- boolean overlap = false;
- while ( ( sn.indexOf( ' ' ) >= 0 ) || ( sn_current.indexOf( ' ' ) >= 0 ) ) {
- if ( ForesterUtil.countChars( sn, ' ' ) > ForesterUtil.countChars( sn_current, ' ' ) ) {
- sn = sn.substring( 0, sn.lastIndexOf( ' ' ) ).trim();
- }
- else {
- sn_current = sn_current.substring( 0, sn_current.lastIndexOf( ' ' ) ).trim();
- }
- if ( sn.equals( sn_current ) ) {
- overlap = true;
- break;
- }
- }
- if ( !overlap ) {
- return null;
- }
- }
- }
- }
- return sn;
- }
-
public static boolean isHasExternalDescendant( final PhylogenyNode node ) {
for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
if ( node.getChildNode( i ).isExternal() ) {
if ( ForesterUtil.isEmpty( ref ) ) {
throw new IllegalArgumentException( "annotation reference is empty or null" );
}
- if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.length() < 3 ) ) {
+ if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 ) || ( ref.length() < 3 ) ) {
throw new IllegalArgumentException( "illegal format for annotation reference: [" + ref + "]" );
}
_ref = ref;