bpp-seq3  3.0.0
bpp::StringSequenceTools Class Reference

Utilitary methods working on raw string objects. More...

#include <Bpp/Seq/StringSequenceTools.h>

Public Member Functions

 StringSequenceTools ()
 
 ~StringSequenceTools ()
 

Static Public Member Functions

static std::string subseq (const std::string &sequence, size_t begin, size_t end)
 Get a subsequence. More...
 
static std::string setToSizeR (const std::string &sequence, size_t size)
 Set up the size of a sequence from the right side. More...
 
static std::string setToSizeL (const std::string &sequence, size_t size)
 Set up the size of a sequence from the left side. More...
 
static std::string deleteChar (const std::string &sequence, char chars)
 Delete all occurrence of a character in the sequence. More...
 
static std::string deleteChar (const std::string &sequence, std::string chars)
 Delete all occurrence of several characters in the sequence. More...
 
static std::string * reverse (const std::string &sequence)
 Reverse the sequence. More...
 
static std::string * complement (const std::string &sequence)
 Get the complement of a sequence. More...
 
static double getGCcontent (const std::string &sequence, size_t pos, size_t window)
 Calculate the local GC content of a sequence. More...
 
static std::vector< int > codeSequence (const std::string &sequence, std::shared_ptr< const Alphabet > &alphabet)
 Convert a string sequence to a vector of int. More...
 
static std::string decodeSequence (const std::vector< int > &sequence, std::shared_ptr< const Alphabet > &alphabet)
 Convert a sequence to its string representation. More...
 
static std::shared_ptr< const AlphabetgetAlphabetFromSequence (const std::string &sequence)
 Parse a sequence and try to guess the correct alphabet to use. More...
 

Detailed Description

Utilitary methods working on raw string objects.

Sequences may be stored as strings, but this approach is not as powerful as using true sequence objects. Consider using the Sequence and SequenceTools classes for more methods.

Some of the methods implemented here are internally used by the Sequence object.

See also
Sequence, Site, SequenceTools, SymbolListTools

Definition at line 31 of file StringSequenceTools.h.

Constructor & Destructor Documentation

◆ StringSequenceTools()

bpp::StringSequenceTools::StringSequenceTools ( )
inline

Definition at line 34 of file StringSequenceTools.h.

◆ ~StringSequenceTools()

bpp::StringSequenceTools::~StringSequenceTools ( )
inline

Definition at line 35 of file StringSequenceTools.h.

Member Function Documentation

◆ codeSequence()

vector< int > StringSequenceTools::codeSequence ( const std::string &  sequence,
std::shared_ptr< const Alphabet > &  alphabet 
)
static

Convert a string sequence to a vector of int.

This method is used in the sequence constructor. This deals with the most simple cases: the sequence (string) contains a succession of all characters. This is indeed the case for simple alphabets, but may be more complicated if the alphabet is coded with variable code length.

Parameters
sequenceThe sequence to parse.
alphabetThe alphabet to use to code the sequence.
Returns
A vector of int codes.
Exceptions
BarCharExceptionIf some character does not match the specified alphabet.

Definition at line 237 of file StringSequenceTools.cpp.

References count(), and bpp::AlphabetTools::getAlphabetCodingSize().

Referenced by bpp::Sequence::append(), bpp::SequenceWithAnnotation::append(), bpp::Sequence::setContent(), and bpp::SequenceWithAnnotation::setContent().

◆ complement()

string * StringSequenceTools::complement ( const std::string &  sequence)
static

Get the complement of a sequence.

Deprecated:
Consider working with sequence objects and translators.

For this method, sequence is supposed to be of type DNA.

Parameters
sequenceThe sequence to complement.
Returns
The complementary sequence.
See also
Sequence
NucleicAcidsReplication

Definition at line 113 of file StringSequenceTools.cpp.

◆ decodeSequence()

string StringSequenceTools::decodeSequence ( const std::vector< int > &  sequence,
std::shared_ptr< const Alphabet > &  alphabet 
)
static

Convert a sequence to its string representation.

Parameters
sequenceThe sequence object to convert.
alphabetThe alphabet to use to decode the sequence.
Returns
A string representation of the sequence.
Exceptions
BarIntExceptionIf some value does not match the specified alphabet.

Definition at line 260 of file StringSequenceTools.cpp.

Referenced by bpp::IntSymbolList::toString(), and bpp::EventDrivenIntSymbolList::toString().

◆ deleteChar() [1/2]

string StringSequenceTools::deleteChar ( const std::string &  sequence,
char  chars 
)
static

Delete all occurrence of a character in the sequence.

Parameters
sequenceThe sequence to parse.
charsThe character to remove.
Returns
The sequence with all specified characters removed.

Definition at line 57 of file StringSequenceTools.cpp.

◆ deleteChar() [2/2]

string StringSequenceTools::deleteChar ( const std::string &  sequence,
std::string  chars 
)
static

Delete all occurrence of several characters in the sequence.

Parameters
sequenceThe sequence to parse.
charsThe characters to remove.
Returns
The sequence with all specified characters removed.

Definition at line 74 of file StringSequenceTools.cpp.

◆ getAlphabetFromSequence()

std::shared_ptr< const Alphabet > StringSequenceTools::getAlphabetFromSequence ( const std::string &  sequence)
static

Parse a sequence and try to guess the correct alphabet to use.

Parameters
sequenceThe sequence to parse.
Returns
A pointer toward a new Alphabet object.
Exceptions
EmptySequenceExceptionif the sequence is empty.
SequenceExceptionif their is an ambiguity between several alphabet.
AlphabetExceptionif the sequence does not match any alphabet.

Definition at line 272 of file StringSequenceTools.cpp.

References bpp::AlphabetTools::DNA_ALPHABET, bpp::AlphabetTools::getType(), bpp::AlphabetTools::PROTEIN_ALPHABET, and bpp::AlphabetTools::RNA_ALPHABET.

◆ getGCcontent()

double StringSequenceTools::getGCcontent ( const std::string &  sequence,
size_t  pos,
size_t  window 
)
static

Calculate the local GC content of a sequence.

GC contents are calculated using a window of specified size around the given position. Note : Calculus for last nucleotides (sequence's size - window size) will return the last possible rate calculated.

Parameters
sequenceThe sequence to analyse.
posThe position where to compute the GC content.
windowThe size of the window to use.
Returns
The GC content as a ratio (# of GC / window).
Exceptions
BadIntExceptionIf the sequence is not of type DNA or RNA.
ExceptionError in calculus (if the sequence contain gaps for instance).

Definition at line 159 of file StringSequenceTools.cpp.

◆ reverse()

string * StringSequenceTools::reverse ( const std::string &  sequence)
static

Reverse the sequence.

Parameters
sequenceThe sequence to reverse.
Returns
The reversed sequence.

Definition at line 95 of file StringSequenceTools.cpp.

◆ setToSizeL()

string StringSequenceTools::setToSizeL ( const std::string &  sequence,
size_t  size 
)
static

Set up the size of a sequence from the left side.

All new characters are filled with gaps. If the specified size is < to the sequence size, the sequence will be truncated.

Parameters
sequenceThe input sequence.
sizeThe new size of the sequence.

Definition at line 50 of file StringSequenceTools.cpp.

References bpp::TextTools::resizeLeft().

◆ setToSizeR()

string StringSequenceTools::setToSizeR ( const std::string &  sequence,
size_t  size 
)
static

Set up the size of a sequence from the right side.

All new characters are filled with gaps. If the specified size is < to the sequence size, the sequence will be truncated.

Parameters
sequenceThe input sequence.
sizeThe new size of the sequence.

Definition at line 45 of file StringSequenceTools.cpp.

References bpp::TextTools::resizeRight().

◆ subseq()

string StringSequenceTools::subseq ( const std::string &  sequence,
size_t  begin,
size_t  end 
)
static

Get a subsequence.

Parameters
sequenceThe input sequence.
beginThe beginning position (included).
endThe ending position (included).
Returns
A string with the subsequence.
Exceptions
ExceptionIf position does not not match the interval [0, length].

Definition at line 26 of file StringSequenceTools.cpp.


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