-/*
- * fastq-kmers: kmer frequences within fastq files
+/*
+ * This file is part of fastq-tools.
*
- * Febuary 2011 / Daniel Jones <dcjones@cs.washington.edu>
+ * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
+ *
+ * fastq-kmers :
+ * Tabulate k-mer frequencies with FASTQ files.
*
*/
-
-
+#include "fastq-common.h"
+#include "fastq-parse.h"
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <getopt.h>
#include <zlib.h>
-#include "kseq.h"
-KSEQ_INIT(gzFile, gzread)
-
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
}
-void count_fastq_kmers(gzFile* fin, uint32_t* cs)
+void count_fastq_kmers(FILE* fin, uint32_t* cs)
{
- kseq_t* seq = kseq_init(fin);
+ seq_t* seq = fastq_alloc_seq();
+ fastq_t* fqf = fastq_open(fin);
int i;
int n;
uint32_t kmer;
- while (kseq_read(seq) >= 0) {
- n = (int)seq->seq.l - k + 1;
+ while (fastq_next(fqf, seq)) {
+ n = (int)seq->seq.n - k + 1;
for (i = 0; i < n; i++) {
if( packkmer(seq->seq.s + i, &kmer, k) ) {
cs[kmer]++;
}
}
- kseq_destroy(seq);
+ fastq_free_seq(seq);
+ fastq_close(fqf);
}
uint32_t* cs; /* counts */
FILE* fin;
- gzFile gzfin;
int opt;
int opt_idx;
}
if (optind >= argc || (argc - optind == 1 && strcmp(argv[optind],"-") == 0)) {
- gzfin = gzdopen( fileno(stdin), "rb" );
- if (gzfin == NULL) {
- fprintf(stderr, "Malformed file 'stdin'.\n");
- return 1;
- }
-
- count_fastq_kmers(gzfin, cs);
-
- gzclose(gzfin);
+ count_fastq_kmers(stdin, cs);
}
else {
for (; optind < argc; optind++) {
continue;
}
- gzfin = gzdopen(fileno(fin), "rb");
- if (gzfin == NULL) {
- fprintf(stderr, "Malformed file '%s'.\n", argv[optind]);
- continue;
- }
-
- count_fastq_kmers(gzfin, cs);
-
- gzclose(gzfin);
+ count_fastq_kmers(fin, cs);
}
}