annotate egglib/egglib-2.1.5/include/egglib-cpp/DataMatrix.hpp @ 3:345f88a8f483 draft

Uploaded
author dereeper
date Fri, 10 Jul 2015 10:38:43 -0400
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 2009-2010 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 #ifndef EGGLIB_DATAMATRIX_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
21 #define EGGLIB_DATAMATRIX_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
22
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
23
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
24 #include "CharMatrix.hpp"
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
25
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
26
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
27 namespace egglib {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
28
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
29 /** \brief Data table
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
30 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
31 * \ingroup core
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
32 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
33 * Holds a data matrix representing genotype data from simulations.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
34 * Data are stored as integers, to each site is associated a
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
35 * position, and to each sequence is associated a group index (any
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
36 * integer labelling, for example, a subpopulation). Supports the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
37 * CharMatrix interface with the condition that allele genotype
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
38 * datum is >=0 and <=9.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
39 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
40 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
41 class DataMatrix : public CharMatrix {
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 Default constructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
46 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
47 * The data table default dimensions are {0,0}
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
48 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
49 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
50 DataMatrix();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
51
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
52
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
53 /** \brief Standard constructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
54 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
55 * The data table dimensions must be given.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
56 * Each cell default default is 0, and each site position is 0..
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
57 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
58 * \param numberOfSequences number of lines of the data table.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
59 * \param numberOfSites number of columns of the data table.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
60 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
61 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
62 DataMatrix(unsigned int numberOfSequences, unsigned int numberOfSites);
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 DataMatrix(const DataMatrix&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
69
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
70
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
71 /** \brief Copy constructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
72 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
73 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
74 DataMatrix(const CharMatrix&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
75
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
76
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
77 /** \brief Assignment operator
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
78 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
79 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
80 virtual DataMatrix& operator=(const DataMatrix&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
81
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
82
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
83 /** \brief Assignment operator
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
84 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
85 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
86 virtual DataMatrix& operator=(const CharMatrix&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
87
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
88
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
89 /** \brief Destructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
90 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
91 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
92 virtual ~DataMatrix();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
93
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
94
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
95 /** \brief Gets number of sites
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
96 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
97 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
98 unsigned int numberOfSites() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
99
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
100
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
101 /** \brief Gets number of sequences
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
102 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
103 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
104 unsigned int numberOfSequences() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
105
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
106
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
107 /** \brief Sets a value of the data table
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
108 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
109 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
110 void set(unsigned int sequence, unsigned int site, int value);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
111
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
112
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
113 /** \brief Gets a value from the data table
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
114 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
115 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
116 int get(unsigned int sequence, unsigned int site) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
117
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
118
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
119 /** \brief Faster and unsecure version of get
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
120 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
121 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
122 inline int fget(unsigned int sequence, unsigned int site) const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
123 return dataMatrix[sequence][site];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
124 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
125
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
126
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
127 /** \brief Sets the position of a site
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
128 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
129 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
130 void sitePosition(unsigned int site, double value);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
131
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
132
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
133 /** \brief Gets the position of a site
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
134 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
135 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
136 double sitePosition(unsigned int site) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
137
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
138
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
139 /** \brief Sets the group label of a sequence
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
140 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
141 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
142 void populationLabel(unsigned int sequence, unsigned int value);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
143
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
144
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
145 /** \brief Gets the group label of a sequence
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
146 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
147 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
148 unsigned int populationLabel(unsigned int sequence) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
149
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
150
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
151 /** \brief Removes all information from the object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
152 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
153 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
154 void clear();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
155
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
156
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
157 /** \brief Resizes the data matrix
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
158 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
159 * \param newNumberOfSequences number of sequences (rows)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
160 * \param newNumberOfSites number of sites (columns)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
161 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
162 * If new values are larger, data already set is left unchanged.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
163 * New data are set to zero.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
164 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
165 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
166 void resize(unsigned int newNumberOfSequences, unsigned int newNumberOfSites);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
167
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
168
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
169 /** \brief Shifts allele value
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
170 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
171 * \param minimum the minimum allele value.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
172 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
173 * Shifts all alleles at all sites to ensure that alleles alleles
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
174 * are equal to or larger than minimum. The shifting is specific
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
175 * to each site.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
176 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
177 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
178 void shift(int minimum);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
179
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
180 /** \brief Gets the character at a given position
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
181 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
182 * An exception is generated if the allele value at this
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
183 * position is not >=0 and <=9. Not out-of-bound check is
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
184 * performed.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
185 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
186 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
187 char character(unsigned int sequence, unsigned int site) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
188
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
189
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
190
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
191 private:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
192
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
193 // Initializes to default values (for empty object)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
194 void init();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
195
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
196 // Copies from a source object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
197 virtual void copy(const CharMatrix&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
198
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
199 // Copies from a source object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
200 virtual void copy(const DataMatrix&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
201
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
202 // Number of lines of the data matrix
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
203 unsigned int _numberOfSequences;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
204
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
205 // Number of columns of the data matrix
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
206 unsigned int _numberOfSites;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
207
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
208 // Data matrix
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
209 int **dataMatrix;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
210
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
211 // Vector of site positions
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
212 double *positions;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
213
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
214 // Vector of group indices
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
215 unsigned int *groups;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
216 };
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
217 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
218
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
219 #endif