bpp-seq  2.2.0
VectorSequenceContainer.h
Go to the documentation of this file.
1 //
2 // File VectorSequenceContainer.h
3 // Created by: Guillaume Deuchst
4 // Julien Dutheil
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _VECTORSEQUENCECONTAINER_H_
41 #define _VECTORSEQUENCECONTAINER_H_
42 
43 #include "../Alphabet/Alphabet.h"
44 #include "../Sequence.h"
46 #include <Bpp/Exceptions.h>
47 
48 // From the STL:
49 #include <algorithm>
50 #include <vector>
51 
52 namespace bpp
53 {
54 
65 {
66  private:
67 
71  mutable std::vector<Sequence*> sequences_;
72 
73  public:
74 
86  const std::vector<const Sequence*>& vs, const Alphabet* alpha)
88 
95 
108 
115 
122 
131 
138 
145 
150 
151  public:
152 
158  Clonable* clone() const { return new VectorSequenceContainer(*this); }
166  bool hasSequence(const std::string& name) const;
167 
168  const Sequence& getSequence(const std::string& name) const throw (SequenceNotFoundException);
169 
170  void setSequence(const std::string& name, const Sequence& sequence, bool checkName = true) throw (Exception)
171  {
172  setSequence(getSequencePosition(name), sequence, checkName);
173  }
174 
175  Sequence* removeSequence(const std::string& name) throw (SequenceNotFoundException)
176  {
177  return removeSequence(getSequencePosition(name));
178  }
179 
180  void deleteSequence(const std::string& name) throw (SequenceNotFoundException)
181  {
183  }
184 
185  size_t getNumberOfSequences() const { return sequences_.size(); }
186 
187  std::vector<std::string> getSequencesNames() const;
188  void setSequencesNames(const std::vector<std::string>& names, bool checkNames = true) throw (Exception);
189  void clear();
191 
192  int& valueAt(const std::string& sequenceName, size_t elementIndex) throw (SequenceNotFoundException, IndexOutOfBoundsException)
193  {
194  return getSequence_(sequenceName)[elementIndex];
195  }
196 
197  const int& valueAt(const std::string& sequenceName, size_t elementIndex) const throw (SequenceNotFoundException, IndexOutOfBoundsException)
198  {
199  return getSequence(sequenceName)[elementIndex];
200  }
201 
202  int& operator()(const std::string& sequenceName, size_t elementIndex)
203  {
204  return getSequence_(sequenceName)[elementIndex];
205  }
206 
207  const int& operator()(const std::string& sequenceName, size_t elementIndex) const
208  {
209  return getSequence(sequenceName)[elementIndex];
210  }
211 
212  int& valueAt(size_t sequenceIndex, size_t elementIndex) throw (IndexOutOfBoundsException)
213  {
214  return getSequence_(sequenceIndex)[elementIndex];
215  }
216 
217  const int& valueAt(size_t sequenceIndex, size_t elementIndex) const throw (IndexOutOfBoundsException)
218  {
219  return getSequence(sequenceIndex)[elementIndex];
220  }
221 
222  int& operator()(size_t sequenceIndex, size_t elementIndex)
223  {
224  return getSequence_(sequenceIndex)[elementIndex];
225  }
226  const int & operator()(size_t sequenceIndex, size_t elementIndex) const
227  {
228  return getSequence(sequenceIndex)[elementIndex];
229  }
238  void setComments(const std::string & name, const Comments& comments) throw (SequenceNotFoundException)
239  {
241  }
242 
243  void setComments(size_t sequenceIndex, const Comments& comments) throw (IndexOutOfBoundsException);
244  size_t getSequencePosition(const std::string& name) const throw (SequenceNotFoundException);
245  const Sequence& getSequence(size_t sequenceIndex) const throw (IndexOutOfBoundsException);
246  void setSequence(size_t sequenceIndex, const Sequence& sequence, bool checkName = true) throw (Exception);
247  Sequence* removeSequence(size_t sequenceIndex) throw (IndexOutOfBoundsException);
248  void deleteSequence(size_t sequenceIndex) throw (IndexOutOfBoundsException);
271  virtual void addSequence(const Sequence& sequence, bool checkName = true) throw (Exception);
272 
289  virtual void addSequence(const Sequence& sequence, size_t sequenceIndex, bool checkName = true) throw (Exception);
290 
291  protected:
292 
298  Sequence& getSequence_(size_t i) throw (IndexOutOfBoundsException);
299  Sequence& getSequence_(const std::string& name) throw (SequenceNotFoundException);
301 };
302 
303 } //end of namespace bpp.
304 
305 #endif // _VECTORSEQUENCECONTAINER_H_
306 
size_t getNumberOfSequences() const
Get the number of sequences in the container.
Exception thrown when a sequence is not found The sequence not found exception base class...
bool hasSequence(const std::string &name) const
Check if a sequence with a given name is present in the container.
VectorSequenceContainer & operator=(const VectorSequenceContainer &vsc)
Assign from a VectorSequenceContainer.
int & operator()(size_t sequenceIndex, size_t elementIndex)
Element access operator.
void setComments(const std::string &name, const Comments &comments)
Set the comments of a particular sequence.
std::vector< std::string > Comments
Declaration of Comments type.
Definition: Sequence.h:60
void setComments(const std::string &name, const Comments &comments)
Set the comments of a particular sequence.
int & valueAt(const std::string &sequenceName, size_t elementIndex)
Element access function.
VectorSequenceContainer(const Alphabet *alpha)
Build an empty container that will contain sequences of a particular alphabet.
void deleteSequence(const std::string &name)
Delete a sequence of the container.
The OrderedSequenceContainer interface.
This alphabet is used to deal NumericAlphabet.
std::vector< Sequence * > sequences_
A std::vector of pointers toward the sequences stored in the container.
The VectorSequenceContainer class.
The Alphabet interface.
Definition: Alphabet.h:130
STL namespace.
const int & valueAt(size_t sequenceIndex, size_t elementIndex) const
Element access operator.
Partial implementation of the OrderedSequenceContainer interface.
virtual void addSequence(const Sequence &sequence, bool checkName=true)
Add a sequence at the end of the container.
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
const int & operator()(size_t sequenceIndex, size_t elementIndex) const
Element access operator.
const int & operator()(const std::string &sequenceName, size_t elementIndex) const
Element access operator.
void setSequencesNames(const std::vector< std::string > &names, bool checkNames=true)
Set all sequence names.
const Sequence & getSequence(const std::string &name) const
Retrieve a sequence object from the container.
int & operator()(const std::string &sequenceName, size_t elementIndex)
Element access operator.
const int & valueAt(const std::string &sequenceName, size_t elementIndex) const
Element access function.
Sequence * removeSequence(const std::string &name)
Extract (and remove) a sequence from the container.
size_t getSequencePosition(const std::string &name) const
Get the position of a sequence in sequence container from its name.
The sequence interface.
Definition: Sequence.h:74
int & valueAt(size_t sequenceIndex, size_t elementIndex)
Element access operator.
virtual ~VectorSequenceContainer()
Container destructor: delete all sequences in the container.
void clear()
Delete all sequences in the container.
std::vector< std::string > getSequencesNames() const
Get all the names of the sequences in the container.
Exception thrown when two alphabets do not match.
VectorSequenceContainer(const std::vector< const Sequence *> &vs, const Alphabet *alpha)
Build a new container from a std::vector of pointers toward sequence objects.
VectorSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no sequence inside.
The SequenceContainer interface.