3b0c6dcf0d6164c2df9140a0413fe657a71d346f
[jalview.git] / forester / java / src / org / forester / surfacing / CombinationsBasedPairwiseDomainSimilarity.java
1 // $Id:
2 // cmzmasek Exp $
3 //
4 // FORESTER -- software libraries and applications
5 // for evolutionary biology research and applications.
6 //
7 // Copyright (C) 2008-2009 Christian M. Zmasek
8 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // All rights reserved
10 //
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.
15 //
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.
20 //
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
24 //
25 // Contact: phylosoft @ gmail . com
26 // WWW: www.phylosoft.org/forester
27
28 package org.forester.surfacing;
29
30 public class CombinationsBasedPairwiseDomainSimilarity implements PairwiseDomainSimilarity {
31
32     private final int    _same_domains;
33     private final int    _different_domains;
34     private final int    _difference_in_counts;
35     private final double _score;
36
37     public CombinationsBasedPairwiseDomainSimilarity( final int same_domains,
38                                                       final int different_domains,
39                                                       final int difference_in_counts ) {
40         if ( ( same_domains < 0 ) || ( different_domains < 0 ) ) {
41             throw new IllegalArgumentException( "attempt to use domain counts less than 0" );
42         }
43         _difference_in_counts = difference_in_counts;
44         _same_domains = same_domains;
45         _different_domains = different_domains;
46         if ( _different_domains == 0 ) {
47             _score = 1.0;
48         }
49         else {
50             _score = ( double ) _same_domains / ( _different_domains + _same_domains );
51         }
52     }
53
54     @Override
55     public int getDifferenceInCounts() {
56         return _difference_in_counts;
57     }
58
59     public int getNumberOfDifferentDomains() {
60         return _different_domains;
61     }
62
63     public int getNumberOfSameDomains() {
64         return _same_domains;
65     }
66
67     @Override
68     public double getSimilarityScore() {
69         return _score;
70     }
71 }