bpp-popgen  3.0.0
PolymorphismSequenceContainer.h
Go to the documentation of this file.
1 //
2 // File: PolymorphismSequenceContainer.h
3 // Authors: Eric Bazin
4 // Sylvain Gaillard
5 // Created on: Wednesday August 04 2004
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for population genetics analysis.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39  */
40 
41 #ifndef _POLYMORPHISMSEQUENCECONTAINER_H_
42 #define _POLYMORPHISMSEQUENCECONTAINER_H_
43 
44 #include <set>
45 #include <string>
46 
47 #include <Bpp/Clonable.h>
49 #include <Bpp/Text/TextTools.h>
50 
53 
92 namespace bpp
93 {
103  public VectorSiteContainer
104 {
105 private:
106  std::vector<bool> ingroup_;
107  std::vector<unsigned int> count_;
108  std::vector<size_t> group_;
109 
110 public:
111  // Constructors and destructor
116 
120  PolymorphismSequenceContainer(size_t size, const Alphabet* alpha);
121 
125  PolymorphismSequenceContainer(const std::vector<std::string>& names, const Alphabet* alpha);
126 
133 
144 
151 
161  PolymorphismSequenceContainer(const SiteContainer& sc, bool count);
162 
167 
172 
177 
182  {
183  return new PolymorphismSequenceContainer(*this);
184  }
185 
186 public:
187  // Other methods
193  Sequence* removeSequence(size_t index);
194 
200  Sequence* removeSequence(const std::string& name);
201 
207  void deleteSequence(size_t index);
208 
214  void deleteSequence(const std::string& name);
215 
223  void addSequenceWithFrequency(const Sequence& sequence, unsigned int frequency, bool checkName = true);
224  void addSequenceWithFrequency(const Sequence& sequence, size_t sequenceIndex, unsigned int frequency, bool checkName = true);
225  void addSequence(const Sequence& sequence, bool checkName = true) {
226  addSequenceWithFrequency(sequence, 1, checkName);
227  }
228  void addSequence(const Sequence& sequence, size_t sequenceIndex, bool checkName = true) {
229  addSequenceWithFrequency(sequence, sequenceIndex, 1, checkName);
230  }
231 
235  void clear();
236 
242  size_t getGroupId(size_t index) const;
243 
249  size_t getGroupId(const std::string& name) const;
250 
254  std::set<size_t> getAllGroupsIds() const;
255 
261  void setGroupId(size_t index, size_t group_id);
262 
268  void setGroupId(const std::string& name, size_t group_id);
269 
273  size_t getNumberOfGroups() const;
274 
278  bool hasOutgroup() const;
279 
285  bool isIngroupMember(size_t index) const;
286 
292  bool isIngroupMember(const std::string& name) const;
293 
299  void setAsIngroupMember(size_t index);
300 
306  void setAsIngroupMember(const std::string& name);
307 
313  void setAsOutgroupMember(size_t index);
314 
320  void setAsOutgroupMember(const std::string& name);
321 
328  void setSequenceCount(size_t index, unsigned int count);
329 
336  void setSequenceCount(const std::string& name, unsigned int count);
337 
343  void incrementSequenceCount(size_t index);
344 
350  void incrementSequenceCount(const std::string& name);
351 
358  void decrementSequenceCount(size_t index);
359 
366  void decrementSequenceCount(const std::string& name);
367 
373  unsigned int getSequenceCount(size_t index) const;
374 
380  unsigned int getSequenceCount(const std::string& name) const;
381 
388 
389 };
390 } // end of namespace bpp;
391 
392 #endif // _POLYMORPHISMSEQUENCECONTAINER_H_
393 
The PolymorphismSequenceContainer class.
void clear()
Clear the container of all its sequences.
void setAsIngroupMember(size_t index)
Set a sequence as ingroup member by index.
void setAsOutgroupMember(size_t index)
Set a sequence as outgroup member by index.
virtual ~PolymorphismSequenceContainer()
Destroy a PolymorphismSequenceContainer.
bool isIngroupMember(size_t index) const
Tell if the sequence is ingroup by index.
void addSequence(const Sequence &sequence, size_t sequenceIndex, bool checkName=true)
PolymorphismSequenceContainer * clone() const
Clone a PolymorphismSequenceContainer.
unsigned int getSequenceCount(size_t index) const
Get the count of a sequence by index.
void addSequence(const Sequence &sequence, bool checkName=true)
SiteContainer * toSiteContainer() const
convert the container to a site container, with sequences dulicated according to their respective fre...
void addSequenceWithFrequency(const Sequence &sequence, unsigned int frequency, bool checkName=true)
Add a sequence to the container.
PolymorphismSequenceContainer & operator=(const PolymorphismSequenceContainer &psc)
Operator= : copy operator.
void incrementSequenceCount(size_t index)
Add 1 to the sequence count.
void decrementSequenceCount(size_t index)
Removz 1 to the sequence count.
std::set< size_t > getAllGroupsIds() const
Get all the groups identifiers.
void setSequenceCount(size_t index, unsigned int count)
Set the count of a sequence by index.
size_t getNumberOfGroups() const
Get the number of groups.
PolymorphismSequenceContainer(const Alphabet *alpha)
Build a new empty PolymorphismSequenceContainer.
void deleteSequence(size_t index)
Delete a sequence by index.
Sequence * removeSequence(size_t index)
Remove a sequence by index and return a pointer to this removed sequence.
void setGroupId(size_t index, size_t group_id)
Set the group identifier of a sequence.
size_t getGroupId(size_t index) const
Get the group identifier of the sequence.