initial commit
[jalview.git] / forester / java / src / org / forester / pccx / ExternalNodeBasedCoverage.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 // 
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 // 
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.pccx;
27
28 import org.forester.util.DescriptiveStatistics;
29 import org.forester.util.ForesterUtil;
30
31 /*
32  * @author Christian M. Zmasek
33  */
34 public class ExternalNodeBasedCoverage implements Coverage {
35
36     private final double _av_normalized_score;
37     private final double _av_raw_score;
38     private final int    _n;
39     private final double _sd;
40     private final double _max;
41     private final double _min;
42
43     public ExternalNodeBasedCoverage( final DescriptiveStatistics stats,
44                                       final double average_raw_score,
45                                       final CoverageCalculationOptions options ) {
46         _av_normalized_score = stats.arithmeticMean();
47         _av_raw_score = average_raw_score;
48         _n = stats.getN();
49         if ( _n > 1 ) {
50             _sd = stats.sampleStandardDeviation();
51         }
52         else {
53             _sd = 0.0;
54         }
55         _max = stats.getMax();
56         _min = stats.getMin();
57     }
58
59     public String asString() {
60         final StringBuffer sb = new StringBuffer();
61         if ( getN() == 1 ) {
62             sb.append( "Normalized score: " + getScore() + ForesterUtil.getLineSeparator() );
63             sb.append( "Raw score       : " + getAvarageRawScore() );
64         }
65         else {
66             sb.append( "Avarage normalized score: " + getScore() + " [sd=" + getSD() + " min=" + getMin() + " max="
67                     + getMax() + " n=" + getN() + "]" + ForesterUtil.getLineSeparator() );
68             sb.append( "Avarage raw score       : " + getAvarageRawScore() );
69         }
70         return sb.toString();
71     }
72
73     public double getAvarageNormalizedScore() {
74         return _av_normalized_score;
75     }
76
77     public double getAvarageRawScore() {
78         return _av_raw_score;
79     }
80
81     public double getMax() {
82         return _max;
83     }
84
85     public double getMin() {
86         return _min;
87     }
88
89     public int getN() {
90         return _n;
91     }
92
93     public double getScore() {
94         return getAvarageNormalizedScore();
95     }
96
97     public double getSD() {
98         return _sd;
99     }
100 }