in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 30 Nov 2012 05:23:19 +0000 (05:23 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 30 Nov 2012 05:23:19 +0000 (05:23 +0000)
forester/java/src/org/forester/archaeopteryx/AptxUtil.java
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/ControlPanel.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java
forester/java/src/org/forester/archaeopteryx/TreePanel.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java
forester/java/src/org/forester/phylogeny/data/Annotation.java

index 1078656..f7fbee6 100644 (file)
@@ -791,24 +791,6 @@ public final class AptxUtil {
         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;
index c388c5e..8755c67 100644 (file)
@@ -136,11 +136,6 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         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();
index f7e6dba..e25ef2c 100644 (file)
@@ -432,6 +432,13 @@ final class ControlPanel extends JPanel implements ActionListener {
         _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)
      */
index ae4f8b4..8b98088 100644 (file)
@@ -135,7 +135,6 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     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;
@@ -263,14 +262,6 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         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;
@@ -1210,35 +1201,43 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             }
             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 );
@@ -1251,6 +1250,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                             n.getNodeData().getSequence().addAnnotation( ann );
                         }
                     }
+                    getMainPanel().getControlPanel().showAnnotations();
                 }
             }
         }
index 62cca3a..8df235b 100644 (file)
@@ -257,9 +257,6 @@ public final class MainFrameApplet extends MainFrame {
         _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 );
index 6194d47..f5cda0b 100644 (file)
@@ -942,10 +942,6 @@ public final class MainFrameApplication extends MainFrame {
                 .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
index 7adf066..1e329d3 100644 (file)
@@ -76,6 +76,7 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Set;
+import java.util.SortedSet;
 
 import javax.swing.BorderFactory;
 import javax.swing.JApplet;
@@ -967,16 +968,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
-    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;
@@ -2248,10 +2239,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
-    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 ) {
@@ -3854,7 +3849,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         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 ) ) {
@@ -3991,14 +3986,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             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 );
@@ -4040,6 +4035,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
+    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,
@@ -4059,6 +4070,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         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() );
         }
index 64c7965..67e9b52 100644 (file)
@@ -1157,42 +1157,6 @@ public class PhylogenyMethods {
         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() ) {
index 4e9eb08..829707a 100644 (file)
@@ -49,7 +49,7 @@ public class Annotation implements PhylogenyData, MultipleUris, Comparable<Annot
         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;