~ubuntu-branches/ubuntu/trusty/libbpp-popgen/trusty

« back to all changes in this revision

Viewing changes to src/Bpp/PopGen/PolymorphismSequenceContainer.h

  • Committer: Package Import Robot
  • Author(s): Julien Dutheil
  • Date: 2013-03-07 10:51:00 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130307105100-7ij3w7iyab9t2mbt
Tags: 2.1.0-1
Bug fixed and warnings removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
//
7
7
 
8
8
/*
9
 
   Copyright or © or Copr. CNRS, (November 17, 2004)
 
9
   Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10
10
 
11
11
   This software is a computer program whose purpose is to provide classes
12
12
   for population genetics analysis.
36
36
 
37
37
   The fact that you are presently reading this means that you have had
38
38
   knowledge of the CeCILL license and that you accept its terms.
39
 
   */
 
39
 */
40
40
 
41
41
#ifndef _POLYMORPHISMSEQUENCECONTAINER_H_
42
42
#define _POLYMORPHISMSEQUENCECONTAINER_H_
58
58
 * The PopGenLib library provides classes for population genetics analysis.
59
59
 * It makes intensive use of the SeqLib library, and adds a dedicated container
60
60
 * named bpp::PolymorphismSequenceContainer, which associates frequencies to the
61
 
 * sequences in the set. The bpp::PolymorphismSequenceContainerTools and 
 
61
 * sequences in the set. The bpp::PolymorphismSequenceContainerTools and
62
62
 * bpp::SequenceStatistics static classes provide several tools for data analysis,
63
63
 * including diversity indices and positive selection tests.
64
64
 *
91
91
 
92
92
namespace bpp
93
93
{
94
 
 
95
 
  /**
96
 
   * @brief The PolymorphismSequenceContainer class.
97
 
   *
98
 
   * This is a VectorSiteContainer with effectif for each sequence.
99
 
   * It also has flag for ingroup and outgroup.
100
 
   *
101
 
   * @author Sylvain Gaillard
102
 
   */
103
 
  class PolymorphismSequenceContainer:
104
 
    public VectorSiteContainer
 
94
/**
 
95
 * @brief The PolymorphismSequenceContainer class.
 
96
 *
 
97
 * This is a VectorSiteContainer with effectif for each sequence.
 
98
 * It also has flag for ingroup and outgroup.
 
99
 *
 
100
 * @author Sylvain Gaillard
 
101
 */
 
102
class PolymorphismSequenceContainer :
 
103
  public VectorSiteContainer
 
104
{
 
105
private:
 
106
  std::vector<bool> ingroup_;
 
107
  std::vector<size_t> count_;
 
108
  std::vector<size_t> group_;
 
109
 
 
110
public:
 
111
  // Constructors and destructor
 
112
  /**
 
113
   * @brief Build a new empty PolymorphismSequenceContainer.
 
114
   */
 
115
  PolymorphismSequenceContainer(const Alphabet* alpha);
 
116
 
 
117
  /**
 
118
   * @brief Build a new empty PolymorphismSequenceContainer of given size.
 
119
   */
 
120
  PolymorphismSequenceContainer(size_t size, const Alphabet* alpha);
 
121
 
 
122
  /**
 
123
   * @brief Build a PolymorphismSequenceContainer by copying data from an OrderedSequenceContainer.
 
124
   */
 
125
  PolymorphismSequenceContainer(const OrderedSequenceContainer& sc);
 
126
 
 
127
  /**
 
128
   * @brief Build a PolymorphismSequenceContainer by copying data from a SiteContainer.
 
129
   */
 
130
  PolymorphismSequenceContainer(const SiteContainer& sc);
 
131
 
 
132
  /**
 
133
   * @brief Copy constructor.
 
134
   */
 
135
  PolymorphismSequenceContainer(const PolymorphismSequenceContainer& psc);
 
136
 
 
137
  /**
 
138
   * @brief Operator= : copy operator.
 
139
   */
 
140
  PolymorphismSequenceContainer& operator=(const PolymorphismSequenceContainer& psc);
 
141
 
 
142
  /**
 
143
   * @brief Destroy a PolymorphismSequenceContainer.
 
144
   */
 
145
  virtual ~PolymorphismSequenceContainer();
 
146
 
 
147
  /**
 
148
   * @brief Clone a PolymorphismSequenceContainer.
 
149
   */
 
150
  PolymorphismSequenceContainer* clone() const
105
151
  {
106
 
    private:
107
 
      std::vector<bool> ingroup_;
108
 
      std::vector<unsigned int> count_;
109
 
      std::vector<unsigned int> group_;
110
 
 
111
 
    public: // Constructors and destructor
112
 
      /**
113
 
       * @brief Build a new empty PolymorphismSequenceContainer.
114
 
       */
115
 
      PolymorphismSequenceContainer(const Alphabet* alpha);
116
 
 
117
 
      /**
118
 
       * @brief Build a new empty PolymorphismSequenceContainer of given size.
119
 
       */
120
 
      PolymorphismSequenceContainer(unsigned int size, const Alphabet* alpha);
121
 
 
122
 
      /**
123
 
       * @brief Build a PolymorphismSequenceContainer by copying data from an OrderedSequenceContainer.
124
 
       */
125
 
      PolymorphismSequenceContainer(const OrderedSequenceContainer& sc);
126
 
 
127
 
      /**
128
 
       * @brief Build a PolymorphismSequenceContainer by copying data from a SiteContainer.
129
 
       */
130
 
      PolymorphismSequenceContainer(const SiteContainer& sc);
131
 
 
132
 
      /**
133
 
       * @brief Copy constructor.
134
 
       */
135
 
      PolymorphismSequenceContainer(const PolymorphismSequenceContainer& psc);
136
 
 
137
 
      /**
138
 
       * @brief Operator= : copy operator.
139
 
       */
140
 
      PolymorphismSequenceContainer& operator=(const PolymorphismSequenceContainer& psc);
141
 
 
142
 
      /**
143
 
       * @brief Destroy a PolymorphismSequenceContainer.
144
 
       */
145
 
      virtual ~PolymorphismSequenceContainer();
146
 
 
147
 
      /**
148
 
       * @brief Clone a PolymorphismSequenceContainer.
149
 
       */
150
 
      PolymorphismSequenceContainer* clone() const
151
 
      {
152
 
        return new PolymorphismSequenceContainer(*this);
153
 
      }
154
 
 
155
 
 
156
 
    public: // Other methods
157
 
      /**
158
 
       * @brief Remove a sequence by index and return a pointer to this removed sequence.
159
 
       *
160
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences.
161
 
       */
162
 
      Sequence * removeSequence(unsigned int index) throw (IndexOutOfBoundsException);
163
 
 
164
 
      /**
165
 
       * @brief Remove a sequence by name and return a pointer to this removed sequence.
166
 
       *
167
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
168
 
       */
169
 
      Sequence * removeSequence(const std::string &name) throw (SequenceNotFoundException);
170
 
 
171
 
      /**
172
 
       * @brief Delete a sequence by index.
173
 
       *
174
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences.
175
 
       */
176
 
      void deleteSequence(unsigned int index) throw (IndexOutOfBoundsException);
177
 
 
178
 
      /**
179
 
       * @brief Delete a sequence by name.
180
 
       *
181
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
182
 
       */
183
 
      void deleteSequence(const std::string &name) throw (SequenceNotFoundException);
184
 
 
185
 
      /**
186
 
       * @brief Add a sequence to the container.
187
 
       *
188
 
       * @throw AlphabetMismatchException if the sequence's alphabet doesn't match the container's alphabet.
189
 
       * @throw SequenceException if the sequence's size doesn't match the sequence's size of the container.
190
 
       * @throw SequenceException if the sequence's name already exists in the container.
191
 
       */
192
 
      void addSequence(const Sequence &sequence,unsigned int effectif=1,  bool checkNames=true) throw (Exception);
193
 
 
194
 
      /**
195
 
       * @brief Clear the container of all its sequences.
196
 
       */
197
 
      void clear();
198
 
 
199
 
      /**
200
 
       * @brief Get the group identifier of the sequence.
201
 
       *
202
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
203
 
       */
204
 
      unsigned int getGroupId(unsigned int index) const throw (IndexOutOfBoundsException);
205
 
 
206
 
      /**
207
 
       * @brief Get the group identifier of a sequence.
208
 
       *
209
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
210
 
       */
211
 
      unsigned int getGroupId(const std::string & name) const throw (SequenceNotFoundException);
212
 
 
213
 
      /**
214
 
       * @brief Get all the groups identifiers.
215
 
       */
216
 
      std::set<unsigned int> getAllGroupsIds() const;
217
 
 
218
 
      /**
219
 
       * @brief Set the group identifier of a sequence.
220
 
       *
221
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
222
 
       */
223
 
      void setGroupId(unsigned int index, unsigned int group_id) throw (IndexOutOfBoundsException);
224
 
 
225
 
      /**
226
 
       * @brief Set the group identifier of a sequence.
227
 
       *
228
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
229
 
       */
230
 
      void setGroupId(const std::string & name, unsigned int group_id) throw (SequenceNotFoundException);
231
 
 
232
 
      /**
233
 
       * @brief Get the number of groups.
234
 
       */
235
 
      unsigned int getNumberOfGroups() const;
236
 
 
237
 
      /**
238
 
       * @brief Tell if the sequence is ingroup by index.
239
 
       *
240
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
241
 
       */
242
 
      bool isIngroupMember(unsigned int index) const throw (IndexOutOfBoundsException);
243
 
 
244
 
      /**
245
 
       * @brief Tell if a sequence is ingroup by name.
246
 
       *
247
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
248
 
       */
249
 
      bool isIngroupMember(const std::string &name) const throw (SequenceNotFoundException);
250
 
 
251
 
      /**
252
 
       * @brief Set a sequence as ingroup member by index.
253
 
       *
254
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
255
 
       */
256
 
      void setAsIngroupMember(unsigned int index) throw (IndexOutOfBoundsException);
257
 
 
258
 
      /**
259
 
       * @brief Set a sequence as ingroup member by name.
260
 
       *
261
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
262
 
       */
263
 
      void setAsIngroupMember(const std::string &name) throw (SequenceNotFoundException);
264
 
 
265
 
      /**
266
 
       * @brief Set a sequence as outgroup member by index.
267
 
       *
268
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
269
 
       */
270
 
      void setAsOutgroupMember(unsigned int index) throw (IndexOutOfBoundsException);
271
 
 
272
 
      /**
273
 
       * @brief Set a sequence as outgroup member by name.
274
 
       *
275
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
276
 
       */
277
 
      void setAsOutgroupMember(const std::string &name) throw (SequenceNotFoundException);
278
 
 
279
 
      /**
280
 
       * @brief Set the count of a sequence by index.
281
 
       *
282
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
283
 
       * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
284
 
       */
285
 
      void setSequenceCount(unsigned int index, unsigned int count) throw (Exception);
286
 
 
287
 
      /**
288
 
       * @brief Set the count of a sequence by name.
289
 
       *
290
 
       * @throw throw SequenceNotFoundException if name is not found among the sequences' names.
291
 
       * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
292
 
       */
293
 
      void setSequenceCount(const std::string &name, unsigned int count) throw (Exception);
294
 
 
295
 
      /**
296
 
       * @brief Add 1 to the sequence count.
297
 
       *
298
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
299
 
       */
300
 
      void incrementSequenceCount(unsigned int index) throw (IndexOutOfBoundsException);
301
 
 
302
 
      /**
303
 
       * @brief Add 1 to the sequence count.
304
 
       *
305
 
       * @throw throw SequenceNotFoundException if name is not found among the sequences' names.
306
 
       */
307
 
      void incrementSequenceCount(const std::string &name) throw (SequenceNotFoundException);
308
 
 
309
 
      /**
310
 
       * @brief Remove 1 to the sequence count.
311
 
       *
312
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
313
 
       * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
314
 
       */
315
 
      void decrementSequenceCount(unsigned int index) throw (Exception);
316
 
 
317
 
      /**
318
 
       * @brief Remove 1 to the sequence count.
319
 
       *
320
 
       * @throw throw SequenceNotFoundException if name is not found among the sequences' names.
321
 
       * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
322
 
       */
323
 
      void decrementSequenceCount(const std::string & name) throw (Exception);
324
 
 
325
 
      /**
326
 
       * @brief Get the count of a sequence by index.
327
 
       *
328
 
       * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
329
 
       */
330
 
      unsigned int getSequenceCount(unsigned int index) const throw (IndexOutOfBoundsException);
331
 
 
332
 
      /**
333
 
       * @brief Get the count of a sequence by name.
334
 
       *
335
 
       * @throw SequenceNotFoundException if name is not found among the sequences' names.
336
 
       */
337
 
      unsigned int getSequenceCount(const std::string &name) const throw (SequenceNotFoundException);
338
 
 
339
 
  };
340
 
 
341
 
} //end of namespace bpp;
342
 
 
343
 
#endif  //_POLYMORPHISMSEQUENCECONTAINER_H_
 
152
    return new PolymorphismSequenceContainer(*this);
 
153
  }
 
154
 
 
155
public:
 
156
  // Other methods
 
157
  /**
 
158
   * @brief Remove a sequence by index and return a pointer to this removed sequence.
 
159
   *
 
160
   * @throw IndexOutOfBoundsException if index excedes the number of sequences.
 
161
   */
 
162
  Sequence* removeSequence(size_t index) throw (IndexOutOfBoundsException);
 
163
 
 
164
  /**
 
165
   * @brief Remove a sequence by name and return a pointer to this removed sequence.
 
166
   *
 
167
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
168
   */
 
169
  Sequence* removeSequence(const std::string& name) throw (SequenceNotFoundException);
 
170
 
 
171
  /**
 
172
   * @brief Delete a sequence by index.
 
173
   *
 
174
   * @throw IndexOutOfBoundsException if index excedes the number of sequences.
 
175
   */
 
176
  void deleteSequence(size_t index) throw (IndexOutOfBoundsException);
 
177
 
 
178
  /**
 
179
   * @brief Delete a sequence by name.
 
180
   *
 
181
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
182
   */
 
183
  void deleteSequence(const std::string& name) throw (SequenceNotFoundException);
 
184
 
 
185
  /**
 
186
   * @brief Add a sequence to the container.
 
187
   *
 
188
   * @throw AlphabetMismatchException if the sequence's alphabet doesn't match the container's alphabet.
 
189
   * @throw SequenceException if the sequence's size doesn't match the sequence's size of the container.
 
190
   * @throw SequenceException if the sequence's name already exists in the container.
 
191
   */
 
192
  void addSequence(const Sequence& sequence, size_t effectif = 1,  bool checkNames = true) throw (Exception);
 
193
 
 
194
  /**
 
195
   * @brief Clear the container of all its sequences.
 
196
   */
 
197
  void clear();
 
198
 
 
199
  /**
 
200
   * @brief Get the group identifier of the sequence.
 
201
   *
 
202
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
203
   */
 
204
  size_t getGroupId(size_t index) const throw (IndexOutOfBoundsException);
 
205
 
 
206
  /**
 
207
   * @brief Get the group identifier of a sequence.
 
208
   *
 
209
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
210
   */
 
211
  size_t getGroupId(const std::string& name) const throw (SequenceNotFoundException);
 
212
 
 
213
  /**
 
214
   * @brief Get all the groups identifiers.
 
215
   */
 
216
  std::set<size_t> getAllGroupsIds() const;
 
217
 
 
218
  /**
 
219
   * @brief Set the group identifier of a sequence.
 
220
   *
 
221
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
222
   */
 
223
  void setGroupId(size_t index, size_t group_id) throw (IndexOutOfBoundsException);
 
224
 
 
225
  /**
 
226
   * @brief Set the group identifier of a sequence.
 
227
   *
 
228
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
229
   */
 
230
  void setGroupId(const std::string& name, size_t group_id) throw (SequenceNotFoundException);
 
231
 
 
232
  /**
 
233
   * @brief Get the number of groups.
 
234
   */
 
235
  size_t getNumberOfGroups() const;
 
236
 
 
237
  /**
 
238
   * @brief Tell if the sequence is ingroup by index.
 
239
   *
 
240
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
241
   */
 
242
  bool isIngroupMember(size_t index) const throw (IndexOutOfBoundsException);
 
243
 
 
244
  /**
 
245
   * @brief Tell if a sequence is ingroup by name.
 
246
   *
 
247
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
248
   */
 
249
  bool isIngroupMember(const std::string& name) const throw (SequenceNotFoundException);
 
250
 
 
251
  /**
 
252
   * @brief Set a sequence as ingroup member by index.
 
253
   *
 
254
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
255
   */
 
256
  void setAsIngroupMember(size_t index) throw (IndexOutOfBoundsException);
 
257
 
 
258
  /**
 
259
   * @brief Set a sequence as ingroup member by name.
 
260
   *
 
261
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
262
   */
 
263
  void setAsIngroupMember(const std::string& name) throw (SequenceNotFoundException);
 
264
 
 
265
  /**
 
266
   * @brief Set a sequence as outgroup member by index.
 
267
   *
 
268
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
269
   */
 
270
  void setAsOutgroupMember(size_t index) throw (IndexOutOfBoundsException);
 
271
 
 
272
  /**
 
273
   * @brief Set a sequence as outgroup member by name.
 
274
   *
 
275
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
276
   */
 
277
  void setAsOutgroupMember(const std::string& name) throw (SequenceNotFoundException);
 
278
 
 
279
  /**
 
280
   * @brief Set the count of a sequence by index.
 
281
   *
 
282
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
283
   * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
 
284
   */
 
285
  void setSequenceCount(size_t index, size_t count) throw (Exception);
 
286
 
 
287
  /**
 
288
   * @brief Set the count of a sequence by name.
 
289
   *
 
290
   * @throw throw SequenceNotFoundException if name is not found among the sequences' names.
 
291
   * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
 
292
   */
 
293
  void setSequenceCount(const std::string& name, size_t count) throw (Exception);
 
294
 
 
295
  /**
 
296
   * @brief Add 1 to the sequence count.
 
297
   *
 
298
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
299
   */
 
300
  void incrementSequenceCount(size_t index) throw (IndexOutOfBoundsException);
 
301
 
 
302
  /**
 
303
   * @brief Add 1 to the sequence count.
 
304
   *
 
305
   * @throw throw SequenceNotFoundException if name is not found among the sequences' names.
 
306
   */
 
307
  void incrementSequenceCount(const std::string& name) throw (SequenceNotFoundException);
 
308
 
 
309
  /**
 
310
   * @brief Remove 1 to the sequence count.
 
311
   *
 
312
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
313
   * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
 
314
   */
 
315
  void decrementSequenceCount(size_t index) throw (Exception);
 
316
 
 
317
  /**
 
318
   * @brief Remove 1 to the sequence count.
 
319
   *
 
320
   * @throw throw SequenceNotFoundException if name is not found among the sequences' names.
 
321
   * @throw BadIntegerException if count < 1 ... use deleteSequence instead of setting the count to 0.
 
322
   */
 
323
  void decrementSequenceCount(const std::string& name) throw (Exception);
 
324
 
 
325
  /**
 
326
   * @brief Get the count of a sequence by index.
 
327
   *
 
328
   * @throw IndexOutOfBoundsException if index excedes the number of sequences in the container.
 
329
   */
 
330
  size_t getSequenceCount(size_t index) const throw (IndexOutOfBoundsException);
 
331
 
 
332
  /**
 
333
   * @brief Get the count of a sequence by name.
 
334
   *
 
335
   * @throw SequenceNotFoundException if name is not found among the sequences' names.
 
336
   */
 
337
  size_t getSequenceCount(const std::string& name) const throw (SequenceNotFoundException);
 
338
};
 
339
} // end of namespace bpp;
 
340
 
 
341
#endif  // _POLYMORPHISMSEQUENCECONTAINER_H_
344
342