Commit e2a2d04b authored by Mathieu Giraud's avatar Mathieu Giraud

core/fasta.{cpp,h}: implements 'only_nth_sequence'

parent 8efb5e0e
......@@ -150,6 +150,7 @@ OnlineFasta::~OnlineFasta() {
}
void OnlineFasta::init() {
nb_sequences_parsed = 0;
nb_sequences_returned = 0;
char_nb = 0;
line_nb = 0;
......@@ -174,6 +175,20 @@ bool OnlineFasta::hasNext() {
&& ((nb_sequences_max == NO_LIMIT_VALUE) || (nb_sequences_returned < nb_sequences_max));
}
void OnlineFasta::skipToNthSequence() {
// Possibly skip some reads, when only_nth_sequence > 1
while (hasNext())
if (nb_sequences_parsed % only_nth_sequence)
{
nb_sequences_returned--;
next();
continue ;
}
else
return ;
}
void OnlineFasta::next() {
fasta_state state = FASTX_UNINIT;
......@@ -196,6 +211,7 @@ void OnlineFasta::next() {
}
// Identifier line
nb_sequences_parsed++;
nb_sequences_returned++;
current.label_full = line.substr(1);
current.label = extract_from_label(current.label_full, extract_field, extract_separator);
......@@ -247,6 +263,8 @@ void OnlineFasta::next() {
} else
unexpectedEOF();
skipToNthSequence();
}
string OnlineFasta::getInterestingLine(int state) {
......
......@@ -97,6 +97,7 @@ class OnlineFasta {
size_t line_nb;
unsigned long long char_nb;
int nb_sequences_parsed;
int nb_sequences_returned;
int nb_sequences_max;
int only_nth_sequence;
......@@ -161,6 +162,11 @@ class OnlineFasta {
*/
void init();
/**
* Skip to the next sequence that is a multiple of 'only_nth_sequence'
*/
void skipToNthSequence();
/**
* Reads line in the input stream until we have a line with at least one
* non-whitespace character.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment