bpp-seq3  3.0.0
Site.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_SITE_H
6 #define BPP_SEQ_SITE_H
7 
8 
9 #include "CoreSite.h"
10 #include "IntSymbolList.h"
11 #include "SiteExceptions.h"
12 
13 namespace bpp
14 {
22  public virtual CoreSiteInterface,
23  public virtual IntSymbolListInterface
24 {
25 public:
26  virtual ~SiteInterface() {}
27 
28 public:
29  SiteInterface* clone() const override = 0;
30 
31  virtual bool operator==(const SiteInterface& site)
32  {
33  // Verify that site's size, position and content are equals
34  if (site.size() != size())
35  return false;
36  if (site.getCoordinate() != getCoordinate())
37  {
38  return false;
39  }
40  else
41  {
42  for (size_t i = 0; i < site.size(); ++i)
43  {
44  if (site[i] != operator[](i))
45  return false;
46  }
47  return true;
48  }
49  }
50 
51  virtual bool operator<(const SiteInterface& site)
52  {
53  return site.getCoordinate() < getCoordinate();
54  }
55 };
56 
69 class Site :
70  public virtual SiteInterface,
71  public AbstractCoreSite,
72  public IntSymbolList
73 {
74 public:
80  Site(std::shared_ptr<const Alphabet>& alphabet) :
84  {}
85 
92  Site(std::shared_ptr<const Alphabet>& alphabet, int coordinate) :
94  AbstractCoreSite(coordinate),
96  {}
97 
106  Site(const std::vector<std::string>& site, std::shared_ptr<const Alphabet>& alphabet) :
109  IntSymbolList(site, alphabet)
110  {}
111 
121  Site(const std::vector<std::string>& site, std::shared_ptr<const Alphabet>& alphabet, int coordinate) :
123  AbstractCoreSite(coordinate),
124  IntSymbolList(site, alphabet)
125  {}
126 
135  Site(const std::vector<int>& site, std::shared_ptr<const Alphabet>& alphabet) :
138  IntSymbolList(site, alphabet)
139  {}
140 
150  Site(const std::vector<int>& site, std::shared_ptr<const Alphabet> alphabet, int coordinate) :
152  AbstractCoreSite(coordinate),
153  IntSymbolList(site, alphabet)
154  {}
155 
159  Site(const Site& site) :
162  IntSymbolList(site)
163  {}
164 
168  Site& operator=(const Site& s)
169  {
173  return *this;
174  }
175 
176  virtual ~Site() {}
177 
178 public:
184  Site* clone() const { return new Site(*this); }
187  double getStateValueAt(size_t sequencePosition, int state) const
188  {
189  if (sequencePosition >= size()) throw IndexOutOfBoundsException("Site::getStateValueAt.", sequencePosition, 0, size() - 1);
190  return getAlphabet()->isResolvedIn((*this)[sequencePosition], state) ? 1. : 0.;
191  }
192 };
193 } // end of namespace bpp.
194 
195 #endif // BPP_SEQ_SITE_H
A partial implementation of the CoreSite interface.
Definition: CoreSite.h:80
AbstractCoreSite & operator=(const CoreSiteInterface &site)
Definition: CoreSite.h:124
int getCoordinate() const override
Get the coordinate associated to this site.
Definition: CoreSite.h:144
A partial implementation of a SymbolList object.
Definition: SymbolList.h:34
const Alphabet & alphabet() const override
Definition: SymbolList.h:122
std::shared_ptr< const Alphabet > getAlphabet() const override
Definition: SymbolList.h:120
size_t size() const override
Definition: SymbolList.h:124
AbstractTemplateSymbolList< T > & operator=(const TemplateCoreSymbolListInterface< T > &list)
The generic assignment operator.
Definition: SymbolList.h:95
The core site interface.
Definition: CoreSite.h:25
virtual int getCoordinate() const =0
Get the coordinate associated to this site.
virtual size_t size() const =0
Get the number of elements in the list.
The specific IntSymbolList interface.
Definition: IntSymbolList.h:29
A basic IntSymbolList object.
IntSymbolList & operator=(const IntSymbolListInterface &list)
The generic assignment operator.
The site interface.
Definition: Site.h:24
virtual bool operator==(const SiteInterface &site)
Definition: Site.h:31
SiteInterface * clone() const override=0
virtual bool operator<(const SiteInterface &site)
Definition: Site.h:51
virtual ~SiteInterface()
Definition: Site.h:26
The Site class.
Definition: Site.h:73
double getStateValueAt(size_t sequencePosition, int state) const
get value of a state at a position
Definition: Site.h:187
Site & operator=(const Site &s)
The assignment operator.
Definition: Site.h:168
Site(const std::vector< int > &site, std::shared_ptr< const Alphabet > alphabet, int coordinate)
Build a new Site object with the specified alphabet and position. The content of the site is initiali...
Definition: Site.h:150
Site * clone() const
Definition: Site.h:184
virtual ~Site()
Definition: Site.h:176
Site(const std::vector< std::string > &site, std::shared_ptr< const Alphabet > &alphabet)
Build a new Site object with the specified alphabet. The content of the site is initialized from a ve...
Definition: Site.h:106
Site(const std::vector< int > &site, std::shared_ptr< const Alphabet > &alphabet)
Build a new Site object with the specified alphabet. The content of the site is initialized from a ve...
Definition: Site.h:135
Site(const Site &site)
The copy constructor.
Definition: Site.h:159
Site(std::shared_ptr< const Alphabet > &alphabet, int coordinate)
Build a new void Site object with the specified alphabet and position.
Definition: Site.h:92
Site(const std::vector< std::string > &site, std::shared_ptr< const Alphabet > &alphabet, int coordinate)
Build a new Site object with the specified alphabet and position. The content of the site is initiali...
Definition: Site.h:121
Site(std::shared_ptr< const Alphabet > &alphabet)
Build a new void Site object with the specified alphabet.
Definition: Site.h:80
This alphabet is used to deal NumericAlphabet.