X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsurfacing%2FPrintableSpeciesSpecificDcData.java;h=be2fcc7852ef934b493fd2deb9226ee37d16cdc8;hb=612e51e63eb66025a04439fc380384a945a4a30f;hp=79dcb375f89c3bd757f2922a1fc2ad8d811741ac;hpb=08a92c65e8b969a3ce2a4b511055cd6029357831;p=jalview.git diff --git a/forester/java/src/org/forester/surfacing/PrintableSpeciesSpecificDcData.java b/forester/java/src/org/forester/surfacing/PrintableSpeciesSpecificDcData.java index 79dcb37..be2fcc7 100644 --- a/forester/java/src/org/forester/surfacing/PrintableSpeciesSpecificDcData.java +++ b/forester/java/src/org/forester/surfacing/PrintableSpeciesSpecificDcData.java @@ -34,13 +34,14 @@ import java.util.TreeMap; import java.util.TreeSet; import org.forester.util.ForesterUtil; +import org.forester.util.SequenceAccessionTools; class PrintableSpeciesSpecificDcData implements SpeciesSpecificDcData { final SortedMap _combinable_domain_id_to_count_map; final SortedSet _key_domain_proteins; - final private int _key_domain_domains_count; final private int _combinable_domains_count; + final private int _key_domain_domains_count; public PrintableSpeciesSpecificDcData( final int key_domain_domains_count, final int combinable_domains ) { _key_domain_proteins = new TreeSet(); @@ -50,6 +51,17 @@ class PrintableSpeciesSpecificDcData implements SpeciesSpecificDcData { } @Override + public void addKeyDomainProtein( final String protein ) { + if ( ForesterUtil.isEmpty( protein ) ) { + throw new IllegalArgumentException( "attempt to add null or empty protein" ); + } + if ( getKeyDomainProteins().contains( protein ) ) { + throw new IllegalArgumentException( "protein \"" + protein + "\" is not unique" ); + } + getKeyDomainProteins().add( protein ); + } + + @Override public void addProteinsExhibitingCombinationCount( final String domain_id, final int count ) { if ( getCombinableDomainIdToCountsMap().containsKey( domain_id ) ) { throw new IllegalArgumentException( "Domain with id " + domain_id + " already exists" ); @@ -62,16 +74,9 @@ class PrintableSpeciesSpecificDcData implements SpeciesSpecificDcData { return _combinable_domain_id_to_count_map; } - private int getCombinableDomainsCount() { - return _combinable_domains_count; - } - - private int getKeyDomainDomainsCount() { - return _key_domain_domains_count; - } - - private int getKeyDomainProteinsCount() { - return _key_domain_proteins.size(); + @Override + public SortedSet getKeyDomainProteins() { + return _key_domain_proteins; } @Override @@ -83,22 +88,6 @@ class PrintableSpeciesSpecificDcData implements SpeciesSpecificDcData { } @Override - public void addKeyDomainProtein( final String protein ) { - if ( ForesterUtil.isEmpty( protein ) ) { - throw new IllegalArgumentException( "attempt to add null or empty protein" ); - } - if ( getKeyDomainProteins().contains( protein ) ) { - throw new IllegalArgumentException( "protein \"" + protein + "\" is not unique" ); - } - getKeyDomainProteins().add( protein ); - } - - @Override - public SortedSet getKeyDomainProteins() { - return _key_domain_proteins; - } - - @Override public String toString() { return toStringBuffer( DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES, false ) .toString(); @@ -108,53 +97,103 @@ class PrintableSpeciesSpecificDcData implements SpeciesSpecificDcData { public StringBuffer toStringBuffer( final DomainSimilarityCalculator.Detailedness detailedness, final boolean html ) { final StringBuffer sb = new StringBuffer(); if ( detailedness == DomainSimilarityCalculator.Detailedness.PUNCTILIOUS ) { - sb.append( " " ); + if ( html ) { + //sb.append( " " ); + sb.append( "" ); + } sb.append( getKeyDomainDomainsCount() ); - sb.append( ", " ); - sb.append( getKeyDomainProteinsCount() ); - sb.append( ", " ); - sb.append( getCombinableDomainsCount() ); - if ( !getCombinableDomainIdToCountsMap().isEmpty() ) { - sb.append( ":" ); + if ( html ) { + //sb.append( ", " ); + sb.append( "" ); } - } - final Set ids = getCombinableDomainIdToCountsMap().keySet(); - int i = 0; - for( final String domain_id : ids ) { - ++i; - sb.append( " " ); + else { + sb.append( "\t" ); + } + sb.append( getKeyDomainProteinsCount() ); if ( html ) { - sb.append( "" + domain_id - + "" ); + // sb.append( ", " ); + sb.append( "" ); } else { - sb.append( domain_id ); + sb.append( "\t" ); } - if ( detailedness == DomainSimilarityCalculator.Detailedness.PUNCTILIOUS ) { - sb.append( ":" ); - sb.append( getCombinableDomainIdToCountsMap().get( domain_id ) ); + sb.append( getCombinableDomainsCount() ); + if ( html /*&& !getCombinableDomainIdToCountsMap().isEmpty()*/) { + // sb.append( ":" ); + sb.append( "" ); } } - sb.append( " [" ); - boolean first = true; - for( final String p : getKeyDomainProteins() ) { - String link = null; - final String up_id = ForesterUtil.extractUniProtKbProteinSeqIdentifier( p ); - if ( !ForesterUtil.isEmpty( up_id ) ) { - link = "" + up_id + ""; + if ( html ) { + final Set ids = getCombinableDomainIdToCountsMap().keySet(); + for( final String domain_id : ids ) { + sb.append( " " ); + if ( html ) { + sb.append( "" + domain_id + + "" ); + } + else { + sb.append( domain_id ); + } + if ( detailedness == DomainSimilarityCalculator.Detailedness.PUNCTILIOUS ) { + sb.append( ":" ); + sb.append( getCombinableDomainIdToCountsMap().get( domain_id ) ); + } } - else { - link = "" + p + ""; + sb.append( " [" ); + boolean first = true; + for( final String p : getKeyDomainProteins() ) { + final String link = obtainSeqLink( p ); + if ( first ) { + first = false; + } + else { + sb.append( ", " ); + } + sb.append( link ); } - if ( first ) { - first = false; + sb.append( "]" ); + sb.append( "" ); + } + return sb; + } + + private int getCombinableDomainsCount() { + return _combinable_domains_count; + } + + private int getKeyDomainDomainsCount() { + return _key_domain_domains_count; + } + + private int getKeyDomainProteinsCount() { + return _key_domain_proteins.size(); + } + + private static String obtainSeqLink( final String p ) { + String link; + final String up_id = SequenceAccessionTools.parseUniProtAccessorFromString( p ); + if ( !ForesterUtil.isEmpty( up_id ) ) { + link = "" + up_id + + ""; + } + else { + final String gb_id = SequenceAccessionTools.parseGenbankProteinAccessorFromString( p ); + if ( !ForesterUtil.isEmpty( gb_id ) ) { + link = "" + + gb_id + ""; } else { - sb.append( ", " ); + final String gi = SequenceAccessionTools.parseGInumberFromString( p ); + if ( !ForesterUtil.isEmpty( gi ) ) { + link = "gi|" + gi + + ""; + } + else { + link = "" + p + ""; + } } - sb.append( p ); } - sb.append( "]" ); - return sb; + return link; } }