2 // 22:09:42 cmzmasek Exp $
4 // FORESTER -- software libraries and applications
5 // for evolutionary biology research and applications.
7 // Copyright (C) 2008-2009 Christian M. Zmasek
8 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 // Contact: phylosoft @ gmail . com
26 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
28 package org.forester.surfacing;
31 import java.util.SortedMap;
32 import java.util.SortedSet;
33 import java.util.TreeMap;
34 import java.util.TreeSet;
36 import org.forester.util.ForesterUtil;
38 class PrintableSpeciesSpecificDcData implements SpeciesSpecificDcData {
40 final SortedMap<String, Integer> _combinable_domain_id_to_count_map;
41 final SortedSet<String> _key_domain_proteins;
42 final private int _key_domain_domains_count;
43 final private int _combinable_domains_count;
45 public PrintableSpeciesSpecificDcData( final int key_domain_domains_count, final int combinable_domains ) {
46 _key_domain_proteins = new TreeSet<String>();
47 _key_domain_domains_count = key_domain_domains_count;
48 _combinable_domains_count = combinable_domains;
49 _combinable_domain_id_to_count_map = new TreeMap<String, Integer>();
53 public void addProteinsExhibitingCombinationCount( final String domain_id, final int count ) {
54 if ( getCombinableDomainIdToCountsMap().containsKey( domain_id ) ) {
55 throw new IllegalArgumentException( "Domain with id " + domain_id + " already exists" );
57 getCombinableDomainIdToCountsMap().put( domain_id, count );
61 public SortedMap<String, Integer> getCombinableDomainIdToCountsMap() {
62 return _combinable_domain_id_to_count_map;
65 private int getCombinableDomainsCount() {
66 return _combinable_domains_count;
69 private int getKeyDomainDomainsCount() {
70 return _key_domain_domains_count;
73 private int getKeyDomainProteinsCount() {
74 return _key_domain_proteins.size();
78 public int getNumberOfProteinsExhibitingCombinationWith( final String domain_id ) {
79 if ( !getCombinableDomainIdToCountsMap().containsKey( domain_id ) ) {
80 throw new IllegalArgumentException( "Domain with id " + domain_id + " not found" );
82 return getCombinableDomainIdToCountsMap().get( domain_id );
86 public void addKeyDomainProtein( final String protein ) {
87 if ( ForesterUtil.isEmpty( protein ) ) {
88 throw new IllegalArgumentException( "attempt to add null or empty protein" );
90 if ( getKeyDomainProteins().contains( protein ) ) {
91 throw new IllegalArgumentException( "protein \"" + protein + "\" is not unique" );
93 getKeyDomainProteins().add( protein );
97 public SortedSet<String> getKeyDomainProteins() {
98 return _key_domain_proteins;
102 public String toString() {
103 return toStringBuffer( DomainSimilarityCalculator.Detailedness.LIST_COMBINING_DOMAIN_FOR_EACH_SPECIES, false )
108 public StringBuffer toStringBuffer( final DomainSimilarityCalculator.Detailedness detailedness, final boolean html ) {
109 final StringBuffer sb = new StringBuffer();
110 if ( detailedness == DomainSimilarityCalculator.Detailedness.PUNCTILIOUS ) {
112 sb.append( getKeyDomainDomainsCount() );
114 sb.append( getKeyDomainProteinsCount() );
116 sb.append( getCombinableDomainsCount() );
117 if ( !getCombinableDomainIdToCountsMap().isEmpty() ) {
121 final Set<String> ids = getCombinableDomainIdToCountsMap().keySet();
123 for( final String domain_id : ids ) {
127 sb.append( "<a href=\"" + SurfacingConstants.PFAM_FAMILY_ID_LINK + domain_id + "\">" + domain_id
131 sb.append( domain_id );
133 if ( detailedness == DomainSimilarityCalculator.Detailedness.PUNCTILIOUS ) {
135 sb.append( getCombinableDomainIdToCountsMap().get( domain_id ) );
139 boolean first = true;
140 for( final String p : getKeyDomainProteins() ) {
142 final String up_id = ForesterUtil.extractUniProtKbProteinSeqIdentifier( p );
143 if ( !ForesterUtil.isEmpty( up_id ) ) {
144 link = "<a href=\"" + ForesterUtil.UNIPROT_KB + up_id + "\" target=\"_up_window\">" + up_id + "</a>";
147 link = "<a href=\"" + "http://www.google.com/search?q=" + p + "\" target=\"_g_window\">" + p + "</a>";