+static int count_flag;
+
+
+
+void print_fastq_entry(FILE* fout, seq_t* seq)
+{
+ fprintf(fout, "@%s\n%s\n+%s\n%s\n",
+ seq->id1.s,
+ seq->seq.s,
+ seq->id2.s,
+ seq->qual.s );
+}
+
+
+void fastq_grep(FILE* fin, FILE* fout, pcre* re)
+{
+ int rc;
+ int ovector[3];
+ size_t count = 0;
+
+ fastq_t* fqf = fastq_open(fin);
+ seq_t* seq = fastq_alloc_seq();
+
+ while (fastq_next(fqf, seq)) {
+ rc = pcre_exec(re, /* pattern */
+ NULL, /* extre data */
+ seq->seq.s, /* subject */
+ seq->seq.n, /* subject length */
+ 0, /* subject offset */
+ 0, /* options */
+ ovector, /* output vector */
+ 3 ); /* output vector length */
+
+ if ((invert_flag && rc == PCRE_ERROR_NOMATCH) || rc >= 0) {
+ if (count_flag) count++;
+ else print_fastq_entry(fout, seq);
+ }
+ }
+
+ fastq_free_seq(seq);
+ fastq_close(fqf);
+
+ if (count_flag) fprintf(fout, "%zu\n", count);
+}
+
+