bpp-seq3  3.0.0
bpp::Phylip Class Reference

The Phylip & co format. More...

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

+ Inheritance diagram for bpp::Phylip:
+ Collaboration diagram for bpp::Phylip:

Public Member Functions

 Phylip (bool extended=true, bool sequential=true, unsigned int charsByLine=100, const std::string &split=" ")
 Build a new Phylip file reader. More...
 
virtual ~Phylip ()
 
unsigned int getNumberOfSequences (const std::string &path) const
 
const std::string & getSplit () const
 
void setSplit (const std::string &split)
 
const std::string getDataType () const
 
The AbstractIAlignment2 interface.
void appendAlignmentFromStream (std::istream &input, SequenceContainerInterface &sc) const override
 Append sequences to a container from a stream. More...
 
The AbstractISequence interface.

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

virtual std::unique_ptr< SequenceContainerInterfacereadSequences (std::istream &input, std::shared_ptr< const Alphabet > alpha) const override
 Create a new container from a stream. More...
 
virtual 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 AbstractOSequence 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) 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

const std::vector< std::string > splitNameAndSequence (const std::string &s) const
 
void readSequential (std::istream &in, SequenceContainerInterface &asc) const
 
void readInterleaved (std::istream &in, SequenceContainerInterface &asc) const
 
std::vector< std::string > getSizedNames (const std::vector< std::string > &names) const
 
void writeSequential (std::ostream &out, const SiteContainerInterface &sc) const
 
void writeInterleaved (std::ostream &out, const SiteContainerInterface &sc) const
 
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 extended_
 
bool sequential_
 
unsigned int charsByLine_
 The maximum number of chars to be written on a line. More...
 
std::string namesSplit_
 

Detailed Description

The Phylip & co format.

Sequences must be aligned. This format is described on the Phylip package documentation website: http://evolution.genetics.washington.edu/phylip/doc/sequence.html

Definition at line 28 of file Phylip.h.

Constructor & Destructor Documentation

◆ Phylip()

bpp::Phylip::Phylip ( bool  extended = true,
bool  sequential = true,
unsigned int  charsByLine = 100,
const std::string &  split = "  " 
)
inline

Build a new Phylip file reader.

Parameters
extendedIf true, sequences with names longer than 10 characters are allowed.
sequentialIf false, sequences are supposed to be interlaved.
charsByLineThe number of base to display in a row.
splitThe string to use to split sequence name from content (only for 'extended' format). This will typically be " " (two spaces) or "\t" (a tabulation).

Definition at line 58 of file Phylip.h.

References split().

◆ ~Phylip()

virtual bpp::Phylip::~Phylip ( )
inlinevirtual

Definition at line 61 of file Phylip.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 Phylip::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 145 of file Phylip.cpp.

◆ 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 Phylip::getFormatDescription ( ) const
overridevirtual

Implements bpp::IOFormat.

Definition at line 290 of file Phylip.cpp.

◆ getFormatName()

const std::string Phylip::getFormatName ( ) const
overridevirtual

Implements bpp::IOFormat.

Definition at line 286 of file Phylip.cpp.

◆ getNumberOfSequences()

unsigned int Phylip::getNumberOfSequences ( const std::string &  path) const
Returns
The number of sequences contained in the specified file.

This methods parses the first line of the phylip file.

Parameters
pathThe path of the file to parse.

Definition at line 161 of file Phylip.cpp.

References bpp::FileTools::getNextLine(), and bpp::StringTokenizer::nextToken().

◆ getSizedNames()

std::vector< std::string > Phylip::getSizedNames ( const std::vector< std::string > &  names) const
protected

Definition at line 180 of file Phylip.cpp.

References bpp::TextTools::resizeRight().

◆ getSplit()

const std::string& bpp::Phylip::getSplit ( ) const
inline
Returns
The string used to split sequence name from content.

Definition at line 123 of file Phylip.h.

References namesSplit_.

◆ 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(), bpp::Clustal::readSequences(), bpp::DCSE::readSequences(), and 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().

◆ readInterleaved()

◆ 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]

virtual std::unique_ptr<SequenceContainerInterface> bpp::Phylip::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 84 of file Phylip.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]

virtual std::unique_ptr<SequenceContainerInterface> bpp::Phylip::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 80 of file Phylip.h.

References bpp::AbstractIAlignment::readAlignment().

◆ readSequential()

◆ setSplit()

void bpp::Phylip::setSplit ( const std::string &  split)
inline
Parameters
splitThe string to be used to split sequence name from content.

Definition at line 128 of file Phylip.h.

References namesSplit_, and split().

◆ splitNameAndSequence()

const std::vector< std::string > Phylip::splitNameAndSequence ( const std::string &  s) const
protected

◆ writeAlignment() [1/2]

void bpp::Phylip::writeAlignment ( const std::string &  path,
const SiteContainerInterface sc,
bool  overwrite 
) 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 104 of file Phylip.h.

References bpp::AbstractOAlignment::writeAlignment().

◆ writeAlignment() [2/2]

void Phylip::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 266 of file Phylip.cpp.

References bpp::TemplateSequenceDataInterface< HashType >::getNumberOfSequences().

◆ writeInterleaved()

◆ writeSequential()

Member Data Documentation

◆ charsByLine_

unsigned int bpp::Phylip::charsByLine_
private

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

Definition at line 45 of file Phylip.h.

◆ extended_

bool bpp::Phylip::extended_
private

Definition at line 37 of file Phylip.h.

◆ namesSplit_

std::string bpp::Phylip::namesSplit_
private

Definition at line 47 of file Phylip.h.

Referenced by getSplit(), and setSplit().

◆ sequential_

bool bpp::Phylip::sequential_
private

Definition at line 40 of file Phylip.h.


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