annotate egglib/egglib-2.1.5/include/egglib-cpp/SitePolymorphism.hpp @ 15:31c23d943c29 draft default tip

Uploaded
author dereeper
date Tue, 08 Jan 2019 08:47:56 -0500
parents 420b57c3c185
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
1 /*
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
2 Copyright 2008-2009 Stéphane De Mita, Mathieu Siol
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
3
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
4 This file is part of the EggLib library.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
5
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
6 EggLib is free software: you can redistribute it and/or modify
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
8 the Free Software Foundation, either version 3 of the License, or
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
9 (at your option) any later version.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
10
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
11 EggLib is distributed in the hope that it will be useful,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
14 GNU General Public License for more details.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
15
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
17 along with EggLib. If not, see <http://www.gnu.org/licenses/>.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
18 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
19
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
20
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
21 #ifndef EGGLIB_SITEPOLYMORPHISM_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
22 #define EGGLIB_SITEPOLYMORPHISM_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
23
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
24
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
25
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
26 namespace egglib {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
27
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
28
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
29 /** \brief Implements diversity analysis at the site level
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
30 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
31 * \ingroup polymorphism
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
32 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
33 * Data are loaded along with a population index. It is necessary to
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
34 * set the number of populations prior to use.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
35 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
36 * Outgroup sequence must be loaded separetedly. There can be any
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
37 * number of outgroups, but they must be all consistent otherwise the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
38 * site will be considered as not orientable.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
39 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
40 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
41 class SitePolymorphism {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
42
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
43 public:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
44
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
45 /** \brief Builds an object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
46 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
47 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
48 SitePolymorphism();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
49
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
50
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
51 /** \brief Builds an object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
52 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
53 * \param npop number of populations
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
54 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
55 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
56 SitePolymorphism(unsigned int npop);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
57
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
58
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
59 /** \brief Destroys an object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
60 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
61 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
62 virtual ~SitePolymorphism();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
63
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
64
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
65 /** \brief Copy constructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
66 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
67 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
68 SitePolymorphism(const SitePolymorphism& source);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
69
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
70
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
71 /** \brief Assignment operator
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
72 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
73 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
74 SitePolymorphism& operator=(const SitePolymorphism& source);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
75
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
76
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
77 /** \brief Sets the number of populations
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
78 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
79 * NOTE THAT all previous data is lost.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
80 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
81 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
82 void numberOfPopulations(unsigned int npop);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
83
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
84
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
85 /** \brief Adds a character
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
86 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
87 * \param populationIndex the index of the population from
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
88 * which is sampled this character (do not use "population
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
89 * label").
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
90 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
91 * \param character the character value (it is assumed it
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
92 * represents a valid character.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
93 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
94 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
95 void load(unsigned int populationIndex, char character);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
96
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
97
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
98 /** \brief Loads outgroup state
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
99 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
100 * There can be any number of outgroup states. Only
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
101 * characters that are considered as valid (whatever the list
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
102 * is) should be loaded.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
103 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
104 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
105 void outgroup(char state);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
106
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
107
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
108 /** \brief Number of different alleles
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
109 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
110 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
111 unsigned int numberOfAlleles() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
112
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
113
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
114 /** \brief Gets an allele (unsecure)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
115 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
116 * Assumes that the index provided lies in the valid range
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
117 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
118 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
119 char allele(unsigned int index) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
120
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
121
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
122 /** \brief Gets a frequency (unsecure)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
123 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
124 * The sum of of frequencies of the allele over populations
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
125 * is computed. Not out-of-bounds check is performed.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
126 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
127 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
128 unsigned int alleleFrequency(unsigned int alleleIndex) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
129
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
130
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
131 /** \brief Gets the frequency of an allele in one pop (unsecure)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
132 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
133 * The frequency of the allele in the given population is
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
134 * returned. Not out-of-bounds check is performed.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
135 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
136 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
137 unsigned int alleleFrequency(unsigned int popIndex, unsigned int alleleIndex) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
138
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
139
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
140 /** \brief Sums the frequency of derived allele(s)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
141 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
142 * This method assumes that the site is orientable. It will
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
143 * use as outgroup the first outgroup character entered,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
144 * assuming at least one was entered and that all (if more
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
145 * than one) were identical.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
146 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
147 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
148 unsigned int derivedAlleleFrequency() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
149
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
150
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
151 /** \brief Number of sequences that were analyzed
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
152 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
153 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
154 unsigned int ns() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
155
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
156
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
157 /** \brief Gets the number of analyzed sequences for a population
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
158 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
159 * No out-of-bound check is performed
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
160 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
161 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
162 unsigned int ns(unsigned int popIndex) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
163
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
164
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
165 /** \brief Checks if the site can be oriented
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
166 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
167 * Returns true if at least one outgroup datum has been
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
168 * loaded, if all outgroup data are identical (regardless of
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
169 * their value) and if the outgroup allele is one of the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
170 * allele in the sample.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
171 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
172 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
173 bool isOrientable() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
174
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
175 bool isPolymorphic(unsigned int popIndex) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
176 bool hasSpecificAllele(unsigned int popIndex, bool restrictToDerived) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
177 bool haveFixedDifference(unsigned int pop1, unsigned int pop2) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
178 bool haveCommonAllele(unsigned int pop1, unsigned int pop2) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
179 bool haveSharedAllele(unsigned int pop1, unsigned int pop2) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
180
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
181
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
182
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
183
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
184 protected:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
185
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
186 // helpers
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
187 void init();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
188 void clear();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
189 void copy(const SitePolymorphism& site);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
190
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
191
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
192 // data
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
193 unsigned int m_numberOfPopulations;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
194 unsigned int m_numberOfStates;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
195 char * m_states;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
196 unsigned int ** m_frequencies;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
197 unsigned int m_numberOfOutgroups;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
198 char * m_outgroups;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
199 unsigned int m_ns;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
200 unsigned int * m_pop_ns;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
201
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
202 bool m_cache_orientable;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
203
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
204 };
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
205 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
206
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
207 #endif