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.analysis.AncestralTaxonomyInferenceException;
34 import org.forester.archaeopteryx.Constants;
35 import org.forester.archaeopteryx.MainFrameApplication;
36 import org.forester.archaeopteryx.TreePanel;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.util.ForesterUtil;
39 import org.forester.ws.uniprot.UniProtWsTools;
41 public class AncestralTaxonomyInferrer implements Runnable {
43 private final Phylogeny _phy;
44 private final MainFrameApplication _mf;
45 private final TreePanel _treepanel;
46 private long _process_id;
48 private long getProcessId() {
52 private void setProcessId( final long process_id ) {
53 _process_id = process_id;
56 public AncestralTaxonomyInferrer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
59 _treepanel = treepanel;
62 private String getBaseUrl() {
63 return UniProtWsTools.BASE_URL;
66 private void start() {
67 _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
68 setProcessId( _mf.getProcessPool().addProcess( "ancestral taxonomy" ) );
72 final boolean removed = _mf.getProcessPool().removeProcess( getProcessId() );
74 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not remove process " + getProcessId()
75 + " from process pool" );
77 _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
80 private void inferTaxonomies() {
83 AncestralTaxonomyInference.inferTaxonomyFromDescendents( _phy );
85 catch ( final AncestralTaxonomyInferenceException e ) {
87 JOptionPane.showMessageDialog( _mf,
89 "Error during ancestral taxonomy inference",
90 JOptionPane.ERROR_MESSAGE );
93 catch ( final UnknownHostException e ) {
95 JOptionPane.showMessageDialog( _mf,
96 "Could not connect to \"" + getBaseUrl() + "\"",
97 "Network error during ancestral taxonomy inference",
98 JOptionPane.ERROR_MESSAGE );
101 catch ( final Exception e ) {
104 JOptionPane.showMessageDialog( _mf,
106 "Unexpected exception during ancestral taxonomy inference",
107 JOptionPane.ERROR_MESSAGE );
110 catch ( final Error e ) {
113 JOptionPane.showMessageDialog( _mf,
115 "Unexpected error during ancestral taxonomy inference",
116 JOptionPane.ERROR_MESSAGE );
119 _phy.setRerootable( false );
120 _treepanel.setTree( _phy );
122 _treepanel.setEdited( true );
125 JOptionPane.showMessageDialog( _mf,
126 "Ancestral taxonomy inference successfully completed",
127 "Ancestral Taxonomy Inference Completed",
128 JOptionPane.INFORMATION_MESSAGE );
130 catch ( final Exception e ) {
131 // Not important if this fails, do nothing.