#endif
-static int help_flag;
+static const char* prog_name = "fastq-match";
void print_help()
{
- fprintf(stderr,
+ fprintf(stdout,
"fastq-match [OPTION]... QUERY [FILE]...\n"
"Perform Smith-Waterman local alignment of a query sequence\n"
"against each sequence in a fastq file.\n\n"
"Options:\n"
" -h, --help print this message\n"
+" -V, --version output version information and exit\n"
);
}
-
-
-void fastq_match(FILE* fin, FILE* fout,
- sw_t* sw,
- unsigned char* query, int n)
+void fastq_match(FILE* fin, FILE* fout, sw_t* sw)
{
int score;
- fastq_t* fqf = fastq_open(fin);
- seq_t* seq = fastq_alloc_seq();
+ fastq_t* fqf = fastq_create(fin);
+ seq_t* seq = seq_create();
- while (fastq_next(fqf, seq)) {
+ while (fastq_read(fqf, seq)) {
fprintf(fout, "%s\t", seq->seq.s);
fastq_sw_conv_seq((unsigned char*)seq->seq.s, seq->seq.n);
fprintf(fout, "%d\n", score);
}
- fastq_free_seq(seq);
- fastq_close(fqf);
+ seq_free(seq);
+ fastq_free(fqf);
}
FILE* fin;
- help_flag = 0;
-
int opt;
int opt_idx;
static struct option long_options[] =
{
- {"help", no_argument, &help_flag, 1},
- {"gap-init", required_argument, NULL, 0},
- {"gap-extend", required_argument, NULL, 0},
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'V'},
{0, 0, 0, 0}
};
while (1) {
- opt = getopt_long(argc, argv, "h", long_options, &opt_idx);
+ opt = getopt_long(argc, argv, "hV", long_options, &opt_idx);
if (opt == -1) break;
break;
case 'h':
- help_flag = 1;
- break;
+ print_help();
+ return 0;
+
+ case 'V':
+ print_version(stdout, prog_name);
+ return 0;
case '?':
return 1;
}
}
- if (help_flag) {
- print_help();
- return 0;
- }
if (optind >= argc) {
fprintf(stderr, "A query sequence must be specified.\n");
sw = fastq_alloc_sw(query, query_len);
if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) {
- fastq_match(stdin, stdout, sw, query, query_len);
+ fastq_match(stdin, stdout, sw);
}
else {
for (; optind < argc; optind++) {
continue;
}
- fastq_match(fin, stdout, sw, query, query_len);
+ fastq_match(fin, stdout, sw);
}
}