in progress...
[jalview.git] / forester / java / src / org / forester / clade_analysis / Result2.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2017 Christian M. Zmasek
6 // Copyright (C) 2017 J. Craig Venter Institute
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: phyloxml @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.clade_analysis;
27
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map.Entry;
31 import java.util.SortedMap;
32 import java.util.TreeMap;
33
34 import org.forester.util.ForesterUtil;
35
36 public final class Result2 {
37
38     private List<Prefix>        _greatest_common_prefix                = new ArrayList<Prefix>();
39     private String             _greatest_common_prefix_up             = "";
40     private String             _greatest_common_prefix_down           = "";
41     private final List<String> _warnings                              = new ArrayList<>();
42     private int                _lec_ext_nodes                         = 0;
43     private int                _p_ext_nodes                           = 0;
44     private String             _greatest_common_clade_subtree_confidence      = "";
45     private String             _greatest_common_clade_subtree_confidence_up   = "";
46     private String             _greatest_common_clade_subtree_confidence_down = "";
47
48     void addWarning( final String warning ) {
49         _warnings.add( warning );
50     }
51
52     void addGreatestCommonPrefix( final String prefix, final double confidence ) {
53         _greatest_common_prefix.add( new Prefix(prefix, confidence) );
54     }
55
56     void setGreatestCommonPrefixUp( final String greatest_common_prefix_up ) {
57         _greatest_common_prefix_up = greatest_common_prefix_up;
58     }
59
60     void setGreatestCommonPrefixDown( final String greatest_common_prefix_down ) {
61         _greatest_common_prefix_down = greatest_common_prefix_down;
62     }
63
64     void setGreatestCommonCladeSubtreeConfidence( final String greatest_common_clade_confidence ) {
65         _greatest_common_clade_subtree_confidence = greatest_common_clade_confidence;
66     }
67
68     void setGreatestCommonCladeUpSubtreeConfidence( final String greatest_common_clade_confidence_up ) {
69         _greatest_common_clade_subtree_confidence_up = greatest_common_clade_confidence_up;
70     }
71
72     void setGreatestCommonCladeDownSubtreeConfidence( final String greatest_common_clade_confidence_down ) {
73         _greatest_common_clade_subtree_confidence_down = greatest_common_clade_confidence_down;
74     }
75
76   //  public String getGreatestCommonPrefix() {
77   //      return _greatest_common_prefix;
78   //  }
79
80     public String getGreatestCommonPrefixUp() {
81         return _greatest_common_prefix_up;
82     }
83
84     public String getGreatestCommonPrefixDown() {
85         return _greatest_common_prefix_down;
86     }
87
88     public String getGreatestCommonCladeSubtreeConfidence() {
89         return _greatest_common_clade_subtree_confidence;
90     }
91
92     public String getGreatestCommonCladeUpSubtreeConfidence() {
93         return _greatest_common_clade_subtree_confidence_up;
94     }
95
96     public String getGreatestCommonCladeDownSubtreeConfidence() {
97         return _greatest_common_clade_subtree_confidence_down;
98     }
99
100     public List<String> getWarnings() {
101         return _warnings;
102     }
103
104     void setLeastEncompassingCladeSize( final int lec_ext_nodes ) {
105         _lec_ext_nodes = lec_ext_nodes;
106     }
107
108     void setTreeSize( final int p_ext_nodes ) {
109         _p_ext_nodes = p_ext_nodes;
110     }
111
112     public int getLeastEncompassingCladeSize() {
113         return _lec_ext_nodes;
114     }
115
116     public int getTreeSize() {
117         return _p_ext_nodes;
118     }
119     
120     public void analyzeGreatestCommonPrefixes(final String separator ) {
121         final SortedMap<String,Double> map = new TreeMap<String,Double>();
122         for( final Prefix prefix : _greatest_common_prefix ) {
123             List<String> prefixes = ForesterUtil.spliIntoPrefixes( prefix.getPrefix(), separator );
124             for( final String p : prefixes ) {
125                 map.put( p, 0.0 );
126             }
127         }
128        // System.out.println( map );
129         for (final String key : map.keySet()) {
130             //System.out.println(key);
131             for( final Prefix prefix : _greatest_common_prefix ) {
132                 if ( prefix.getPrefix().startsWith( key ) ) {
133                     map.put( key, map.get( key ) + prefix.getConfidence()  );
134                 }
135             }
136         }
137         System.out.println( map );
138     }
139     
140     
141 }