"Options:\n"
" -h, --help print this message\n"
" -v, --invert-match select nonmatching entries\n"
+" -c, --count output only the number of matching sequences\n"
);
}
static int invert_flag;
static int help_flag;
-static int zout_flag;
+static int count_flag;
{
int rc;
int ovector[3];
+ size_t count = 0;
kseq_t* seq;
seq = kseq_init(fin);
3 ); /* output vector length */
if ((invert_flag && rc == PCRE_ERROR_NOMATCH) || rc >= 0) {
- print_fastq_entry( fout, seq );
+ if (count_flag) count++;
+ else print_fastq_entry(fout, seq);
}
}
kseq_destroy(seq);
+
+ if (count_flag) fprintf(fout, "%zu\n", count);
}
int main(int argc, char* argv[])
{
+ SET_BINARY_MODE(stdin);
+ SET_BINARY_MODE(stdout);
+
const char* pat;
pcre* re;
const char* pat_error;
gzFile gzfin;
- invert_flag = 0;
- help_flag = 0;
- zout_flag = 0;
+ invert_flag = 0;
+ help_flag = 0;
+ count_flag = 0;
int opt;
int opt_idx;
{
{"help", no_argument, &help_flag, 1},
{"invert-match", no_argument, &invert_flag, 1},
+ {"count", no_argument, &count_flag, 1},
{0, 0, 0, 0}
};
while (1) {
- opt = getopt_long(argc, argv, "hv", long_options, &opt_idx);
+ opt = getopt_long(argc, argv, "hvc", long_options, &opt_idx);
if( opt == -1 ) break;
invert_flag = 1;
break;
+ case 'c':
+ count_flag = 1;
+ break;
+
case '?':
return 1;