- private static final int MAX_CACHE_SIZE = 100000;
- private static final int MAX_TAXONOMIES_TO_RETURN = 100;
- private static final HashMap<String, UniProtTaxonomy> _sn_up_cache_map = new HashMap<String, UniProtTaxonomy>();
- private static final HashMap<String, UniProtTaxonomy> _code_up_cache_map = new HashMap<String, UniProtTaxonomy>();
- private static final HashMap<String, UniProtTaxonomy> _cn_up_cache_map = new HashMap<String, UniProtTaxonomy>();
- private static final HashMap<String, UniProtTaxonomy> _id_up_cache_map = new HashMap<String, UniProtTaxonomy>();
-
- synchronized private static void clearCachesIfTooLarge() {
- if ( getSnTaxCacheMap().size() > MAX_CACHE_SIZE ) {
- getSnTaxCacheMap().clear();
- }
- if ( getCnTaxCacheMap().size() > MAX_CACHE_SIZE ) {
- getCnTaxCacheMap().clear();
- }
- if ( getCodeTaxCacheMap().size() > MAX_CACHE_SIZE ) {
- getCodeTaxCacheMap().clear();
- }
- if ( getIdTaxCacheMap().size() > MAX_CACHE_SIZE ) {
- getIdTaxCacheMap().clear();
- }
- }
-
- synchronized private static HashMap<String, UniProtTaxonomy> getCnTaxCacheMap() {
- return _cn_up_cache_map;
- }
-
- synchronized private static HashMap<String, UniProtTaxonomy> getCodeTaxCacheMap() {
- return _code_up_cache_map;
- }
-
- synchronized private static HashMap<String, UniProtTaxonomy> getIdTaxCacheMap() {
- return _id_up_cache_map;
- }
-
- synchronized private static HashMap<String, UniProtTaxonomy> getSnTaxCacheMap() {
- return _sn_up_cache_map;
- }
-
- synchronized private static UniProtTaxonomy getTaxonomies( final HashMap<String, UniProtTaxonomy> cache,
- final String query,
- final QUERY_TYPE qt ) throws IOException {
- if ( cache.containsKey( query ) ) {
- return cache.get( query ).copy();
- }
- else {
- List<UniProtTaxonomy> up_taxonomies = null;
- switch ( qt ) {
- case ID:
- up_taxonomies = getTaxonomiesFromId( query );
- break;
- case CODE:
- up_taxonomies = getTaxonomiesFromTaxonomyCode( query );
- break;
- case SN:
- up_taxonomies = getTaxonomiesFromScientificName( query );
- break;
- case CN:
- up_taxonomies = getTaxonomiesFromCommonName( query );
- break;
- default:
- throw new RuntimeException();
- }
- if ( ( up_taxonomies != null ) && ( up_taxonomies.size() == 1 ) ) {
- final UniProtTaxonomy up_tax = up_taxonomies.get( 0 );
- if ( !ForesterUtil.isEmpty( up_tax.getScientificName() ) ) {
- getSnTaxCacheMap().put( up_tax.getScientificName(), up_tax );
- }
- if ( !ForesterUtil.isEmpty( up_tax.getCode() ) ) {
- getCodeTaxCacheMap().put( up_tax.getCode(), up_tax );
- }
- if ( !ForesterUtil.isEmpty( up_tax.getCommonName() ) ) {
- getCnTaxCacheMap().put( up_tax.getCommonName(), up_tax );
- }
- if ( !ForesterUtil.isEmpty( up_tax.getId() ) ) {
- getIdTaxCacheMap().put( up_tax.getId(), up_tax );
- }
- return up_tax;
- }
- else {
- return null;
- }
- }
- }
-
- synchronized private static List<UniProtTaxonomy> getTaxonomiesFromCommonName( final String query )
- throws IOException {
- return UniProtWsTools.getTaxonomiesFromCommonNameStrict( query, MAX_TAXONOMIES_TO_RETURN );
- }
-
- synchronized private static List<UniProtTaxonomy> getTaxonomiesFromId( final String query ) throws IOException {
- return UniProtWsTools.getTaxonomiesFromId( query, MAX_TAXONOMIES_TO_RETURN );
- }
-
- synchronized private static List<UniProtTaxonomy> getTaxonomiesFromScientificName( final String query )
- throws IOException {
- return UniProtWsTools.getTaxonomiesFromScientificNameStrict( query, MAX_TAXONOMIES_TO_RETURN );
- }
-
- synchronized private static List<UniProtTaxonomy> getTaxonomiesFromTaxonomyCode( final String query )
- throws IOException {
- return UniProtWsTools.getTaxonomiesFromTaxonomyCode( query, MAX_TAXONOMIES_TO_RETURN );
- }
-
- synchronized public static SortedSet<String> inferTaxonomyFromDescendents( final Phylogeny phy ) throws IOException {
- clearCachesIfTooLarge();
- final SortedSet<String> not_found = new TreeSet<String>();