inprogress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 15 Nov 2013 22:59:44 +0000 (22:59 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 15 Nov 2013 22:59:44 +0000 (22:59 +0000)
forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java
forester/java/src/org/forester/analysis/TaxonomyDataManager.java
forester/java/src/org/forester/archaeopteryx/NodePanel.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java
forester/java/src/org/forester/phylogeny/data/Taxonomy.java
forester/java/src/org/forester/test/Test.java
forester/java/src/org/forester/ws/seqdb/UniProtTaxonomy.java

index 61b9465..11d678d 100644 (file)
@@ -124,6 +124,7 @@ public final class AncestralTaxonomyInference {
         if ( last_common_lineage.isEmpty() ) {
             boolean saw_viruses = false;
             boolean saw_cellular_organism = false;
+            boolean saw_x = false;
             for( final String[] lineage : lineages ) {
                 if ( lineage.length > 0 ) {
                     if ( lineage[ 0 ].equalsIgnoreCase( UniProtTaxonomy.VIRUSES ) ) {
@@ -132,14 +133,17 @@ public final class AncestralTaxonomyInference {
                     else if ( lineage[ 0 ].equalsIgnoreCase( UniProtTaxonomy.CELLULAR_ORGANISMS ) ) {
                         saw_cellular_organism = true;
                     }
-                    if ( saw_cellular_organism && saw_viruses ) {
+                    else if ( lineage[ 0 ].equalsIgnoreCase( UniProtTaxonomy.X ) ) {
+                        saw_x = true;
+                    }
+                    if ( ( saw_cellular_organism && saw_viruses ) || saw_x ) {
                         break;
                     }
                 }
             }
-            if ( saw_cellular_organism && saw_viruses ) {
-                //last_common_lineage.add( UniProtTaxonomy.CELLULAR_ORGANISMS );
-               // last_common = UniProtTaxonomy.CELLULAR_ORGANISMS;
+            if ( ( saw_cellular_organism && saw_viruses ) || saw_x ) {
+                last_common_lineage.add( UniProtTaxonomy.X );
+                last_common = UniProtTaxonomy.X;
             }
             else {
                 String msg = "no common lineage for:\n";
index 79ab713..31de4f9 100644 (file)
@@ -184,16 +184,13 @@ public final class TaxonomyDataManager extends RunnableProcess {
     }
 
     private final static List<UniProtTaxonomy> getTaxonomiesFromScientificName( final String query ) throws IOException {
-        if ( query.equalsIgnoreCase( UniProtTaxonomy.BACTERIA ) ||
-                query.equalsIgnoreCase( UniProtTaxonomy.ARCHAEA ) ||
-                query.equalsIgnoreCase( UniProtTaxonomy.VIRUSES ) ||
-                query.equalsIgnoreCase( UniProtTaxonomy.EUKARYOTA ) 
-                ) {
+        if ( query.equalsIgnoreCase( UniProtTaxonomy.BACTERIA ) || query.equalsIgnoreCase( UniProtTaxonomy.ARCHAEA )
+                || query.equalsIgnoreCase( UniProtTaxonomy.VIRUSES )
+                || query.equalsIgnoreCase( UniProtTaxonomy.EUKARYOTA ) || query.equalsIgnoreCase( UniProtTaxonomy.X ) ) {
             final List<UniProtTaxonomy> l = new ArrayList<UniProtTaxonomy>();
             l.add( UniProtTaxonomy.createSpecialFromScientificName( query ) );
             return l;
         }
-        
         return SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( query, MAX_TAXONOMIES_TO_RETURN );
     }
 
index c861354..e39b580 100644 (file)
@@ -27,6 +27,7 @@ package org.forester.archaeopteryx;
 
 import java.awt.Color;
 import java.util.List;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.SortedSet;
 
@@ -207,8 +208,7 @@ class NodePanel extends JPanel implements TreeSelectionListener {
             addSubelement( category,
                            "External children",
                            String.valueOf( phylogeny_node.getAllExternalDescendants().size() ) );
-            final SortedMap<Taxonomy, Integer> distinct_tax = PhylogenyMethods
-                    .obtainDistinctTaxonomyCounts( phylogeny_node );
+            final Map<Taxonomy, Integer> distinct_tax = PhylogenyMethods.obtainDistinctTaxonomyCounts( phylogeny_node );
             if ( distinct_tax != null ) {
                 final int no_tax = PhylogenyMethods.calculateNumberOfExternalNodesWithoutTaxonomy( phylogeny_node );
                 final int tax_count = distinct_tax.size();
index 08fe7f0..b644e9e 100644 (file)
@@ -36,9 +36,8 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
 
 import org.forester.io.parsers.PhylogenyParser;
 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
@@ -711,9 +710,9 @@ public class PhylogenyMethods {
      * null is returned.
      * 
      */
-    public static SortedMap<Taxonomy, Integer> obtainDistinctTaxonomyCounts( final PhylogenyNode node ) {
+    public static Map<Taxonomy, Integer> obtainDistinctTaxonomyCounts( final PhylogenyNode node ) {
         final List<PhylogenyNode> descs = node.getAllExternalDescendants();
-        final SortedMap<Taxonomy, Integer> tax_map = new TreeMap<Taxonomy, Integer>();
+        final Map<Taxonomy, Integer> tax_map = new HashMap<Taxonomy, Integer>();
         for( final PhylogenyNode n : descs ) {
             if ( !n.getNodeData().isHasTaxonomy() || n.getNodeData().getTaxonomy().isEmpty() ) {
                 return null;
index b354921..26ed940 100644 (file)
@@ -248,9 +248,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
 
     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
+                && ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() ) && ForesterUtil
                 .isEmpty( _lineage ) );
     }
 
@@ -289,13 +287,8 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
             return getCommonName().equalsIgnoreCase( tax.getCommonName() );
         }
-        else if ( !ForesterUtil.isEmpty( getScientificName() ) && !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
-            return getScientificName().equalsIgnoreCase( tax.getCommonName() );
-        }
-        else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
-            return getCommonName().equalsIgnoreCase( tax.getScientificName() );
-        }
-        throw new RuntimeException( "comparison not possible with empty fields" );
+        //throw new RuntimeException( "comparison not possible with empty fields" );
+        return false;
     }
 
     public void setAuthority( final String authority ) {
@@ -423,16 +416,29 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         if ( equals( o ) ) {
             return 0;
         }
-        else if ( !ForesterUtil.isEmpty( getScientificName() ) && !ForesterUtil.isEmpty( o.getScientificName() ) ) {
+        if ( ( getIdentifier() != null ) && ( o.getIdentifier() != null )
+                && !ForesterUtil.isEmpty( getIdentifier().getValue() )
+                && !ForesterUtil.isEmpty( o.getIdentifier().getValue() ) ) {
+            final int x = getIdentifier().getValuePlusProvider().compareTo( o.getIdentifier().getValuePlusProvider() );
+            if ( x != 0 ) {
+                return x;
+            }
+        }
+        if ( !ForesterUtil.isEmpty( getScientificName() ) && !ForesterUtil.isEmpty( o.getScientificName() ) ) {
             return getScientificName().compareToIgnoreCase( o.getScientificName() );
         }
-        else if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( o.getCommonName() ) ) {
+        if ( !ForesterUtil.isEmpty( getCommonName() ) && !ForesterUtil.isEmpty( o.getCommonName() ) ) {
             return getCommonName().compareToIgnoreCase( o.getCommonName() );
         }
-        else if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( o.getTaxonomyCode() ) ) {
+        if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( o.getTaxonomyCode() ) ) {
             return getTaxonomyCode().compareToIgnoreCase( o.getTaxonomyCode() );
         }
-        return 0;
+        if ( ( getIdentifier() != null ) && ( o.getIdentifier() != null )
+                && !ForesterUtil.isEmpty( getIdentifier().getValue() )
+                && !ForesterUtil.isEmpty( o.getIdentifier().getValue() ) ) {
+            return getIdentifier().getValuePlusProvider().compareTo( o.getIdentifier().getValuePlusProvider() );
+        }
+        return 1;
     }
 
     public void setLineage( final List<String> lineage ) {
index 47516e4..2583a90 100644 (file)
@@ -11511,7 +11511,7 @@ public final class Test {
                 System.out.println( entry4.getMap() );
                 return false;
             }
-           //TODO FIXME gi...
+            //TODO FIXME gi...
             //
             //TODO fails:
             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
index b959899..c379607 100644 (file)
@@ -32,18 +32,19 @@ import org.forester.util.ForesterUtil;
 
 public final class UniProtTaxonomy {
 
-    public  static final String ARCHAEA            = "Archaea";
-    public  static final String BACTERIA           = "Bacteria";
-    public  static final String EUKARYOTA          = "Eukaryota";
-    private final List<String>  _lineage;
-    private final String        _code;
-    private final String        _scientific_name;
-    private final String        _common_name;
-    private final String        _synonym;
-    private final String        _rank;
-    private final String        _id;
-    public final static String  CELLULAR_ORGANISMS = "cellular organisms";
-    public final static String  VIRUSES            = "Viruses";
+    public static final String ARCHAEA            = "Archaea";
+    public static final String BACTERIA           = "Bacteria";
+    public static final String EUKARYOTA          = "Eukaryota";
+    private final List<String> _lineage;
+    private final String       _code;
+    private final String       _scientific_name;
+    private final String       _common_name;
+    private final String       _synonym;
+    private final String       _rank;
+    private final String       _id;
+    public final static String CELLULAR_ORGANISMS = "cellular organisms";
+    public final static String VIRUSES            = "Viruses";
+    public static final String X                  = "x";
 
     public UniProtTaxonomy( final String line ) {
         final String[] items = line.split( "\t" );
@@ -107,14 +108,13 @@ public final class UniProtTaxonomy {
         _synonym = synonym;
         _rank = rank;
         _id = id;
-        if ( ( _lineage != null &&  _lineage.isEmpty() ) || ( ( !ForesterUtil.isEmpty( _lineage ) ) && !_lineage.get( _lineage.size() - 1 ).equalsIgnoreCase( _scientific_name ) ) ) {
+        if ( ( ( _lineage != null ) && _lineage.isEmpty() )
+                || ( ( !ForesterUtil.isEmpty( _lineage ) ) && !_lineage.get( _lineage.size() - 1 )
+                        .equalsIgnoreCase( _scientific_name ) ) ) {
             _lineage.add( _scientific_name );
         }
-      
     }
 
-    
-
     /**
      * Creates deep copy for all fields, except lineage.
      * 
@@ -157,17 +157,15 @@ public final class UniProtTaxonomy {
     public String getSynonym() {
         return _synonym;
     }
-    
+
     public final static UniProtTaxonomy createSpecialFromScientificName( final String sn ) {
-        
-        List<String> lineage = new ArrayList<String>();
-        String code = "";
-        String common_name = "";
+        final List<String> lineage = new ArrayList<String>();
+        final String code = "";
+        final String common_name = "";
         String scientific_name = "";
-        String synonym = "";
+        final String synonym = "";
         String rank = "";
         String id = "";
-        
         if ( sn.equalsIgnoreCase( BACTERIA ) ) {
             scientific_name = BACTERIA;
             lineage.add( "cellular organisms" );
@@ -177,7 +175,6 @@ public final class UniProtTaxonomy {
         else if ( sn.equalsIgnoreCase( ARCHAEA ) ) {
             scientific_name = ARCHAEA;
             lineage.add( "cellular organisms" );
-          
             rank = "superkingdom";
             id = "2157";
         }
@@ -192,11 +189,12 @@ public final class UniProtTaxonomy {
             rank = "superkingdom";
             id = "10239";
         }
+        else if ( sn.equalsIgnoreCase( X ) ) {
+            scientific_name = X;
+        }
         else {
             throw new IllegalArgumentException( "illegal attempt to make UniProt taxonomy for :" + sn );
         }
         return new UniProtTaxonomy( lineage, code, common_name, scientific_name, synonym, rank, id );
-        
-        
     }
 }