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.Iterator;
31 import java.util.List;
32 import java.util.SortedMap;
33 import java.util.TreeMap;
35 import org.forester.protein.BinaryDomainCombination;
36 import org.forester.protein.DomainId;
37 import org.forester.species.Species;
38 import org.forester.util.DescriptiveStatistics;
40 public class BasicCombinableDomains implements CombinableDomains {
42 final private DomainId _key_domain;
43 private int _key_domain_count;
44 private int _key_domain_proteins_count;
45 final private Species _species;
46 final private TreeMap<DomainId, Integer> _combining_domains;
47 private DescriptiveStatistics _key_domain_confidence_statistics;
49 public BasicCombinableDomains( final DomainId key_domain, final Species species ) {
50 _key_domain = key_domain;
52 _combining_domains = new TreeMap<DomainId, Integer>();
57 public void addCombinableDomain( final DomainId protein_domain ) {
58 if ( getCombiningDomains().containsKey( protein_domain ) ) {
59 getCombiningDomains().put( protein_domain, getCombiningDomains().get( protein_domain ) + 1 );
62 getCombiningDomains().put( protein_domain, 1 );
67 public List<DomainId> getAllDomains() {
68 final List<DomainId> domains = getCombinableDomains();
69 if ( !domains.contains( getKeyDomain() ) ) {
70 domains.add( getKeyDomain() );
76 public List<DomainId> getCombinableDomains() {
77 final List<DomainId> domains = new ArrayList<DomainId>( getNumberOfCombinableDomains() );
78 for( final DomainId domain : getCombiningDomains().keySet() ) {
79 domains.add( domain );
85 public SortedMap<DomainId, Integer> getCombinableDomainsIds() {
86 final SortedMap<DomainId, Integer> ids = new TreeMap<DomainId, Integer>();
87 for( final DomainId domain : getCombiningDomains().keySet() ) {
88 final DomainId pd = domain;
89 ids.put( pd, getCombiningDomains().get( pd ) );
95 public StringBuilder getCombiningDomainIdsAsStringBuilder() {
96 final StringBuilder sb = new StringBuilder();
97 for( final Iterator<DomainId> iter = getCombiningDomains().keySet().iterator(); iter.hasNext(); ) {
98 final DomainId key = iter.next();
99 sb.append( key.toString() );
101 final int count = getCombiningDomains().get( key );
104 if ( iter.hasNext() ) {
111 protected TreeMap<DomainId, Integer> getCombiningDomains() {
112 return _combining_domains;
116 public DomainId getKeyDomain() {
121 public DescriptiveStatistics getKeyDomainConfidenceDescriptiveStatistics() {
122 return _key_domain_confidence_statistics;
126 public int getKeyDomainCount() {
127 return _key_domain_count;
131 public int getKeyDomainProteinsCount() {
132 return _key_domain_proteins_count;
136 public int getNumberOfCombinableDomains() {
137 return _combining_domains.size();
141 public int getNumberOfProteinsExhibitingCombination( final DomainId protein_domain ) {
142 if ( getCombiningDomains().containsKey( protein_domain ) ) {
143 return getCombiningDomains().get( protein_domain );
151 public Species getSpecies() {
155 private void init() {
156 _key_domain_count = 0;
157 _key_domain_proteins_count = 0;
158 _key_domain_confidence_statistics = null;
162 public boolean isCombinable( final DomainId protein_domain ) {
163 return getCombiningDomains().containsKey( protein_domain );
167 public void setKeyDomainConfidenceDescriptiveStatistics( final DescriptiveStatistics key_domain_confidence_statistics ) {
168 _key_domain_confidence_statistics = key_domain_confidence_statistics;
172 public void setKeyDomainCount( final int key_domain_count ) {
173 _key_domain_count = key_domain_count;
177 public void setKeyDomainProteinsCount( final int key_domain_proteins_count ) {
178 _key_domain_proteins_count = key_domain_proteins_count;
182 public List<BinaryDomainCombination> toBinaryDomainCombinations() {
183 final List<BinaryDomainCombination> binary_combinations = new ArrayList<BinaryDomainCombination>( getNumberOfCombinableDomains() );
184 for( final DomainId domain : getCombiningDomains().keySet() ) {
185 binary_combinations.add( new BasicBinaryDomainCombination( getKeyDomain(), domain ) );
187 return binary_combinations;
191 public String toString() {
192 final StringBuilder sb = new StringBuilder();
193 sb.append( getKeyDomain() );
195 sb.append( getKeyDomainCount() );
197 sb.append( getKeyDomainProteinsCount() );
199 sb.append( getNumberOfCombinableDomains() );
201 sb.append( getCombiningDomainIdsAsStringBuilder() );
202 return sb.toString();