bpp-seq3  3.0.0
bpp::Fasta Class Referenceabstract

The fasta sequence file format. More...

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

+ Inheritance diagram for bpp::Fasta:
+ Collaboration diagram for bpp::Fasta:

Classes

class  FileIndex
 The SequenceFileIndex class for Fasta format. More...
 

Public Member Functions

 Fasta (unsigned int charsByLine=100, bool checkSequenceNames=true, bool extended=false, bool strictSequenceNames=false)
 Build a new Fasta object. More...
 
virtual ~Fasta ()
 
bool checkNames () const
 
void checkNames (bool yn)
 Tell whether the sequence names should be checked when reading from files. More...
 
bool strictNames () const
 
void strictNames (bool yn)
 Tell wethed the sequence name should be restrected to the first non blank characters. More...
 
const std::string getDataType () const
 
virtual bool nextSequence (std::istream &input, SequenceType &seq) const =0
 Read sequence from stream. More...
 
virtual void writeSequence (std::ostream &output, const SequenceType &seq) const =0
 Read sequence from stream. More...
 
The AbstractISequence interface.
void appendSequencesFromStream (std::istream &input, SequenceContainerInterface &sc) const override
 Append sequences to a container from a stream. More...
 
The AbstractIAlignment interface.
void appendAlignmentFromStream (std::istream &input, SequenceContainerInterface &sc) const override
 Append sequences to a container from a stream. More...
 
The OSequence interface.
void writeSequences (std::ostream &output, const SequenceContainerInterface &sc) const override
 Write a container to a stream. More...
 
void writeSequences (const std::string &path, const SequenceContainerInterface &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 ISequenceStream interface.
bool nextSequence (std::istream &input, Sequence &seq) const override
 
The OSequenceStream interface.
void writeSequence (std::ostream &output, const Sequence &seq) const override
 
ISequence methods:
void readSequences (std::istream &input, SequenceContainerInterface &sc) const override
 Add sequences to a container from a stream. More...
 
void readSequences (const std::string &path, SequenceContainerInterface &sc) const override
 Add sequences to a container from a file. More...
 
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...
 
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...
 
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 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...
 

Protected Member Functions

virtual void appendSequencesFromFile (const std::string &path, SequenceContainerInterface &sc) const
 Append sequences to a container from a file. More...
 
std::unique_ptr< SequenceContainerInterfacereadSequencesFromStream (std::istream &input, std::shared_ptr< const Alphabet > &alpha) const
 Read sequences from a stream. More...
 
std::unique_ptr< SequenceContainerInterfacereadSequencesFromFile (const std::string &path, std::shared_ptr< const Alphabet > &alpha) const
 Append sequences to a container from a file. More...
 
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...
 

Protected Attributes

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

Detailed Description

The fasta sequence file format.

Read and write from/to Fasta files.

Definition at line 26 of file Fasta.h.

Constructor & Destructor Documentation

◆ Fasta()

bpp::Fasta::Fasta ( unsigned int  charsByLine = 100,
bool  checkSequenceNames = true,
bool  extended = false,
bool  strictSequenceNames = false 
)
inline

Build a new Fasta object.

Parameters
charsByLineNumber of character per line when writing files.
checkSequenceNamesTells if the names in the file should be checked for unicity (slower, in o(n*n) where n is the number of sequences).
extendedTells if we should read general comments and sequence comments in HUPO-PSI format.
strictSequenceNamesTells if the sequence names should be restricted to the characters between '>' and the first blank one.

Definition at line 51 of file Fasta.h.

◆ ~Fasta()

virtual bpp::Fasta::~Fasta ( )
inlinevirtual

Definition at line 54 of file Fasta.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 bpp::Fasta::appendAlignmentFromStream ( std::istream &  input,
SequenceContainerInterface sc 
) const
inlineoverridevirtual

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

References appendSequencesFromStream().

◆ appendSequencesFromFile()

virtual void bpp::AbstractISequence::appendSequencesFromFile ( 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 92 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromStream().

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

◆ appendSequencesFromStream()

void Fasta::appendSequencesFromStream ( 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::AbstractISequence.

Definition at line 119 of file Fasta.cpp.

References bpp::TemplateSequenceContainerInterface< SequenceType, HashType >::addSequence(), bpp::TemplateSequenceDataInterface< HashType >::getAlphabet(), and bpp::Commentable::setComments().

Referenced by appendAlignmentFromStream().

◆ checkNames() [1/2]

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

Definition at line 121 of file Fasta.h.

References checkNames_.

◆ checkNames() [2/2]

void bpp::Fasta::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 128 of file Fasta.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::Fasta::getFormatDescription ( ) const
inlineoverridevirtual

Implements bpp::IOFormat.

Definition at line 96 of file Fasta.h.

◆ getFormatName()

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

Implements bpp::IOFormat.

Definition at line 94 of file Fasta.h.

◆ nextSequence() [1/2]

◆ nextSequence() [2/2]

template<class SequenceType >
virtual bool bpp::TemplateISequenceStream< SequenceType >::nextSequence ( std::istream &  input,
SequenceType &  seq 
) const
pure virtualinherited

Read sequence from stream.

Read one sequence from a stream.

Parameters
inputThe stream to read.
seqThe sequence to fill.
Returns
true if a sequence was read or false if not.
Exceptions
ExceptionIOExecption and Sequence related Exceptions.

◆ 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 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::AbstractISequence::readSequences ( 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::ISequence.

Definition at line 57 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromFile().

◆ readSequences() [2/4]

std::unique_ptr<SequenceContainerInterface> bpp::AbstractISequence::readSequences ( 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 SequenceContainer object.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::ISequence.

Definition at line 67 of file AbstractISequence.h.

References bpp::AbstractISequence::readSequencesFromFile().

◆ readSequences() [3/4]

void bpp::AbstractISequence::readSequences ( 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::ISequence.

Definition at line 45 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromStream().

Referenced by bpp::Mase::readMeta().

◆ readSequences() [4/4]

std::unique_ptr<SequenceContainerInterface> bpp::AbstractISequence::readSequences ( 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 SequenceContainer object.
Exceptions
ExceptionIf the file is not in the specified format.

Implements bpp::ISequence.

Definition at line 62 of file AbstractISequence.h.

References bpp::AbstractISequence::readSequencesFromStream().

◆ readSequencesFromFile()

std::unique_ptr<SequenceContainerInterface> bpp::AbstractISequence::readSequencesFromFile ( const std::string &  path,
std::shared_ptr< const Alphabet > &  alpha 
) const
inlineprotectedinherited

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 123 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromFile().

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

◆ readSequencesFromStream()

std::unique_ptr<SequenceContainerInterface> bpp::AbstractISequence::readSequencesFromStream ( std::istream &  input,
std::shared_ptr< const Alphabet > &  alpha 
) const
inlineprotectedinherited

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 109 of file AbstractISequence.h.

References bpp::AbstractISequence::appendSequencesFromStream().

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

◆ strictNames() [1/2]

bool bpp::Fasta::strictNames ( ) const
inline
Returns
true if the sequence name is restricted to be between '>' and the first space character.

Definition at line 133 of file Fasta.h.

References strictNames_.

Referenced by bpp::Fasta::FileIndex::getSequence().

◆ strictNames() [2/2]

void bpp::Fasta::strictNames ( bool  yn)
inline

Tell wethed the sequence name should be restrected to the first non blank characters.

Parameters
ynwhether the sequence names should be restrected.

Definition at line 140 of file Fasta.h.

References strictNames_.

◆ writeAlignment() [1/2]

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

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 78 of file AbstractOSequence.h.

References bpp::AbstractOSequence::writeSequences().

◆ writeAlignment() [2/2]

void bpp::AbstractOSequence2::writeAlignment ( std::ostream &  output,
const SiteContainerInterface sc 
) const
inlineoverridevirtualinherited

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 73 of file AbstractOSequence.h.

References bpp::AbstractOSequence::writeSequences().

◆ writeSequence() [1/2]

void Fasta::writeSequence ( std::ostream &  output,
const Sequence seq 
) const
override

◆ writeSequence() [2/2]

template<class SequenceType >
virtual void bpp::TemplateOSequenceStream< SequenceType >::writeSequence ( std::ostream &  output,
const SequenceType &  seq 
) const
pure virtualinherited

Read sequence from stream.

Read one sequence from a stream.

Parameters
outputThe stream where write.
seqThe sequence to write.
Exceptions
ExceptionIOExecption.

◆ writeSequences() [1/2]

void bpp::Fasta::writeSequences ( const std::string &  path,
const SequenceContainerInterface 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::AbstractOSequence.

Definition at line 83 of file Fasta.h.

References bpp::AbstractOSequence::writeSequences().

◆ writeSequences() [2/2]

void Fasta::writeSequences ( std::ostream &  output,
const SequenceContainerInterface 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::AbstractOSequence.

Definition at line 178 of file Fasta.cpp.

References bpp::Commentable::getComments(), bpp::TemplateSequenceDataInterface< HashType >::getSequenceNames(), and bpp::TemplateSequenceContainerInterface< SequenceType, HashType >::sequence().

Member Data Documentation

◆ charsByLine_

unsigned int bpp::Fasta::charsByLine_
protected

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

Definition at line 37 of file Fasta.h.

◆ checkNames_

bool bpp::Fasta::checkNames_
protected

Definition at line 38 of file Fasta.h.

Referenced by checkNames().

◆ extended_

bool bpp::Fasta::extended_
protected

Definition at line 39 of file Fasta.h.

◆ strictNames_

bool bpp::Fasta::strictNames_
protected

Definition at line 40 of file Fasta.h.

Referenced by strictNames().


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