bpp-seq  2.2.0
MapSequenceContainer.h
Go to the documentation of this file.
1 //
2 // File MapSequenceContainer.h
3 // Authors : Guillaume Deuchst
4 // Julien Dutheil
5 // Sylvain Gaillard
6 // Last modification : Friday June 25 2004
7 //
8 
9 /*
10 Copyright or © or Copr. CNRS, (November 17, 2004)
11 
12 This software is a computer program whose purpose is to provide classes
13 for sequences analysis.
14 
15 This software is governed by the CeCILL license under French law and
16 abiding by the rules of distribution of free software. You can use,
17 modify and/ or redistribute the software under the terms of the CeCILL
18 license as circulated by CEA, CNRS and INRIA at the following URL
19 "http://www.cecill.info".
20 
21 As a counterpart to the access to the source code and rights to copy,
22 modify and redistribute granted by the license, users are provided only
23 with a limited warranty and the software's author, the holder of the
24 economic rights, and the successive licensors have only limited
25 liability.
26 
27 In this respect, the user's attention is drawn to the risks associated
28 with loading, using, modifying and/or developing or reproducing the
29 software by the user in light of its specific status of free software,
30 that may mean that it is complicated to manipulate, and that also
31 therefore means that it is reserved for developers and experienced
32 professionals having in-depth computer knowledge. Users are therefore
33 encouraged to load and test the software's suitability as regards their
34 requirements in conditions enabling the security of their systems and/or
35 data to be ensured and, more generally, to use and operate it in the
36 same conditions as regards security.
37 
38 The fact that you are presently reading this means that you have had
39 knowledge of the CeCILL license and that you accept its terms.
40 */
41 
42 #ifndef _MAPSEQUENCECONTAINER_H_
43 #define _MAPSEQUENCECONTAINER_H_
44 
45 #include "../Alphabet/Alphabet.h"
46 #include "../Sequence.h"
48 
49 #include <string>
50 #include <map>
51 
52 namespace bpp
53 {
54 
65 {
66  private:
67  std::map<std::string, Sequence*> sequences_;
68 
69  public:
70  MapSequenceContainer(const std::map<std::string, Sequence*>& ms, const Alphabet* alpha);
73 
76 
77  virtual ~MapSequenceContainer();
78 
79  public:
87  const Sequence& getSequenceByKey(const std::string& key) const throw (SequenceNotFoundException);
88 
97  void setSequenceByKey(const std::string& key , const Sequence& sequence, bool checkNames = true) throw (SequenceNotFoundException);
98 
106  Sequence* removeSequenceByKey(const std::string& key) throw (SequenceNotFoundException);
107 
114  void deleteSequenceByKey(const std::string& key) throw (SequenceNotFoundException);
115 
123  void addSequence(const std::string& key, const Sequence& sequence, bool checkNames = true) throw (Exception);
124 
128  std::vector<std::string> getKeys() const;
129 
135  std::string getKey(size_t pos) const throw (IndexOutOfBoundsException);
136 
142  std::string getKey(const std::string& name) const throw (SequenceNotFoundException);
143 
149  MapSequenceContainer* clone() const { return new MapSequenceContainer(*this); }
159  const Sequence& getSequence(const std::string& name) const throw (SequenceNotFoundException);
160 
161  bool hasSequence(const std::string& name) const;
162 
166  void addSequence(const Sequence& sequence, bool checkNames = true) throw (Exception)
167  {
168  addSequence(sequence.getName(), sequence, checkNames);
169  }
170  void setSequence(const std::string& name, const Sequence& sequence, bool checkName = true) throw (SequenceNotFoundException);
171  Sequence* removeSequence(const std::string& name) throw (SequenceNotFoundException);
172  void deleteSequence(const std::string& name) throw (SequenceNotFoundException);
173  size_t getNumberOfSequences() const { return sequences_.size(); }
174  void clear();
176 
177  int& valueAt(const std::string& sequenceName, size_t elementIndex) throw (SequenceNotFoundException, IndexOutOfBoundsException)
178  {
179  return getSequence_(sequenceName)[elementIndex];
180  }
181  const int& valueAt(const std::string& sequenceName, size_t elementIndex) const throw (SequenceNotFoundException, IndexOutOfBoundsException)
182  {
183  return getSequence(sequenceName)[elementIndex];
184  }
185  int& operator()(const std::string& sequenceName, size_t elementIndex)
186  {
187  return getSequence_(sequenceName)[elementIndex];
188  }
189  const int& operator()(const std::string & sequenceName, size_t elementIndex) const
190  {
191  return getSequence(sequenceName)[elementIndex];
192  }
193 
194  int& valueAt(size_t sequenceIndex, size_t elementIndex) throw (IndexOutOfBoundsException)
195  {
196  return getSequence_(sequenceIndex)[elementIndex];
197  }
198  const int& valueAt(size_t sequenceIndex, size_t elementIndex) const throw (IndexOutOfBoundsException)
199  {
200  return getSequence(sequenceIndex)[elementIndex];
201  }
202  int& operator()(size_t sequenceIndex, size_t elementIndex)
203  {
204  return getSequence_(sequenceIndex)[elementIndex];
205  }
206  const int& operator()(size_t sequenceIndex, size_t elementIndex) const
207  {
208  return getSequence(sequenceIndex)[elementIndex];
209  }
217  const Sequence& getSequence(size_t sequenceIndex) const throw (IndexOutOfBoundsException);
218  size_t getSequencePosition(const std::string& name) const throw (SequenceNotFoundException);
219  void setSequence(size_t sequenceIndex, const Sequence& sequence, bool checkName = true) throw (IndexOutOfBoundsException);
220  Sequence* removeSequence(size_t sequenceIndex) throw (IndexOutOfBoundsException);
221  void deleteSequence(size_t sequenceIndex) throw (IndexOutOfBoundsException);
222  void setComments(size_t sequenceIndex, const Comments& comments) throw (IndexOutOfBoundsException);
223  std::vector<std::string> getSequencesNames() const;
224  void setSequencesNames(const std::vector<std::string>& names, bool checkNames) throw (Exception);
232  Sequence& getSequence_(size_t i) throw (IndexOutOfBoundsException);
233  Sequence& getSequence_(const std::string& name) throw (SequenceNotFoundException);
235 };
236 
237 } //end of namespace bpp.
238 
239 #endif // _MAPSEQUENCECONTAINER_H_
240 
const int & valueAt(size_t sequenceIndex, size_t elementIndex) const
Element access operator.
Exception thrown when a sequence is not found The sequence not found exception base class...
size_t getNumberOfSequences() const
Get the number of sequences in the container.
std::vector< std::string > Comments
Declaration of Comments type.
Definition: Sequence.h:60
size_t getSequencePosition(const std::string &name) const
Get the position of a sequence in sequence container from its name.
Sequence & getSequence_(size_t i)
int & operator()(size_t sequenceIndex, size_t elementIndex)
Element access operator.
void addSequence(const std::string &key, const Sequence &sequence, bool checkNames=true)
Add a sequence and key.
void clear()
Delete all sequences in the container.
const int & operator()(const std::string &sequenceName, size_t elementIndex) const
Element access operator.
int & valueAt(const std::string &sequenceName, size_t elementIndex)
Element access function.
std::string getKey(size_t pos) const
This alphabet is used to deal NumericAlphabet.
MapSequenceContainer(const Alphabet *alpha)
int & operator()(const std::string &sequenceName, size_t elementIndex)
Element access operator.
The Alphabet interface.
Definition: Alphabet.h:130
void deleteSequenceByKey(const std::string &key)
Delete a sequence.
STL namespace.
Partial implementation of the OrderedSequenceContainer interface.
virtual const std::string & getName() const =0
Get the name of this sequence.
MapSequenceContainer class.
const Sequence & getSequenceByKey(const std::string &key) const
Get a sequence.
MapSequenceContainer(const std::map< std::string, Sequence *> &ms, const Alphabet *alpha)
const int & operator()(size_t sequenceIndex, size_t elementIndex) const
Element access operator.
const Sequence & getSequence(const std::string &name) const
Retrieve a sequence object from the container.
std::map< std::string, Sequence * > sequences_
void setComments(size_t sequenceIndex, const Comments &comments)
Set the comments of a particular sequence.
void addSequence(const Sequence &sequence, bool checkNames=true)
The SequenceContainer method. Calls the addSeqeucne(key, Sequence) method while using the resut of se...
std::vector< std::string > getSequencesNames() const
Get all the names of the sequences in the container.
const int & valueAt(const std::string &sequenceName, size_t elementIndex) const
Element access function.
int & valueAt(size_t sequenceIndex, size_t elementIndex)
Element access operator.
void setSequenceByKey(const std::string &key, const Sequence &sequence, bool checkNames=true)
Set a sequence.
MapSequenceContainer * clone() const
The sequence interface.
Definition: Sequence.h:74
Sequence * removeSequence(const std::string &name)
Extract (and remove) a sequence from the container.
MapSequenceContainer & operator=(const MapSequenceContainer &msc)
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
void setSequencesNames(const std::vector< std::string > &names, bool checkNames)
Set all sequence names.
std::vector< std::string > getKeys() const
void deleteSequence(const std::string &name)
Delete a sequence of the container.
Sequence * removeSequenceByKey(const std::string &key)
Remove a sequence.
MapSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no sequence inside.
bool hasSequence(const std::string &name) const
Check if a sequence with a given name is present in the container.