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>();
}
}
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 );
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();
&& 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() );
}
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 ) {