From: cmzmasek@gmail.com Date: Wed, 28 Sep 2011 02:22:34 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6dd5261500fa70aceb447815de061476c78553ab;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 09291f6..73af2c1 100644 --- a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java +++ b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java @@ -392,7 +392,7 @@ public final class AncestralTaxonomyInference { return not_found; } - synchronized private static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt ) + synchronized public static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, Object query, QUERY_TYPE qt ) throws IOException, AncestralTaxonomyInferenceException { if ( isHasAppropriateId( tax ) ) { query = tax.getIdentifier().getValue(); @@ -499,7 +499,8 @@ public final class AncestralTaxonomyInference { tax.setRank( "" ); } } - if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() ) && ( tax.getIdentifier() == null ) ) { + if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() ) + && ( ( tax.getIdentifier() == null ) || ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) ) { tax.setIdentifier( new Identifier( up_tax.getId(), "uniprot" ) ); } if ( up_tax.getLineage() != null ) { diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index aa2582d..684f90c 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -767,6 +767,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return; } setWaitCursor(); + Util.removeBranchColors( _phylogeny ); Util.colorPhylogenyAccordingToConfidenceValues( _phylogeny, this ); _control_panel.setColorBranches( true ); if ( _control_panel.getColorBranchesCb() != null ) { @@ -781,6 +782,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return; } setWaitCursor(); + Util.removeBranchColors( _phylogeny ); Util.colorPhylogenyAccordingToRanks( _phylogeny, rank, this ); _control_panel.setColorBranches( true ); if ( _control_panel.getColorBranchesCb() != null ) { diff --git a/forester/java/src/org/forester/archaeopteryx/Util.java b/forester/java/src/org/forester/archaeopteryx/Util.java index daceb3e..59eb617 100644 --- a/forester/java/src/org/forester/archaeopteryx/Util.java +++ b/forester/java/src/org/forester/archaeopteryx/Util.java @@ -59,6 +59,7 @@ import javax.swing.JApplet; import javax.swing.JOptionPane; import javax.swing.text.MaskFormatter; +import org.forester.analysis.AncestralTaxonomyInference; import org.forester.io.parsers.PhylogenyParser; import org.forester.io.parsers.tol.TolParser; import org.forester.phylogeny.Phylogeny; @@ -72,6 +73,7 @@ import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.phylogeny.iterators.PreorderTreeIterator; import org.forester.util.DescriptiveStatistics; import org.forester.util.ForesterUtil; +import org.forester.ws.uniprot.UniProtTaxonomy; public final class Util { @@ -295,7 +297,7 @@ public final class Util { final static void colorPhylogenyAccordingToRanks( final Phylogeny tree, final String rank, final TreePanel tree_panel ) { - final Map m = new HashMap(); + final Map true_lineage_to_color_map = new HashMap(); for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { final PhylogenyNode n = it.next(); if ( n.getNodeData().isHasTaxonomy() @@ -312,24 +314,52 @@ public final class Util { desc.getBranchData().setBranchColor( c ); } if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { - m.put( n.getNodeData().getTaxonomy().getScientificName(), c.getValue() ); + true_lineage_to_color_map.put( n.getNodeData().getTaxonomy().getScientificName(), c.getValue() ); } } } } - if ( !m.isEmpty() ) { - for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { - final PhylogenyNode n = it.next(); - if ( ( n.getBranchData().getBranchColor() == null ) && n.getNodeData().isHasTaxonomy() - && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getLineage() ) ) { - for( final String lin : n.getNodeData().getTaxonomy().getLineage() ) { - if ( m.containsKey( lin ) ) { - final BranchColor c = new BranchColor( m.get( lin ) ); - n.getBranchData().setBranchColor( c ); - final List descs = PhylogenyMethods.getAllDescendants( n ); + for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) { + final PhylogenyNode node = it.next(); + if ( ( node.getBranchData().getBranchColor() == null ) && node.getNodeData().isHasTaxonomy() + && !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getLineage() ) ) { + boolean success = false; + if ( !true_lineage_to_color_map.isEmpty() ) { + for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { + if ( true_lineage_to_color_map.containsKey( lin ) ) { + final BranchColor c = new BranchColor( true_lineage_to_color_map.get( lin ) ); + node.getBranchData().setBranchColor( c ); + final List descs = PhylogenyMethods.getAllDescendants( node ); + for( final PhylogenyNode desc : descs ) { + desc.getBranchData().setBranchColor( c ); + } + success = true; + break; + } + } + } + //TODO refactor refactor refactor refactor refactor refactor + if ( !success ) { + for( final String lin : node.getNodeData().getTaxonomy().getLineage() ) { + final Taxonomy temp_tax = new Taxonomy(); + temp_tax.setScientificName( lin ); + UniProtTaxonomy up = null; + try { + up = AncestralTaxonomyInference.obtainUniProtTaxonomy( temp_tax, null, null ); + } + catch ( final Exception e ) { + e.printStackTrace(); + } + if ( ( up != null ) && !ForesterUtil.isEmpty( up.getRank() ) + && up.getRank().equalsIgnoreCase( rank ) ) { + final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( temp_tax ) ); + node.getBranchData().setBranchColor( c ); + final List descs = PhylogenyMethods.getAllDescendants( node ); for( final PhylogenyNode desc : descs ) { desc.getBranchData().setBranchColor( c ); } + true_lineage_to_color_map.put( lin, c.getValue() ); + break; } } }