bpp-seq  2.2.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, bool checkSequenceNames=true, const std::string &split=" ")
 Build a new Phylip file reader. More...
 
virtual ~Phylip ()
 
unsigned int getNumberOfSequences (const std::string &path) const throw (IOException)
 
bool checkNames () const
 
void checkNames (bool yn)
 Tell whether the sequence names should be checked when reading from files. More...
 
const std::string & getSplit () const
 
void setSplit (const std::string &split)
 
const std::string getDataType () const
 
The AbstractIAlignment interface.
void appendAlignmentFromStream (std::istream &input, SiteContainer &sc) const throw (Exception)
 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.

virtual SequenceContainerreadSequences (std::istream &input, const Alphabet *alpha) const throw (Exception)
 Create a new container from a stream. More...
 
virtual SequenceContainerreadSequences (const std::string &path, const Alphabet *alpha) const throw (Exception)
 Create a new container from a file. More...
 
The OSequence interface.
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) const throw (Exception)
 Write a container to a file. More...
 
The IOSequence interface.
const std::string getFormatName () const
 
const std::string getFormatDescription () const
 
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...
 

Protected Member Functions

const std::vector< std::string > splitNameAndSequence (const std::string &s) const throw (Exception)
 
void readSequential (std::istream &in, SiteContainer &asc) const throw (Exception)
 
void readInterleaved (std::istream &in, SiteContainer &asc) const throw (Exception)
 
std::vector< std::string > getSizedNames (const std::vector< std::string > &names) const
 
void writeSequential (std::ostream &out, const SequenceContainer &sc) const
 
void writeInterleaved (std::ostream &out, const SequenceContainer &sc) const
 
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 Attributes

bool extended_
 
bool sequential_
 
unsigned int charsByLine_
 The maximum number of chars to be written on a line. More...
 
bool checkNames_
 
std::string namesSplit_
 

Detailed Description

The Phylip & co format.

An AlignedSequenceContainer is used instead of a VectorSequenceContainer.

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

Definition at line 64 of file Phylip.h.

Constructor & Destructor Documentation

◆ Phylip()

bpp::Phylip::Phylip ( bool  extended = true,
bool  sequential = true,
unsigned int  charsByLine = 100,
bool  checkSequenceNames = true,
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.
checkSequenceNamesTell if the names in the file should be checked for unicity (slower, in o(n*n) where n is the number of sequences).
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 99 of file Phylip.h.

◆ ~Phylip()

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

Definition at line 102 of file Phylip.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 Phylip::appendAlignmentFromStream ( std::istream &  input,
SiteContainer 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::AbstractIAlignment.

Definition at line 174 of file Phylip.cpp.

◆ checkNames() [1/2]

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

Definition at line 163 of file Phylip.h.

References checkNames_.

◆ checkNames() [2/2]

void bpp::Phylip::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 170 of file Phylip.h.

References checkNames_.

◆ getDataType()

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

Definition at line 65 of file IoSequence.h.

◆ getFormatDescription()

const std::string Phylip::getFormatDescription ( ) const

Definition at line 298 of file Phylip.cpp.

◆ getFormatName()

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

Definition at line 294 of file Phylip.cpp.

◆ getNumberOfSequences()

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

This methods parses the firt line of the phylip file.

Parameters
pathThe path of the file to parse.

Definition at line 185 of file Phylip.cpp.

◆ getSizedNames()

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

Definition at line 201 of file Phylip.cpp.

◆ getSplit()

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

Definition at line 175 of file Phylip.h.

References namesSplit_.

◆ 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 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().

◆ readInterleaved()

void Phylip::readInterleaved ( std::istream &  in,
SiteContainer asc 
) const
throw (Exception
)
protected

Definition at line 132 of file Phylip.cpp.

◆ readSequences() [1/2]

virtual SequenceContainer* bpp::Phylip::readSequences ( std::istream &  input,
const Alphabet alpha 
) const
throw (Exception
)
inlinevirtual

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 122 of file Phylip.h.

References bpp::AbstractIAlignment::readAlignment().

◆ readSequences() [2/2]

virtual SequenceContainer* bpp::Phylip::readSequences ( const std::string &  path,
const Alphabet alpha 
) const
throw (Exception
)
inlinevirtual

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 125 of file Phylip.h.

References bpp::AbstractIAlignment::readAlignment().

◆ readSequential()

void Phylip::readSequential ( std::istream &  in,
SiteContainer asc 
) const
throw (Exception
)
protected

Definition at line 75 of file Phylip.cpp.

◆ 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 180 of file Phylip.h.

References namesSplit_.

◆ splitNameAndSequence()

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

Definition at line 55 of file Phylip.cpp.

◆ writeAlignment() [1/2]

void Phylip::writeAlignment ( std::ostream &  output,
const SiteContainer 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::AbstractOAlignment.

Definition at line 279 of file Phylip.cpp.

◆ writeAlignment() [2/2]

void bpp::Phylip::writeAlignment ( const std::string &  path,
const SiteContainer sc,
bool  overwrite 
) 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::AbstractOAlignment.

Definition at line 144 of file Phylip.h.

References bpp::AbstractOAlignment::writeAlignment().

◆ 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 83 of file Phylip.h.

◆ checkNames_

bool bpp::Phylip::checkNames_
private

Definition at line 85 of file Phylip.h.

Referenced by checkNames().

◆ extended_

bool bpp::Phylip::extended_
private

Definition at line 75 of file Phylip.h.

◆ namesSplit_

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

Definition at line 87 of file Phylip.h.

Referenced by getSplit(), and setSplit().

◆ sequential_

bool bpp::Phylip::sequential_
private

Definition at line 78 of file Phylip.h.


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