bpp-seq  2.2.0
bpp::NexusIOSequence Class Reference

The Nexus format reader for sequences. More...

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

+ Inheritance diagram for bpp::NexusIOSequence:
+ Collaboration diagram for bpp::NexusIOSequence:

Public Member Functions

 NexusIOSequence (unsigned int charsByLine=100, bool checkSequenceNames=true)
 Build a new Phylip file reader. More...
 
virtual ~NexusIOSequence ()
 
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, 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 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

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

Protected Attributes

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

Private Member Functions

const std::vector< std::string > splitNameAndSequence_ (const std::string &s) const throw (Exception)
 

Detailed Description

The Nexus format reader for sequences.

An AlignedSequenceContainer is used instead of a VectorSequenceContainer.

This reader is not supposed to be a full parser of the Nexus files, but only extract the sequence data. Only a basic subset of the options are and will be supported.

This format is described in the following paper: Maddison D, Swofford D, and Maddison W (1997), Syst Biol 46(4):590-621

Author
Julien Dutheil

Definition at line 69 of file NexusIoSequence.h.

Constructor & Destructor Documentation

◆ NexusIOSequence()

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

Build a new Phylip file reader.

Parameters
charsByLineThe number of base to display in a row (ignored for now, no writing support).
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 89 of file NexusIoSequence.h.

◆ ~NexusIOSequence()

virtual bpp::NexusIOSequence::~NexusIOSequence ( )
inlinevirtual

Definition at line 92 of file NexusIoSequence.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 NexusIOSequence::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 70 of file NexusIoSequence.cpp.

References bpp::SequenceContainer::addSequence(), bpp::AlphabetTools::DEFAULT_ALPHABET, bpp::SequenceContainer::getAlphabet(), bpp::NexusTools::getNextCommand(), bpp::OrderedSequenceContainer::getNumberOfSequences(), bpp::OrderedSequenceContainer::getSequence(), and bpp::SiteContainerTools::resolveDottedAlignment().

◆ checkNames() [1/2]

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

Definition at line 132 of file NexusIoSequence.h.

References checkNames_.

◆ checkNames() [2/2]

void bpp::NexusIOSequence::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 139 of file NexusIoSequence.h.

References checkNames_.

◆ getDataType()

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

Definition at line 65 of file IoSequence.h.

◆ getFormatDescription()

const std::string NexusIOSequence::getFormatDescription ( ) const

Definition at line 203 of file NexusIoSequence.cpp.

◆ getFormatName()

const std::string NexusIOSequence::getFormatName ( ) const

Definition at line 199 of file NexusIoSequence.cpp.

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

◆ readSequences() [1/2]

virtual SequenceContainer* bpp::NexusIOSequence::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 112 of file NexusIoSequence.h.

References bpp::AbstractIAlignment::readAlignment().

◆ readSequences() [2/2]

virtual SequenceContainer* bpp::NexusIOSequence::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 115 of file NexusIoSequence.h.

References bpp::AbstractIAlignment::readAlignment().

◆ splitNameAndSequence_()

const std::vector< std::string > NexusIOSequence::splitNameAndSequence_ ( const std::string &  s) const
throw (Exception
)
private

Definition at line 57 of file NexusIoSequence.cpp.

Member Data Documentation

◆ charsByLine_

unsigned int bpp::NexusIOSequence::charsByLine_
protected

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

Definition at line 78 of file NexusIoSequence.h.

◆ checkNames_

bool bpp::NexusIOSequence::checkNames_
protected

Definition at line 80 of file NexusIoSequence.h.

Referenced by checkNames().


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