2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.archaeopteryx.tools;
28 import java.net.UnknownHostException;
30 import javax.swing.JOptionPane;
32 import org.forester.analysis.AncestralTaxonomyInference;
33 import org.forester.archaeopteryx.MainFrameApplication;
34 import org.forester.archaeopteryx.TreePanel;
35 import org.forester.phylogeny.Phylogeny;
36 import org.forester.ws.uniprot.UniProtWsTools;
38 public class AncestralTaxonomyInferrer implements Runnable {
40 private final Phylogeny _phy;
41 private final MainFrameApplication _mf;
42 private final TreePanel _treepanel;
44 public AncestralTaxonomyInferrer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
47 _treepanel = treepanel;
50 private String getBaseUrl() {
51 return UniProtWsTools.BASE_URL;
54 private void inferTaxonomies() {
55 _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
57 AncestralTaxonomyInference.inferTaxonomyFromDescendents( _phy );
59 catch ( final AncestralTaxonomyInferenceException e ) {
60 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
61 JOptionPane.showMessageDialog( _mf,
63 "Error during ancestral taxonomy inference",
64 JOptionPane.ERROR_MESSAGE );
67 catch ( final UnknownHostException e ) {
68 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
69 JOptionPane.showMessageDialog( _mf,
70 "Could not connect to \"" + getBaseUrl() + "\"",
71 "Network error during ancestral taxonomy inference",
72 JOptionPane.ERROR_MESSAGE );
75 catch ( final Exception e ) {
76 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
78 JOptionPane.showMessageDialog( _mf,
80 "Unexpected error during ancestral taxonomy inference",
81 JOptionPane.ERROR_MESSAGE );
84 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
85 _phy.setRerootable( false );
86 _treepanel.setTree( _phy );
88 _treepanel.setEdited( true );
90 JOptionPane.showMessageDialog( _mf,
91 "Ancestral taxonomy inference successfully completed",
92 "Ancestral Taxonomy Inference Completed",
93 JOptionPane.INFORMATION_MESSAGE );
95 catch ( final Exception e ) {
96 // Not important if this fails, do nothing.