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