in progress
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 19 Sep 2011 02:30:04 +0000 (02:30 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 19 Sep 2011 02:30:04 +0000 (02:30 +0000)
forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java
forester/java/src/org/forester/archaeopteryx/NodePanel.java
forester/java/src/org/forester/phylogeny/data/Taxonomy.java
forester/java/src/org/forester/ws/uniprot/UniProtTaxonomy.java
forester/java/src/org/forester/ws/uniprot/UniProtWsTools.java

index da68994..dec0a63 100644 (file)
@@ -174,9 +174,8 @@ public final class AncestralTaxonomyInference {
                             || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getScientificName() )
                             || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getTaxonomyCode() ) || !ForesterUtil
                             .isEmpty( desc.getNodeData().getTaxonomy().getCommonName() ) ) ) {
-                final QUERY_TYPE qt = null;
-                final String query = null;
-                final UniProtTaxonomy up_tax = obtainUniProtTaxonomy( desc.getNodeData().getTaxonomy(), query, qt );
+             
+                final UniProtTaxonomy up_tax = obtainUniProtTaxonomy( desc.getNodeData().getTaxonomy(), null, null );
                 String[] lineage = null;
                 if ( up_tax != null ) {
                     //lineage = obtainLineagePlusOwnScientificName( up_tax );
@@ -203,16 +202,16 @@ public final class AncestralTaxonomyInference {
                     node = "[" + desc.getId() + "]";
                 }
                 msg = "Node " + node + " has no or inappropriate taxonomic information";
-                final List<PhylogenyNode> e = desc.getAllExternalDescendants();
+             //   final List<PhylogenyNode> e = desc.getAllExternalDescendants();
                 //TODO remove me!
-                System.out.println();
-                int x = 0;
-                for( final PhylogenyNode object : e ) {
-                    System.out.println( x + ":" );
-                    System.out.println( object.getName() + "  " );
-                    x++;
-                }
-                System.out.println();
+//                System.out.println();
+//                int x = 0;
+//                for( final PhylogenyNode object : e ) {
+//                    System.out.println( x + ":" );
+//                    System.out.println( object.getName() + "  " );
+//                    x++;
+//                }
+//                System.out.println();
                 //
                 throw new IllegalArgumentException( msg );
             }
@@ -245,7 +244,7 @@ public final class AncestralTaxonomyInference {
         final Taxonomy tax = new Taxonomy();
         n.getNodeData().setTaxonomy( tax );
         tax.setScientificName( last_common_lineage );
-        final UniProtTaxonomy up_tax = obtainUniProtTaxonomyFromSn( last_common_lineage );
+        final UniProtTaxonomy up_tax = obtainUniProtTaxonomyFromSn( last_common_lineage, lineage );
         if ( up_tax != null ) {
             if ( !ForesterUtil.isEmpty( up_tax.getRank() ) ) {
                 try {
@@ -264,6 +263,15 @@ public final class AncestralTaxonomyInference {
             if ( !ForesterUtil.isEmpty( up_tax.getSynonym() ) && !tax.getSynonyms().contains( up_tax.getSynonym() ) ) {
                 tax.getSynonyms().add( up_tax.getSynonym() );
             }
+            if ( up_tax.getLineage() != null ) {
+                tax.setLineage( new ArrayList<String>() );
+                for( final String lin : up_tax.getLineage() ) {
+                    if ( !ForesterUtil.isEmpty( lin ) ) {
+                        tax.getLineage().add( lin );
+                    }
+                }
+            }
+            
         }
         for( final PhylogenyNode desc : descs ) {
             if ( !desc.isExternal() && desc.getNodeData().isHasTaxonomy()
@@ -307,14 +315,14 @@ public final class AncestralTaxonomyInference {
                     not_found_external_nodes.add( node );
                 }
             }
-            UniProtTaxonomy up_tax = null;
+            UniProtTaxonomy uniprot_tax = null;
             if ( ( tax != null )
                     && ( isHasAppropriateId( tax ) || !ForesterUtil.isEmpty( tax.getScientificName() )
                             || !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) || !ForesterUtil.isEmpty( tax
                             .getCommonName() ) ) ) {
-                up_tax = obtainUniProtTaxonomy( tax, null, qt );
-                if ( up_tax != null ) {
-                    updateTaxonomy( qt, node, tax, up_tax );
+                uniprot_tax = obtainUniProtTaxonomy( tax, null, qt );
+                if ( uniprot_tax != null ) {
+                    updateTaxonomy( qt, node, tax, uniprot_tax );
                 }
                 else {
                     not_found.add( tax.toString() );
@@ -350,11 +358,13 @@ public final class AncestralTaxonomyInference {
         if ( isHasAppropriateId( tax ) ) {
             query = tax.getIdentifier().getValue();
             qt = QUERY_TYPE.ID;
+            System.out.println( "query by id: " + query);
             return getTaxonomies( getIdTaxCacheMap(), query, qt );
         }
         else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
             query = tax.getScientificName();
             qt = QUERY_TYPE.SN;
+            System.out.println( "query by sn: " + query);
             return getTaxonomies( getSnTaxCacheMap(), query, qt );
         }
         else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
@@ -369,7 +379,7 @@ public final class AncestralTaxonomyInference {
         }
     }
 
-    synchronized private static UniProtTaxonomy obtainUniProtTaxonomyFromSn( final String sn ) throws IOException {
+    synchronized private static UniProtTaxonomy obtainUniProtTaxonomyFromSn( final String sn, List<String> lineage ) throws IOException {
         UniProtTaxonomy up_tax = null;
         if ( getSnTaxCacheMap().containsKey( sn ) ) {
             up_tax = getSnTaxCacheMap().get( sn ).copy();
@@ -388,6 +398,7 @@ public final class AncestralTaxonomyInference {
                 if ( !ForesterUtil.isEmpty( up_tax.getId() ) ) {
                     getIdTaxCacheMap().put( up_tax.getId(), up_tax );
                 }
+                
             }
         }
         return up_tax;
@@ -401,9 +412,9 @@ public final class AncestralTaxonomyInference {
                 && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
             tax.setScientificName( up_tax.getScientificName() );
         }
-        if ( node.isExternal()
-                && ( ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() ) && ForesterUtil
-                        .isEmpty( tax.getTaxonomyCode() ) ) ) {
+        //  if ( node.isExternal()
+        if ( ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() )
+                && ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
             tax.setTaxonomyCode( up_tax.getCode() );
         }
         if ( ( qt != QUERY_TYPE.CN ) && !ForesterUtil.isEmpty( up_tax.getCommonName() )
@@ -424,6 +435,15 @@ public final class AncestralTaxonomyInference {
         if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() ) && ( tax.getIdentifier() == null ) ) {
             tax.setIdentifier( new Identifier( up_tax.getId(), "uniprot" ) );
         }
+        if ( up_tax.getLineage() != null ) {
+            tax.setLineage( new ArrayList<String>() );
+            for( final String lin : up_tax.getLineage() ) {
+                if ( !ForesterUtil.isEmpty( lin ) ) {
+                    tax.getLineage().add( lin );
+                }
+            }
+        }
+        
     }
 
     private enum QUERY_TYPE {
index 0cc491c..fb4ac82 100644 (file)
@@ -209,6 +209,30 @@ class NodePanel extends JPanel implements TreeSelectionListener {
             }
         }
     }
+    
+    private static void addLineage( final DefaultMutableTreeNode top,
+                                 final List<String> lineage,
+                                 final DefaultMutableTreeNode category ) {
+        if ( ( lineage != null ) && (  lineage.size() > 0 ) ) {
+          
+            StringBuilder sb = new StringBuilder();
+            for( final String lin : lineage ) {
+                if ( !ForesterUtil.isEmpty( lin ) ) {
+                    sb.append( lin );
+                    sb.append( " > " );
+                }
+            }
+            String str = null;
+            if (sb.length() > 1 ) {
+                str = sb.substring( 0, sb.length() - 3 );
+            }
+            if ( !ForesterUtil.isEmpty( str ) ) {
+                addSubelement( category, "Lineage", str );
+            }
+        }
+    }
+    
+    
 
     private static void addBasics( final DefaultMutableTreeNode top,
                                    final PhylogenyNode phylogeny_node,
@@ -240,10 +264,10 @@ class NodePanel extends JPanel implements TreeSelectionListener {
                 if ( no_tax > 0 ) {
                     addSubelement( category, "External nodes without taxonomy", String.valueOf( no_tax ) );
                 }
-                //TODO remove me...
-                for( final Taxonomy taxonomy : distinct_tax.keySet() ) {
-                    System.out.println( taxonomy + ": " + distinct_tax.get( taxonomy ) );
-                }
+                //TODO remove me... maybe make me into a method?
+                //for( final Taxonomy taxonomy : distinct_tax.keySet() ) {
+                //    System.out.println( taxonomy + ": " + distinct_tax.get( taxonomy ) );
+                //}
             }
         }
         if ( !phylogeny_node.isRoot() ) {
@@ -391,6 +415,9 @@ class NodePanel extends JPanel implements TreeSelectionListener {
         if ( ( tax.getUris() != null ) && !tax.getUris().isEmpty() ) {
             addUris( top, tax.getUris(), category );
         }
+        if ( ( tax.getLineage() != null ) && !tax.getLineage().isEmpty() ) {
+            addLineage( top, tax.getLineage(), category );
+        }
     }
 
     private static void createNodes( final DefaultMutableTreeNode top, final PhylogenyNode phylogeny_node ) {
index 5d4411d..ee78912 100644 (file)
@@ -46,6 +46,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
     private String       _taxonomy_code;
     private String       _rank;
     private List<Uri>    _uris;
+    private List<String> _lineage;
 
     public Taxonomy() {
         init();
@@ -130,6 +131,14 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
                 }
             }
         }
+        if ( getLineage() != null ) {
+            t.setLineage( new ArrayList<String>() );
+            for( final String l : getLineage() ) {
+                if ( l != null ) {
+                    t.getLineage().add( l );
+                }
+            }
+        }
         return t;
     }
 
@@ -214,13 +223,14 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         setAuthority( "" );
         setSynonyms( null );
         setUris( null );
+        setLineage( null );
     }
 
     public boolean isEmpty() {
         return ( ( getIdentifier() == null ) && ForesterUtil.isEmpty( getTaxonomyCode() )
                 && ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() )
                 && ForesterUtil.isEmpty( getRank() ) && ForesterUtil.isEmpty( _uris )
-                && ForesterUtil.isEmpty( getAuthority() ) && ForesterUtil.isEmpty( _synonyms ) );
+                && ForesterUtil.isEmpty( getAuthority() ) && ForesterUtil.isEmpty( _synonyms ) && ForesterUtil.isEmpty( _lineage ) );
     }
 
     /**
@@ -401,4 +411,12 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         }
         return 0;
     }
+
+    public void setLineage( List<String> lineage ) {
+        _lineage = lineage;
+    }
+
+    public List<String> getLineage() {
+        return _lineage;
+    }
 }
index 57a483e..14fa14a 100644 (file)
@@ -111,7 +111,6 @@ public final class UniProtTaxonomy {
         if ( _lineage.isEmpty()
                 && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
                         .equalsIgnoreCase( ARCHAEA ) ) ) {
-            System.out.println( "  >>>>>>>>>>>>>>>>>>>>>>>>>        did it!" );
             _lineage.add( CELLULAR_ORGANISMS );
         }
         _lineage.add( _scientific_name );
index 5906a8c..05c1c8d 100644 (file)
@@ -175,6 +175,7 @@ public final class UniProtWsTools {
 
     private static List<String> getTaxonomyStringFromId( final String id, final int max_lines_to_return )
             throws IOException {
+        System.out.println( "getting tax from ID" );
         return queryUniprot( "taxonomy/?query=id%3a%22" + encode( id ) + "%22&format=tab", max_lines_to_return );
     }