bpp-seq  2.2.0
bpp::Fasta Class Reference

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
 
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...
 
The IOSequence interface.
const std::string getFormatName () const
 
const std::string getFormatDescription () const
 
The ISequenceStream interface.
bool nextSequence (std::istream &input, Sequence &seq) const throw (Exception)
 Read sequence from stream. More...
 
The OSequenceStream interface.
void writeSequence (std::ostream &output, const Sequence &seq) const throw (Exception)
 Read sequence from stream. More...
 
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 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 63 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 90 of file Fasta.h.

◆ ~Fasta()

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

Definition at line 93 of file Fasta.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::Fasta::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 110 of file Fasta.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 Fasta::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 147 of file Fasta.cpp.

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 159 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 166 of file Fasta.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::Fasta::getFormatDescription ( ) const
inline

Definition at line 134 of file Fasta.h.

◆ getFormatName()

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

Definition at line 133 of file Fasta.h.

◆ nextSequence()

bool Fasta::nextSequence ( std::istream &  input,
Sequence seq 
) const
throw (Exception
)
virtual

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.

Implements bpp::ISequenceStream.

Definition at line 56 of file Fasta.cpp.

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

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

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

◆ 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 171 of file Fasta.h.

References strictNames_.

◆ 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 178 of file Fasta.h.

References strictNames_.

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

◆ writeSequence()

void Fasta::writeSequence ( std::ostream &  output,
const Sequence seq 
) const
throw (Exception
)
virtual

Read sequence from stream.

Read one sequence from a stream.

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

Implements bpp::OSequenceStream.

Definition at line 116 of file Fasta.cpp.

◆ writeSequences() [1/2]

void Fasta::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 204 of file Fasta.cpp.

◆ writeSequences() [2/2]

void bpp::Fasta::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 122 of file Fasta.h.

References bpp::AbstractOSequence::writeSequences().

Member Data Documentation

◆ charsByLine_

unsigned int bpp::Fasta::charsByLine_
private

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

Definition at line 75 of file Fasta.h.

◆ checkNames_

bool bpp::Fasta::checkNames_
private

Definition at line 76 of file Fasta.h.

Referenced by checkNames().

◆ extended_

bool bpp::Fasta::extended_
private

Definition at line 77 of file Fasta.h.

◆ strictNames_

bool bpp::Fasta::strictNames_
private

Definition at line 78 of file Fasta.h.

Referenced by strictNames().


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