Skip to content

Commit

Permalink
Ignore consecutive empty newlines, and don't exit, in interactive mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Aug 22, 2024
1 parent 6e31734 commit 70bc8ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion bwaseqio.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,17 @@ bwa_seq_t *bwa_read_seq2(bwa_seqio_t *bs, int n_needed, int *n, int mode, int tr
if (bs->is_bam) return bwa_read_bam(bs, n_needed, n, is_comp, trim_qual); // l_bc has no effect for BAM input
n_seqs = 0;
seqs = (bwa_seq_t*)calloc(n_needed, sizeof(bwa_seq_t));
while ((l = kseq_read2(seq, !interactive_mode)) >= 0) {
for (;;) {
// Reading in one-sequence at a time.
// - in interactive mode, keep reading until we have read at least one sequence and then stop after the first blank line.
// - in non-interactive mode, read up to the number of sequences needed or the end-of-file.
l = kseq_read2(seq, !interactive_mode); // read it in
if (interactive_mode && l == -3) { // -3 is an empty line
if (n_seqs == 0) continue; // need more, skip the empty line
else break; // we have at least one read, so return the reads before the first emtpy line.
}
else if (l < 0) break; // did we get a read?

if ((mode & BWA_MODE_CFY) && (seq->comment.l != 0)) {
// skip reads that are marked to be filtered by Casava
char *s = index(seq->comment.s, ':');
Expand Down
2 changes: 1 addition & 1 deletion kseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ typedef struct __kstring_t {
if (ignore_empty_lines) while ((c = ks_getc(ks)) != -1 && c != '>' && c != '@'); \
else { \
while ((c = ks_getc(ks)) != -1 && c != '>' && c != '@') { \
if (c == '\n') return -3; \
if (c == '\n') { seq->last_char = 0; return -3; } \
} \
} \
if (c == -1) return -1; /* end of file */ \
Expand Down

0 comments on commit 70bc8ca

Please sign in to comment.