]> git.donarmstrong.com Git - fastq-tools.git/blobdiff - src/parse.h
Fix the weird output behavior of fastq-sample.
[fastq-tools.git] / src / parse.h
index 64d3726174acc10648f45d9ce45cbba5015a3c64..6224ab8d07368e735cfcb7d504ea67da05994b6e 100644 (file)
@@ -3,21 +3,18 @@
  *
  * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
  *
- * fastq-parse :
+ * parse :
  * A parser for FASTQ files.
  *
- * This parser is mostly derivative of Heng Li's.
- * See: http://lh3lh3.users.sourceforge.net/kseq.shtml
- *
  */
 
 #ifndef FASTQ_TOOLS_PARSE_H
 #define FASTQ_TOOLS_PARSE_H
 
-#include <stdio.h>
-#include <zlib.h>
-
+#include <stdbool.h>
+#include <stdlib.h>
 
+/* A string structure to keep-track of a reserved space. */
 typedef struct
 {
     char*  s;    /* null-terminated string */
@@ -26,7 +23,7 @@ typedef struct
 } str_t;
 
 
-
+/* A single fastq entry. */
 typedef struct
 {
     str_t id1;
@@ -36,24 +33,51 @@ typedef struct
 } seq_t;
 
 
-seq_t* fastq_alloc_seq();
-void fastq_free_seq(seq_t*);
+/* Allocate a new empty seq_t. */
+seq_t* seq_create();
 
 
-typedef struct
-{
-    gzFile file;
-    int    state;
-    char*  buf;
-    char*  c;
-} fastq_t;
+/* Free a seq allocated with seq_create. */
+void seq_free(seq_t* seq);
+
+
+/* Internal data for the fastq parser. */
+typedef struct fastq_t_ fastq_t;
+
+
+/* Create a new fastq parser object.
+ *
+ * Args:
+ *   file: A file that has been opened for reading.
+ */
+fastq_t* fastq_create(FILE* file);
 
 
-fastq_t* fastq_open(FILE*);
-void fastq_close(fastq_t*);
-int  fastq_next(fastq_t*, seq_t*);
+/* Free memory associated with a fastq_t object. */
+void fastq_free(fastq_t*);
+
+
+/* Read one fastq entry.
+ *
+ * Args:
+ *   f: A fastq_t parser object.
+ *   seq: A seq_t object that has been allocated with seq_create.
+ *
+ * Returns:
+ *   True if an entry was read, false if end-of-file was reached.
+ */
+bool fastq_read(fastq_t* f, seq_t* seq);
+
+
+/* Rewind the fastq file.
+ *
+ * The FILE passed to fastq_create must be seekable for this to work.
+ */
+void fastq_rewind(fastq_t* f);
+
 
-void fastq_print(FILE* fout, seq_t* seq);
+/* Print a fastq entry. */
+void fastq_print(FILE* fout, const seq_t* seq);
 
 
 #endif