From: cmzmasek Date: Mon, 4 Jun 2012 16:11:15 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c3ef647b344999a7989bc61589a2286ceeeb2f7f;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java index 6999f8b..0b84522 100644 --- a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java +++ b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java @@ -41,7 +41,7 @@ public final class AncestralTaxonomyInference { public static void inferTaxonomyFromDescendents( final Phylogeny phy ) throws IOException, AncestralTaxonomyInferenceException { - TaxonomyDataObtainer.clearCachesIfTooLarge(); + TaxonomyDataManager.clearCachesIfTooLarge(); for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); if ( !node.isExternal() ) { @@ -61,12 +61,12 @@ public final class AncestralTaxonomyInference { int shortest_lin_length = Integer.MAX_VALUE; for( final PhylogenyNode desc : descs ) { if ( desc.getNodeData().isHasTaxonomy() - && ( TaxonomyDataObtainer.isHasAppropriateId( desc.getNodeData().getTaxonomy() ) + && ( TaxonomyDataManager.isHasAppropriateId( desc.getNodeData().getTaxonomy() ) || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getScientificName() ) || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getLineage() ) || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getTaxonomyCode() ) || !ForesterUtil .isEmpty( desc.getNodeData().getTaxonomy().getCommonName() ) ) ) { - final UniProtTaxonomy up_tax = TaxonomyDataObtainer.obtainUniProtTaxonomy( desc.getNodeData() + final UniProtTaxonomy up_tax = TaxonomyDataManager.obtainUniProtTaxonomy( desc.getNodeData() .getTaxonomy(), null, null ); if ( ( up_tax == null ) && ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getLineage() ) ) { String desc_str = ""; @@ -169,7 +169,7 @@ public final class AncestralTaxonomyInference { final Taxonomy tax = new Taxonomy(); n.getNodeData().setTaxonomy( tax ); tax.setScientificName( last_common ); - final UniProtTaxonomy up_tax = TaxonomyDataObtainer.obtainUniProtTaxonomyFromLineage( last_common_lineage ); + final UniProtTaxonomy up_tax = TaxonomyDataManager.obtainUniProtTaxonomyFromLineage( last_common_lineage ); if ( up_tax != null ) { if ( !ForesterUtil.isEmpty( up_tax.getRank() ) ) { try { diff --git a/forester/java/src/org/forester/analysis/TaxonomyDataObtainer.java b/forester/java/src/org/forester/analysis/TaxonomyDataManager.java similarity index 80% rename from forester/java/src/org/forester/analysis/TaxonomyDataObtainer.java rename to forester/java/src/org/forester/analysis/TaxonomyDataManager.java index 9222c44..0e48458 100644 --- a/forester/java/src/org/forester/analysis/TaxonomyDataObtainer.java +++ b/forester/java/src/org/forester/analysis/TaxonomyDataManager.java @@ -49,7 +49,7 @@ import org.forester.util.ForesterUtil; import org.forester.ws.uniprot.UniProtTaxonomy; import org.forester.ws.uniprot.UniProtWsTools; -public class TaxonomyDataObtainer extends RunnableProcess { +public final class TaxonomyDataManager extends RunnableProcess { enum QUERY_TYPE { CODE, SN, CN, ID, LIN; @@ -62,6 +62,33 @@ public class TaxonomyDataObtainer extends RunnableProcess { private static final HashMap _cn_up_cache_map = new HashMap(); private static final HashMap _id_up_cache_map = new HashMap(); + private final Phylogeny _phy; + private final MainFrameApplication _mf; + private final TreePanel _treepanel; + private final boolean _delete; + private final boolean _allow_simple_names; + + public TaxonomyDataManager( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) { + _phy = phy; + _mf = mf; + _treepanel = treepanel; + _delete = false; + _allow_simple_names = false; + } + + public TaxonomyDataManager( final MainFrameApplication mf, + final TreePanel treepanel, + final Phylogeny phy, + final boolean delete, + final boolean allow_simple_name ) { + _phy = phy; + _mf = mf; + _treepanel = treepanel; + _delete = delete; + _allow_simple_names = allow_simple_name; + } + + synchronized static void clearCachesIfTooLarge() { if ( getSnTaxCacheMap().size() > MAX_CACHE_SIZE ) { getSnTaxCacheMap().clear(); @@ -80,27 +107,27 @@ public class TaxonomyDataObtainer extends RunnableProcess { } } - synchronized static HashMap getCnTaxCacheMap() { + synchronized final static HashMap getCnTaxCacheMap() { return _cn_up_cache_map; } - synchronized static HashMap getCodeTaxCacheMap() { + synchronized final static HashMap getCodeTaxCacheMap() { return _code_up_cache_map; } - synchronized static HashMap getIdTaxCacheMap() { + synchronized final static HashMap getIdTaxCacheMap() { return _id_up_cache_map; } - synchronized static HashMap getLineageTaxCacheMap() { + synchronized final static HashMap getLineageTaxCacheMap() { return _lineage_up_cache_map; } - synchronized static HashMap getSnTaxCacheMap() { + synchronized final static HashMap getSnTaxCacheMap() { return _sn_up_cache_map; } - private static UniProtTaxonomy getTaxonomies( final HashMap cache, + private final static UniProtTaxonomy getTaxonomies( final HashMap cache, final Object query, final QUERY_TYPE qt ) throws IOException, AncestralTaxonomyInferenceException { @@ -130,16 +157,16 @@ public class TaxonomyDataObtainer extends RunnableProcess { if ( ( up_taxonomies != null ) && ( up_taxonomies.size() == 1 ) ) { final UniProtTaxonomy up_tax = up_taxonomies.get( 0 ); if ( !ForesterUtil.isEmpty( up_tax.getScientificName() ) ) { - TaxonomyDataObtainer.getSnTaxCacheMap().put( up_tax.getScientificName(), up_tax ); + TaxonomyDataManager.getSnTaxCacheMap().put( up_tax.getScientificName(), up_tax ); } if ( !ForesterUtil.isEmpty( up_tax.getCode() ) ) { - TaxonomyDataObtainer.getCodeTaxCacheMap().put( up_tax.getCode(), up_tax ); + TaxonomyDataManager.getCodeTaxCacheMap().put( up_tax.getCode(), up_tax ); } if ( !ForesterUtil.isEmpty( up_tax.getCommonName() ) ) { - TaxonomyDataObtainer.getCnTaxCacheMap().put( up_tax.getCommonName(), up_tax ); + TaxonomyDataManager.getCnTaxCacheMap().put( up_tax.getCommonName(), up_tax ); } if ( !ForesterUtil.isEmpty( up_tax.getId() ) ) { - TaxonomyDataObtainer.getIdTaxCacheMap().put( up_tax.getId(), up_tax ); + TaxonomyDataManager.getIdTaxCacheMap().put( up_tax.getId(), up_tax ); } return up_tax; } @@ -149,33 +176,34 @@ public class TaxonomyDataObtainer extends RunnableProcess { } } - private static List getTaxonomiesFromCommonName( final String query ) throws IOException { + private final static List getTaxonomiesFromCommonName( final String query ) throws IOException { return UniProtWsTools.getTaxonomiesFromCommonNameStrict( query, MAX_TAXONOMIES_TO_RETURN ); } - private static List getTaxonomiesFromId( final String query ) throws IOException { + private final static List getTaxonomiesFromId( final String query ) throws IOException { return UniProtWsTools.getTaxonomiesFromId( query, MAX_TAXONOMIES_TO_RETURN ); } - // - private static List getTaxonomiesFromScientificName( final String query ) throws IOException { + + private final static List getTaxonomiesFromScientificName( final String query ) throws IOException { return UniProtWsTools.getTaxonomiesFromScientificNameStrict( query, MAX_TAXONOMIES_TO_RETURN ); } - // - private static List getTaxonomiesFromTaxonomyCode( final String query ) throws IOException { + + private final static List getTaxonomiesFromTaxonomyCode( final String query ) throws IOException { return UniProtWsTools.getTaxonomiesFromTaxonomyCode( query, MAX_TAXONOMIES_TO_RETURN ); } - static boolean isHasAppropriateId( final Taxonomy tax ) { + static final boolean isHasAppropriateId( final Taxonomy tax ) { return ( ( tax.getIdentifier() != null ) && ( !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) && ( tax .getIdentifier().getProvider().equalsIgnoreCase( "ncbi" ) || tax.getIdentifier().getProvider().equalsIgnoreCase( "uniprot" ) || tax.getIdentifier().getProvider() .equalsIgnoreCase( "uniprotkb" ) ) ) ); } - synchronized private static SortedSet obtainDetailedTaxonomicInformation( final Phylogeny phy, - final boolean delete ) + synchronized final private static SortedSet obtainDetailedTaxonomicInformation( final Phylogeny phy, + final boolean delete, + final boolean allow_to_use_basic_node_names ) throws IOException, AncestralTaxonomyInferenceException { clearCachesIfTooLarge(); final SortedSet not_found = new TreeSet(); @@ -190,6 +218,9 @@ public class TaxonomyDataObtainer extends RunnableProcess { if ( node.getNodeData().isHasTaxonomy() ) { tax = node.getNodeData().getTaxonomy(); } + else if ( allow_to_use_basic_node_names && !ForesterUtil.isEmpty( node.getName() ) ) { + // Nothing to be done. + } else if ( node.isExternal() ) { if ( !ForesterUtil.isEmpty( node.getName() ) ) { not_found.add( node.getName() ); @@ -202,10 +233,11 @@ public class TaxonomyDataObtainer extends RunnableProcess { } } UniProtTaxonomy uniprot_tax = null; - if ( ( tax != null ) + if ( ( ( tax != null ) && ( isHasAppropriateId( tax ) || !ForesterUtil.isEmpty( tax.getScientificName() ) || !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) || !ForesterUtil.isEmpty( tax - .getCommonName() ) ) ) { + .getCommonName() ) ) ) || + ( allow_to_use_basic_node_names && !ForesterUtil.isEmpty( node.getName() ) ) ) { uniprot_tax = obtainUniProtTaxonomy( tax, null, qt ); if ( uniprot_tax != null ) { updateTaxonomy( qt, node, tax, uniprot_tax ); @@ -229,43 +261,48 @@ public class TaxonomyDataObtainer extends RunnableProcess { return not_found; } - public static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt ) + public final static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt ) throws IOException, AncestralTaxonomyInferenceException { - if ( TaxonomyDataObtainer.isHasAppropriateId( tax ) ) { + if ( tax == null ) { + throw new IllegalArgumentException( "illegal attempt to use empty taxonomy object"); + } + + + if ( TaxonomyDataManager.isHasAppropriateId( tax ) ) { query = tax.getIdentifier().getValue(); qt = QUERY_TYPE.ID; - return getTaxonomies( TaxonomyDataObtainer.getIdTaxCacheMap(), query, qt ); + return getTaxonomies( TaxonomyDataManager.getIdTaxCacheMap(), query, qt ); } else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) { if ( !ForesterUtil.isEmpty( tax.getLineage() ) ) { query = tax.getLineage(); qt = QUERY_TYPE.LIN; - return getTaxonomies( TaxonomyDataObtainer.getLineageTaxCacheMap(), query, qt ); + return getTaxonomies( TaxonomyDataManager.getLineageTaxCacheMap(), query, qt ); } else { query = tax.getScientificName(); qt = QUERY_TYPE.SN; - return getTaxonomies( TaxonomyDataObtainer.getSnTaxCacheMap(), query, qt ); + return getTaxonomies( TaxonomyDataManager.getSnTaxCacheMap(), query, qt ); } } else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { query = tax.getTaxonomyCode(); qt = QUERY_TYPE.CODE; - return getTaxonomies( TaxonomyDataObtainer.getCodeTaxCacheMap(), query, qt ); + return getTaxonomies( TaxonomyDataManager.getCodeTaxCacheMap(), query, qt ); } else { query = tax.getCommonName(); qt = QUERY_TYPE.CN; - return getTaxonomies( TaxonomyDataObtainer.getCnTaxCacheMap(), query, qt ); + return getTaxonomies( TaxonomyDataManager.getCnTaxCacheMap(), query, qt ); } } - static UniProtTaxonomy obtainUniProtTaxonomyFromLineage( final List lineage ) + static final UniProtTaxonomy obtainUniProtTaxonomyFromLineage( final List lineage ) throws AncestralTaxonomyInferenceException, IOException { final String lineage_str = ForesterUtil.stringListToString( lineage, ">" ); UniProtTaxonomy up_tax = null; - if ( TaxonomyDataObtainer.getLineageTaxCacheMap().containsKey( lineage_str ) ) { - up_tax = TaxonomyDataObtainer.getLineageTaxCacheMap().get( lineage_str ).copy(); + if ( TaxonomyDataManager.getLineageTaxCacheMap().containsKey( lineage_str ) ) { + up_tax = TaxonomyDataManager.getLineageTaxCacheMap().get( lineage_str ).copy(); } else { final List up_taxonomies = getTaxonomiesFromScientificName( lineage @@ -291,25 +328,25 @@ public class TaxonomyDataObtainer extends RunnableProcess { throw new AncestralTaxonomyInferenceException( "lineage \"" + ForesterUtil.stringListToString( lineage, " > " ) + "\" not found" ); } - TaxonomyDataObtainer.getLineageTaxCacheMap().put( lineage_str, up_tax ); + TaxonomyDataManager.getLineageTaxCacheMap().put( lineage_str, up_tax ); if ( !ForesterUtil.isEmpty( up_tax.getScientificName() ) ) { - TaxonomyDataObtainer.getSnTaxCacheMap().put( up_tax.getScientificName(), up_tax ); + TaxonomyDataManager.getSnTaxCacheMap().put( up_tax.getScientificName(), up_tax ); } if ( !ForesterUtil.isEmpty( up_tax.getCode() ) ) { - TaxonomyDataObtainer.getCodeTaxCacheMap().put( up_tax.getCode(), up_tax ); + TaxonomyDataManager.getCodeTaxCacheMap().put( up_tax.getCode(), up_tax ); } if ( !ForesterUtil.isEmpty( up_tax.getCommonName() ) ) { - TaxonomyDataObtainer.getCnTaxCacheMap().put( up_tax.getCommonName(), up_tax ); + TaxonomyDataManager.getCnTaxCacheMap().put( up_tax.getCommonName(), up_tax ); } if ( !ForesterUtil.isEmpty( up_tax.getId() ) ) { - TaxonomyDataObtainer.getIdTaxCacheMap().put( up_tax.getId(), up_tax ); + TaxonomyDataManager.getIdTaxCacheMap().put( up_tax.getId(), up_tax ); } } } return up_tax; } - synchronized private static void updateTaxonomy( final QUERY_TYPE qt, + synchronized final private static void updateTaxonomy( final QUERY_TYPE qt, final PhylogenyNode node, final Taxonomy tax, final UniProtTaxonomy up_tax ) { @@ -349,33 +386,12 @@ public class TaxonomyDataObtainer extends RunnableProcess { } } } - private final Phylogeny _phy; - private final MainFrameApplication _mf; - private final TreePanel _treepanel; - private final boolean _delete; - - public TaxonomyDataObtainer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) { - _phy = phy; - _mf = mf; - _treepanel = treepanel; - _delete = false; - } - - public TaxonomyDataObtainer( final MainFrameApplication mf, - final TreePanel treepanel, - final Phylogeny phy, - final boolean delete ) { - _phy = phy; - _mf = mf; - _treepanel = treepanel; - _delete = delete; - } - - private void execute() { + + private final void execute() { start( _mf, "taxonomy data" ); SortedSet not_found = null; try { - not_found = obtainDetailedTaxonomicInformation( _phy, _delete ); + not_found = obtainDetailedTaxonomicInformation( _phy, _delete, _allow_simple_names ); } catch ( final UnknownHostException e ) { JOptionPane.showMessageDialog( _mf, @@ -479,7 +495,7 @@ public class TaxonomyDataObtainer extends RunnableProcess { } } - private String getBaseUrl() { + private final String getBaseUrl() { return UniProtWsTools.BASE_URL; } diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index 5f8aa34..f49792c 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -63,7 +63,7 @@ import javax.swing.JOptionPane; import javax.swing.text.MaskFormatter; import org.forester.analysis.AncestralTaxonomyInference; -import org.forester.analysis.TaxonomyDataObtainer; +import org.forester.analysis.TaxonomyDataManager; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; import org.forester.io.parsers.tol.TolParser; @@ -465,7 +465,7 @@ public final class AptxUtil { else { UniProtTaxonomy up = null; try { - up = TaxonomyDataObtainer.obtainUniProtTaxonomy( temp_tax, null, null ); + up = TaxonomyDataManager.obtainUniProtTaxonomy( temp_tax, null, null ); } catch ( final Exception e ) { e.printStackTrace(); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 51d1129..bdfd369 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -59,7 +59,7 @@ import javax.swing.event.ChangeListener; import javax.swing.filechooser.FileFilter; import javax.swing.plaf.synth.SynthLookAndFeel; -import org.forester.analysis.TaxonomyDataObtainer; +import org.forester.analysis.TaxonomyDataManager; import org.forester.archaeopteryx.AptxUtil.GraphicsExportType; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; @@ -1516,7 +1516,7 @@ public final class MainFrameApplication extends MainFrame { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); if ( ( phy != null ) && !phy.isEmpty() ) { - final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this, + final TaxonomyDataManager t = new TaxonomyDataManager( this, _mainpanel.getCurrentTreePanel(), phy.copy() ); new Thread( t ).start(); @@ -1528,10 +1528,10 @@ public final class MainFrameApplication extends MainFrame { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); if ( ( phy != null ) && !phy.isEmpty() ) { - final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this, + final TaxonomyDataManager t = new TaxonomyDataManager( this, _mainpanel.getCurrentTreePanel(), phy.copy(), - true ); + true,true ); new Thread( t ).start(); } }