bpp-seq3  3.0.0
VectorProbabilisticSiteContainer.h
Go to the documentation of this file.
1 //
2 // File: VectorProbabilisticSiteContainer.h
3 // Authors:
4 // Murray Patterson
5 // Created: 2015-10-19 00:00:00
6 //
7 
8 /*
9  Copyright or © or Copr. CNRS, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for sequences 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 BPP_SEQ_CONTAINER_VECTORPROBABILISTICSITECONTAINER_H
42 #define BPP_SEQ_CONTAINER_VECTORPROBABILISTICSITECONTAINER_H
43 
44 
45 #include "../ProbabilisticSite.h"
47 #include "AlignedValuesContainer.h"
50 #include "VectorMappedContainer.h"
52 
53 // From the STL :
54 #include <vector>
55 
56 namespace bpp
57 {
74 // This container implements the SequenceContainer interface
75 // and use the AbstractSequenceContainer adapter.
76  public virtual ProbabilisticSiteContainer,
77 // This container is a SiteContainer.
78  virtual public VectorPositionedContainer<ProbabilisticSite>,
79  virtual public VectorMappedContainer<ProbabilisticSequence>
80 {
81 public:
88 
98  VectorProbabilisticSiteContainer(const std::vector<const CruxSymbolListSite*>& vs, const Alphabet* alpha, bool checkPositions = true);
99 
106 
114  VectorProbabilisticSiteContainer(const std::vector<std::string>& names, const Alphabet* alpha);
115 
130 
132 
133 
135 
137 
142  // class destructor
144 
145 public:
147 
148  /*
149  * @brief get Objects
150  *
151  * @{
152  */
153  const std::shared_ptr<ProbabilisticSite> getSite(size_t i) const
154  {
155  if (i >= getNumberOfSites())
156  throw IndexOutOfBoundsException("VectorProbabilisticSiteContainer::getProbabilisticSite.", i, 0, getNumberOfSites() - 1);
157 
159  }
160 
161  std::shared_ptr<ProbabilisticSite> getSite(size_t i)
162  {
163  if (i >= getNumberOfSites())
164  throw IndexOutOfBoundsException("VectorProbabilisticSiteContainer::getProbabilisticSite.", i, 0, getNumberOfSites() - 1);
165 
167  }
168 
175  const ProbabilisticSequence& getSequence(std::size_t i) const;
176 
182  const ProbabilisticSequence& getSequence(const std::string& name) const;
183 
184  bool hasSequence(const std::string& name) const
185  {
186  // Look for sequence name:
188  }
189 
190  size_t getSequencePosition(const std::string& name) const
191  {
192  // Look for sequence name:
194  }
195 
196  std::vector<std::string> getSequenceNames() const
197  {
199  }
200 
201  void setSequenceNames(const std::vector<std::string>& names, bool checkNames = true)
202  {
204  }
205 
206 
207  void setComments(size_t sequenceIndex, const Comments& comments)
208  {
209  VectorMappedContainer<ProbabilisticSequence>::getObject(sequenceIndex)->setComments(comments);
210  }
211 
212 
213  /*
214  * @}
215  *
216  */
217 
218 
225  /*
226  * @brief get value of a state in a position
227  * @param siteIndex index of the site in the container
228  * @param sequenceIndex index of the looked value in the site
229  * @param state state alphabet
230  */
231  double getStateValueAt(size_t siteIndex, const std::string& sequenceName, int state) const
232  {
233  if (siteIndex >= getNumberOfSites()) throw IndexOutOfBoundsException("VectorProbabilisticSiteContainer::getStateValueAt.", siteIndex, 0, getNumberOfSites() - 1);
234  return (*getSite(siteIndex))[getSequencePosition(sequenceName)][getAlphabet()->getStateIndex(state)-1];
235  }
236 
237  double operator()(size_t siteIndex, const std::string& sequenceName, int state) const
238  {
239  return (*getSite(siteIndex))[getSequencePosition(sequenceName)][getAlphabet()->getStateIndex(state)-1];
240  }
241 
242  /*
243  * @}
244  *
245  */
246 
253  /*
254  * @brief get value of a state in a position
255  * @param siteIndex index of the site in the container
256  * @param sequenceIndex index of the looked value in the site
257  * @param state state alphabet
258  */
259  double getStateValueAt(size_t siteIndex, size_t sequenceIndex, int state) const
260  {
261  if (sequenceIndex >= getNumberOfSequences()) throw IndexOutOfBoundsException("VectorProbabilisticSiteContainer::getStateValueAt.", sequenceIndex, 0, getNumberOfSequences() - 1);
262  if (siteIndex >= getNumberOfSites()) throw IndexOutOfBoundsException("VectorProbabilisticSiteContainer::getStateValueAt.", siteIndex, 0, getNumberOfSites() - 1);
263  return (*getSite(siteIndex))[sequenceIndex][getAlphabet()->getStateIndex(state)-1];
264  }
265 
266  double operator()(size_t siteIndex, size_t sequenceIndex, int state) const
267  {
268  return (*getSite(siteIndex))[sequenceIndex][getAlphabet()->getStateIndex(state)-1];
269  }
270 
271  /*
272  * @}
273  *
274  */
275 
276  /*
277  * @brief Append a Site. The shared_ptr is shared.
278  *
279  */
280 
281  void addSite(std::shared_ptr<ProbabilisticSite> site, bool checkPosition = false);
282 
283  /*
284  * @brief Add a Sequence of sites. Sites are copied.
285  *
286  */
287 
288  void addSequence(const ProbabilisticSequence& sequence, bool checkName = true);
289 
290  void addSequence(const Sequence& sequence, bool checkName = true);
291 
292  void setSequence(const std::string& name, const ProbabilisticSequence& sequence, bool checkName);
293 
294  void setSequence(size_t sequenceIndex, const ProbabilisticSequence& sequence, bool checkName);
295 
296  void clear();
297 
299 
300  /*
301  * @name From AlignedValuesContainer interface
302  *
303  * @{
304  */
305  void deleteSites(size_t siteIndex, size_t length)
306  {
308  }
309 
310  size_t getNumberOfSites() const
311  {
313  }
314 
315  void reindexSites();
316 
317  Vint getSitePositions() const;
318 
319  void setSitePositions(Vint vPositions);
320 
321 protected:
322  // Create n void sites:
323  void realloc(size_t n);
324 
326 };
327 } // end of namespace bpp
328 #endif // BPP_SEQ_CONTAINER_VECTORPROBABILISTICSITECONTAINER_H
Partial implementation of the OrderedSequenceContainer interface.
const Alphabet * getAlphabet() const
Get container's alphabet.
The Container of Aligned Values interface.
The Alphabet interface.
Definition: Alphabet.h:133
virtual size_t getStateIndex(int state) const =0
The OrderedSequenceContainer interface.
The probabilistic sequence interface.
The ProbabilisticSiteContainer interface.
The sequence interface.
Definition: Sequence.h:71
The template VectorMappedContainer class.
const std::shared_ptr< T > getObject(size_t objectIndex) const
Retrieve an object from the container. Set as protected since they will be public under T specific na...
size_t getObjectPosition(const std::string &name) const
Link between position & name.
bool hasObject(const std::string &name) const
Check if a object with a given name is present in the container.
std::vector< std::string > getObjectNames() const
void setObjectNames(const std::vector< std::string > &names)
size_t getSize() const
Get the number of objects in the container.
The template VectorPositionedContainer class.
const std::shared_ptr< T > getObject(size_t objectIndex) const
Retrieve an object from the container. Set as protected since they will be public under T specific na...
void deleteObjects(size_t objectIndex, size_t length)
The VectorProbabilisticSiteContainer class.
Vint getSitePositions() const
Get all position attributes of sites.
void deleteSites(size_t siteIndex, size_t length)
Remove a continuous range of sites in the container.
VectorProbabilisticSiteContainer & operator=(const VectorProbabilisticSiteContainer &vpsc)
void setSequence(const std::string &name, const ProbabilisticSequence &sequence, bool checkName)
Replace a probabilistic sequence in the container.
VectorProbabilisticSiteContainer(const Alphabet *alpha)
Build a new emtpy container.
double operator()(size_t siteIndex, const std::string &sequenceName, int state) const
const ProbabilisticSequence & getSequence(std::size_t i) const
Get Sequence from a position in the container.
double getStateValueAt(size_t siteIndex, const std::string &sequenceName, int state) const
get value of a state in a position
bool hasSequence(const std::string &name) const
Check if a sequence with a given name is present in the container.
void setComments(size_t sequenceIndex, const Comments &comments)
void addSite(std::shared_ptr< ProbabilisticSite > site, bool checkPosition=false)
Add a site at the end of the container.
size_t getNumberOfSites() const
Get the number of aligned positions in the container.
std::shared_ptr< ProbabilisticSite > getSite(size_t i)
void setSequenceNames(const std::vector< std::string > &names, bool checkNames=true)
Set all sequence names.
void clear()
Delete all objects in the container.
size_t getNumberOfSequences() const
Get the number of sequences in the container.
std::vector< std::string > getSequenceNames() const
Get all the names of the sequences in the container.
const std::shared_ptr< ProbabilisticSite > getSite(size_t i) const
Get a site from the container.
void addSequence(const ProbabilisticSequence &sequence, bool checkName=true)
Add a probabilistic sequence to the container.
double operator()(size_t siteIndex, size_t sequenceIndex, int state) const
double getStateValueAt(size_t siteIndex, size_t sequenceIndex, int state) const
VectorProbabilisticSiteContainer * clone() const
size_t getSequencePosition(const std::string &name) const
Get the position of a sequence in sequence container from its name.
VectorProbabilisticSiteContainer * createEmptyContainer() const
Return a copy of this container, but with no data inside.
void setSitePositions(Vint vPositions)
Set all position attributes of sites.
This alphabet is used to deal NumericAlphabet.
std::vector< int > Vint
std::vector< std::string > Comments
Declaration of Comments type.
Definition: Commentable.h:58