3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.surfacing;
29 import java.util.ArrayList;
30 import java.util.HashSet;
31 import java.util.Iterator;
32 import java.util.List;
34 import java.util.SortedMap;
35 import java.util.TreeMap;
37 import org.forester.protein.BinaryDomainCombination;
38 import org.forester.species.Species;
39 import org.forester.util.ForesterUtil;
41 public class BasicCombinableDomains implements CombinableDomains {
43 final private String _key_domain;
44 private int _key_domain_count;
45 final private Species _species;
46 final private TreeMap<String, Integer> _combining_domains;
47 final private Set<String> _proteins_with_key_domain;
49 public BasicCombinableDomains( final String key_domain, final Species species ) {
50 _key_domain = key_domain;
52 _combining_domains = new TreeMap<String, Integer>();
53 _proteins_with_key_domain = new HashSet<String>();
54 _key_domain_count = 0;
58 public void addCombinableDomain( final String protein_domain ) {
59 if ( getCombiningDomains().containsKey( protein_domain ) ) {
60 getCombiningDomains().put( protein_domain, getCombiningDomains().get( protein_domain ) + 1 );
63 getCombiningDomains().put( protein_domain, 1 );
68 public void addKeyDomainProtein( final String protein ) {
69 if ( ForesterUtil.isEmpty( protein ) ) {
70 throw new IllegalArgumentException( "attempt to add null or empty protein" );
72 getKeyDomainProteins().add( protein );
76 public List<String> getAllDomains() {
77 final List<String> domains = getCombinableDomains();
78 if ( !domains.contains( getKeyDomain() ) ) {
79 domains.add( getKeyDomain() );
85 public List<String> getCombinableDomains() {
86 final List<String> domains = new ArrayList<String>( getNumberOfCombinableDomains() );
87 for( final String domain : getCombiningDomains().keySet() ) {
88 domains.add( domain );
94 public SortedMap<String, Integer> getCombinableDomainsIds() {
95 final SortedMap<String, Integer> ids = new TreeMap<String, Integer>();
96 for( final String domain : getCombiningDomains().keySet() ) {
97 final String pd = domain;
98 ids.put( pd, getCombiningDomains().get( pd ) );
104 public StringBuilder getCombiningDomainIdsAsStringBuilder() {
105 final StringBuilder sb = new StringBuilder();
106 for( final Iterator<String> iter = getCombiningDomains().keySet().iterator(); iter.hasNext(); ) {
107 final String key = iter.next();
108 sb.append( key.toString() );
110 final int count = getCombiningDomains().get( key );
113 if ( iter.hasNext() ) {
120 protected TreeMap<String, Integer> getCombiningDomains() {
121 return _combining_domains;
125 public String getKeyDomain() {
130 public int getKeyDomainCount() {
131 return _key_domain_count;
135 public int getKeyDomainProteinsCount() {
136 return getKeyDomainProteins().size();
140 public int getNumberOfCombinableDomains() {
141 return _combining_domains.size();
145 public int getNumberOfProteinsExhibitingCombination( final String protein_domain ) {
146 if ( getCombiningDomains().containsKey( protein_domain ) ) {
147 return getCombiningDomains().get( protein_domain );
155 public Species getSpecies() {
160 public boolean isCombinable( final String protein_domain ) {
161 return getCombiningDomains().containsKey( protein_domain );
165 public void setKeyDomainCount( final int key_domain_count ) {
166 _key_domain_count = key_domain_count;
170 public List<BinaryDomainCombination> toBinaryDomainCombinations() {
171 final List<BinaryDomainCombination> binary_combinations = new ArrayList<BinaryDomainCombination>( getNumberOfCombinableDomains() );
172 for( final String domain : getCombiningDomains().keySet() ) {
173 binary_combinations.add( new BasicBinaryDomainCombination( getKeyDomain(), domain ) );
175 return binary_combinations;
179 public String toString() {
180 final StringBuilder sb = new StringBuilder();
181 sb.append( getKeyDomain() );
183 sb.append( getKeyDomainCount() );
185 sb.append( getKeyDomainProteinsCount() );
187 sb.append( getNumberOfCombinableDomains() );
189 sb.append( getCombiningDomainIdsAsStringBuilder() );
190 return sb.toString();
194 public Set<String> getKeyDomainProteins() {
195 return _proteins_with_key_domain;