X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Ffastq-uniq.c;h=f77a10ce95cebe9ac0b6be27ba5e5ac40a4ed492;hb=42c2a6b10b6313b7f87189f1467996fc3cf18e24;hp=fddb52a7073fdb7d7120a22df855988779083652;hpb=40ab4c0cde1bfee1616777995998b0cbc5ffc741;p=fastq-tools.git diff --git a/src/fastq-uniq.c b/src/fastq-uniq.c index fddb52a..f77a10c 100644 --- a/src/fastq-uniq.c +++ b/src/fastq-uniq.c @@ -10,9 +10,10 @@ #include "common.h" -#include "hash.h" +#include "hash_table.h" #include "parse.h" #include +#include #include #include @@ -25,10 +26,7 @@ # 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() { @@ -37,18 +35,24 @@ 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++; @@ -57,8 +61,8 @@ void fastq_hash(FILE* fin, hash_table* T) } } - fastq_free_seq(seq); - fastq_close(fqf); + seq_free(seq); + fastq_free(fqf); } @@ -81,7 +85,7 @@ void print_hash_table(FILE* fout, hash_table* T) 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"); } @@ -99,20 +103,19 @@ int main(int argc, char* argv[]) 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; @@ -123,10 +126,6 @@ int main(int argc, char* argv[]) } break; - case 'h': - help_flag = 1; - break; - case 'v': verbose_flag = 1; break; @@ -134,15 +133,19 @@ int main(int argc, char* argv[]) 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);