X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fanalysis%2FAncestralTaxonomyInference.java;h=73af2c142c86be1e23ec5858599e7b0db661a8fe;hb=5a79605dde82b956c0cf429dd016c3b478012f9c;hp=054ac7b9397e213d247ca931aca554c7df156c09;hpb=93ef19e783e50f00e4e4d1467613d74142b40654;p=jalview.git diff --git a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java index 054ac7b..73af2c1 100644 --- a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java +++ b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java @@ -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 _sn_up_cache_map = new HashMap(); private static final HashMap _lineage_up_cache_map = new HashMap(); private static final HashMap _code_up_cache_map = new HashMap(); @@ -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 ) {