diff --git a/algo/core/fasta.cpp b/algo/core/fasta.cpp index b57bff181b09c24c0cc27cef442f13d7999a07d3..f4ba7cbf0ee41d0839348abb29d4486706dddde3 100644 --- a/algo/core/fasta.cpp +++ b/algo/core/fasta.cpp @@ -150,6 +150,7 @@ OnlineFasta::~OnlineFasta() { } void OnlineFasta::init() { + nb_sequences_returned = 0; char_nb = 0; line_nb = 0; line = getInterestingLine(); @@ -169,7 +170,8 @@ Sequence OnlineFasta::getSequence() { } bool OnlineFasta::hasNext() { - return (! input->eof()) || line.length() > 0; + return ((!input->eof()) || line.length() > 0) + && ((nb_sequences_max == NO_LIMIT_VALUE) || (nb_sequences_returned < nb_sequences_max)); } void OnlineFasta::next() { @@ -194,6 +196,7 @@ void OnlineFasta::next() { } // Identifier line + nb_sequences_returned++; current.label_full = line.substr(1); current.label = extract_from_label(current.label_full, extract_field, extract_separator); diff --git a/algo/core/fasta.h b/algo/core/fasta.h index 0e78aa4bdb3ae9a52ca59d0246b7fa38cd66001c..c8c00cf89c9bc58ecc25288110bb70d3469a715b 100644 --- a/algo/core/fasta.h +++ b/algo/core/fasta.h @@ -97,6 +97,7 @@ class OnlineFasta { size_t line_nb; unsigned long long char_nb; + int nb_sequences_returned; int nb_sequences_max; int only_nth_sequence;