A library for working with phylogenetic and population genetic data.
v0.27.0
FastaInputIterator Class Reference

#include <genesis/sequence/formats/fasta_input_iterator.hpp>

Detailed Description

Iterate an input source and parse it as Fasta sequences.

This class allows to iterate over an input source, interpreting it as Fasta sequences, and yielding one such sequence per iteration step. This is useful for processing large files without having to keep them fully in memory.

Example:

for( auto const& s : FastaInputIterator( from_file( "/path/to/large_file.fasta" ))) {
    std::cout << s.length() << "\n";
}

Alternatively, the following also works:

auto it = FastaInputIterator( from_file( "/path/to/large_file.fasta" ) );
while( it ) {
    std::cout << it->length() << "\n";
    ++it;
}

Use functions such as utils::from_file() and utils::from_string() to conveniently get an input source that can be used here.

See FastaReader for a description of the expected format. In order to change the reading behaviour, a FastaReader object can be handed over from which the settings are copied.

The copy constructur copies a pointer to the underlying source. Thus, when advancing the copy to the next Sequence, the original "skips" this Sequence, as the source then is at the next one.

Thread safety: No thread safety. The common use case for this iterator is to loop over a file. Thus, guarding induces unnecessary overhead. If multiple threads read from this iterator, both dereferencing and incrementing need to be guarded.

Definition at line 87 of file fasta_input_iterator.hpp.

Public Member Functions

 FastaInputIterator ()
 Create a default instance, with no input. More...
 
 FastaInputIterator (self_type &&)=default
 
 FastaInputIterator (self_type const &)=default
 
 FastaInputIterator (std::shared_ptr< utils::BaseInputSource > source)
 Create an instance that reads from an input source, using a default FastaReader. More...
 
 FastaInputIterator (std::shared_ptr< utils::BaseInputSource > source, FastaReader const &settings)
 Create an instance that reads from an input source, using the settings of a given FastaReader. More...
 
 ~FastaInputIterator ()=default
 
self_typebegin ()
 Beginning of the iterator. More...
 
value_type const & dereference () const
 
self_type end ()
 End of the iterator. More...
 
void increment ()
 
 operator bool () const
 Return true iff dereferencing is valid, i.e., iff there is a Sequence available. More...
 
bool operator!= (self_type const &other) const
 
value_type const & operator* () const
 
self_typeoperator++ ()
 
self_type operator++ (int)
 
value_type const * operator-> () const
 
self_typeoperator= (self_type &&)=default
 
self_typeoperator= (self_type const &)=default
 
bool operator== (self_type const &other) const
 

Public Types

using difference_type = std::ptrdiff_t
 
using iterator_category = std::input_iterator_tag
 
using pointer = value_type *
 
using reference = value_type &
 
using self_type = FastaInputIterator
 
using value_type = Sequence
 

Constructor & Destructor Documentation

◆ FastaInputIterator() [1/5]

FastaInputIterator ( )
inline

Create a default instance, with no input.

Definition at line 109 of file fasta_input_iterator.hpp.

◆ FastaInputIterator() [2/5]

FastaInputIterator ( std::shared_ptr< utils::BaseInputSource source)
inlineexplicit

Create an instance that reads from an input source, using a default FastaReader.

Definition at line 118 of file fasta_input_iterator.hpp.

◆ FastaInputIterator() [3/5]

FastaInputIterator ( std::shared_ptr< utils::BaseInputSource source,
FastaReader const &  settings 
)
inline

Create an instance that reads from an input source, using the settings of a given FastaReader.

Definition at line 130 of file fasta_input_iterator.hpp.

◆ ~FastaInputIterator()

~FastaInputIterator ( )
default

◆ FastaInputIterator() [4/5]

FastaInputIterator ( self_type const &  )
default

◆ FastaInputIterator() [5/5]

FastaInputIterator ( self_type &&  )
default

Member Function Documentation

◆ begin()

self_type& begin ( )
inline

Beginning of the iterator.

This is a bit uncommon, as the iterator provides its own begin() and end() functions. We do this to allow the easy use case that is explained above.

Definition at line 197 of file fasta_input_iterator.hpp.

◆ dereference()

value_type const& dereference ( ) const
inline

Definition at line 182 of file fasta_input_iterator.hpp.

◆ end()

self_type end ( )
inline

End of the iterator.

Beginning of the iterator. This is a bit uncommon, as the iterator provides its own begin() and end() functions. We do this to allow the easy use case that is explained above.

Definition at line 207 of file fasta_input_iterator.hpp.

◆ increment()

void increment ( )
inline

Definition at line 225 of file fasta_input_iterator.hpp.

◆ operator bool()

operator bool ( ) const
inlineexplicit

Return true iff dereferencing is valid, i.e., iff there is a Sequence available.

Definition at line 163 of file fasta_input_iterator.hpp.

◆ operator!=()

bool operator!= ( self_type const &  other) const
inline

Definition at line 155 of file fasta_input_iterator.hpp.

◆ operator*()

value_type const& operator* ( ) const
inline

Definition at line 172 of file fasta_input_iterator.hpp.

◆ operator++() [1/2]

self_type& operator++ ( )
inline

Definition at line 212 of file fasta_input_iterator.hpp.

◆ operator++() [2/2]

self_type operator++ ( int  )
inline

Definition at line 218 of file fasta_input_iterator.hpp.

◆ operator->()

value_type const* operator-> ( ) const
inline

Definition at line 177 of file fasta_input_iterator.hpp.

◆ operator=() [1/2]

self_type& operator= ( self_type &&  )
default

◆ operator=() [2/2]

self_type& operator= ( self_type const &  )
default

◆ operator==()

bool operator== ( self_type const &  other) const
inline

Definition at line 150 of file fasta_input_iterator.hpp.

Member Typedef Documentation

◆ difference_type

using difference_type = std::ptrdiff_t

Definition at line 99 of file fasta_input_iterator.hpp.

◆ iterator_category

using iterator_category = std::input_iterator_tag

Definition at line 100 of file fasta_input_iterator.hpp.

◆ pointer

using pointer = value_type*

Definition at line 97 of file fasta_input_iterator.hpp.

◆ reference

Definition at line 98 of file fasta_input_iterator.hpp.

◆ self_type

Definition at line 95 of file fasta_input_iterator.hpp.

◆ value_type

Definition at line 96 of file fasta_input_iterator.hpp.


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