bpp-seq  2.2.0
bpp::BasicSymbolList Class Reference

A basic SymbolList object. More...

#include <Bpp/Seq/SymbolList.h>

+ Inheritance diagram for bpp::BasicSymbolList:
+ Collaboration diagram for bpp::BasicSymbolList:

Public Member Functions

 BasicSymbolList (const Alphabet *alpha)
 Build a new void BasicSymbolList object with the specified alphabet. More...
 
 BasicSymbolList (const std::vector< std::string > &list, const Alphabet *alpha) throw (BadCharException)
 Build a new BasicSymbolList object with the specified alphabet. The content of the site is initialized from a vector of characters. More...
 
 BasicSymbolList (const std::vector< int > &list, const Alphabet *alpha) throw (BadIntException)
 Build a new BasicSymbolList object with the specified alphabet. The content of the site is initialized from a vector of integers. More...
 
 BasicSymbolList (const SymbolList &list)
 The generic copy constructor. More...
 
 BasicSymbolList (const BasicSymbolList &list)
 The copy constructor. More...
 
BasicSymbolListoperator= (const SymbolList &list)
 The generic assignment operator. More...
 
BasicSymbolListoperator= (const BasicSymbolList &list)
 The assignment operator. More...
 
virtual ~BasicSymbolList ()
 
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 setElement (size_t pos, const std::string &c) throw (BadCharException, IndexOutOfBoundsException)
 Set the element at position 'pos' to character 'c'. 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 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, int v) throw (BadIntException, IndexOutOfBoundsException)
 Set the element at position 'pos' to character 'v'. 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
BasicSymbolListclone () const
 

Protected Attributes

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

Private Attributes

const Alphabetalphabet_
 The Alphabet attribute must be initialized in constructor and then can never be changed. More...
 

Detailed Description

A basic SymbolList object.

This is a general purpose container, containing an ordered list of states(= letters). The states that allowed to be present in the list are defined by an alphabet object, which is passed to the list constructor by a pointer.

For programming convenience, the states are stored as integers, but the translation toward and from a char description is easily performed with the Alphabet classes.

See also
Alphabet

Definition at line 264 of file SymbolList.h.

Constructor & Destructor Documentation

◆ BasicSymbolList() [1/5]

bpp::BasicSymbolList::BasicSymbolList ( const Alphabet alpha)
inline

Build a new void BasicSymbolList object with the specified alphabet.

Parameters
alphaThe alphabet to use.

Definition at line 288 of file SymbolList.h.

Referenced by clone().

◆ BasicSymbolList() [2/5]

BasicSymbolList::BasicSymbolList ( const std::vector< std::string > &  list,
const Alphabet alpha 
)
throw (BadCharException
)

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

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

Definition at line 49 of file SymbolList.cpp.

◆ BasicSymbolList() [3/5]

BasicSymbolList::BasicSymbolList ( const std::vector< int > &  list,
const Alphabet alpha 
)
throw (BadIntException
)

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

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

Definition at line 55 of file SymbolList.cpp.

◆ BasicSymbolList() [4/5]

BasicSymbolList::BasicSymbolList ( const SymbolList list)

The generic copy constructor.

Definition at line 63 of file SymbolList.cpp.

◆ BasicSymbolList() [5/5]

BasicSymbolList::BasicSymbolList ( const BasicSymbolList list)

The copy constructor.

Definition at line 66 of file SymbolList.cpp.

◆ ~BasicSymbolList()

virtual bpp::BasicSymbolList::~BasicSymbolList ( )
inlinevirtual

Definition at line 344 of file SymbolList.h.

Member Function Documentation

◆ addElement() [1/4]

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

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
)
virtual

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
)
virtual

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
)
virtual

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()

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

Implements bpp::SymbolList.

Definition at line 340 of file SymbolList.h.

References BasicSymbolList().

◆ deleteElement()

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

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
)
virtual

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
inlinevirtual

◆ getChar()

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

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
inlinevirtual

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 content_.

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

◆ getValue()

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

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=() [1/2]

BasicSymbolList & BasicSymbolList::operator= ( const SymbolList list)

The generic assignment operator.

Definition at line 69 of file SymbolList.cpp.

References alphabet_, content_, bpp::SymbolList::getAlphabet(), and bpp::SymbolList::getContent().

Referenced by bpp::BasicSequence::operator=().

◆ operator=() [2/2]

BasicSymbolList & BasicSymbolList::operator= ( const BasicSymbolList list)

The assignment operator.

Definition at line 76 of file SymbolList.cpp.

References alphabet_, content_, getAlphabet(), and getContent().

◆ operator[]() [1/2]

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

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 content_.

◆ operator[]() [2/2]

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

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 content_.

◆ setContent() [1/2]

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

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
)
virtual

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
)
virtual

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
)
virtual

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.

◆ shuffle()

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

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

Implements bpp::SymbolList.

Definition at line 384 of file SymbolList.h.

References content_.

◆ size()

◆ toString()

string BasicSymbolList::toString ( ) const
virtual

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 alphabet_, content_, and bpp::StringSequenceTools::decodeSequence().

Member Data Documentation

◆ alphabet_

const Alphabet* bpp::BasicSymbolList::alphabet_
private

The Alphabet attribute must be initialized in constructor and then can never be changed.

To apply another alphabet to a list you'll have to create a new list.

Definition at line 274 of file SymbolList.h.

Referenced by getAlphabet(), operator=(), and toString().

◆ content_

std::vector<int> bpp::BasicSymbolList::content_
protected

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