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: www.phylosoft.org/forester
27 package org.forester.surfacing;
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.SortedMap;
33 import java.util.TreeMap;
35 import org.forester.util.DescriptiveStatistics;
37 public class BasicCombinableDomains implements CombinableDomains {
39 final private DomainId _key_domain;
40 private int _key_domain_count;
41 private int _key_domain_proteins_count;
42 final private Species _species;
43 final private TreeMap<DomainId, Integer> _combining_domains;
44 private DescriptiveStatistics _key_domain_confidence_statistics;
46 public BasicCombinableDomains( final DomainId key_domain, final Species species ) {
47 _key_domain = key_domain;
49 _combining_domains = new TreeMap<DomainId, Integer>();
54 public void addCombinableDomain( final DomainId protein_domain ) {
55 if ( getCombiningDomains().containsKey( protein_domain ) ) {
56 getCombiningDomains().put( protein_domain, getCombiningDomains().get( protein_domain ) + 1 );
59 getCombiningDomains().put( protein_domain, 1 );
64 public List<DomainId> getAllDomains() {
65 final List<DomainId> domains = getCombinableDomains();
66 if ( !domains.contains( getKeyDomain() ) ) {
67 domains.add( getKeyDomain() );
73 public List<DomainId> getCombinableDomains() {
74 final List<DomainId> domains = new ArrayList<DomainId>( getNumberOfCombinableDomains() );
75 for( final DomainId domain : getCombiningDomains().keySet() ) {
76 domains.add( domain );
82 public SortedMap<DomainId, Integer> getCombinableDomainsIds() {
83 final SortedMap<DomainId, Integer> ids = new TreeMap<DomainId, Integer>();
84 for( final DomainId domain : getCombiningDomains().keySet() ) {
85 final DomainId pd = domain;
86 ids.put( pd, getCombiningDomains().get( pd ) );
92 public StringBuilder getCombiningDomainIdsAsStringBuilder() {
93 final StringBuilder sb = new StringBuilder();
94 for( final Iterator<DomainId> iter = getCombiningDomains().keySet().iterator(); iter.hasNext(); ) {
95 final DomainId key = iter.next();
96 sb.append( key.toString() );
98 final int count = getCombiningDomains().get( key );
101 if ( iter.hasNext() ) {
108 protected TreeMap<DomainId, Integer> getCombiningDomains() {
109 return _combining_domains;
113 public DomainId getKeyDomain() {
118 public DescriptiveStatistics getKeyDomainConfidenceDescriptiveStatistics() {
119 return _key_domain_confidence_statistics;
123 public int getKeyDomainCount() {
124 return _key_domain_count;
128 public int getKeyDomainProteinsCount() {
129 return _key_domain_proteins_count;
133 public int getNumberOfCombinableDomains() {
134 return _combining_domains.size();
138 public int getNumberOfProteinsExhibitingCombination( final DomainId protein_domain ) {
139 if ( getCombiningDomains().containsKey( protein_domain ) ) {
140 return getCombiningDomains().get( protein_domain );
148 public Species getSpecies() {
152 private void init() {
153 _key_domain_count = 0;
154 _key_domain_proteins_count = 0;
155 _key_domain_confidence_statistics = null;
159 public boolean isCombinable( final DomainId protein_domain ) {
160 return getCombiningDomains().containsKey( protein_domain );
164 public void setKeyDomainConfidenceDescriptiveStatistics( final DescriptiveStatistics key_domain_confidence_statistics ) {
165 _key_domain_confidence_statistics = key_domain_confidence_statistics;
169 public void setKeyDomainCount( final int key_domain_count ) {
170 _key_domain_count = key_domain_count;
174 public void setKeyDomainProteinsCount( final int key_domain_proteins_count ) {
175 _key_domain_proteins_count = key_domain_proteins_count;
179 public List<BinaryDomainCombination> toBinaryDomainCombinations() {
180 final List<BinaryDomainCombination> binary_combinations = new ArrayList<BinaryDomainCombination>( getNumberOfCombinableDomains() );
181 for( final DomainId domain : getCombiningDomains().keySet() ) {
182 binary_combinations.add( new BasicBinaryDomainCombination( getKeyDomain(), domain ) );
184 return binary_combinations;
188 public String toString() {
189 final StringBuilder sb = new StringBuilder();
190 sb.append( getKeyDomain() );
192 sb.append( getKeyDomainCount() );
194 sb.append( getKeyDomainProteinsCount() );
196 sb.append( getNumberOfCombinableDomains() );
198 sb.append( getCombiningDomainIdsAsStringBuilder() );
199 return sb.toString();