bpp-seq  2.2.0
bpp::Site Class Reference

The Site class. More...

#include <Bpp/Seq/Site.h>

+ Inheritance diagram for bpp::Site:
+ Collaboration diagram for bpp::Site:

Public Member Functions

 Site (const Alphabet *alpha)
 Build a new void Site object with the specified alphabet. More...
 
 Site (const Alphabet *alpha, int position)
 Build a new void Site object with the specified alphabet and position. More...
 
 Site (const std::vector< std::string > &site, const Alphabet *alpha) throw (BadCharException)
 Build a new Site object with the specified alphabet. The content of the site is initialized from a vector of characters. More...
 
 Site (const std::vector< std::string > &site, const Alphabet *alpha, int position) throw (BadCharException)
 Build a new Site object with the specified alphabet and position. The content of the site is initialized from a vector of characters. More...
 
 Site (const std::vector< int > &site, const Alphabet *alpha) throw (BadIntException)
 Build a new Site object with the specified alphabet. The content of the site is initialized from a vector of integers. More...
 
 Site (const std::vector< int > &site, const Alphabet *alpha, int position) throw (BadIntException)
 Build a new Site object with the specified alphabet and position. The content of the site is initialized from a vector of integers. More...
 
 Site (const Site &site)
 The copy constructor. More...
 
Siteoperator= (const Site &s)
 The assignment operator. More...
 
virtual ~Site ()
 
virtual const AlphabetgetAlphabet () const
 Get the alphabet associated to the list. More...
 
virtual size_t size () const
 Get the number of elements in the list. More...
 
virtual const std::vector< int > & getContent () const
 Get the whole content of the list as a vector of int. More...
 
virtual void setContent (const std::vector< int > &list) throw (BadIntException)
 Set the whole content of the list. More...
 
virtual void setContent (const std::vector< std::string > &list) throw (BadCharException)
 Set the whole content of the list. More...
 
virtual std::string toString () const
 Convert the list as a string. More...
 
virtual void addElement (const std::string &c) throw (BadCharException)
 Add a character to the end of the list. More...
 
virtual void addElement (size_t pos, const std::string &c) throw (BadCharException, IndexOutOfBoundsException)
 Add a character at a certain position in the list. More...
 
virtual void addElement (int v) throw (BadIntException)
 Add a character to the end of the list. More...
 
virtual void addElement (size_t pos, int v) throw (BadIntException, IndexOutOfBoundsException)
 Add a character at a certain position in the list. More...
 
virtual void setElement (size_t pos, const std::string &c) throw (BadCharException, IndexOutOfBoundsException)
 Set the element at position 'pos' to character 'c'. More...
 
virtual void setElement (size_t pos, int v) throw (BadIntException, IndexOutOfBoundsException)
 Set the element at position 'pos' to character 'v'. More...
 
virtual void deleteElement (size_t pos) throw (IndexOutOfBoundsException)
 Delete the element at position 'pos'. More...
 
virtual void deleteElements (size_t pos, size_t len) throw (IndexOutOfBoundsException)
 Delete the elements at position 'pos'. More...
 
virtual std::string getChar (size_t pos) const throw (IndexOutOfBoundsException)
 Get the element at position 'pos' as a character. More...
 
virtual int getValue (size_t pos) const throw (IndexOutOfBoundsException)
 Get the element at position 'pos' as an int. More...
 
virtual const int & operator[] (size_t i) const
 Operator [] overloaded for quick access to a character in list. More...
 
virtual int & operator[] (size_t i)
 Operator [] overloaded for quick access to a character in list. More...
 
virtual void shuffle ()
 Randomly shuffle the content of the list, with linear complexity. More...
 
The Clonable interface
Siteclone () const
 
Setting/getting the position of the site.
virtual int getPosition () const
 Get the position of this site. More...
 
virtual void setPosition (int position)
 Set the position of this site. More...
 

Protected Attributes

std::vector< int > content_
 The list content. More...
 

Private Attributes

int position_
 The position associated to this site. More...
 

Detailed Description

The Site class.

Define specific attributes and methods for sites manipulation. It is very similar to the Sequence object (a site is a vertical sequence!), and characters at each position are coded as integers. Sites have a 'position' attribute. This attribute stands for an indice in a an alignment, and may be used as a unique identifier, in the same manner that names identify sequence objects. But for now, we do not allow to construct a Site directly from a string. This should not be a constraint, since you never read sites directly from a file.

Definition at line 61 of file Site.h.

Constructor & Destructor Documentation

◆ Site() [1/7]

Site::Site ( const Alphabet alpha)

Build a new void Site object with the specified alphabet.

Parameters
alphaThe alphabet to use.

Definition at line 54 of file Site.cpp.

Referenced by clone().

◆ Site() [2/7]

Site::Site ( const Alphabet alpha,
int  position 
)

Build a new void Site object with the specified alphabet and position.

Parameters
alphaThe alphabet to use.
positionThe position attribute for this site.

Definition at line 56 of file Site.cpp.

◆ Site() [3/7]

Site::Site ( const std::vector< std::string > &  site,
const Alphabet alpha 
)
throw (BadCharException
)

Build a new Site object with the specified alphabet. The content of the site is initialized from a vector of characters.

Parameters
siteThe content of the site.
alphaThe alphabet to use.
Exceptions
BadCharExceptionIf the content does not match the specified alphabet.

Definition at line 58 of file Site.cpp.

◆ Site() [4/7]

Site::Site ( const std::vector< std::string > &  site,
const Alphabet alpha,
int  position 
)
throw (BadCharException
)

Build a new Site object with the specified alphabet and position. The content of the site is initialized from a vector of characters.

Parameters
siteThe content of the site.
alphaThe alphabet to use.
positionThe position attribute for this site.
Exceptions
BadCharExceptionIf the content does not match the specified alphabet.

Definition at line 60 of file Site.cpp.

◆ Site() [5/7]

Site::Site ( const std::vector< int > &  site,
const Alphabet alpha 
)
throw (BadIntException
)

Build a new Site object with the specified alphabet. The content of the site is initialized from a vector of integers.

Parameters
siteThe content of the site.
alphaThe alphabet to use.
Exceptions
BadIntExceptionIf the content does not match the specified alphabet.

Definition at line 62 of file Site.cpp.

◆ Site() [6/7]

Site::Site ( const std::vector< int > &  site,
const Alphabet alpha,
int  position 
)
throw (BadIntException
)

Build a new Site object with the specified alphabet and position. The content of the site is initialized from a vector of integers.

Parameters
siteThe content of the site.
alphaThe alphabet to use.
positionThe position attribute for this site.
Exceptions
BadIntExceptionIf the content does not match the specified alphabet.

Definition at line 64 of file Site.cpp.

◆ Site() [7/7]

Site::Site ( const Site site)

The copy constructor.

Definition at line 68 of file Site.cpp.

◆ ~Site()

virtual bpp::Site::~Site ( )
inlinevirtual

Definition at line 139 of file Site.h.

Member Function Documentation

◆ addElement() [1/4]

void BasicSymbolList::addElement ( const std::string &  c)
throw (BadCharException
)
virtualinherited

Add a character to the end of the list.

Parameters
cThe character to add, given as a string.

Implements bpp::SymbolList.

Definition at line 121 of file SymbolList.cpp.

Referenced by bpp::NucleicAcidsReplication::reverse(), and bpp::NucleicAcidsReplication::translate().

◆ addElement() [2/4]

void BasicSymbolList::addElement ( size_t  pos,
const std::string &  c 
)
throw (BadCharException,
IndexOutOfBoundsException
)
virtualinherited

Add a character at a certain position in the list.

Parameters
posThe postion where to insert the element.
cThe character to add, given as a string.

Implements bpp::SymbolList.

Definition at line 128 of file SymbolList.cpp.

◆ addElement() [3/4]

void BasicSymbolList::addElement ( int  v)
throw (BadIntException
)
virtualinherited

Add a character to the end of the list.

Parameters
vThe character to add, given as an int.

Implements bpp::SymbolList.

Definition at line 181 of file SymbolList.cpp.

◆ addElement() [4/4]

void BasicSymbolList::addElement ( size_t  pos,
int  v 
)
throw (BadIntException,
IndexOutOfBoundsException
)
virtualinherited

Add a character at a certain position in the list.

Parameters
posThe postion where to insert the element.
vThe character to add, given as an int.

Implements bpp::SymbolList.

Definition at line 190 of file SymbolList.cpp.

◆ clone()

Site* bpp::Site::clone ( ) const
inlinevirtual

Implements bpp::SymbolList.

Definition at line 148 of file Site.h.

References Site().

◆ deleteElement()

void BasicSymbolList::deleteElement ( size_t  pos)
throw (IndexOutOfBoundsException
)
virtualinherited

Delete the element at position 'pos'.

Parameters
posThe position of the element to delete.

Implements bpp::SymbolList.

Definition at line 163 of file SymbolList.cpp.

Referenced by bpp::AlignedSequenceContainer::removeSite().

◆ deleteElements()

void BasicSymbolList::deleteElements ( size_t  pos,
size_t  len 
)
throw (IndexOutOfBoundsException
)
virtualinherited

Delete the elements at position 'pos'.

Parameters
posThe position of the first element to delete.
lenThe length of the region to delete.

Implements bpp::SymbolList.

Definition at line 172 of file SymbolList.cpp.

◆ getAlphabet()

virtual const Alphabet* bpp::BasicSymbolList::getAlphabet ( ) const
inlinevirtualinherited

◆ getChar()

string BasicSymbolList::getChar ( size_t  pos) const
throw (IndexOutOfBoundsException
)
virtualinherited

Get the element at position 'pos' as a character.

Parameters
posThe position of the character to retrieve.

Implements bpp::SymbolList.

Definition at line 145 of file SymbolList.cpp.

Referenced by bpp::SiteContainerTools::resolveDottedAlignment().

◆ getContent()

virtual const std::vector<int>& bpp::BasicSymbolList::getContent ( ) const
inlinevirtualinherited

Get the whole content of the list as a vector of int.

Returns
A reference to the content of the list.

Implements bpp::SymbolList.

Definition at line 352 of file SymbolList.h.

References bpp::BasicSymbolList::content_.

Referenced by operator=(), and bpp::BasicSymbolList::operator=().

◆ getPosition()

virtual int bpp::Site::getPosition ( ) const
inlinevirtual

Get the position of this site.

Returns
This site position.

Definition at line 162 of file Site.h.

References position_.

Referenced by bpp::SiteContainerTools::merge(), bpp::operator<(), operator=(), bpp::operator==(), and bpp::SiteContainerTools::resolveDottedAlignment().

◆ getValue()

int BasicSymbolList::getValue ( size_t  pos) const
throw (IndexOutOfBoundsException
)
virtualinherited

Get the element at position 'pos' as an int.

Parameters
posThe position of the character to retrieve.

Implements bpp::SymbolList.

Definition at line 212 of file SymbolList.cpp.

Referenced by bpp::CodonSiteTools::generateCodonSiteWithoutRareVariant(), bpp::CodonSiteTools::isFourFoldDegenerated(), and bpp::CodonSiteTools::numberOfSubsitutions().

◆ operator=()

Site & Site::operator= ( const Site s)

The assignment operator.

Definition at line 70 of file Site.cpp.

References bpp::BasicSymbolList::content_, bpp::BasicSymbolList::getContent(), getPosition(), and position_.

◆ operator[]() [1/2]

virtual const int& bpp::BasicSymbolList::operator[] ( size_t  i) const
inlinevirtualinherited

Operator [] overloaded for quick access to a character in list.

Parameters
iThe position to retrieve.
Returns
The integer value of character at position i.

Implements bpp::SymbolList.

Definition at line 380 of file SymbolList.h.

References bpp::BasicSymbolList::content_.

◆ operator[]() [2/2]

virtual int& bpp::BasicSymbolList::operator[] ( size_t  i)
inlinevirtualinherited

Operator [] overloaded for quick access to a character in list.

Parameters
iThe position to retrieve.
Returns
The integer value of character at position i.

Implements bpp::SymbolList.

Definition at line 382 of file SymbolList.h.

References bpp::BasicSymbolList::content_.

◆ setContent() [1/2]

void BasicSymbolList::setContent ( const std::vector< int > &  list)
throw (BadIntException
)
virtualinherited

Set the whole content of the list.

Parameters
listThe new content of the list.
See also
The list constructor for information about the way lists are internaly stored.

Implements bpp::SymbolList.

Reimplemented in bpp::BasicSequence.

Definition at line 101 of file SymbolList.cpp.

Referenced by bpp::BasicSequence::setContent().

◆ setContent() [2/2]

void BasicSymbolList::setContent ( const std::vector< std::string > &  list)
throw (BadCharException
)
virtualinherited

Set the whole content of the list.

Parameters
listThe new content of the list.
See also
The list constructor for information about the way lists are internaly stored.

Implements bpp::SymbolList.

Reimplemented in bpp::BasicSequence.

Definition at line 85 of file SymbolList.cpp.

◆ setElement() [1/2]

void BasicSymbolList::setElement ( size_t  pos,
const std::string &  c 
)
throw (BadCharException,
IndexOutOfBoundsException
)
virtualinherited

Set the element at position 'pos' to character 'c'.

Parameters
posThe position of the character to set.
cThe value of the element, given as a string.

Implements bpp::SymbolList.

Definition at line 136 of file SymbolList.cpp.

◆ setElement() [2/2]

void BasicSymbolList::setElement ( size_t  pos,
int  v 
)
throw (BadIntException,
IndexOutOfBoundsException
)
virtualinherited

Set the element at position 'pos' to character 'v'.

Parameters
posThe position of the character to set.
vThe value of the element, given as an int.

Implements bpp::SymbolList.

Definition at line 201 of file SymbolList.cpp.

◆ setPosition()

virtual void bpp::Site::setPosition ( int  position)
inlinevirtual

Set the position of this site.

Parameters
positionThe new position of the site.

Definition at line 169 of file Site.h.

References position_.

Referenced by bpp::VectorSiteContainer::addSite().

◆ shuffle()

virtual void bpp::BasicSymbolList::shuffle ( )
inlinevirtualinherited

Randomly shuffle the content of the list, with linear complexity.

Implements bpp::SymbolList.

Definition at line 384 of file SymbolList.h.

References bpp::BasicSymbolList::content_.

◆ size()

◆ toString()

string BasicSymbolList::toString ( ) const
virtualinherited

Convert the list as a string.

This method is useful for dumping a list to a file or to the screen for display.

Returns
The whole list as a string.

Implements bpp::SymbolList.

Definition at line 114 of file SymbolList.cpp.

References bpp::BasicSymbolList::alphabet_, bpp::BasicSymbolList::content_, and bpp::StringSequenceTools::decodeSequence().

Member Data Documentation

◆ content_

◆ position_

int bpp::Site::position_
private

The position associated to this site.

Definition at line 68 of file Site.h.

Referenced by getPosition(), operator=(), and setPosition().


The documentation for this class was generated from the following files: