bpp-popgen  2.2.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>
48 #include <Bpp/Text/StringTokenizer.h>
49 #include <Bpp/Text/TextTools.h>
50 
51 #include <Bpp/Seq/Container/VectorSiteContainer.h>
52 #include <Bpp/Seq/Container/SequenceContainerTools.h>
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
115  PolymorphismSequenceContainer(const Alphabet* alpha);
116 
120  PolymorphismSequenceContainer(size_t size, const Alphabet* alpha);
121 
125  PolymorphismSequenceContainer(const OrderedSequenceContainer& sc);
126 
130  PolymorphismSequenceContainer(const SiteContainer& sc);
131 
136 
141 
146 
151  {
152  return new PolymorphismSequenceContainer(*this);
153  }
154 
155 public:
156  // Other methods
162  Sequence* removeSequence(size_t index) throw (IndexOutOfBoundsException);
163 
169  Sequence* removeSequence(const std::string& name) throw (SequenceNotFoundException);
170 
176  void deleteSequence(size_t index) throw (IndexOutOfBoundsException);
177 
183  void deleteSequence(const std::string& name) throw (SequenceNotFoundException);
184 
192  void addSequenceWithFrequency(const Sequence& sequence, unsigned int frequency, bool checkName = true) throw (Exception);
193  void addSequenceWithFrequency(const Sequence& sequence, size_t sequenceIndex, unsigned int frequency, bool checkName = true) throw (Exception);
194  void addSequence(const Sequence& sequence, bool checkName = true) throw (Exception) {
195  addSequenceWithFrequency(sequence, 1, checkName);
196  }
197  void addSequence(const Sequence& sequence, size_t sequenceIndex, bool checkName = true) throw (Exception) {
198  addSequenceWithFrequency(sequence, sequenceIndex, 1, checkName);
199  }
200 
204  void clear();
205 
211  size_t getGroupId(size_t index) const throw (IndexOutOfBoundsException);
212 
218  size_t getGroupId(const std::string& name) const throw (SequenceNotFoundException);
219 
223  std::set<size_t> getAllGroupsIds() const;
224 
230  void setGroupId(size_t index, size_t group_id) throw (IndexOutOfBoundsException);
231 
237  void setGroupId(const std::string& name, size_t group_id) throw (SequenceNotFoundException);
238 
242  size_t getNumberOfGroups() const;
243 
249  bool isIngroupMember(size_t index) const throw (IndexOutOfBoundsException);
250 
256  bool isIngroupMember(const std::string& name) const throw (SequenceNotFoundException);
257 
263  void setAsIngroupMember(size_t index) throw (IndexOutOfBoundsException);
264 
270  void setAsIngroupMember(const std::string& name) throw (SequenceNotFoundException);
271 
277  void setAsOutgroupMember(size_t index) throw (IndexOutOfBoundsException);
278 
284  void setAsOutgroupMember(const std::string& name) throw (SequenceNotFoundException);
285 
292  void setSequenceCount(size_t index, unsigned int count) throw (Exception);
293 
300  void setSequenceCount(const std::string& name, unsigned int count) throw (Exception);
301 
307  void incrementSequenceCount(size_t index) throw (IndexOutOfBoundsException);
308 
314  void incrementSequenceCount(const std::string& name) throw (SequenceNotFoundException);
315 
322  void decrementSequenceCount(size_t index) throw(IndexOutOfBoundsException, BadIntegerException);
323 
330  void decrementSequenceCount(const std::string& name) throw (SequenceNotFoundException, BadIntegerException);
331 
337  unsigned int getSequenceCount(size_t index) const throw (IndexOutOfBoundsException);
338 
344  unsigned int getSequenceCount(const std::string& name) const throw (SequenceNotFoundException);
345 };
346 } // end of namespace bpp;
347 
348 #endif // _POLYMORPHISMSEQUENCECONTAINER_H_
349 
void setAsOutgroupMember(size_t index)
Set a sequence as outgroup member by index.
void clear()
Clear the container of all its sequences.
PolymorphismSequenceContainer * clone() const
Clone a PolymorphismSequenceContainer.
void incrementSequenceCount(size_t index)
Add 1 to the sequence count.
PolymorphismSequenceContainer(const Alphabet *alpha)
Build a new empty PolymorphismSequenceContainer.
size_t getGroupId(size_t index) const
Get the group identifier of the sequence.
void addSequence(const Sequence &sequence, size_t sequenceIndex, bool checkName=true)
bool isIngroupMember(size_t index) const
Tell if the sequence is ingroup by index.
PolymorphismSequenceContainer & operator=(const PolymorphismSequenceContainer &psc)
Operator= : copy operator.
unsigned int getSequenceCount(size_t index) const
Get the count of a sequence by index.
void addSequenceWithFrequency(const Sequence &sequence, unsigned int frequency, bool checkName=true)
Add a sequence to the container.
void setGroupId(size_t index, size_t group_id)
Set the group identifier of a sequence.
size_t getNumberOfGroups() const
Get the number of groups.
void deleteSequence(size_t index)
Delete a sequence by index.
void addSequence(const Sequence &sequence, bool checkName=true)
virtual ~PolymorphismSequenceContainer()
Destroy a PolymorphismSequenceContainer.
void decrementSequenceCount(size_t index)
Removz 1 to the sequence count.
void setAsIngroupMember(size_t index)
Set a sequence as ingroup member by index.
Sequence * removeSequence(size_t index)
Remove a sequence by index and return a pointer to this removed sequence.
void setSequenceCount(size_t index, unsigned int count)
Set the count of a sequence by index.
The PolymorphismSequenceContainer class.
std::set< size_t > getAllGroupsIds() const
Get all the groups identifiers.