Mercurial > repos > dereeper > sniplay
comparison egglib/egglib-2.1.5/include/egglib-cpp/DataMatrix.hpp @ 1:420b57c3c185 draft
Uploaded
| author | dereeper |
|---|---|
| date | Fri, 10 Jul 2015 04:39:30 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:3e19d0dfcf3e | 1:420b57c3c185 |
|---|---|
| 1 /* | |
| 2 Copyright 2009-2010 Stéphane De Mita, Mathieu Siol | |
| 3 | |
| 4 This file is part of the EggLib library. | |
| 5 | |
| 6 EggLib is free software: you can redistribute it and/or modify | |
| 7 it under the terms of the GNU General Public License as published by | |
| 8 the Free Software Foundation, either version 3 of the License, or | |
| 9 (at your option) any later version. | |
| 10 | |
| 11 EggLib is distributed in the hope that it will be useful, | |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 GNU General Public License for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with EggLib. If not, see <http://www.gnu.org/licenses/>. | |
| 18 */ | |
| 19 | |
| 20 #ifndef EGGLIB_DATAMATRIX_HPP | |
| 21 #define EGGLIB_DATAMATRIX_HPP | |
| 22 | |
| 23 | |
| 24 #include "CharMatrix.hpp" | |
| 25 | |
| 26 | |
| 27 namespace egglib { | |
| 28 | |
| 29 /** \brief Data table | |
| 30 * | |
| 31 * \ingroup core | |
| 32 * | |
| 33 * Holds a data matrix representing genotype data from simulations. | |
| 34 * Data are stored as integers, to each site is associated a | |
| 35 * position, and to each sequence is associated a group index (any | |
| 36 * integer labelling, for example, a subpopulation). Supports the | |
| 37 * CharMatrix interface with the condition that allele genotype | |
| 38 * datum is >=0 and <=9. | |
| 39 * | |
| 40 */ | |
| 41 class DataMatrix : public CharMatrix { | |
| 42 | |
| 43 public: | |
| 44 | |
| 45 /** \brief Default constructor | |
| 46 * | |
| 47 * The data table default dimensions are {0,0} | |
| 48 * | |
| 49 */ | |
| 50 DataMatrix(); | |
| 51 | |
| 52 | |
| 53 /** \brief Standard constructor | |
| 54 * | |
| 55 * The data table dimensions must be given. | |
| 56 * Each cell default default is 0, and each site position is 0.. | |
| 57 * | |
| 58 * \param numberOfSequences number of lines of the data table. | |
| 59 * \param numberOfSites number of columns of the data table. | |
| 60 * | |
| 61 */ | |
| 62 DataMatrix(unsigned int numberOfSequences, unsigned int numberOfSites); | |
| 63 | |
| 64 | |
| 65 /** \brief Copy constructor | |
| 66 * | |
| 67 */ | |
| 68 DataMatrix(const DataMatrix&); | |
| 69 | |
| 70 | |
| 71 /** \brief Copy constructor | |
| 72 * | |
| 73 */ | |
| 74 DataMatrix(const CharMatrix&); | |
| 75 | |
| 76 | |
| 77 /** \brief Assignment operator | |
| 78 * | |
| 79 */ | |
| 80 virtual DataMatrix& operator=(const DataMatrix&); | |
| 81 | |
| 82 | |
| 83 /** \brief Assignment operator | |
| 84 * | |
| 85 */ | |
| 86 virtual DataMatrix& operator=(const CharMatrix&); | |
| 87 | |
| 88 | |
| 89 /** \brief Destructor | |
| 90 * | |
| 91 */ | |
| 92 virtual ~DataMatrix(); | |
| 93 | |
| 94 | |
| 95 /** \brief Gets number of sites | |
| 96 * | |
| 97 */ | |
| 98 unsigned int numberOfSites() const; | |
| 99 | |
| 100 | |
| 101 /** \brief Gets number of sequences | |
| 102 * | |
| 103 */ | |
| 104 unsigned int numberOfSequences() const; | |
| 105 | |
| 106 | |
| 107 /** \brief Sets a value of the data table | |
| 108 * | |
| 109 */ | |
| 110 void set(unsigned int sequence, unsigned int site, int value); | |
| 111 | |
| 112 | |
| 113 /** \brief Gets a value from the data table | |
| 114 * | |
| 115 */ | |
| 116 int get(unsigned int sequence, unsigned int site) const; | |
| 117 | |
| 118 | |
| 119 /** \brief Faster and unsecure version of get | |
| 120 * | |
| 121 */ | |
| 122 inline int fget(unsigned int sequence, unsigned int site) const { | |
| 123 return dataMatrix[sequence][site]; | |
| 124 } | |
| 125 | |
| 126 | |
| 127 /** \brief Sets the position of a site | |
| 128 * | |
| 129 */ | |
| 130 void sitePosition(unsigned int site, double value); | |
| 131 | |
| 132 | |
| 133 /** \brief Gets the position of a site | |
| 134 * | |
| 135 */ | |
| 136 double sitePosition(unsigned int site) const; | |
| 137 | |
| 138 | |
| 139 /** \brief Sets the group label of a sequence | |
| 140 * | |
| 141 */ | |
| 142 void populationLabel(unsigned int sequence, unsigned int value); | |
| 143 | |
| 144 | |
| 145 /** \brief Gets the group label of a sequence | |
| 146 * | |
| 147 */ | |
| 148 unsigned int populationLabel(unsigned int sequence) const; | |
| 149 | |
| 150 | |
| 151 /** \brief Removes all information from the object | |
| 152 * | |
| 153 */ | |
| 154 void clear(); | |
| 155 | |
| 156 | |
| 157 /** \brief Resizes the data matrix | |
| 158 * | |
| 159 * \param newNumberOfSequences number of sequences (rows) | |
| 160 * \param newNumberOfSites number of sites (columns) | |
| 161 * | |
| 162 * If new values are larger, data already set is left unchanged. | |
| 163 * New data are set to zero. | |
| 164 * | |
| 165 */ | |
| 166 void resize(unsigned int newNumberOfSequences, unsigned int newNumberOfSites); | |
| 167 | |
| 168 | |
| 169 /** \brief Shifts allele value | |
| 170 * | |
| 171 * \param minimum the minimum allele value. | |
| 172 * | |
| 173 * Shifts all alleles at all sites to ensure that alleles alleles | |
| 174 * are equal to or larger than minimum. The shifting is specific | |
| 175 * to each site. | |
| 176 * | |
| 177 */ | |
| 178 void shift(int minimum); | |
| 179 | |
| 180 /** \brief Gets the character at a given position | |
| 181 * | |
| 182 * An exception is generated if the allele value at this | |
| 183 * position is not >=0 and <=9. Not out-of-bound check is | |
| 184 * performed. | |
| 185 * | |
| 186 */ | |
| 187 char character(unsigned int sequence, unsigned int site) const; | |
| 188 | |
| 189 | |
| 190 | |
| 191 private: | |
| 192 | |
| 193 // Initializes to default values (for empty object) | |
| 194 void init(); | |
| 195 | |
| 196 // Copies from a source object | |
| 197 virtual void copy(const CharMatrix&); | |
| 198 | |
| 199 // Copies from a source object | |
| 200 virtual void copy(const DataMatrix&); | |
| 201 | |
| 202 // Number of lines of the data matrix | |
| 203 unsigned int _numberOfSequences; | |
| 204 | |
| 205 // Number of columns of the data matrix | |
| 206 unsigned int _numberOfSites; | |
| 207 | |
| 208 // Data matrix | |
| 209 int **dataMatrix; | |
| 210 | |
| 211 // Vector of site positions | |
| 212 double *positions; | |
| 213 | |
| 214 // Vector of group indices | |
| 215 unsigned int *groups; | |
| 216 }; | |
| 217 } | |
| 218 | |
| 219 #endif |
