d0df4c745d4e6ac5420da91fcd535c846d26104c
[jalview.git] / TaxonomyDataManager.java
1 // $Id:
2 //
3 // forester -- software libraries and applications
4 // for genomics and evolutionary biology research.
5 //
6 // Copyright (C) 2010 Christian M Zmasek
7 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
8 // All rights reserved
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26
27 package org.forester.analysis;
28
29 import java.io.IOException;
30 import java.net.UnknownHostException;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.SortedSet;
35 import java.util.TreeSet;
36
37 import javax.swing.JOptionPane;
38
39 import org.forester.archaeopteryx.MainFrameApplication;
40 import org.forester.archaeopteryx.TreePanel;
41 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
42 import org.forester.archaeopteryx.tools.RunnableProcess;
43 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
44 import org.forester.phylogeny.Phylogeny;
45 import org.forester.phylogeny.PhylogenyNode;
46 import org.forester.phylogeny.data.Identifier;
47 import org.forester.phylogeny.data.Taxonomy;
48 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
49 import org.forester.util.ForesterUtil;
50 import org.forester.util.TaxonomyUtil;
51 import org.forester.ws.seqdb.SequenceDbWsTools;
52 import org.forester.ws.seqdb.UniProtTaxonomy;
53 import org.forester.archaeopteryx.*;
54
55 public final class TaxonomyDataManager extends RunnableProcess {
56
57     enum QUERY_TYPE {
58         CODE, SN, CN, ID, LIN;
59     }
60     private static final int                              MAX_CACHE_SIZE           = 100000;
61     private static final int                              MAX_TAXONOMIES_TO_RETURN = 10;
62     private static final HashMap<String, UniProtTaxonomy> _sn_up_cache_map         = new HashMap<String, UniProtTaxonomy>();
63     private static final HashMap<String, UniProtTaxonomy> _lineage_up_cache_map    = new HashMap<String, UniProtTaxonomy>();
64     private static final HashMap<String, UniProtTaxonomy> _code_up_cache_map       = new HashMap<String, UniProtTaxonomy>();
65     private static final HashMap<String, UniProtTaxonomy> _cn_up_cache_map         = new HashMap<String, UniProtTaxonomy>();
66     private static final HashMap<String, UniProtTaxonomy> _id_up_cache_map         = new HashMap<String, UniProtTaxonomy>();
67     private final Phylogeny                               _phy;
68     private final MainFrameApplication                    _mf;
69     private final TreePanel                               _treepanel;
70     private final boolean                                 _delete;
71     private final boolean                                 _allow_simple_names;
72
73     public TaxonomyDataManager( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
74         _phy = phy;
75         _mf = mf;
76         _treepanel = treepanel;
77         _delete = false;
78         _allow_simple_names = false;
79     }
80
81     public TaxonomyDataManager( final MainFrameApplication mf,
82                                 final TreePanel treepanel,
83                                 final Phylogeny phy,
84                                 final boolean delete,
85                                 final boolean allow_simple_name ) {
86         _phy = phy;
87         _mf = mf;
88         _treepanel = treepanel;
89         _delete = delete;
90         _allow_simple_names = allow_simple_name;
91     }
92
93     synchronized static void clearCachesIfTooLarge() {
94         if ( getSnTaxCacheMap().size() > MAX_CACHE_SIZE ) {
95             getSnTaxCacheMap().clear();
96         }
97         if ( getLineageTaxCacheMap().size() > MAX_CACHE_SIZE ) {
98             getLineageTaxCacheMap().clear();
99         }
100         if ( getCnTaxCacheMap().size() > MAX_CACHE_SIZE ) {
101             getCnTaxCacheMap().clear();
102         }
103         if ( getCodeTaxCacheMap().size() > MAX_CACHE_SIZE ) {
104             getCodeTaxCacheMap().clear();
105         }
106         if ( getIdTaxCacheMap().size() > MAX_CACHE_SIZE ) {
107             getIdTaxCacheMap().clear();
108         }
109     }
110
111     synchronized final static HashMap<String, UniProtTaxonomy> getCnTaxCacheMap() {
112         return _cn_up_cache_map;
113     }
114
115     synchronized final static HashMap<String, UniProtTaxonomy> getCodeTaxCacheMap() {
116         return _code_up_cache_map;
117     }
118
119     synchronized final static HashMap<String, UniProtTaxonomy> getIdTaxCacheMap() {
120         return _id_up_cache_map;
121     }
122
123     synchronized final static HashMap<String, UniProtTaxonomy> getLineageTaxCacheMap() {
124         return _lineage_up_cache_map;
125     }
126
127     synchronized final static HashMap<String, UniProtTaxonomy> getSnTaxCacheMap() {
128         return _sn_up_cache_map;
129     }
130
131     private final static UniProtTaxonomy obtainTaxonomy( final HashMap<String, UniProtTaxonomy> cache,
132                                                          final Object query,
133                                                          final QUERY_TYPE qt ) throws IOException,
134             AncestralTaxonomyInferenceException {
135         if ( cache.containsKey( query ) ) {
136             return cache.get( query ).copy();
137         }
138         else {
139             List<UniProtTaxonomy> up_taxonomies = null;
140             switch ( qt ) {
141                 case ID:
142                     up_taxonomies = getTaxonomiesFromId( ( String ) query );
143                     break;
144                 case CODE:
145                     up_taxonomies = getTaxonomiesFromTaxonomyCode( ( String ) query );
146                     break;
147                 case SN:
148                     up_taxonomies = getTaxonomiesFromScientificName( ( String ) query );
149                     break;
150                 case CN:
151                     up_taxonomies = getTaxonomiesFromCommonName( ( String ) query );
152                     break;
153                 case LIN:
154                     return obtainUniProtTaxonomyFromLineage( ( List<String> ) query );
155                 default:
156                     throw new RuntimeException();
157             }
158             if ( ( up_taxonomies != null ) && ( up_taxonomies.size() == 1 ) ) {
159                 final UniProtTaxonomy up_tax = up_taxonomies.get( 0 );
160                 if ( !ForesterUtil.isEmpty( up_tax.getScientificName() ) ) {
161                     TaxonomyDataManager.getSnTaxCacheMap().put( up_tax.getScientificName(), up_tax );
162                 }
163                 if ( !ForesterUtil.isEmpty( up_tax.getCode() ) ) {
164                     TaxonomyDataManager.getCodeTaxCacheMap().put( up_tax.getCode(), up_tax );
165                 }
166                 if ( !ForesterUtil.isEmpty( up_tax.getCommonName() ) ) {
167                     TaxonomyDataManager.getCnTaxCacheMap().put( up_tax.getCommonName(), up_tax );
168                 }
169                 if ( !ForesterUtil.isEmpty( up_tax.getId() ) ) {
170                     TaxonomyDataManager.getIdTaxCacheMap().put( up_tax.getId(), up_tax );
171                 }
172                 return up_tax;
173             }
174             else {
175                 return null;
176             }
177         }
178     }
179
180     private final static List<UniProtTaxonomy> getTaxonomiesFromCommonName( final String query ) throws IOException {
181         return SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( query, MAX_TAXONOMIES_TO_RETURN );
182     }
183
184     private final static List<UniProtTaxonomy> getTaxonomiesFromId( final String query ) throws IOException {
185         return SequenceDbWsTools.getTaxonomiesFromId( query, MAX_TAXONOMIES_TO_RETURN );
186     }
187
188     private final static List<UniProtTaxonomy> getTaxonomiesFromScientificName( final String query ) throws IOException {
189         if ( query.equalsIgnoreCase( UniProtTaxonomy.BACTERIA ) || query.equalsIgnoreCase( UniProtTaxonomy.ARCHAEA )
190                 || query.equalsIgnoreCase( UniProtTaxonomy.VIRUSES )
191                 || query.equalsIgnoreCase( UniProtTaxonomy.EUKARYOTA ) || query.equalsIgnoreCase( UniProtTaxonomy.X ) ) {
192             final List<UniProtTaxonomy> l = new ArrayList<UniProtTaxonomy>();
193             l.add( UniProtTaxonomy.createSpecialFromScientificName( query ) );
194             return l;
195         }
196         return SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( query, MAX_TAXONOMIES_TO_RETURN );
197     }
198
199     private final static List<UniProtTaxonomy> getTaxonomiesFromTaxonomyCode( final String query ) throws IOException {
200         if ( query.indexOf( "XX" ) == 3 && TaxonomyUtil.isHasTaxIdFromFakeTaxCode( query ) ) {
201             final int id = TaxonomyUtil.getTaxIdFromFakeTaxCode( query );
202             return SequenceDbWsTools.getTaxonomiesFromId( String.valueOf( id ), MAX_TAXONOMIES_TO_RETURN );
203  
204         }
205         
206         return SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( query, MAX_TAXONOMIES_TO_RETURN );
207     }
208
209     static final boolean isHasAppropriateId( final Taxonomy tax ) {
210         return ( ( tax.getIdentifier() != null ) && ( !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) && ( tax
211                 .getIdentifier().getProvider().equalsIgnoreCase( "ncbi" )
212                 || tax.getIdentifier().getProvider().equalsIgnoreCase( "uniprot" ) || tax.getIdentifier().getProvider()
213                 .equalsIgnoreCase( "uniprotkb" ) ) ) );
214     }
215
216     synchronized final private static SortedSet<String> obtainDetailedTaxonomicInformation( final Phylogeny phy,
217                                                                                             final boolean delete,
218                                                                                             final boolean allow_to_use_basic_node_names )
219             throws IOException, AncestralTaxonomyInferenceException {
220         clearCachesIfTooLarge();
221         final SortedSet<String> not_found = new TreeSet<String>();
222         List<PhylogenyNode> not_found_external_nodes = null;
223         if ( delete ) {
224             not_found_external_nodes = new ArrayList<PhylogenyNode>();
225         }
226         for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) {
227             final PhylogenyNode node = iter.next();
228             final QUERY_TYPE qt = null;
229             Taxonomy tax = null;
230             if ( node.getNodeData().isHasTaxonomy() ) {
231                 tax = node.getNodeData().getTaxonomy();
232             }
233             else if ( allow_to_use_basic_node_names && !ForesterUtil.isEmpty( node.getName() ) ) {
234                 // Nothing to be done.
235             }
236             else if ( node.isExternal() ) {
237                 if ( !ForesterUtil.isEmpty( node.getName() ) ) {
238                     not_found.add( node.getName() );
239                 }
240                 else {
241                     not_found.add( node.toString() );
242                 }
243                 if ( delete ) {
244                     not_found_external_nodes.add( node );
245                 }
246             }
247             UniProtTaxonomy uniprot_tax = null;
248             if ( ( ( tax != null ) && ( isHasAppropriateId( tax ) || !ForesterUtil.isEmpty( tax.getScientificName() )
249                     || !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) || !ForesterUtil.isEmpty( tax.getCommonName() ) ) )
250                     || ( allow_to_use_basic_node_names && !ForesterUtil.isEmpty( node.getName() ) ) ) {
251                 if ( tax != null ) {
252                     uniprot_tax = obtainUniProtTaxonomy( tax, null, qt );
253                 }
254                 else {
255                     uniprot_tax = obtainUniProtTaxonomy( node.getName(), qt );
256                 }
257                 if ( uniprot_tax != null ) {
258                     if ( tax == null ) {
259                         tax = new Taxonomy();
260                         node.getNodeData().addTaxonomy( tax );
261                         node.setName( "" );
262                     }
263                     updateTaxonomy( qt, node, tax, uniprot_tax );
264                 }
265                 else {
266                     if ( tax != null ) {
267                         not_found.add( tax.toString() );
268                     }
269                     else {
270                         not_found.add( node.getName() );
271                     }
272                     if ( delete && node.isExternal() ) {
273                         not_found_external_nodes.add( node );
274                     }
275                 }
276             }
277         }
278         if ( delete ) {
279             for( final PhylogenyNode node : not_found_external_nodes ) {
280                 phy.deleteSubtree( node, true );
281             }
282             phy.externalNodesHaveChanged();
283             phy.clearHashIdToNodeMap();
284             phy.recalculateNumberOfExternalDescendants( true );
285         }
286         return not_found;
287     }
288
289     public final static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt )
290             throws IOException, AncestralTaxonomyInferenceException {
291         if ( tax == null ) {
292             throw new IllegalArgumentException( "illegal attempt to use empty taxonomy object" );
293         }
294         if ( TaxonomyDataManager.isHasAppropriateId( tax ) ) {
295             query = tax.getIdentifier().getValue();
296             qt = QUERY_TYPE.ID;
297             return obtainTaxonomy( TaxonomyDataManager.getIdTaxCacheMap(), query, qt );
298         }
299         else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
300             if ( !ForesterUtil.isEmpty( tax.getLineage() ) ) {
301                 query = tax.getLineage();
302                 qt = QUERY_TYPE.LIN;
303                 return obtainTaxonomy( TaxonomyDataManager.getLineageTaxCacheMap(), query, qt );
304             }
305             else {
306                 query = tax.getScientificName();
307                 qt = QUERY_TYPE.SN;
308                 return obtainTaxonomy( TaxonomyDataManager.getSnTaxCacheMap(), query, qt );
309             }
310         }
311         else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
312             query = tax.getTaxonomyCode();
313             qt = QUERY_TYPE.CODE;
314             return obtainTaxonomy( TaxonomyDataManager.getCodeTaxCacheMap(), query, qt );
315         }
316         else {
317             query = tax.getCommonName();
318             qt = QUERY_TYPE.CN;
319             return obtainTaxonomy( TaxonomyDataManager.getCnTaxCacheMap(), query, qt );
320         }
321     }
322
323     public final static UniProtTaxonomy obtainUniProtTaxonomy( final String simple_name, QUERY_TYPE qt )
324             throws IOException, AncestralTaxonomyInferenceException {
325         if ( ForesterUtil.isEmpty( simple_name ) ) {
326             throw new IllegalArgumentException( "illegal attempt to use empty simple name" );
327         }
328         qt = QUERY_TYPE.SN;
329         UniProtTaxonomy ut = obtainTaxonomy( TaxonomyDataManager.getSnTaxCacheMap(), simple_name, qt );
330         if ( ut == null ) {
331             qt = QUERY_TYPE.CODE;
332             ut = obtainTaxonomy( TaxonomyDataManager.getCodeTaxCacheMap(), simple_name, qt );
333         }
334         if ( ut == null ) {
335             qt = QUERY_TYPE.CN;
336             ut = obtainTaxonomy( TaxonomyDataManager.getCnTaxCacheMap(), simple_name, qt );
337         }
338         return ut;
339     }
340
341     static final UniProtTaxonomy obtainUniProtTaxonomyFromLineage( final List<String> lineage )
342             throws AncestralTaxonomyInferenceException, IOException {
343         final String lineage_str = ForesterUtil.stringListToString( lineage, ">" );
344         if ( TaxonomyDataManager.getLineageTaxCacheMap().containsKey( lineage_str ) ) {
345             return TaxonomyDataManager.getLineageTaxCacheMap().get( lineage_str ).copy();
346         }
347         else {
348             final List<UniProtTaxonomy> matching_taxonomies = new ArrayList<UniProtTaxonomy>();
349             final List<UniProtTaxonomy> up_taxonomies = getTaxonomiesFromScientificName( lineage
350                     .get( lineage.size() - 1 ) );
351             if ( ( up_taxonomies != null ) && ( up_taxonomies.size() > 0 ) ) {
352                 for( final UniProtTaxonomy up_taxonomy : up_taxonomies ) {
353                     boolean match = true;
354                     I: for( int i = 0; i < lineage.size(); ++i ) {
355                         if ( ( i == up_taxonomy.getLineage().size() )
356                                 || !lineage.get( i ).equalsIgnoreCase( up_taxonomy.getLineage().get( i ) ) ) {
357                             match = false;
358                             break I;
359                         }
360                     }
361                     if ( match ) {
362                         matching_taxonomies.add( up_taxonomy );
363                     }
364                 }
365                 if ( matching_taxonomies.isEmpty() ) {
366                     throw new AncestralTaxonomyInferenceException( "lineage \""
367                             + ForesterUtil.stringListToString( lineage, " > " ) + "\" not found" );
368                 }
369                 //in case of more than one (e.g. "Xenopus" Genus and Subgenus), keep shorter, less specific  one:
370                 int shortest = Integer.MAX_VALUE;
371                 UniProtTaxonomy least_specific_up_tax = null;
372                 for( final UniProtTaxonomy m : matching_taxonomies ) {
373                     final int s = m.getLineage().size();
374                     if ( s < shortest ) {
375                         shortest = s;
376                         least_specific_up_tax = m;
377                     }
378                 }
379                 TaxonomyDataManager.getLineageTaxCacheMap().put( lineage_str, least_specific_up_tax );
380                 if ( !ForesterUtil.isEmpty( least_specific_up_tax.getScientificName() ) ) {
381                     TaxonomyDataManager.getSnTaxCacheMap().put( least_specific_up_tax.getScientificName(),
382                                                                 least_specific_up_tax );
383                 }
384                 if ( !ForesterUtil.isEmpty( least_specific_up_tax.getCode() ) ) {
385                     TaxonomyDataManager.getCodeTaxCacheMap().put( least_specific_up_tax.getCode(),
386                                                                   least_specific_up_tax );
387                 }
388                 if ( !ForesterUtil.isEmpty( least_specific_up_tax.getCommonName() ) ) {
389                     TaxonomyDataManager.getCnTaxCacheMap().put( least_specific_up_tax.getCommonName(),
390                                                                 least_specific_up_tax );
391                 }
392                 if ( !ForesterUtil.isEmpty( least_specific_up_tax.getId() ) ) {
393                     TaxonomyDataManager.getIdTaxCacheMap().put( least_specific_up_tax.getId(), least_specific_up_tax );
394                 }
395                 return least_specific_up_tax;
396             }
397             else {
398                 throw new AncestralTaxonomyInferenceException( "taxonomy \"" + ( lineage.get( lineage.size() - 1 ) )
399                         + "\" not found" );
400             }
401         }
402     }
403
404     synchronized final private static void updateTaxonomy( final QUERY_TYPE qt,
405                                                            final PhylogenyNode node,
406                                                            final Taxonomy tax,
407                                                            final UniProtTaxonomy up_tax )
408             throws PhyloXmlDataFormatException {
409         if ( ( qt != QUERY_TYPE.SN ) && !ForesterUtil.isEmpty( up_tax.getScientificName() )
410                 && ForesterUtil.isEmpty( tax.getScientificName() ) ) {
411             tax.setScientificName( up_tax.getScientificName() );
412         }
413         if ( node.isExternal() && ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() )
414                 && ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
415             tax.setTaxonomyCode( up_tax.getCode() );
416         }
417         if ( ( qt != QUERY_TYPE.CN ) && !ForesterUtil.isEmpty( up_tax.getCommonName() )
418                 && ForesterUtil.isEmpty( tax.getCommonName() ) ) {
419             tax.setCommonName( up_tax.getCommonName() );
420         }
421         if ( !ForesterUtil.isEmpty( up_tax.getSynonym() ) && !tax.getSynonyms().contains( up_tax.getSynonym() ) ) {
422             tax.getSynonyms().add( up_tax.getSynonym() );
423         }
424         if ( !ForesterUtil.isEmpty( up_tax.getRank() ) && ForesterUtil.isEmpty( tax.getRank() ) ) {
425             try {
426                 tax.setRank( up_tax.getRank().toLowerCase() );
427             }
428             catch ( final PhyloXmlDataFormatException ex ) {
429                 tax.setRank( "" );
430             }
431         }
432         if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() )
433                 && ( ( tax.getIdentifier() == null ) || ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) ) {
434             tax.setIdentifier( new Identifier( up_tax.getId(), "uniprot" ) );
435         }
436         if ( up_tax.getLineage() != null ) {
437             tax.setLineage( new ArrayList<String>() );
438             for( final String lin : up_tax.getLineage() ) {
439                 if ( !ForesterUtil.isEmpty( lin ) ) {
440                     tax.getLineage().add( lin );
441                 }
442             }
443         }
444     }
445
446     private final void execute() {
447         start( _mf, "taxonomy data" );
448         SortedSet<String> not_found = null;
449         try {
450             not_found = obtainDetailedTaxonomicInformation( _phy, _delete, _allow_simple_names );
451         }
452         catch ( final UnknownHostException e ) {
453             JOptionPane.showMessageDialog( _mf,
454                                            "Could not connect to \"" + getBaseUrl() + "\"",
455                                            "Network error during taxonomic information gathering",
456                                            JOptionPane.ERROR_MESSAGE );
457             return;
458         }
459         catch ( final IOException e ) {
460             e.printStackTrace();
461             JOptionPane.showMessageDialog( _mf,
462                                            e.toString(),
463                                            "Failed to obtain taxonomic information",
464                                            JOptionPane.ERROR_MESSAGE );
465             return;
466         }
467         catch ( final AncestralTaxonomyInferenceException e ) {
468             e.printStackTrace();
469             JOptionPane.showMessageDialog( _mf,
470                                            e.toString(),
471                                            "Failed to obtain taxonomic information",
472                                            JOptionPane.ERROR_MESSAGE );
473             return;
474         }
475         finally {
476             end( _mf );
477         }
478         if ( ( _phy == null ) || _phy.isEmpty() ) {
479             try {
480                 JOptionPane.showMessageDialog( _mf,
481                                                "None of the external node taxonomies could be resolved",
482                                                "Taxonomy Tool Failed",
483                                                JOptionPane.WARNING_MESSAGE );
484             }
485             catch ( final Exception e ) {
486                 // Not important if this fails, do nothing. 
487             }
488             return;
489         }
490         _treepanel.setTree( _phy );
491         _mf.showWhole();
492         _treepanel.setEdited( true );
493         if ( ( not_found != null ) && ( not_found.size() > 0 ) ) {
494             int max = not_found.size();
495             boolean more = false;
496             if ( max > 20 ) {
497                 more = true;
498                 max = 20;
499             }
500             final StringBuffer sb = new StringBuffer();
501             sb.append( "Not all taxonomies could be resolved.\n" );
502             if ( not_found.size() == 1 ) {
503                 if ( _delete ) {
504                     sb.append( "The following taxonomy was not found and deleted (if external):\n" );
505                 }
506                 else {
507                     sb.append( "The following taxonomy was not found:\n" );
508                 }
509             }
510             else {
511                 if ( _delete ) {
512                     sb.append( "The following taxonomies were not found and deleted (if external) (total: "
513                             + not_found.size() + "):\n" );
514                 }
515                 else {
516                     sb.append( "The following taxonomies were not found (total: " + not_found.size() + "):\n" );
517                 }
518             }
519             int i = 0;
520             for( final String string : not_found ) {
521                 if ( i > 19 ) {
522                     break;
523                 }
524                 sb.append( string );
525                 sb.append( "\n" );
526                 ++i;
527             }
528             if ( more ) {
529                 sb.append( "..." );
530             }
531             try {
532                 JOptionPane.showMessageDialog( _mf,
533                                                sb.toString(),
534                                                "Taxonomy Tool Completed",
535                                                JOptionPane.WARNING_MESSAGE );
536             }
537             catch ( final Exception e ) {
538                 // Not important if this fails, do nothing. 
539             }
540         }
541         else {
542             try {
543                 JOptionPane.showMessageDialog( _mf,
544                                                "Taxonomy tool successfully completed",
545                                                "Taxonomy Tool Completed",
546                                                JOptionPane.INFORMATION_MESSAGE );
547             }
548             catch ( final Exception e ) {
549                 // Not important if this fails, do nothing.
550             }
551         }
552     }
553
554     private final String getBaseUrl() {
555         return AncestralTaxonomyInferrer.getBaseUrl();
556     }
557
558     @Override
559     public void run() {
560         execute();
561     }
562 }