in progress
[jalview.git] / forester / java / src / org / forester / analysis / AncestralTaxonomyInference.java
index 054ac7b..73af2c1 100644 (file)
@@ -44,7 +44,7 @@ import org.forester.ws.uniprot.UniProtWsTools;
 public final class AncestralTaxonomyInference {
 
     private static final int                              MAX_CACHE_SIZE           = 100000;
-    private static final int                              MAX_TAXONOMIES_TO_RETURN = 1000;
+    private static final int                              MAX_TAXONOMIES_TO_RETURN = 10;
     private static final HashMap<String, UniProtTaxonomy> _sn_up_cache_map         = new HashMap<String, UniProtTaxonomy>();
     private static final HashMap<String, UniProtTaxonomy> _lineage_up_cache_map    = new HashMap<String, UniProtTaxonomy>();
     private static final HashMap<String, UniProtTaxonomy> _code_up_cache_map       = new HashMap<String, UniProtTaxonomy>();
@@ -250,17 +250,38 @@ public final class AncestralTaxonomyInference {
             }
         }
         if ( last_common_lineage.isEmpty() ) {
-            String msg = "no common lineage for:\n";
-            int counter = 0;
-            for( final String[] strings : lineages ) {
-                msg += counter + ": ";
-                ++counter;
-                for( final String string : strings ) {
-                    msg += string + " ";
+            boolean saw_viruses = false;
+            boolean saw_cellular_organism = false;
+            for( final String[] lineage : lineages ) {
+                if ( lineage.length > 0 ) {
+                    if ( lineage[ 0 ].equalsIgnoreCase( UniProtTaxonomy.VIRUSES ) ) {
+                        saw_viruses = true;
+                    }
+                    else if ( lineage[ 0 ].equalsIgnoreCase( UniProtTaxonomy.CELLULAR_ORGANISMS ) ) {
+                        saw_cellular_organism = true;
+                    }
+                    if ( saw_cellular_organism && saw_viruses ) {
+                        break;
+                    }
+                }
+            }
+            if ( saw_cellular_organism && saw_viruses ) {
+                last_common_lineage.add( UniProtTaxonomy.CELLULAR_ORGANISMS );
+                last_common = UniProtTaxonomy.CELLULAR_ORGANISMS;
+            }
+            else {
+                String msg = "no common lineage for:\n";
+                int counter = 0;
+                for( final String[] strings : lineages ) {
+                    msg += counter + ": ";
+                    ++counter;
+                    for( final String string : strings ) {
+                        msg += string + " ";
+                    }
+                    msg += "\n";
                 }
-                msg += "\n";
+                throw new AncestralTaxonomyInferenceException( msg );
             }
-            throw new AncestralTaxonomyInferenceException( msg );
         }
         final Taxonomy tax = new Taxonomy();
         n.getNodeData().setTaxonomy( tax );
@@ -371,7 +392,7 @@ public final class AncestralTaxonomyInference {
         return not_found;
     }
 
-    synchronized private static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt )
+    synchronized public static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt )
             throws IOException, AncestralTaxonomyInferenceException {
         if ( isHasAppropriateId( tax ) ) {
             query = tax.getIdentifier().getValue();
@@ -459,7 +480,7 @@ public final class AncestralTaxonomyInference {
                 && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
             tax.setScientificName( up_tax.getScientificName() );
         }
-        if ( ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() )
+        if ( node.isExternal() && ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() )
                 && ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
             tax.setTaxonomyCode( up_tax.getCode() );
         }
@@ -478,7 +499,8 @@ public final class AncestralTaxonomyInference {
                 tax.setRank( "" );
             }
         }
-        if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() ) && ( tax.getIdentifier() == null ) ) {
+        if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() )
+                && ( ( tax.getIdentifier() == null ) || ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) ) {
             tax.setIdentifier( new Identifier( up_tax.getId(), "uniprot" ) );
         }
         if ( up_tax.getLineage() != null ) {