#include "hash.h"
#include "parse.h"
#include <string.h>
+#include <inttypes.h>
#include <zlib.h>
#include <getopt.h>
# define SET_BINARY_MODE(file)
#endif
-
-static int help_flag;
-static int verbose_flag;
-size_t total_reads;
+static const char* prog_name = "fastq-uniq";
void print_help()
{
"Output a non-redundant FASTQ file, in which there are no duplicate reads.\n"
"(Warning: this program can be somewhat memory intensive.)\n\n"
"Options:\n"
-" -h, --help print this message\n"
" -v, --verbose print status along the way\n"
+" -h, --help print this message\n"
+" -V, --version output version information and exit\n"
);
}
+static int verbose_flag;
+static size_t total_reads;
+
+
+
void fastq_hash(FILE* fin, hash_table* T)
{
- 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)) {
inc_hash_table(T, seq->seq.s, seq->seq.n);
total_reads++;
}
}
- fastq_free_seq(seq);
- fastq_close(fqf);
+ seq_free(seq);
+ fastq_free(fqf);
}
size_t i;
for (i = 0; i < T->m; i++) {
- fprintf(fout, ">unique-read-%07zu (%zu copies)\n", i, S[i]->count);
+ fprintf(fout, ">unique-read-%07zu (%"PRIu32" copies)\n", i, S[i]->count);
fwrite(S[i]->value, S[i]->len, sizeof(char), fout);
fprintf(fout, "\n");
}
FILE* fin ;
- help_flag = 0;
-
int opt;
int opt_idx;
static struct option long_options[] =
{
- {"help", no_argument, &help_flag, 1},
{"verbose", no_argument, &verbose_flag, 1},
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'V'},
{0, 0, 0, 0}
};
while (1) {
- opt = getopt_long(argc, argv, "hv", long_options, &opt_idx);
+ opt = getopt_long(argc, argv, "vhV", long_options, &opt_idx);
if (opt == -1) break;
}
break;
- case 'h':
- help_flag = 1;
- break;
-
case 'v':
verbose_flag = 1;
break;
case '?':
return 1;
+ case 'h':
+ print_help();
+ return 0;
+
+ case 'V':
+ print_version(stdout, prog_name);
+ return 0;
+
default:
abort();
}
}
- if (help_flag) {
- print_help();
- return 0;
- }
if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) {
fastq_hash(stdin, T);