~ubuntu-branches/ubuntu/oneiric/libbpp-seq/oneiric

« back to all changes in this revision

Viewing changes to src/Bpp/Seq/SiteTools.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-hnfrd9it0np58l54
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File SiteTools.h
 
3
// Author: Julien Dutheil
 
4
//         Guillaume Deuchst
 
5
// Last modification : Friday August 8 2003
 
6
//
 
7
 
 
8
/*
 
9
   Copyright or © or Copr. CNRS, (November 17, 2004)
 
10
 
 
11
   This software is a computer program whose purpose is to provide classes
 
12
   for sequences analysis.
 
13
 
 
14
   This software is governed by the CeCILL  license under French law and
 
15
   abiding by the rules of distribution of free software.  You can  use,
 
16
   modify and/ or redistribute the software under the terms of the CeCILL
 
17
   license as circulated by CEA, CNRS and INRIA at the following URL
 
18
   "http://www.cecill.info".
 
19
 
 
20
   As a counterpart to the access to the source code and  rights to copy,
 
21
   modify and redistribute granted by the license, users are provided only
 
22
   with a limited warranty  and the software's author,  the holder of the
 
23
   economic rights,  and the successive licensors  have only  limited
 
24
   liability.
 
25
 
 
26
   In this respect, the user's attention is drawn to the risks associated
 
27
   with loading,  using,  modifying and/or developing or reproducing the
 
28
   software by the user in light of its specific status of free software,
 
29
   that may mean  that it is complicated to manipulate,  and  that  also
 
30
   therefore means  that it is reserved for developers  and  experienced
 
31
   professionals having in-depth computer knowledge. Users are therefore
 
32
   encouraged to load and test the software's suitability as regards their
 
33
   requirements in conditions enabling the security of their systems and/or
 
34
   data to be ensured and,  more generally, to use and operate it in the
 
35
   same conditions as regards security.
 
36
 
 
37
   The fact that you are presently reading this means that you have had
 
38
   knowledge of the CeCILL license and that you accept its terms.
 
39
 */
 
40
 
 
41
#ifndef _SITETOOLS_H_
 
42
#define _SITETOOLS_H_
 
43
 
 
44
#include "SymbolListTools.h"
 
45
#include "Site.h"
 
46
#include <Bpp/Exceptions.h>
 
47
 
 
48
// From the STL:
 
49
#include <map>
 
50
 
 
51
namespace bpp
 
52
{
 
53
/**
 
54
 * @brief Utilitary methods dealing with sites.
 
55
 */
 
56
 
 
57
class SiteTools :
 
58
  public SymbolListTools
 
59
{
 
60
public:
 
61
  SiteTools() {}
 
62
  virtual ~SiteTools() {}
 
63
 
 
64
public:
 
65
  /**
 
66
   * @param site A site.
 
67
   * @return True if the site contains one or several gap(s).
 
68
   */
 
69
  static bool hasGap(const Site& site);
 
70
 
 
71
  /**
 
72
   * @param site A site.
 
73
   * @return True if the site contains only gaps.
 
74
   */
 
75
  static bool isGapOnly(const Site& site);
 
76
 
 
77
  /**
 
78
   * @param site A site.
 
79
   * @return True if the site contains only gaps.
 
80
   */
 
81
  static bool isGapOrUnresolvedOnly(const Site& site);
 
82
 
 
83
  /**
 
84
   * @param site A site.
 
85
   * @return True if the site contains one or several unknwn characters.
 
86
   */
 
87
  static bool hasUnknown(const Site& site);
 
88
 
 
89
  /**
 
90
   * @param site A site.
 
91
   * @return True if the site contains a Stop Codon, when the alphabet  is a CodonAlphabet.
 
92
   */
 
93
  static bool hasStopCodon(const Site& site);
 
94
  /**
 
95
   * @param site A site.
 
96
   * @return True if the site contains no gap and no unknown characters.
 
97
   */
 
98
  static bool isComplete(const Site& site);
 
99
 
 
100
  /**
 
101
   * @brief Tell if a site is constant, that is displaying the same state in all sequences that do not present a gap.
 
102
   *
 
103
   * @param site A site.
 
104
   * @param ignoreUnknown If true, positions with unknown positions will be ignored.
 
105
   * Otherwise, a site with one single state + any uncertain state will not be considered as constant.
 
106
   * @return True if the site is made of only one state.
 
107
   * @throw EmptySiteException If the site has size 0.
 
108
   */
 
109
  static bool isConstant(const Site& site, bool ignoreUnknown = false) throw (EmptySiteException);
 
110
 
 
111
  /**
 
112
   * @param site1 The first site.
 
113
   * @param site2 The second site.
 
114
   * @return True if the two states have the same content (and, of course, alphabet).
 
115
   */
 
116
  static bool areSitesIdentical(const Site& site1, const Site& site2);
 
117
 
 
118
  /**
 
119
   * @brief Compute the Shannon entropy index of a site.
 
120
   *
 
121
   * \f[
 
122
   * I = - \sum_x f_x\cdot \ln(f_x)
 
123
   * \f]
 
124
   * where \f$f_x\f$ is the frequency of state \f$x\f$.
 
125
   *
 
126
   * @author J. Dutheil
 
127
   * @param site A site.
 
128
   * @param resolveUnknowns Tell is unknown characters must be resolved.
 
129
   * @return The Shannon entropy index of this site.
 
130
   * @throw EmptySiteException If the site has size 0.
 
131
   */
 
132
  static double variabilityShannon(const Site& site, bool resolveUnknowns) throw (EmptySiteException);
 
133
 
 
134
  /**
 
135
   * @brief Compute the factorial diversity index of a site.
 
136
   *
 
137
   * \f[
 
138
   * F = \frac{log\left(\left(\sum_x p_x\right)!\right)}{\sum_x \log(p_x)!}
 
139
   * \f]
 
140
   * where \f$p_x\f$ is the number of times state \f$x\f$ is observed in the site.
 
141
   *
 
142
   * @author J. Dutheil
 
143
   * @param site A site.
 
144
   * @return The factorial diversity index of this site.
 
145
   * @throw EmptySiteException If the site has size 0.
 
146
   */
 
147
  static double variabilityFactorial(const Site& site) throw (EmptySiteException);
 
148
 
 
149
  /**
 
150
   * @brief Compute the mutual information between two sites.
 
151
   *
 
152
   * \f[
 
153
   * MI = \sum_x \sum_y p_{x,y}\ln\left(\frac{p_{x,y}}{p_x \cdot p_y}\right)
 
154
   * \f]
 
155
   * where \f$p_x\f$ and \f$p_y\f$ are the frequencies of states \f$x\f$ and \f$y\f$, and
 
156
   * \f$p_{x,y}\f$ is the frequency of the pair \f$(x,y)\f$.
 
157
   *
 
158
   * @author J. Dutheil
 
159
   * @param site1 First site
 
160
   * @param site2 Second site
 
161
   * @param resolveUnknowns Tell is unknown characters must be resolved.
 
162
   * @return The mutual information for the pair of sites.
 
163
   * @throw DimensionException If the sites do not have the same length.
 
164
   * @throw EmptySiteException If the sites have size 0.
 
165
   */
 
166
  static double mutualInformation(const Site& site1, const Site& site2, bool resolveUnknowns) throw (DimensionException,EmptySiteException);
 
167
 
 
168
  /**
 
169
   * @brief Compute the entropy of a site. This is an alias of method variabilityShannon.
 
170
   *
 
171
   * \f[
 
172
   * I = - \sum_x f_x\cdot \ln(f_x)
 
173
   * \f]
 
174
   * where \f$f_x\f$ is the frequency of state \f$x\f$.
 
175
   *
 
176
   * @author J. Dutheil
 
177
   * @param site A site.
 
178
   * @param resolveUnknowns Tell is unknown characters must be resolved.
 
179
   * @return The Shannon entropy index of this site.
 
180
   * @throw EmptySiteException If the site has size 0.
 
181
   */
 
182
  static double entropy(const Site& site, bool resolveUnknowns) throw (EmptySiteException) {
 
183
    return variabilityShannon(site, resolveUnknowns); 
 
184
  }
 
185
 
 
186
 
 
187
  /**
 
188
   * @brief Compute the joint entropy between two sites.
 
189
   *
 
190
   * \f[
 
191
   * H_{i,j} = - \sum_x \sum_y p_{x,y}\ln\left(p_{x,y}\right)
 
192
   * \f]
 
193
   * where \f$p_{x,y}\f$ is the frequency of the pair \f$(x,y)\f$.
 
194
   *
 
195
   * @author J. Dutheil
 
196
   * @param site1 First site
 
197
   * @param site2 Second site
 
198
   * @param resolveUnknowns Tell is unknown characters must be resolved.
 
199
   * @return The mutual information for the pair of sites.
 
200
   * @throw DimensionException If the sites do not have the same length.
 
201
   * @throw EmptySiteException If the sites have size 0.
 
202
   */
 
203
  static double jointEntropy(const Site& site1, const Site& site2, bool resolveUnknowns) throw (DimensionException,EmptySiteException);
 
204
 
 
205
  /**
 
206
   * @brief Compute the heterozygosity index of a site.
 
207
   *
 
208
   * \f[
 
209
   * H = 1 - \sum_x f_x^2
 
210
   * \f]
 
211
   * where \f$f_x\f$ is the frequency of state \f$x\f$.
 
212
   *
 
213
   * @param site A site.
 
214
   * @return The heterozygosity index of this site.
 
215
   * @throw EmptySiteException If the site has size 0.
 
216
   */
 
217
  static double heterozygosity(const Site& site) throw (EmptySiteException);
 
218
 
 
219
  /**
 
220
   * @brief Give the number of distinct characters at a site.
 
221
   *
 
222
   * @param site a Site
 
223
   * @return The number of distinct characters in the given site.
 
224
   */
 
225
  static unsigned int getNumberOfDistinctCharacters(const Site& site) throw (EmptySiteException);
 
226
 
 
227
  /**
 
228
   * @brief Tell if a site has singletons
 
229
   *
 
230
   *
 
231
   * @param site a Site.
 
232
   * @return True if the site has singletons.
 
233
   */
 
234
  static bool hasSingleton(const Site& site) throw (EmptySiteException);
 
235
 
 
236
  /**
 
237
   * @brief Tell if a site is a parsimony informative site.
 
238
   *
 
239
   * At least two distinct characters must be present.
 
240
   *
 
241
   * @param site a Site.
 
242
   * @return True if the site is parsimony informative.
 
243
   */
 
244
  static bool isParsimonyInformativeSite(const Site& site) throw (EmptySiteException);
 
245
 
 
246
 
 
247
  /**
 
248
   * @brief Tell if a site has more than 2 distinct characters
 
249
   *
 
250
   * @param site a Site.
 
251
   * @return True if the site has more than 2 distinct characters
 
252
   */
 
253
  static bool isTriplet(const Site& site) throw (EmptySiteException);
 
254
};
 
255
} // end of namespace bpp.
 
256
 
 
257
#endif  // _SITETOOLS_H_
 
258