3 // forester -- software libraries and applications
4 // for genomics and evolutionary biology research.
6 // Copyright (C) 2010 Christian M Zmasek
7 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
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.
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.
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
24 // Contact: phylosoft @ gmail . com
25 // WWW: www.phylosoft.org/forester
27 package org.forester.archaeopteryx.tools;
29 import java.io.IOException;
30 import java.net.UnknownHostException;
31 import java.util.SortedSet;
33 import javax.swing.JOptionPane;
35 import org.forester.analysis.AncestralTaxonomyInference;
36 import org.forester.archaeopteryx.MainFrameApplication;
37 import org.forester.archaeopteryx.TreePanel;
38 import org.forester.phylogeny.Phylogeny;
39 import org.forester.ws.uniprot.UniProtWsTools;
41 public class TaxonomyDataObtainer implements Runnable {
43 private final Phylogeny _phy;
44 private final MainFrameApplication _mf;
45 private final TreePanel _treepanel;
47 public TaxonomyDataObtainer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
50 _treepanel = treepanel;
53 private String getBaseUrl() {
54 return UniProtWsTools.BASE_URL;
57 private void execute() {
58 _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
59 SortedSet<String> not_found = null;
61 not_found = AncestralTaxonomyInference.obtainDetailedTaxonomicInformation( _phy );
63 catch ( final UnknownHostException e ) {
64 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
65 JOptionPane.showMessageDialog( _mf,
66 "Could not connect to \"" + getBaseUrl() + "\"",
67 "Network error during taxonomic information gathering",
68 JOptionPane.ERROR_MESSAGE );
71 catch ( final IOException e ) {
72 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
74 JOptionPane.showMessageDialog( _mf,
76 "Failed to obtain taxonomic information",
77 JOptionPane.ERROR_MESSAGE );
81 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
83 _treepanel.setTree( _phy );
85 _treepanel.setEdited( true );
86 if ( ( not_found != null ) && ( not_found.size() > 0 ) ) {
87 int max = not_found.size();
93 final StringBuffer sb = new StringBuffer();
94 sb.append( "Not all taxonomies could be resolved.\n" );
95 if ( not_found.size() == 1 ) {
96 sb.append( "The following taxonomy was not found:\n" );
99 sb.append( "The following taxonomies were not found (total: " + not_found.size() + "):\n" );
102 for( final String string : not_found ) {
114 JOptionPane.showMessageDialog( _mf,
116 "Taxonomy Tool Completed",
117 JOptionPane.WARNING_MESSAGE );
119 catch ( final Exception e ) {
120 // Not important if this fails, do nothing.
125 JOptionPane.showMessageDialog( _mf,
126 "Taxonomy tool successfully completed",
127 "Taxonomy Tool Completed",
128 JOptionPane.INFORMATION_MESSAGE );
130 catch ( final Exception e ) {
131 // Not important if this fails, do nothing.