bpp-seq3  3.0.0
bpp::Clustal Class Reference

The clustal sequence file format. More...

#include <Bpp/Seq/Io/Clustal.h>

+ Inheritance diagram for bpp::Clustal:
+ Collaboration diagram for bpp::Clustal:

Public Member Functions

 Clustal (bool checkSequenceNames=true, unsigned int nbExtraSpacesBeforeSeq=5, unsigned int charsByLine=100)
 Build a new Clustal object. More...
 
virtual ~Clustal ()
 
bool checkNames () const
 
void checkNames (bool yn)
 Tell whether the sequence names should be checked when reading from files. More...
 
const std::string getDataType () const
 
The AbstractIAlignment interface.
void appendAlignmentFromStream (std::istream &input, SequenceContainerInterface &sc) const override
 Append sequences to a container from a stream. More...
 
The ISequence interface.

As a SiteContainer is a subclass of SequenceContainer, we hereby implement the ISequence interface by downcasting the interface.

std::unique_ptr< SequenceContainerInterfacereadSequences (std::istream &input, std::shared_ptr< const Alphabet > alpha) const override
 Create a new container from a stream. More...
 
std::unique_ptr< SequenceContainerInterfacereadSequences (const std::string &path, std::shared_ptr< const Alphabet > alpha) const override
 Create a new container from a file. More...
 
The AbstractOAlignment interface.
void writeAlignment (std::ostream &output, const SiteContainerInterface &sc) const override
 Write a container to a stream. More...
 
void writeAlignment (const std::string &path, const SiteContainerInterface &sc, bool overwrite=true) const override
 Write a container to a file. More...
 
The IOSequence interface.
const std::string getFormatName () const override
 
const std::string getFormatDescription () const override
 
The ISequence interface.

As a SiteContainer is a subclass of SequenceContainer, we hereby implement the ISequence interface by downcasting the interface.

void readSequences (std::istream &input, SequenceContainerInterface &sc) const override
 Create a new container from a stream. More...
 
void readSequences (const std::string &path, SequenceContainerInterface &sc) const override
 Create a new container from a file. More...
 
IAlignment methods:
virtual void readAlignment (std::istream &input, SequenceContainerInterface &sc) const override
 Add sequences to a container from a stream. More...
 
virtual void readAlignment (const std::string &path, SequenceContainerInterface &sc) const override
 Add sequences to a container from a file. More...
 
std::unique_ptr< SiteContainerInterfacereadAlignment (const std::string &path, std::shared_ptr< const Alphabet > alpha) const override
 Create a new container from a file. More...
 
std::unique_ptr< SiteContainerInterfacereadAlignment (std::istream &input, std::shared_ptr< const Alphabet > alpha) const override
 Create a new container from a stream. More...
 

Protected Member Functions

virtual void appendAlignmentFromFile (const std::string &path, SequenceContainerInterface &sc) const
 Append sequences to a container from a file. More...
 
virtual std::unique_ptr< SiteContainerInterfacereadAlignmentFromStream (std::istream &input, std::shared_ptr< const Alphabet > alpha) const
 Read sequences from a stream. More...
 
virtual std::unique_ptr< SiteContainerInterfacereadAlignmentFromFile (const std::string &path, std::shared_ptr< const Alphabet > alpha) const
 Read sequences from a file. More...
 

Private Attributes

bool checkNames_
 
unsigned int nbSpacesBeforeSeq_
 
unsigned int charsByLine_
 

Detailed Description

The clustal sequence file format.

An AlignedSequenceContainer object is used instead of a VectorSequenceContainer.

Definition at line 23 of file Clustal.h.

Constructor & Destructor Documentation

◆ Clustal()

bpp::Clustal::Clustal ( bool  checkSequenceNames = true,
unsigned int  nbExtraSpacesBeforeSeq = 5,
unsigned int  charsByLine = 100 
)
inline

Build a new Clustal object.

Parameters
checkSequenceNamesTell if the names in the file should be checked for unicity (slower, in o(n*n) where n is the number of sequences).
nbExtraSpacesBeforeSeqSpecify the number of extra space characters separating the sequence name form content. The default is 5 (hence 6 spaces in total) for backward compatibility, using 0 will not allow for any space in the sequence names.
charsByLineNumber of character per line when writing file.

Definition at line 40 of file Clustal.h.

◆ ~Clustal()

virtual bpp::Clustal::~Clustal ( )
inlinevirtual

Definition at line 46 of file Clustal.h.

Member Function Documentation

◆ appendAlignmentFromFile()

virtual void bpp::AbstractIAlignment::appendAlignmentFromFile ( const std::string &  path,
SequenceContainerInterface sc 
) const
inlineprotectedvirtualinherited

Append sequences to a container from a file.

Parameters
pathThe path to the file to read.
scThe sequence container to update.
Exceptions
ExceptionIf the file is not in the specified format.

Definition at line 93 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

Referenced by bpp::AbstractIAlignment::readAlignment(), bpp::AbstractIAlignment::readAlignmentFromFile(), and bpp::AbstractIAlignment2::readSequences().

◆ appendAlignmentFromStream()

void Clustal::appendAlignmentFromStream ( std::istream &  input,
SequenceContainerInterface sc 
) const
overridevirtual

Append sequences to a container from a stream.

This is the unique method to implement!

Parameters
inputThe input stream to read.
scThe sequence container to update.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::AbstractIAlignment.

Definition at line 18 of file Clustal.cpp.

References bpp::TemplateSequenceContainerInterface< SequenceType, HashType >::addSequence(), count(), bpp::TemplateSequenceDataInterface< HashType >::getAlphabet(), bpp::FileTools::getNextLine(), bpp::TextTools::isEmpty(), bpp::TextTools::removeSurroundingWhiteSpaces(), and bpp::Commentable::setComments().

◆ checkNames() [1/2]

bool bpp::Clustal::checkNames ( ) const
inline
Returns
true if the names are to be checked when reading sequences from files.

Definition at line 103 of file Clustal.h.

References checkNames_.

◆ checkNames() [2/2]

void bpp::Clustal::checkNames ( bool  yn)
inline

Tell whether the sequence names should be checked when reading from files.

Parameters
ynwhether the sequence names should be checked when reading from files.

Definition at line 110 of file Clustal.h.

References checkNames_.

◆ getDataType()

const std::string bpp::IOSequence::getDataType ( ) const
inlinevirtualinherited

Implements bpp::IOFormat.

Reimplemented in bpp::Pasta.

Definition at line 29 of file IoSequence.h.

◆ getFormatDescription()

const std::string bpp::Clustal::getFormatDescription ( ) const
inlineoverridevirtual

Implements bpp::IOFormat.

Definition at line 96 of file Clustal.h.

◆ getFormatName()

const std::string bpp::Clustal::getFormatName ( ) const
inlineoverridevirtual

Implements bpp::IOFormat.

Definition at line 94 of file Clustal.h.

◆ readAlignment() [1/4]

virtual void bpp::AbstractIAlignment::readAlignment ( const std::string &  path,
SequenceContainerInterface sc 
) const
inlineoverridevirtualinherited

Add sequences to a container from a file.

Parameters
pathThe path to the file to read.
scThe sequence container to update.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::IAlignment.

Definition at line 57 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromFile().

◆ readAlignment() [2/4]

std::unique_ptr<SiteContainerInterface> bpp::AbstractIAlignment::readAlignment ( const std::string &  path,
std::shared_ptr< const Alphabet alpha 
) const
inlineoverridevirtualinherited

Create a new container from a file.

Parameters
pathThe path to the file to read.
alphaThe alphabet to be associated to the container.
Returns
A new SiteContainer object.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::IAlignment.

Definition at line 62 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::readAlignmentFromFile().

◆ readAlignment() [3/4]

virtual void bpp::AbstractIAlignment::readAlignment ( std::istream &  input,
SequenceContainerInterface sc 
) const
inlineoverridevirtualinherited

Add sequences to a container from a stream.

Parameters
inputThe input stream to read.
scThe sequence container to update.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::IAlignment.

Definition at line 45 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

Referenced by bpp::AbstractIAlignment2::readSequences(), readSequences(), bpp::DCSE::readSequences(), and bpp::Phylip::readSequences().

◆ readAlignment() [4/4]

std::unique_ptr<SiteContainerInterface> bpp::AbstractIAlignment::readAlignment ( std::istream &  input,
std::shared_ptr< const Alphabet alpha 
) const
inlineoverridevirtualinherited

Create a new container from a stream.

Parameters
inputThe input stream to read.
alphaThe alphabet to be associated to the container.
Returns
A new SiteContainer object.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::IAlignment.

Definition at line 67 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::readAlignmentFromStream().

◆ readAlignmentFromFile()

virtual std::unique_ptr<SiteContainerInterface> bpp::AbstractIAlignment::readAlignmentFromFile ( const std::string &  path,
std::shared_ptr< const Alphabet alpha 
) const
inlineprotectedvirtualinherited

Read sequences from a file.

Parameters
pathThe path to the file to read.
alphaThe alphabet to use.
Returns
A sequence container.
Exceptions
ExceptionIf the file is not in the specified format.

Definition at line 125 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromFile().

Referenced by bpp::AbstractIAlignment::readAlignment().

◆ readAlignmentFromStream()

virtual std::unique_ptr<SiteContainerInterface> bpp::AbstractIAlignment::readAlignmentFromStream ( std::istream &  input,
std::shared_ptr< const Alphabet alpha 
) const
inlineprotectedvirtualinherited

Read sequences from a stream.

Parameters
inputThe input stream to read.
alphaThe alphabet to use.
Returns
A sequence container.
Exceptions
ExceptionIf the file is not in the specified format.

Definition at line 110 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

Referenced by bpp::AbstractIAlignment::readAlignment().

◆ readSequences() [1/4]

void bpp::AbstractIAlignment2::readSequences ( const std::string &  path,
SequenceContainerInterface container 
) const
inlineoverridevirtualinherited

Create a new container from a file.

Parameters
pathThe path to the file to read.
containerThe container where to add data.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::ISequence.

Definition at line 162 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromFile().

◆ readSequences() [2/4]

std::unique_ptr<SequenceContainerInterface> bpp::Clustal::readSequences ( const std::string &  path,
std::shared_ptr< const Alphabet alpha 
) const
inlineoverridevirtual

Create a new container from a file.

Parameters
pathThe path to the file to read.
alphaThe alphabet to be associated to the container.
Returns
A new SequenceContainer object.
Exceptions
ExceptionIf the file is not in the specified format.

Reimplemented from bpp::AbstractIAlignment2.

Definition at line 70 of file Clustal.h.

References bpp::AbstractIAlignment::readAlignment().

◆ readSequences() [3/4]

void bpp::AbstractIAlignment2::readSequences ( std::istream &  input,
SequenceContainerInterface container 
) const
inlineoverridevirtualinherited

Create a new container from a stream.

Parameters
inputThe input stream to read.
containerThe container where to add data.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::ISequence.

Definition at line 157 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

◆ readSequences() [4/4]

std::unique_ptr<SequenceContainerInterface> bpp::Clustal::readSequences ( std::istream &  input,
std::shared_ptr< const Alphabet alpha 
) const
inlineoverridevirtual

Create a new container from a stream.

Parameters
inputThe input stream to read.
alphaThe alphabet to be associated to the container.
Returns
A new SequenceContainer object.
Exceptions
ExceptionIf the file is not in the specified format.

Reimplemented from bpp::AbstractIAlignment2.

Definition at line 65 of file Clustal.h.

References bpp::AbstractIAlignment::readAlignment().

◆ writeAlignment() [1/2]

void bpp::Clustal::writeAlignment ( const std::string &  path,
const SiteContainerInterface sc,
bool  overwrite = true 
) const
inlineoverridevirtual

Write a container to a file.

Parameters
pathThe path to the file to write.
scThe container to write.
overwriteIf true the sequences are written at the beginning of the file instead of being appended. Any previous content will be lost.
Exceptions
ExceptionIf the file is not in the specified format.

Reimplemented from bpp::AbstractOAlignment.

Definition at line 83 of file Clustal.h.

References bpp::AbstractOAlignment::writeAlignment().

◆ writeAlignment() [2/2]

void Clustal::writeAlignment ( std::ostream &  output,
const SiteContainerInterface sc 
) const
overridevirtual

Write a container to a stream.

Parameters
outputThe output stream where to write.
scThe container to write.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::AbstractOAlignment.

Definition at line 93 of file Clustal.cpp.

References bpp::AbstractCoreSequence::getName(), bpp::TemplateSequenceDataInterface< HashType >::getNumberOfSequences(), bpp::TextTools::resizeRight(), and bpp::TemplateSequenceContainerInterface< SequenceType, HashType >::sequence().

Member Data Documentation

◆ charsByLine_

unsigned int bpp::Clustal::charsByLine_
private

Definition at line 30 of file Clustal.h.

◆ checkNames_

bool bpp::Clustal::checkNames_
private

Definition at line 28 of file Clustal.h.

Referenced by checkNames().

◆ nbSpacesBeforeSeq_

unsigned int bpp::Clustal::nbSpacesBeforeSeq_
private

Definition at line 29 of file Clustal.h.


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