From: cmzmasek@gmail.com Date: Sat, 17 Sep 2011 00:14:45 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=93b3ffddb203151c92200b3498d5559cc4de7d18;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 4f114a2..7ddfe99 100644 --- a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java +++ b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java @@ -275,10 +275,15 @@ public final class AncestralTaxonomyInference { .equalsIgnoreCase( "uniprotkb" ) ) ) ); } - synchronized public static SortedSet obtainDetailedTaxonomicInformation( final Phylogeny phy ) + synchronized public static SortedSet obtainDetailedTaxonomicInformation( final Phylogeny phy, + final boolean delete ) throws IOException { clearCachesIfTooLarge(); final SortedSet not_found = new TreeSet(); + List not_found_external_nodes = null; + if ( delete ) { + not_found_external_nodes = new ArrayList(); + } for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); final QUERY_TYPE qt = null; @@ -293,6 +298,9 @@ public final class AncestralTaxonomyInference { else { not_found.add( node.toString() ); } + if ( delete ) { + not_found_external_nodes.add( node ); + } } UniProtTaxonomy up_tax = null; if ( ( tax != null ) @@ -305,9 +313,18 @@ public final class AncestralTaxonomyInference { } else { not_found.add( tax.toString() ); + if ( delete && node.isExternal() ) { + not_found_external_nodes.add( node ); + } } } } + if ( delete ) { + for( PhylogenyNode node : not_found_external_nodes ) { + phy.deleteSubtree( node, false ); + } + phy.recalculateNumberOfExternalDescendants( true ); + } return not_found; } diff --git a/forester/java/src/org/forester/application/get_subtree_specific_chars.java b/forester/java/src/org/forester/application/get_subtree_specific_chars.java index 830b043..2f0f143 100644 --- a/forester/java/src/org/forester/application/get_subtree_specific_chars.java +++ b/forester/java/src/org/forester/application/get_subtree_specific_chars.java @@ -61,8 +61,12 @@ public class get_subtree_specific_chars { final SortedSet all_chars = getAllExternalPresentAndGainedCharacters( phy.getRoot() ); System.out.println( "Sum of all external characters:\t" + all_chars.size() ); System.out.println(); + final boolean SIMPLE = false; for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); + if ( !SIMPLE && node.isExternal() ) { + continue; + } if ( !node.isRoot() ) { System.out.println(); if ( node.getNodeData().isHasTaxonomy() @@ -84,7 +88,24 @@ public class get_subtree_specific_chars { final SortedSet unique_chars = new TreeSet(); for( final String node_char : node_chars ) { if ( !not_node_chars.contains( node_char ) ) { - unique_chars.add( node_char ); + if ( SIMPLE ) { + unique_chars.add( node_char ); + } + else { + boolean found = true; + for( final int external_id : external_ids ) { + if ( !phy.getNode( external_id ).getNodeData().getBinaryCharacters() + .getGainedCharacters().contains( node_char ) + && !phy.getNode( external_id ).getNodeData().getBinaryCharacters() + .getPresentCharacters().contains( node_char ) ) { + found = false; + break; + } + } + if ( found ) { + unique_chars.add( node_char ); + } + } } } System.out.println( "\tSUM:\t" + unique_chars.size() ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 80555c0..5e78865 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -120,6 +120,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { JMenuItem _collapse_species_specific_subtrees; JMenuItem _collapse_below_threshold; //TODO implememt me JMenuItem _obtain_detailed_taxonomic_information_jmi; + JMenuItem _obtain_detailed_taxonomic_information_deleting_jmi; JMenuItem _obtain_uniprot_seq_information_jmi; JMenuItem _move_node_names_to_tax_sn_jmi; JMenuItem _move_node_names_to_seq_names_jmi; diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 461f9f3..80c3b5b 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -496,6 +496,12 @@ public final class MainFrameApplication extends MainFrame { } obtainDetailedTaxonomicInformation(); } + else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) { + if ( isSubtreeDisplayed() ) { + return; + } + obtainDetailedTaxonomicInformationDelete(); + } else if ( o == _obtain_uniprot_seq_information_jmi ) { obtainUniProtSequenceInformation(); } @@ -870,6 +876,11 @@ public final class MainFrameApplication extends MainFrame { _obtain_detailed_taxonomic_information_jmi .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" ); _tools_menu + .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (Delete Nodes)" ) ); + customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi ); + _obtain_detailed_taxonomic_information_deleting_jmi + .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" ); + _tools_menu .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) ); customizeJMenuItem( _obtain_uniprot_seq_information_jmi ); _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" ); @@ -1427,6 +1438,19 @@ public final class MainFrameApplication extends MainFrame { } } + private void obtainDetailedTaxonomicInformationDelete() { + if ( getCurrentTreePanel() != null ) { + final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); + if ( ( phy != null ) && !phy.isEmpty() ) { + final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this, + _mainpanel.getCurrentTreePanel(), + phy.copy(), + true ); + new Thread( t ).start(); + } + } + } + private void obtainUniProtSequenceInformation() { if ( getCurrentTreePanel() != null ) { final Phylogeny phy = getCurrentTreePanel().getPhylogeny(); diff --git a/forester/java/src/org/forester/archaeopteryx/tools/TaxonomyDataObtainer.java b/forester/java/src/org/forester/archaeopteryx/tools/TaxonomyDataObtainer.java index 17d871b..952d3fa 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/TaxonomyDataObtainer.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/TaxonomyDataObtainer.java @@ -43,11 +43,23 @@ public class TaxonomyDataObtainer implements Runnable { 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, + boolean delete ) { + _phy = phy; + _mf = mf; + _treepanel = treepanel; + _delete = delete; + } public TaxonomyDataObtainer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) { _phy = phy; _mf = mf; _treepanel = treepanel; + _delete = false; } private String getBaseUrl() { @@ -58,7 +70,7 @@ public class TaxonomyDataObtainer implements Runnable { _mf.getMainPanel().getCurrentTreePanel().setWaitCursor(); SortedSet not_found = null; try { - not_found = AncestralTaxonomyInference.obtainDetailedTaxonomicInformation( _phy ); + not_found = AncestralTaxonomyInference.obtainDetailedTaxonomicInformation( _phy, _delete ); } catch ( final UnknownHostException e ) { _mf.getMainPanel().getCurrentTreePanel().setArrowCursor(); @@ -93,10 +105,21 @@ public class TaxonomyDataObtainer implements Runnable { final StringBuffer sb = new StringBuffer(); sb.append( "Not all taxonomies could be resolved.\n" ); if ( not_found.size() == 1 ) { - sb.append( "The following taxonomy was not found:\n" ); + if ( _delete ) { + sb.append( "The following taxonomy was not found and deleted (if external):\n" ); + } + else { + sb.append( "The following taxonomy was not found:\n" ); + } } else { - sb.append( "The following taxonomies were not found (total: " + not_found.size() + "):\n" ); + if ( _delete ) { + sb.append( "The following taxonomies were not found and deleted (if external) (total: " + + not_found.size() + "):\n" ); + } + else { + sb.append( "The following taxonomies were not found (total: " + not_found.size() + "):\n" ); + } } int i = 0; for( final String string : not_found ) {