From 8efb5e0ecb27b30b76b600a6c9312536dd2b81f7 Mon Sep 17 00:00:00 2001 From: Mathieu Giraud Date: Sat, 17 Oct 2015 15:20:30 +0200 Subject: [PATCH] core/fasta.{cpp,h}: implements 'nb_sequences_max' --- algo/core/fasta.cpp | 5 ++++- algo/core/fasta.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/algo/core/fasta.cpp b/algo/core/fasta.cpp index b57bff181..f4ba7cbf0 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 0e78aa4bd..c8c00cf89 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; -- GitLab