annotate egglib/egglib-2.1.5/include/egglib-cpp/Align.hpp @ 1:420b57c3c185 draft

Uploaded
author dereeper
date Fri, 10 Jul 2015 04:39:30 -0400
parents
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_ALIGN_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
22 #define EGGLIB_ALIGN_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
23
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
24 #include "Container.hpp"
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
25 #include "CharMatrix.hpp"
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
26 #include <vector>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
27
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
28 /** \mainpage Summary
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
29 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
30 * This is the automatically-generated reference manual of the C++
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
31 * egglib-cpp library. The library is presented as several modules, but
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
32 * note that they are only used to structure the documentation.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
33 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
34 * There is a single namespace (egglib) in which all classes are
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
35 * defined. See an example of programming with egglib-cpp in the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
36 * EggLib package main documentation. Use "Modules" or "Classes" above
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
37 * to navigate in the library reference manual.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
38 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
39 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
40
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
41
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
42 /** \defgroup core core
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
43 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
44 * \brief Central core of the C++ library of Egglib
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
45 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
46 * Data storage classes, parsers/formatters and tools, plus exception
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
47 * types.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
48 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
49 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
50
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
51 namespace egglib {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
52
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
53
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
54 /** \brief Handles a sequence alignment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
55 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
56 * \ingroup core
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
57 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
58 * Creation from a file or string stream should be performed using
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
59 * the class Fasta. Align objects can be created by deep copy from
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
60 * both Align and Container type. In the latter case, the length are
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
61 * artificially equalized by "?" characters. Align objects can be
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
62 * created from a DataMatrix object (and all the way arround) using
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
63 * the specific class DMAConverter.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
64 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
65 * Sequences are represented by two strings (name and sequence) and
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
66 * an integer (group) that can be accessed or modified by index.The
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
67 * order of sequences is guaranteed to be conserved, as if Align was
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
68 * a list of triplets (name, sequence, group).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
69 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
70 * The data matrix is implemented as continuous array (char**) and
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
71 * allows efficient access and modification of data. For very large
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
72 * data matrices you might claim immediately the required memory
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
73 * using the constructor Align(unsigned int, char**).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
74 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
75 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
76 class Align : public Container, public CharMatrix {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
77 public:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
78
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
79 /** \brief Creates an empty alignment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
80 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
81 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
82 Align();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
83
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
84
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
85 /** \brief Creates an alignment from a data matrix.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
86 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
87 * Allows you to create an object from data stored in a char*
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
88 * array. The array's dimensions must be passed to the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
89 * constructor, and as a result there is not need to
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
90 * terminate each sequence by a NULL character.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
91 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
92 * \param number_of_sequences the number of sequences (the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
93 * length of the first dimension of the array).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
94 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
95 * \param alignment_length the length of sequences (the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
96 * length of all lines of the array).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
97 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
98 * \param cstring_array the pointer to the data matrix.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
99 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
100 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
101 Align(unsigned int number_of_sequences, unsigned int alignment_length, char const * const * const cstring_array);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
102
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
103
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
104 /** \brief Creates an alignment with given dimensions
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
105 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
106 * Allows you to allocate directly a data matrix of a given
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
107 * size. Names are empty strings, groups 0, and all
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
108 * characters are ?.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
109 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
110 * \param number_of_sequences the number of sequences (the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
111 * length of the first dimension of the array).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
112 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
113 * \param alignment_length the length of sequences (the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
114 * length of all lines of the array).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
115 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
116 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
117 Align(unsigned int number_of_sequences, unsigned int alignment_length);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
118
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
119
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
120 /** \brief Copy constructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
121 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
122 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
123 Align(const Align& align);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
124
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
125
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
126 /** \brief Copy constructor accepting a Container object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
127 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
128 * All but the longest sequences are padded with ? to match
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
129 * the longest sequence's length.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
130 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
131 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
132 Align(const Container& container);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
133
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
134
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
135 /** \brief Copy operator
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
136 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
137 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
138 Align& operator=(const Align& align);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
139
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
140
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
141 /** \brief Copy operator accepting a Container object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
142 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
143 * All but the longest sequences are padded with ? to match
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
144 * the longest sequence's length.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
145 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
146 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
147 Align& operator=(const Container& container);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
148
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
149
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
150 /** \brief Destructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
151 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
152 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
153 virtual ~Align();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
154
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
155
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
156 /** \brief Adds a sequence
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
157 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
158 * If the object already contains at least one sequence, the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
159 * new sequence must have the same length. Otherwise, a
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
160 * EggUnalignedError is raised.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
161 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
162 * \param name the name of the sequence.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
163 * \param sequence the sequence string.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
164 * \param group the group index of the sequence.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
165 * \return The new number of sequences.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
166 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
167 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
168 virtual unsigned int append(const char* name, const char* sequence, unsigned int group=0);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
169
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
170
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
171 /** \brief Removes a position (column) of the alignment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
172 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
173 * \param pos the position to remove in the alignment.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
174 * \return The new length of the alignment.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
175 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
176 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
177 virtual unsigned int removePosition(unsigned int pos);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
178
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
179
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
180 /** \brief Removes a sequence from the alignment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
181 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
182 * \param pos the index of the sequence to remove.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
183 * \return The new number of sequences.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
184 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
185 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
186 virtual unsigned int remove(unsigned int pos);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
187
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
188
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
189 /** \brief Replace a sequence string
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
190 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
191 * The new sequence must have the same length than the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
192 * alignment. Otherwise, a EggUnalignedError is raised.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
193 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
194 * \param seq the index of the sequence to change.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
195 * \param sequence the new sequence.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
196 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
197 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
198 virtual void sequence(unsigned int seq, const char* sequence);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
199
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
200
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
201 /** \brief Gets the name of a given sequence
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
202 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
203 * \param pos the index of the sequence.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
204 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
205 * \return The sequence string for that particular sequence.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
206 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
207 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
208 virtual inline const char* sequence(unsigned int pos) const { return Container::sequence(pos); }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
209
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
210
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
211 /** \brief Alignment length
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
212 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
213 * Returns 0 if the alignment is empty.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
214 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
215 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
216 virtual unsigned int ls() const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
217
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
218
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
219 /** \brief Length of a given sequence
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
220 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
221 * Calling this function is exactly the same as calling ls()
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
222 * (without arguments), regardless of the index provided,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
223 * except that an exception is thrown if the index is out of
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
224 * bounds. Provided for compatibility with Container.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
225 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
226 * \param pos the index of the sequence.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
227 * \return the length of the alignment.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
228 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
229 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
230 virtual unsigned int ls(unsigned int pos) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
231
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
232
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
233 /** \brief Fast and unsecure accessor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
234 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
235 * This accessor doesn't perform out-of-bound checking!
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
236 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
237 * \param s the index of the sequence (line).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
238 * \param p the position in the alignment (column).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
239 * \return The character at the given position.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
240 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
241 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
242 inline char character(unsigned int s, unsigned int p) const { return sequences[s][p]; }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
243
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
244
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
245 /** \brief Gets a nucleotide
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
246 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
247 * This modifier does perform out-of-bound checking.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
248 * The specified position must exist.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
249 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
250 * \param sequence the index of the sequence (line).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
251 * \param position the position in the alignment (column).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
252 * \return the character at the given position.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
253 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
254 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
255 virtual char get(unsigned int sequence, unsigned int position) const;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
256
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
257
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
258 /** \brief Sets a matrix position to a new character
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
259 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
260 * This modifier does perform out-of-bound checking.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
261 * The specified position must exist.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
262 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
263 * \param sequence the index of the sequence (line).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
264 * \param position the position in the alignment (column).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
265 * \param ch the new character value.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
266 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
267 virtual void set(unsigned int sequence, unsigned position, char ch);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
268
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
269
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
270 /** \brief Reverse a given column in binary data
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
271 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
272 * The specified column must contain only "0" ans "1" characters.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
273 * "0" is replaced by "1" and all the way around
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
274 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
275 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
276 void binSwitch(unsigned int pos);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
277
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
278
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
279 /** \brief Extracts specified positions (columns) of the alignment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
280 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
281 * All the specified sites are extracted in the specified
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
282 * order. This function is suitable for bootstrap (resample
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
283 * allowing redrawing the same site) and permutations.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
284 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
285 * This function doesn't perform out-of-bound checking.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
286 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
287 * \param list_of_sites a vector containing alignment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
288 * positions.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
289 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
290 * \return A copy of the object containing the specified
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
291 * set of positions.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
292 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
293 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
294 Align vslice(std::vector<unsigned int> list_of_sites);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
295
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
296
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
297 /** \brief Extracts a range of positions (columns)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
298 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
299 * \param a the first position.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
300 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
301 * \param b the index immediately passed the last sequence to
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
302 * extract.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
303 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
304 * \return A copy of the object containing the specified
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
305 * range of sequences.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
306 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
307 * Positions a to b-1 are extracted, provided that the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
308 * indices fit in the current length of sequences. To extract
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
309 * all sequences, use align.vslice(0, align.ls()).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
310 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
311 * Note: invalid ranges will be silently supported. If
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
312 * a>=ls or b<=a, an empty object is returned. If b>ns,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
313 * ls will be substituted to a.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
314 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
315 Align vslice(unsigned int a, unsigned int b);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
316
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
317
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
318 /** \brief Deletes all the content of the object
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
319 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
320 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
321 virtual void clear();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
322
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
323
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
324 /** \brief Same as ns()
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
325 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
326 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
327 inline unsigned int numberOfSequences() const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
328 return _ns;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
329 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
330
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
331
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
332 /** \brief Same as ls()
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
333 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
334 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
335 inline unsigned int numberOfSites() const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
336 return _ls;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
337 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
338
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
339
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
340 /** \brief Gets a group label (insecure)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
341 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
342 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
343 inline unsigned int populationLabel(unsigned int sequenceIndex) const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
344 return groups[sequenceIndex];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
345 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
346
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
347
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
348 /** \brief Just return the passed value
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
349 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
350 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
351 inline double sitePosition(unsigned int position) const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
352 return (double) position;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
353 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
354
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
355
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
356 protected:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
357
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
358 /// This function is not available for alignments
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
359 virtual void appendSequence(unsigned int pos, const char* sequence) {}
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
360
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
361 // Initializer (creates a valid empty alignment)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
362 virtual void init();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
363
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
364 // Makes a deep copy of the specified data matrix - if cstring_array is NULL, then ignores it and pads with ?'s
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
365 virtual void setFromSource(unsigned int number_of_sequences, unsigned int alignment_length, const char* const * const cstring_array);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
366
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
367 // Copies from a Container
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
368 virtual void copyObject(const Container&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
369
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
370 // Copies from an Align
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
371 virtual void copyObject(const Align&);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
372
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
373 // Alignment length
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
374 unsigned int _ls;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
375 };
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
376 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
377
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
378 #endif