From c365c2e336ee79677d9e0f5d5c8d280afb56a3ab Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Mon, 19 Sep 2011 02:30:04 +0000 Subject: [PATCH] in progress --- .../analysis/AncestralTaxonomyInference.java | 62 +++++++++++++------- .../src/org/forester/archaeopteryx/NodePanel.java | 35 +++++++++-- .../src/org/forester/phylogeny/data/Taxonomy.java | 20 ++++++- .../org/forester/ws/uniprot/UniProtTaxonomy.java | 1 - .../org/forester/ws/uniprot/UniProtWsTools.java | 1 + 5 files changed, 92 insertions(+), 27 deletions(-) diff --git a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java index da68994..dec0a63 100644 --- a/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java +++ b/forester/java/src/org/forester/analysis/AncestralTaxonomyInference.java @@ -174,9 +174,8 @@ public final class AncestralTaxonomyInference { || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getScientificName() ) || !ForesterUtil.isEmpty( desc.getNodeData().getTaxonomy().getTaxonomyCode() ) || !ForesterUtil .isEmpty( desc.getNodeData().getTaxonomy().getCommonName() ) ) ) { - final QUERY_TYPE qt = null; - final String query = null; - final UniProtTaxonomy up_tax = obtainUniProtTaxonomy( desc.getNodeData().getTaxonomy(), query, qt ); + + final UniProtTaxonomy up_tax = obtainUniProtTaxonomy( desc.getNodeData().getTaxonomy(), null, null ); String[] lineage = null; if ( up_tax != null ) { //lineage = obtainLineagePlusOwnScientificName( up_tax ); @@ -203,16 +202,16 @@ public final class AncestralTaxonomyInference { node = "[" + desc.getId() + "]"; } msg = "Node " + node + " has no or inappropriate taxonomic information"; - final List e = desc.getAllExternalDescendants(); + // final List e = desc.getAllExternalDescendants(); //TODO remove me! - System.out.println(); - int x = 0; - for( final PhylogenyNode object : e ) { - System.out.println( x + ":" ); - System.out.println( object.getName() + " " ); - x++; - } - System.out.println(); +// System.out.println(); +// int x = 0; +// for( final PhylogenyNode object : e ) { +// System.out.println( x + ":" ); +// System.out.println( object.getName() + " " ); +// x++; +// } +// System.out.println(); // throw new IllegalArgumentException( msg ); } @@ -245,7 +244,7 @@ public final class AncestralTaxonomyInference { final Taxonomy tax = new Taxonomy(); n.getNodeData().setTaxonomy( tax ); tax.setScientificName( last_common_lineage ); - final UniProtTaxonomy up_tax = obtainUniProtTaxonomyFromSn( last_common_lineage ); + final UniProtTaxonomy up_tax = obtainUniProtTaxonomyFromSn( last_common_lineage, lineage ); if ( up_tax != null ) { if ( !ForesterUtil.isEmpty( up_tax.getRank() ) ) { try { @@ -264,6 +263,15 @@ public final class AncestralTaxonomyInference { if ( !ForesterUtil.isEmpty( up_tax.getSynonym() ) && !tax.getSynonyms().contains( up_tax.getSynonym() ) ) { tax.getSynonyms().add( up_tax.getSynonym() ); } + if ( up_tax.getLineage() != null ) { + tax.setLineage( new ArrayList() ); + for( final String lin : up_tax.getLineage() ) { + if ( !ForesterUtil.isEmpty( lin ) ) { + tax.getLineage().add( lin ); + } + } + } + } for( final PhylogenyNode desc : descs ) { if ( !desc.isExternal() && desc.getNodeData().isHasTaxonomy() @@ -307,14 +315,14 @@ public final class AncestralTaxonomyInference { not_found_external_nodes.add( node ); } } - UniProtTaxonomy up_tax = null; + UniProtTaxonomy uniprot_tax = null; if ( ( tax != null ) && ( isHasAppropriateId( tax ) || !ForesterUtil.isEmpty( tax.getScientificName() ) || !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) || !ForesterUtil.isEmpty( tax .getCommonName() ) ) ) { - up_tax = obtainUniProtTaxonomy( tax, null, qt ); - if ( up_tax != null ) { - updateTaxonomy( qt, node, tax, up_tax ); + uniprot_tax = obtainUniProtTaxonomy( tax, null, qt ); + if ( uniprot_tax != null ) { + updateTaxonomy( qt, node, tax, uniprot_tax ); } else { not_found.add( tax.toString() ); @@ -350,11 +358,13 @@ public final class AncestralTaxonomyInference { if ( isHasAppropriateId( tax ) ) { query = tax.getIdentifier().getValue(); qt = QUERY_TYPE.ID; + System.out.println( "query by id: " + query); return getTaxonomies( getIdTaxCacheMap(), query, qt ); } else if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) { query = tax.getScientificName(); qt = QUERY_TYPE.SN; + System.out.println( "query by sn: " + query); return getTaxonomies( getSnTaxCacheMap(), query, qt ); } else if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { @@ -369,7 +379,7 @@ public final class AncestralTaxonomyInference { } } - synchronized private static UniProtTaxonomy obtainUniProtTaxonomyFromSn( final String sn ) throws IOException { + synchronized private static UniProtTaxonomy obtainUniProtTaxonomyFromSn( final String sn, List lineage ) throws IOException { UniProtTaxonomy up_tax = null; if ( getSnTaxCacheMap().containsKey( sn ) ) { up_tax = getSnTaxCacheMap().get( sn ).copy(); @@ -388,6 +398,7 @@ public final class AncestralTaxonomyInference { if ( !ForesterUtil.isEmpty( up_tax.getId() ) ) { getIdTaxCacheMap().put( up_tax.getId(), up_tax ); } + } } return up_tax; @@ -401,9 +412,9 @@ public final class AncestralTaxonomyInference { && ForesterUtil.isEmpty( tax.getScientificName() ) ) { tax.setScientificName( up_tax.getScientificName() ); } - if ( node.isExternal() - && ( ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() ) && ForesterUtil - .isEmpty( tax.getTaxonomyCode() ) ) ) { + // if ( node.isExternal() + if ( ( qt != QUERY_TYPE.CODE ) && !ForesterUtil.isEmpty( up_tax.getCode() ) + && ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { tax.setTaxonomyCode( up_tax.getCode() ); } if ( ( qt != QUERY_TYPE.CN ) && !ForesterUtil.isEmpty( up_tax.getCommonName() ) @@ -424,6 +435,15 @@ public final class AncestralTaxonomyInference { if ( ( qt != QUERY_TYPE.ID ) && !ForesterUtil.isEmpty( up_tax.getId() ) && ( tax.getIdentifier() == null ) ) { tax.setIdentifier( new Identifier( up_tax.getId(), "uniprot" ) ); } + if ( up_tax.getLineage() != null ) { + tax.setLineage( new ArrayList() ); + for( final String lin : up_tax.getLineage() ) { + if ( !ForesterUtil.isEmpty( lin ) ) { + tax.getLineage().add( lin ); + } + } + } + } private enum QUERY_TYPE { diff --git a/forester/java/src/org/forester/archaeopteryx/NodePanel.java b/forester/java/src/org/forester/archaeopteryx/NodePanel.java index 0cc491c..fb4ac82 100644 --- a/forester/java/src/org/forester/archaeopteryx/NodePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/NodePanel.java @@ -209,6 +209,30 @@ class NodePanel extends JPanel implements TreeSelectionListener { } } } + + private static void addLineage( final DefaultMutableTreeNode top, + final List lineage, + final DefaultMutableTreeNode category ) { + if ( ( lineage != null ) && ( lineage.size() > 0 ) ) { + + StringBuilder sb = new StringBuilder(); + for( final String lin : lineage ) { + if ( !ForesterUtil.isEmpty( lin ) ) { + sb.append( lin ); + sb.append( " > " ); + } + } + String str = null; + if (sb.length() > 1 ) { + str = sb.substring( 0, sb.length() - 3 ); + } + if ( !ForesterUtil.isEmpty( str ) ) { + addSubelement( category, "Lineage", str ); + } + } + } + + private static void addBasics( final DefaultMutableTreeNode top, final PhylogenyNode phylogeny_node, @@ -240,10 +264,10 @@ class NodePanel extends JPanel implements TreeSelectionListener { if ( no_tax > 0 ) { addSubelement( category, "External nodes without taxonomy", String.valueOf( no_tax ) ); } - //TODO remove me... - for( final Taxonomy taxonomy : distinct_tax.keySet() ) { - System.out.println( taxonomy + ": " + distinct_tax.get( taxonomy ) ); - } + //TODO remove me... maybe make me into a method? + //for( final Taxonomy taxonomy : distinct_tax.keySet() ) { + // System.out.println( taxonomy + ": " + distinct_tax.get( taxonomy ) ); + //} } } if ( !phylogeny_node.isRoot() ) { @@ -391,6 +415,9 @@ class NodePanel extends JPanel implements TreeSelectionListener { if ( ( tax.getUris() != null ) && !tax.getUris().isEmpty() ) { addUris( top, tax.getUris(), category ); } + if ( ( tax.getLineage() != null ) && !tax.getLineage().isEmpty() ) { + addLineage( top, tax.getLineage(), category ); + } } private static void createNodes( final DefaultMutableTreeNode top, final PhylogenyNode phylogeny_node ) { diff --git a/forester/java/src/org/forester/phylogeny/data/Taxonomy.java b/forester/java/src/org/forester/phylogeny/data/Taxonomy.java index 5d4411d..ee78912 100644 --- a/forester/java/src/org/forester/phylogeny/data/Taxonomy.java +++ b/forester/java/src/org/forester/phylogeny/data/Taxonomy.java @@ -46,6 +46,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable _uris; + private List _lineage; public Taxonomy() { init(); @@ -130,6 +131,14 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable() ); + for( final String l : getLineage() ) { + if ( l != null ) { + t.getLineage().add( l ); + } + } + } return t; } @@ -214,13 +223,14 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable lineage ) { + _lineage = lineage; + } + + public List getLineage() { + return _lineage; + } } diff --git a/forester/java/src/org/forester/ws/uniprot/UniProtTaxonomy.java b/forester/java/src/org/forester/ws/uniprot/UniProtTaxonomy.java index 57a483e..14fa14a 100644 --- a/forester/java/src/org/forester/ws/uniprot/UniProtTaxonomy.java +++ b/forester/java/src/org/forester/ws/uniprot/UniProtTaxonomy.java @@ -111,7 +111,6 @@ public final class UniProtTaxonomy { if ( _lineage.isEmpty() && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name .equalsIgnoreCase( ARCHAEA ) ) ) { - System.out.println( " >>>>>>>>>>>>>>>>>>>>>>>>> did it!" ); _lineage.add( CELLULAR_ORGANISMS ); } _lineage.add( _scientific_name ); diff --git a/forester/java/src/org/forester/ws/uniprot/UniProtWsTools.java b/forester/java/src/org/forester/ws/uniprot/UniProtWsTools.java index 5906a8c..05c1c8d 100644 --- a/forester/java/src/org/forester/ws/uniprot/UniProtWsTools.java +++ b/forester/java/src/org/forester/ws/uniprot/UniProtWsTools.java @@ -175,6 +175,7 @@ public final class UniProtWsTools { private static List getTaxonomyStringFromId( final String id, final int max_lines_to_return ) throws IOException { + System.out.println( "getting tax from ID" ); return queryUniprot( "taxonomy/?query=id%3a%22" + encode( id ) + "%22&format=tab", max_lines_to_return ); } -- 1.7.10.2