bpp-seq  2.2.0
bpp::Mase Class Reference

The mase sequence file format. More...

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

+ Inheritance diagram for bpp::Mase:
+ Collaboration diagram for bpp::Mase:

Public Member Functions

 Mase (unsigned int charsByLine=100, bool checkSequenceNames=true)
 Build a new Mase object. More...
 
virtual ~Mase ()
 
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
 
Reading method including header:
VectorSequenceContainerreadMeta (std::istream &input, const Alphabet *alpha, MaseHeader &header) const throw (Exception)
 
VectorSequenceContainerreadMeta (std::string &path, const Alphabet *alpha, MaseHeader &header) const throw (Exception)
 
The AbstractISequence interface.
void appendSequencesFromStream (std::istream &input, SequenceContainer &sc) const throw (Exception)
 Append sequences to a container from a stream. More...
 
The AbstractIAlignment interface.
void appendAlignmentFromStream (std::istream &input, SiteContainer &sc) const throw (Exception)
 Append sequences to a container from a stream. More...
 
The OSequence interface.
void writeSequences (std::ostream &output, const SequenceContainer &sc) const throw (Exception)
 Write a container to a stream. More...
 
void writeSequences (const std::string &path, const SequenceContainer &sc, bool overwrite=true) const throw (Exception)
 Write a container to a file. More...
 
Writing methods including header:
void writeMeta (std::ostream &output, const SequenceContainer &sc, const MaseHeader &header) const throw (Exception)
 
void writeMeta (const std::string &path, const SequenceContainer &sc, const MaseHeader &header, bool overwrite=true) const throw (Exception)
 
The IOSequence interface.
const std::string getFormatName () const
 
const std::string getFormatDescription () const
 
ISequence methods:
virtual void readSequences (std::istream &input, SequenceContainer &sc) const throw (Exception)
 Add sequences to a container from a stream. More...
 
virtual void readSequences (const std::string &path, SequenceContainer &sc) const throw (Exception)
 Add sequences to a container from a file. More...
 
virtual VectorSequenceContainerreadSequences (std::istream &input, const Alphabet *alpha) const throw (Exception)
 Create a new container from a stream. More...
 
virtual VectorSequenceContainerreadSequences (const std::string &path, const Alphabet *alpha) const throw (Exception)
 Create a new container from a file. More...
 
IAlignment methods:
virtual void readAlignment (std::istream &input, SiteContainer &sc) const throw (Exception)
 Add sequences to a container from a stream. More...
 
virtual void readAlignment (const std::string &path, SiteContainer &sc) const throw (Exception)
 Add sequences to a container from a file. More...
 
virtual AlignedSequenceContainerreadAlignment (const std::string &path, const Alphabet *alpha) const throw (Exception)
 Create a new container from a file. More...
 
virtual AlignedSequenceContainerreadAlignment (std::istream &input, const Alphabet *alpha) const throw (Exception)
 Create a new container from a stream. More...
 
OAlignment methods:

As a SiteContainer is a specialization of SequenceContainer, it is assumed that a OSequence object can write aligned sequence just like a OAlignment object. Therefore it implements the OAlignment interface by down-casting the SiteContainer to a SequenceContainer.

void writeAlignment (std::ostream &output, const SiteContainer &sc) const throw (Exception)
 Write a container to a stream. More...
 
void writeAlignment (const std::string &path, const SiteContainer &sc, bool overwrite=true) const throw (Exception)
 Write a container to a file. More...
 

Protected Member Functions

virtual void appendSequencesFromFile (const std::string &path, SequenceContainer &sc) const throw (Exception)
 Append sequences to a container from a file. More...
 
virtual VectorSequenceContainerreadSequencesFromStream (std::istream &input, const Alphabet *alpha) const throw (Exception)
 Read sequences from a stream. More...
 
virtual VectorSequenceContainerreadSequencesFromFile (const std::string &path, const Alphabet *alpha) const throw (Exception)
 Append sequences to a container from a file. More...
 
virtual void appendAlignmentFromFile (const std::string &path, SiteContainer &sc) const throw (Exception)
 Append sequences to a container from a file. More...
 
virtual AlignedSequenceContainerreadAlignmentFromStream (std::istream &input, const Alphabet *alpha) const throw (Exception)
 Read sequences from a stream. More...
 
virtual AlignedSequenceContainerreadAlignmentFromFile (const std::string &path, const Alphabet *alpha) const throw (Exception)
 Read sequences from a file. More...
 

Private Member Functions

void readHeader_ (std::istream &input, MaseHeader &header) const throw (Exception)
 
void writeHeader_ (std::ostream &output, const MaseHeader &header) const
 

Private Attributes

unsigned int charsByLine_
 The maximum number of chars to be written on a line. More...
 
bool checkNames_
 

Detailed Description

The mase sequence file format.

In addition to traditional read and write method, this class offers overloaded method with MaseHeader objects, dedicated to header information storage. If used, then the header of the mase file will be parsed accordingly. Otherwise, the header lines will be stored as general comments.

See also
MaseTools for alternative way of parsing headers.

Definition at line 125 of file Mase.h.

Constructor & Destructor Documentation

◆ Mase()

bpp::Mase::Mase ( unsigned int  charsByLine = 100,
bool  checkSequenceNames = true 
)
inline

Build a new Mase object.

Parameters
charsByLineNumber of character per line when writing files.
checkSequenceNamesTell if the names in the file should be checked for unicity (slower, in o(n*n) where n is the number of sequences).

Definition at line 146 of file Mase.h.

◆ ~Mase()

virtual bpp::Mase::~Mase ( )
inlinevirtual

Definition at line 149 of file Mase.h.

Member Function Documentation

◆ appendAlignmentFromFile()

virtual void bpp::AbstractIAlignment::appendAlignmentFromFile ( const std::string &  path,
SiteContainer sc 
) const
throw (Exception
)
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 143 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

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

◆ appendAlignmentFromStream()

void bpp::Mase::appendAlignmentFromStream ( std::istream &  input,
SiteContainer sc 
) const
throw (Exception
)
inlinevirtual

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 185 of file Mase.h.

References appendSequencesFromStream().

◆ appendSequencesFromFile()

virtual void bpp::AbstractISequence::appendSequencesFromFile ( const std::string &  path,
SequenceContainer sc 
) const
throw (Exception
)
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 142 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromStream().

Referenced by bpp::AbstractISequence::readSequences(), and bpp::AbstractISequence::readSequencesFromFile().

◆ appendSequencesFromStream()

void Mase::appendSequencesFromStream ( std::istream &  input,
SequenceContainer sc 
) const
throw (Exception
)
virtual

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::AbstractISequence.

Definition at line 49 of file Mase.cpp.

Referenced by appendAlignmentFromStream().

◆ checkNames() [1/2]

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

Definition at line 239 of file Mase.h.

References checkNames_.

◆ checkNames() [2/2]

void bpp::Mase::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 246 of file Mase.h.

References checkNames_.

◆ getDataType()

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

Definition at line 65 of file IoSequence.h.

◆ getFormatDescription()

const std::string bpp::Mase::getFormatDescription ( ) const
inline

Definition at line 230 of file Mase.h.

◆ getFormatName()

const std::string bpp::Mase::getFormatName ( ) const
inline

Definition at line 228 of file Mase.h.

◆ readAlignment() [1/4]

virtual void bpp::AbstractIAlignment::readAlignment ( std::istream &  input,
SiteContainer sc 
) const
throw (Exception
)
inlinevirtualinherited

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.

Definition at line 81 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

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

◆ readAlignment() [2/4]

virtual void bpp::AbstractIAlignment::readAlignment ( const std::string &  path,
SiteContainer sc 
) const
throw (Exception
)
inlinevirtualinherited

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.

Definition at line 93 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromFile().

◆ readAlignment() [3/4]

virtual AlignedSequenceContainer* bpp::AbstractIAlignment::readAlignment ( const std::string &  path,
const Alphabet alpha 
) const
throw (Exception
)
inlinevirtualinherited

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 104 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::readAlignmentFromFile().

◆ readAlignment() [4/4]

virtual AlignedSequenceContainer* bpp::AbstractIAlignment::readAlignment ( std::istream &  input,
const Alphabet alpha 
) const
throw (Exception
)
inlinevirtualinherited

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 115 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::readAlignmentFromStream().

◆ readAlignmentFromFile()

virtual AlignedSequenceContainer* bpp::AbstractIAlignment::readAlignmentFromFile ( const std::string &  path,
const Alphabet alpha 
) const
throw (Exception
)
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 173 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromFile().

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

◆ readAlignmentFromStream()

virtual AlignedSequenceContainer* bpp::AbstractIAlignment::readAlignmentFromStream ( std::istream &  input,
const Alphabet alpha 
) const
throw (Exception
)
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 158 of file AbstractIAlignment.h.

References bpp::AbstractIAlignment::appendAlignmentFromStream().

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

◆ readHeader_()

void Mase::readHeader_ ( std::istream &  input,
MaseHeader header 
) const
throw (Exception
)
private

Definition at line 181 of file Mase.cpp.

Referenced by readMeta().

◆ readMeta() [1/2]

VectorSequenceContainer* bpp::Mase::readMeta ( std::istream &  input,
const Alphabet alpha,
MaseHeader header 
) const
throw (Exception
)
inline

Definition at line 158 of file Mase.h.

References readHeader_(), and bpp::AbstractISequence::readSequences().

Referenced by readMeta().

◆ readMeta() [2/2]

VectorSequenceContainer* bpp::Mase::readMeta ( std::string &  path,
const Alphabet alpha,
MaseHeader header 
) const
throw (Exception
)
inline

Definition at line 163 of file Mase.h.

References readMeta().

◆ readSequences() [1/4]

virtual void bpp::AbstractISequence::readSequences ( std::istream &  input,
SequenceContainer sc 
) const
throw (Exception
)
inlinevirtualinherited

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.

Definition at line 82 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromStream().

Referenced by readMeta().

◆ readSequences() [2/4]

virtual void bpp::AbstractISequence::readSequences ( const std::string &  path,
SequenceContainer sc 
) const
throw (Exception
)
inlinevirtualinherited

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.

Definition at line 94 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromFile().

◆ readSequences() [3/4]

virtual VectorSequenceContainer* bpp::AbstractISequence::readSequences ( std::istream &  input,
const Alphabet alpha 
) const
throw (Exception
)
inlinevirtualinherited

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.

Implements bpp::ISequence.

Definition at line 105 of file AbstractISequence.h.

References bpp::AbstractISequence::readSequencesFromStream().

◆ readSequences() [4/4]

virtual VectorSequenceContainer* bpp::AbstractISequence::readSequences ( const std::string &  path,
const Alphabet alpha 
) const
throw (Exception
)
inlinevirtualinherited

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.

Implements bpp::ISequence.

Definition at line 116 of file AbstractISequence.h.

References bpp::AbstractISequence::readSequencesFromFile().

◆ readSequencesFromFile()

virtual VectorSequenceContainer* bpp::AbstractISequence::readSequencesFromFile ( const std::string &  path,
const Alphabet alpha 
) const
throw (Exception
)
inlineprotectedvirtualinherited

Append sequences to a container from a file.

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

Definition at line 171 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromFile().

Referenced by bpp::AbstractISequence::readSequences().

◆ readSequencesFromStream()

virtual VectorSequenceContainer* bpp::AbstractISequence::readSequencesFromStream ( std::istream &  input,
const Alphabet alpha 
) const
throw (Exception
)
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 157 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromStream().

Referenced by bpp::AbstractISequence::readSequences().

◆ writeAlignment() [1/2]

void bpp::AbstractOSequence::writeAlignment ( std::ostream &  output,
const SiteContainer sc 
) const
throw (Exception
)
inlinevirtualinherited

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::OAlignment.

Definition at line 92 of file AbstractOSequence.h.

References bpp::AbstractOSequence::writeSequences().

◆ writeAlignment() [2/2]

void bpp::AbstractOSequence::writeAlignment ( const std::string &  path,
const SiteContainer sc,
bool  overwrite = true 
) const
throw (Exception
)
inlinevirtualinherited

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.

Implements bpp::OAlignment.

Definition at line 96 of file AbstractOSequence.h.

References bpp::AbstractOSequence::writeSequences().

◆ writeHeader_()

◆ writeMeta() [1/2]

void bpp::Mase::writeMeta ( std::ostream &  output,
const SequenceContainer sc,
const MaseHeader header 
) const
throw (Exception
)
inline

Definition at line 208 of file Mase.h.

References writeHeader_(), and writeSequences().

◆ writeMeta() [2/2]

void bpp::Mase::writeMeta ( const std::string &  path,
const SequenceContainer sc,
const MaseHeader header,
bool  overwrite = true 
) const
throw (Exception
)
inline

Definition at line 213 of file Mase.h.

References writeHeader_(), and writeSequences().

◆ writeSequences() [1/2]

void Mase::writeSequences ( std::ostream &  output,
const SequenceContainer sc 
) const
throw (Exception
)
virtual

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::AbstractOSequence.

Definition at line 119 of file Mase.cpp.

Referenced by writeMeta().

◆ writeSequences() [2/2]

void bpp::Mase::writeSequences ( const std::string &  path,
const SequenceContainer sc,
bool  overwrite = true 
) const
throw (Exception
)
inlinevirtual

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::AbstractOSequence.

Definition at line 197 of file Mase.h.

References bpp::AbstractOSequence::writeSequences().

Member Data Documentation

◆ charsByLine_

unsigned int bpp::Mase::charsByLine_
private

The maximum number of chars to be written on a line.

Definition at line 136 of file Mase.h.

◆ checkNames_

bool bpp::Mase::checkNames_
private

Definition at line 137 of file Mase.h.

Referenced by checkNames().


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