bpp-seq  2.1.0
bpp::SequenceContainerTools Class Reference

Utilitary methods dealing with sequence containers. More...

#include <Bpp/Seq/Container/SequenceContainerTools.h>

List of all members.

Public Member Functions

 SequenceContainerTools ()
virtual ~SequenceContainerTools ()

Static Public Member Functions

static SequenceContainercreateContainerOfSpecifiedSize (const Alphabet *alphabet, size_t size)
 Create a container with $n$ void sequences.
static SequenceContainercreateContainerWithSequenceNames (const Alphabet *alphabet, const std::vector< std::string > &seqNames) throw (Exception)
 Create a container with specified names.
template<class ContFrom , class ContTo , class Seq >
static void convertContainer (const ContFrom &input, ContTo &output)
 Generic function which creates a new container from another one, by specifying the class of sequence to be stored.
static void getSelectedSequences (const OrderedSequenceContainer &sequences, const SequenceSelection &selection, SequenceContainer &outputCont) throw (Exception)
 Add a specified set of sequences from a container to another.
static void getSelectedSequences (const SequenceContainer &sequences, const std::vector< std::string > &selection, SequenceContainer &outputCont, bool strict=true) throw (Exception)
 Add a specified set of sequences from a container to another.
static void keepOnlySelectedSequences (OrderedSequenceContainer &sequences, const SequenceSelection &selection)
 Remove all sequences that are not in a given selection from a given container.
static bool sequencesHaveTheSameLength (const SequenceContainer &sequences)
 Check if all sequences in a SequenceContainer have the same length.
static void getCounts (const SequenceContainer &sequences, std::map< int, int > &)
 Compute base counts.
static void getFrequencies (const SequenceContainer &sequences, std::map< int, double > &f, double pseudoCount=0)
 Compute base frequencies.
static void append (SequenceContainer &seqCont1, const SequenceContainer &seqCont2, bool checkNames=true) throw (Exception)
 Append all the sequences of a SequenceContainer to the end of another.
static void append (SequenceContainer &seqCont1, const OrderedSequenceContainer &seqCont2, bool checkNames=true) throw (Exception)
 Append all the sequences of a SequenceContainer to the end of another, OrderedSequenceContainer implementation.
static void merge (const SequenceContainer &seqCont1, const SequenceContainer &seqCont2, SequenceContainer &outputCont) throw (Exception)
 Concatenate the sequences from two containers.
static void convertAlphabet (const SequenceContainer &seqCont, SequenceContainer &outputCont) throw (Exception)
 Convert a SequenceContainer with a new alphabet.
static SequenceContainergetCodonPosition (const SequenceContainer &sequences, size_t pos) throw (AlphabetException)
 Extract a certain position (1, 2 or 3) from a container of codon sequences and returns the resulting nucleotide container.

Detailed Description

Utilitary methods dealing with sequence containers.

Definition at line 61 of file SequenceContainerTools.h.


Constructor & Destructor Documentation

Definition at line 66 of file SequenceContainerTools.h.


Member Function Documentation

static void bpp::SequenceContainerTools::append ( SequenceContainer seqCont1,
const SequenceContainer seqCont2,
bool  checkNames = true 
) throw (Exception) [inline, static]

Append all the sequences of a SequenceContainer to the end of another.

Parameters:
seqCont1The SequenceContainer in which the sequences will be added.
seqCont2The SequenceContainer from which the sequences are taken.
checkNamesTell if the sequence names should be check for unicity.

Definition at line 214 of file SequenceContainerTools.h.

static void bpp::SequenceContainerTools::append ( SequenceContainer seqCont1,
const OrderedSequenceContainer seqCont2,
bool  checkNames = true 
) throw (Exception) [inline, static]

Append all the sequences of a SequenceContainer to the end of another, OrderedSequenceContainer implementation.

Parameters:
seqCont1The SequenceContainer in which the sequences will be added.
seqCont2The SequenceContainer from which the sequences are taken.
checkNamesTell if the sequence names should be check for unicity.

Definition at line 228 of file SequenceContainerTools.h.

References bpp::SequenceContainer::addSequence(), bpp::OrderedSequenceContainer::getNumberOfSequences(), and bpp::OrderedSequenceContainer::getSequence().

static void bpp::SequenceContainerTools::convertAlphabet ( const SequenceContainer seqCont,
SequenceContainer outputCont 
) throw (Exception) [inline, static]

Convert a SequenceContainer with a new alphabet.

This method assume that the original container has proper sequence names. Names will be checked only if the output container is not empty.

Parameters:
seqContThe container to convert.
outputContA container (most likely empty) with an alphabet into which the container will be converted.

Definition at line 272 of file SequenceContainerTools.h.

template<class ContFrom , class ContTo , class Seq >
static void bpp::SequenceContainerTools::convertContainer ( const ContFrom &  input,
ContTo &  output 
) [inline, static]

Generic function which creates a new container from another one, by specifying the class of sequence to be stored.

Compared to several copy constructors, this function allows to change the class of the inner sequence class used for storing sequences. The function used the addSequence method, so that it can also be used to concatenate containers.

Parameters:
inputThe container to copy.
outputThe container where new sequences will be appended.

Definition at line 112 of file SequenceContainerTools.h.

SequenceContainer * SequenceContainerTools::createContainerOfSpecifiedSize ( const Alphabet alphabet,
size_t  size 
) [static]

Create a container with $n$ void sequences.

A new VectorSequenceContainer with the specified alphabet is created. The destruction of this new container is up to the user. Sequences have name "0", "1",... "n-1" and no content and comments.

Parameters:
alphabetThe alphabet to use in the container.
sizeThe number of sequences in the container.
Returns:
A pointer toward a newly created container.

Definition at line 53 of file SequenceContainerTools.cpp.

References bpp::VectorSequenceContainer::addSequence().

SequenceContainer * SequenceContainerTools::createContainerWithSequenceNames ( const Alphabet alphabet,
const std::vector< std::string > &  seqNames 
) throw (Exception) [static]

Create a container with specified names.

A new VectorSequenceContainer with the specified alphabet is created. The destruction of this new container is up to the user. Sequences have the specified names and no content and comments.

Parameters:
alphabetThe alphabet to use in the container.
seqNamesThe names of the sequences.
Returns:
A pointer toward a newly created container.
Exceptions:
ExceptionIf two sequence names are not unique.

Definition at line 65 of file SequenceContainerTools.cpp.

References bpp::SequenceContainer::setSequencesNames().

SequenceContainer * SequenceContainerTools::getCodonPosition ( const SequenceContainer sequences,
size_t  pos 
) throw (AlphabetException) [static]

Extract a certain position (1, 2 or 3) from a container of codon sequences and returns the resulting nucleotide container.

Parameters:
sequencesThe input sequence container, with codon alphabet.
posThe codon position to retrieve.
Returns:
A SequenceContainer with a nucleotide alphabet.
Exceptions:
AlphabetExceptionIf input sequences are not registered with a codon alphabet.

Definition at line 201 of file SequenceContainerTools.cpp.

References bpp::VectorSequenceContainer::addSequence(), bpp::AbstractSequenceContainer::getContent(), bpp::WordAlphabet::getNPosition(), and bpp::CodonAlphabet::getNucleicAlphabet().

void SequenceContainerTools::getCounts ( const SequenceContainer sequences,
std::map< int, int > &  f 
) [static]

Compute base counts.

Example of usage: getting the GC count from a sequence container. map<int, int> counts; SequenceContainerTools::getCounts(myContainer, counts); //My container is previously defined. int GCcontent = counts[1] + counts[2] ;

States are stored as their int code.

Definition at line 184 of file SequenceContainerTools.cpp.

References bpp::SequenceContainer::getContent(), and bpp::SequenceContainer::getSequencesNames().

void SequenceContainerTools::getFrequencies ( const SequenceContainer sequences,
std::map< int, double > &  f,
double  pseudoCount = 0 
) [static]

Compute base frequencies.

Example of usage: getting the GC content from a sequence container. map<int, double> freqs; SequenceContainerTools::getFrequencies(myContainer, freqs); //My container is previously defined. double GCcontent = (freqs[1] + freqs[2]) / (freqs[0] + freqs[1] + freqs[2] + freqs[3]);

States are stored as their int code.

Definition at line 151 of file SequenceContainerTools.cpp.

References bpp::SequenceContainer::getAlphabet(), bpp::SequenceContainer::getContent(), bpp::SequenceContainer::getSequencesNames(), and bpp::Alphabet::getSize().

void SequenceContainerTools::getSelectedSequences ( const OrderedSequenceContainer sequences,
const SequenceSelection &  selection,
SequenceContainer outputCont 
) throw (Exception) [static]

Add a specified set of sequences from a container to another.

Sequences are specified by their position, beginning at 0. Name verification will be performed, only if the output container is not empty, based on the assumption that the container passed as argument is a correct one. Redundant selection is not checked, so be careful with what you're doing!

Author:
Julien Dutheil
Parameters:
sequencesThe container from wich sequences are to be taken.
selectionThe positions of all sequences to retrieve.
outputContA container where the selection should be added.
Exceptions:
ExceptionIn case of bad sequence name, alphabet mismatch, etc.

Definition at line 77 of file SequenceContainerTools.cpp.

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

void SequenceContainerTools::getSelectedSequences ( const SequenceContainer sequences,
const std::vector< std::string > &  selection,
SequenceContainer outputCont,
bool  strict = true 
) throw (Exception) [static]

Add a specified set of sequences from a container to another.

Sequences are specified by their names. Name verification will be performed, only if the output container is not empty, based on the assumption that the container passed as argument is a correct one. Redundant selection is not checked, so be careful with what you're doing!

Author:
Julien Dutheil
Parameters:
sequencesThe container from wich sequences are to be taken.
selectionThe names of all sequences to retrieve.
outputContA container where the selection should be added.
strictIf yes, trying to select a sequence that is not present will raise an exception. If no, only available sequence will be added.
Exceptions:
ExceptionIn case of bad sequence name, alphabet mismatch, etc.

Definition at line 91 of file SequenceContainerTools.cpp.

void SequenceContainerTools::keepOnlySelectedSequences ( OrderedSequenceContainer sequences,
const SequenceSelection &  selection 
) [static]

Remove all sequences that are not in a given selection from a given container.

A new VectorSequenceContainer is created with specified sequences. The destruction of the container is up to the user. Sequences are specified by their position, beginning at 0. Redundant selection is not checked, so be careful with what you're doing!

Parameters:
sequencesThe container from wich sequences are to be taken.
selectionThe positions of all sequences to retrieve.
Returns:
A new container with all selected sequences.

Definition at line 113 of file SequenceContainerTools.cpp.

References bpp::OrderedSequenceContainer::deleteSequence(), and bpp::OrderedSequenceContainer::getSequencesNames().

static void bpp::SequenceContainerTools::merge ( const SequenceContainer seqCont1,
const SequenceContainer seqCont2,
SequenceContainer outputCont 
) throw (Exception) [inline, static]

Concatenate the sequences from two containers.

This method will not check the original sequence names for unicity. If sequences do not have a unique name, then the resulting merged container will contain the first sequence with the given duplicated name.

Author:
Julien Dutheil
Parameters:
seqCont1First container.
seqCont2Second container. This container must contain sequences with the same names as in seqcont1. Additional sequences will be ignored.
outputContOutput sequence container to which concatenated sequences will be added.
Exceptions:
AlphabetMismatchExceptionIf the alphabet in the 3 containers do not match.

Definition at line 249 of file SequenceContainerTools.h.

References bpp::BasicSequence::append().

Check if all sequences in a SequenceContainer have the same length.

Parameters:
sequencesThe container to check.
Returns:
True is all sequence have the same length.

Definition at line 135 of file SequenceContainerTools.cpp.

References bpp::SequenceContainer::getSequence(), bpp::SequenceContainer::getSequencesNames(), and bpp::SymbolList::size().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends