JAL-2805 made needed color set methods public
[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: https://sites.google.com/site/cmzmasek/home/software/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     @Override
60     public String asString() {
61         final StringBuffer sb = new StringBuffer();
62         if ( getN() == 1 ) {
63             sb.append( "Normalized score: " + getScore() + ForesterUtil.getLineSeparator() );
64             sb.append( "Raw score       : " + getAvarageRawScore() );
65         }
66         else {
67             sb.append( "Avarage normalized score: " + getScore() + " [sd=" + getSD() + " min=" + getMin() + " max="
68                     + getMax() + " n=" + getN() + "]" + ForesterUtil.getLineSeparator() );
69             sb.append( "Avarage raw score       : " + getAvarageRawScore() );
70         }
71         return sb.toString();
72     }
73
74     public double getAvarageNormalizedScore() {
75         return _av_normalized_score;
76     }
77
78     public double getAvarageRawScore() {
79         return _av_raw_score;
80     }
81
82     public double getMax() {
83         return _max;
84     }
85
86     public double getMin() {
87         return _min;
88     }
89
90     public int getN() {
91         return _n;
92     }
93
94     @Override
95     public double getScore() {
96         return getAvarageNormalizedScore();
97     }
98
99     public double getSD() {
100         return _sd;
101     }
102 }