JAL-2805 made needed color set methods public
[jalview.git] / forester / java / src / org / forester / pccx / BranchCountingBasedScoringMethod.java
1 // $Id:
2 // Exp $
3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
5 //
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
8 // All rights reserved
9 //
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.
14 //
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.
19 //
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
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26
27 package org.forester.pccx;
28
29 import java.util.SortedMap;
30
31 import org.forester.phylogeny.Phylogeny;
32 import org.forester.phylogeny.PhylogenyNode;
33
34 /*
35  * Scoring method according to an idea by Adam Godzik, PhD.
36  *
37  * @author Christian M. Zmasek
38  */
39 public class BranchCountingBasedScoringMethod implements ScoringMethodForExternalNode {
40
41     double calculateScoreContributionPerExternalNode( final PhylogenyNode external_node,
42                                                       final PhylogenyNode current_node ) {
43         double score_contribution = 0.0;
44         if ( current_node == external_node ) {
45             score_contribution = 1.0;
46         }
47         else {
48             score_contribution = 1.0 / ModelingUtils.calculateBranchSum( external_node, current_node );
49         }
50         return score_contribution;
51     }
52
53     @Override
54     public void calculateScoreForExternalNode( final SortedMap<PhylogenyNode, Double> external_node_scores,
55                                                final Phylogeny phylogeny,
56                                                final PhylogenyNode external_node,
57                                                final CoverageCalculationOptions options ) {
58         for( final Object element : external_node_scores.keySet() ) {
59             final PhylogenyNode current_node = ( PhylogenyNode ) element;
60             final double score_contribution = calculateScoreContributionPerExternalNode( external_node, current_node );
61             final double prev_score_contribution = external_node_scores.get( current_node );
62             if ( score_contribution > prev_score_contribution ) {
63                 external_node_scores.put( current_node, score_contribution );
64             }
65         }
66     }
67
68     @Override
69     public String getDesciption() {
70         return "sum of 1/branch-segment-sum";
71     }
72
73     @Override
74     public double getNormalizationFactor( final Phylogeny phylogeny ) {
75         return ( 1.0 / phylogeny.getNumberOfExternalNodes() );
76     }
77 }