JAL-2844 work started on moving the graphical partitioning code to Aptx
[jalview.git] / forester / java / src / org / forester / surfacing / CountsBasedPairwiseDomainSimilarity.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: https://sites.google.com/site/cmzmasek/home/software/forester
27
28 package org.forester.surfacing;
29
30 public class CountsBasedPairwiseDomainSimilarity implements PairwiseDomainSimilarity {
31
32     private final short _copy_number_difference;
33     private final short _counts_sum;
34
35     /**
36      * counts_difference: (counts for domain 1) minus (counts for domain 2).
37      *
38      *
39      * @param counts_difference value of domain_1 minus value of domain_2
40      * @param counts_sum
41      */
42     public CountsBasedPairwiseDomainSimilarity( final short counts_difference, final short counts_sum ) {
43         if ( counts_sum <= 0 ) {
44             throw new IllegalArgumentException( "attempt to use copy sum of less than or equal to 0: " + counts_sum );
45         }
46         if ( Math.abs( counts_difference ) > counts_sum ) {
47             throw new IllegalArgumentException( "attempt to use absolute copy number difference larger than copy number sum" );
48         }
49         _copy_number_difference = counts_difference;
50         _counts_sum = counts_sum;
51     }
52
53     /**
54      * Returns (counts for domain 1) minus (counts for domain 2).
55      *
56      */
57     @Override
58     public int getDifferenceInCounts() {
59         return _copy_number_difference;
60     }
61
62     @Override
63     public double getSimilarityScore() {
64         return ( 1.0 - ( ( double ) Math.abs( _copy_number_difference ) / _counts_sum ) );
65     }
66 }