bpp-seq3  3.0.0
MapSequenceContainer.h
Go to the documentation of this file.
1 //
2 // File: MapSequenceContainer.h
3 // Authors:
4 // Guillaume Deuchst
5 // Julien Dutheil
6 // Sylvain Gaillard
7 // Last modified: 2004-06-25 00:00:00
8 //
9 
10 /*
11  Copyright or © or Copr. CNRS, (November 17, 2004)
12 
13  This software is a computer program whose purpose is to provide classes
14  for sequences analysis.
15 
16  This software is governed by the CeCILL license under French law and
17  abiding by the rules of distribution of free software. You can use,
18  modify and/ or redistribute the software under the terms of the CeCILL
19  license as circulated by CEA, CNRS and INRIA at the following URL
20  "http://www.cecill.info".
21 
22  As a counterpart to the access to the source code and rights to copy,
23  modify and redistribute granted by the license, users are provided only
24  with a limited warranty and the software's author, the holder of the
25  economic rights, and the successive licensors have only limited
26  liability.
27 
28  In this respect, the user's attention is drawn to the risks associated
29  with loading, using, modifying and/or developing or reproducing the
30  software by the user in light of its specific status of free software,
31  that may mean that it is complicated to manipulate, and that also
32  therefore means that it is reserved for developers and experienced
33  professionals having in-depth computer knowledge. Users are therefore
34  encouraged to load and test the software's suitability as regards their
35  requirements in conditions enabling the security of their systems and/or
36  data to be ensured and, more generally, to use and operate it in the
37  same conditions as regards security.
38 
39  The fact that you are presently reading this means that you have had
40  knowledge of the CeCILL license and that you accept its terms.
41 */
42 
43 #ifndef BPP_SEQ_CONTAINER_MAPSEQUENCECONTAINER_H
44 #define BPP_SEQ_CONTAINER_MAPSEQUENCECONTAINER_H
45 
46 #include <map>
47 #include <string>
48 
49 #include "../Alphabet/Alphabet.h"
50 #include "../Sequence.h"
52 
53 namespace bpp
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:
86  const Sequence& getSequenceByKey(const std::string& key) const;
87 
95  void setSequenceByKey(const std::string& key, const Sequence& sequence, bool checkNames = true);
96 
103  Sequence* removeSequenceByKey(const std::string& key);
104 
110  void deleteSequenceByKey(const std::string& key);
111 
119  void addSequence(const std::string& key, const Sequence& sequence, bool checkNames = true);
120 
124  std::vector<std::string> getKeys() const;
125 
130  std::string getKey(size_t pos) const;
131 
136  std::string getKey(const std::string& name) const;
137 
143  MapSequenceContainer* clone() const { return new MapSequenceContainer(*this); }
153  const Sequence& getSequence(const std::string& name) const;
154 
155  bool hasSequence(const std::string& name) const;
156 
160  void addSequence(const Sequence& sequence, bool checkNames = true)
161  {
162  addSequence(sequence.getName(), sequence, checkNames);
163  }
164  void setSequence(const std::string& name, const Sequence& sequence, bool checkName = true);
165  Sequence* removeSequence(const std::string& name);
166  void deleteSequence(const std::string& name);
167  size_t getNumberOfSequences() const { return sequences_.size(); }
168  void clear();
170 
171  int& valueAt(const std::string& sequenceName, size_t elementIndex)
172  {
173  return getSequence_(sequenceName)[elementIndex];
174  }
175  const int& valueAt(const std::string& sequenceName, size_t elementIndex) const
176  {
177  return getSequence(sequenceName)[elementIndex];
178  }
179  int& operator()(const std::string& sequenceName, size_t elementIndex)
180  {
181  return getSequence_(sequenceName)[elementIndex];
182  }
183  const int& operator()(const std::string& sequenceName, size_t elementIndex) const
184  {
185  return getSequence(sequenceName)[elementIndex];
186  }
187 
188  int& valueAt(size_t sequenceIndex, size_t elementIndex)
189  {
190  return getSequence_(sequenceIndex)[elementIndex];
191  }
192  const int& valueAt(size_t sequenceIndex, size_t elementIndex) const
193  {
194  return getSequence(sequenceIndex)[elementIndex];
195  }
196  int& operator()(size_t sequenceIndex, size_t elementIndex)
197  {
198  return getSequence_(sequenceIndex)[elementIndex];
199  }
200  const int& operator()(size_t sequenceIndex, size_t elementIndex) const
201  {
202  return getSequence(sequenceIndex)[elementIndex];
203  }
211  const Sequence& getSequence(size_t sequenceIndex) const;
212  size_t getSequencePosition(const std::string& name) const;
213  void setSequence(size_t sequenceIndex, const Sequence& sequence, bool checkName = true);
214  Sequence* removeSequence(size_t sequenceIndex);
215  void deleteSequence(size_t sequenceIndex);
216  void setComments(size_t sequenceIndex, const Comments& comments);
217  std::vector<std::string> getSequencesNames() const;
218  void setSequencesNames(const std::vector<std::string>& names, bool checkNames);
226  Sequence& getSequence_(size_t i);
227  Sequence& getSequence_(const std::string& name);
235  double getStateValueAt(size_t siteIndex, const std::string& sequenceName, int state) const
236  {
237  return getSequence(sequenceName).getStateValueAt(siteIndex, state);
238  }
239 
240  double operator()(size_t siteIndex, const std::string& sequenceName, int state) const
241  {
242  return getSequence(sequenceName)(siteIndex, state);
243  }
244 
245  /*
246  *
247  * @}
248  *
249  */
250 
256  double getStateValueAt(size_t siteIndex, size_t sequenceIndex, int state) const
257  {
258  if (sequenceIndex >= getNumberOfSequences()) throw IndexOutOfBoundsException("VectorSequenceContainer::getStateValueAt.", sequenceIndex, 0, getNumberOfSequences() - 1);
259  const Sequence& seq = getSequence(sequenceIndex);
260 
261  if (siteIndex >= seq.size())
262  throw IndexOutOfBoundsException("VectorSequenceContainer::getStateValueAt.", siteIndex, 0, seq.size() - 1);
263 
264  return getAlphabet()->isResolvedIn(seq[siteIndex], state) ? 1. : 0.;
265  }
266 
267  double operator()(size_t siteIndex, size_t sequenceIndex, int state) const
268  {
269  return getAlphabet()->isResolvedIn(getSequence(sequenceIndex)[siteIndex], state) ? 1. : 0.;
270  }
271 
272  /*
273  *
274  * @}
275  *
276  */
277 };
278 } // end of namespace bpp.
279 #endif // BPP_SEQ_CONTAINER_MAPSEQUENCECONTAINER_H
Partial implementation of the OrderedSequenceContainer interface.
const Alphabet * getAlphabet() const
Get container's alphabet.
The Alphabet interface.
Definition: Alphabet.h:131
virtual bool isResolvedIn(int state1, int state2) const =0
Tells if a given (potentially unresolved) state can be resolved in another resolved state.
virtual double getStateValueAt(size_t siteIndex, int state) const
virtual size_t size() const =0
Get the number of elements in the list.
MapSequenceContainer class.
MapSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no data inside.
const int & operator()(const std::string &sequenceName, size_t elementIndex) const
Element access operator.
void deleteSequence(const std::string &name)
void clear()
Delete all data in the container.
void addSequence(const std::string &key, const Sequence &sequence, bool checkNames=true)
Add a sequence and key.
const int & valueAt(const std::string &sequenceName, size_t elementIndex) const
Element access function.
MapSequenceContainer(const std::map< std::string, Sequence * > &ms, const Alphabet *alpha)
void setSequenceByKey(const std::string &key, const Sequence &sequence, bool checkNames=true)
Set a sequence.
MapSequenceContainer & operator=(const MapSequenceContainer &msc)
double getStateValueAt(size_t siteIndex, size_t sequenceIndex, int state) const
Sequence * removeSequence(const std::string &name)
Extract (and remove) a sequence from the container.
MapSequenceContainer * clone() const
size_t getSequencePosition(const std::string &name) const
Get the position of a sequence in sequence container from its name.
const int & valueAt(size_t sequenceIndex, size_t elementIndex) const
Element access operator.
Sequence * removeSequenceByKey(const std::string &key)
Remove a sequence.
double operator()(size_t siteIndex, size_t sequenceIndex, int state) const
int & valueAt(size_t sequenceIndex, size_t elementIndex)
Element access operator.
void addSequence(const Sequence &sequence, bool checkNames=true)
The SequenceContainer method. Calls the addSeqeucne(key, Sequence) method while using the resut of se...
int & operator()(size_t sequenceIndex, size_t elementIndex)
Element access operator.
bool hasSequence(const std::string &name) const
Check if a sequence with a given name is present in the container.
size_t getNumberOfSequences() const
Get the number of sequences in the container.
const Sequence & getSequenceByKey(const std::string &key) const
Get a sequence.
const int & operator()(size_t sequenceIndex, size_t elementIndex) const
Element access operator.
std::vector< std::string > getKeys() const
std::map< std::string, Sequence * > sequences_
int & operator()(const std::string &sequenceName, size_t elementIndex)
Element access operator.
double getStateValueAt(size_t siteIndex, const std::string &sequenceName, int state) const
get value of a state in a position
std::vector< std::string > getSequencesNames() const
Get all the names of the sequences in the container.
const Sequence & getSequence(const std::string &name) const
Retrieve a sequence object from the container.
void setSequencesNames(const std::vector< std::string > &names, bool checkNames)
Set all sequence names.
double operator()(size_t siteIndex, const std::string &sequenceName, int state) const
Sequence & getSequence_(size_t i)
MapSequenceContainer(const Alphabet *alpha)
void deleteSequenceByKey(const std::string &key)
Delete a sequence.
std::string getKey(size_t pos) const
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
int & valueAt(const std::string &sequenceName, size_t elementIndex)
Element access function.
virtual void setComments(size_t sequenceIndex, const Comments &comments)=0
The sequence interface.
Definition: Sequence.h:71
virtual const std::string & getName() const =0
Get the name of this sequence.
This alphabet is used to deal NumericAlphabet.
std::vector< std::string > Comments
Declaration of Comments type.
Definition: Commentable.h:57