X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsurfacing%2FPrintableSpeciesSpecificDcData.java;h=2cfbf0b7f524ba43efc968eb568e8a3793cd3a6e;hb=f47b5de663d2ca59a4d53587ea8d5cd20c594db2;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..2cfbf0b 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.SequenceIdParser; 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,100 @@ 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( getKeyDomainDomainsCount() ); - sb.append( ", " ); - sb.append( getKeyDomainProteinsCount() ); - sb.append( ", " ); - sb.append( getCombinableDomainsCount() ); - if ( !getCombinableDomainIdToCountsMap().isEmpty() ) { - sb.append( ":" ); + if ( html ) { + 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( ", " ); } else { - sb.append( domain_id ); + sb.append( "\t" ); } - if ( detailedness == DomainSimilarityCalculator.Detailedness.PUNCTILIOUS ) { + sb.append( getCombinableDomainsCount() ); + if ( html && !getCombinableDomainIdToCountsMap().isEmpty() ) { sb.append( ":" ); - sb.append( getCombinableDomainIdToCountsMap().get( domain_id ) ); } } - 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(); + int i = 0; + for( final String domain_id : ids ) { + ++i; + 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( "]" ); + } + 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 = ForesterUtil.extractUniProtKbProteinSeqIdentifier( p ); + if ( !ForesterUtil.isEmpty( up_id ) ) { + link = "" + up_id + + ""; + } + else { + final String gb_id = SequenceIdParser.parseGenbankProteinAccessor( p ); + if ( !ForesterUtil.isEmpty( gb_id ) ) { + link = "" + + gb_id + ""; } else { - sb.append( ", " ); + final String gi = SequenceIdParser.parseGInumber( p ); + if ( !ForesterUtil.isEmpty( gi ) ) { + link = "gi|" + gi + + ""; + } + else { + link = "" + p + ""; + } } - sb.append( p ); } - sb.append( "]" ); - return sb; + return link; } }