]> git.donarmstrong.com Git - fastq-tools.git/blob - src/parse.h
4a0a0dded6d8668c03ad81e20400e60bec14ecfe
[fastq-tools.git] / src / parse.h
1 /*
2  * This file is part of fastq-tools.
3  *
4  * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
5  *
6  * parse :
7  * A parser for FASTQ files.
8  *
9  */
10
11 #ifndef FASTQ_TOOLS_PARSE_H
12 #define FASTQ_TOOLS_PARSE_H
13
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17
18 /* A string structure to keep-track of a reserved space. */
19 typedef struct
20 {
21     char*  s;    /* null-terminated string */
22     size_t n;    /* length of s */
23     size_t size; /* bytes allocated for s */
24 } str_t;
25
26
27 /* A single fastq entry. */
28 typedef struct
29 {
30     str_t id1;
31     str_t seq;
32     str_t id2;
33     str_t qual;
34 } seq_t;
35
36
37 /* Allocate a new empty seq_t. */
38 seq_t* seq_create();
39
40
41 /* Free a seq allocated with seq_create. */
42 void seq_free(seq_t* seq);
43
44
45 /* Hash a fastq entry. */
46 uint32_t seq_hash(const seq_t* seq);
47
48
49 /* Internal data for the fastq parser. */
50 typedef struct fastq_t_ fastq_t;
51
52
53 /* Create a new fastq parser object.
54  *
55  * Args:
56  *   file: A file that has been opened for reading.
57  */
58 fastq_t* fastq_create(FILE* file);
59
60
61 /* Free memory associated with a fastq_t object. */
62 void fastq_free(fastq_t*);
63
64
65 /* Read one fastq entry.
66  *
67  * Args:
68  *   f: A fastq_t parser object.
69  *   seq: A seq_t object that has been allocated with seq_create.
70  *
71  * Returns:
72  *   True if an entry was read, false if end-of-file was reached.
73  */
74 bool fastq_read(fastq_t* f, seq_t* seq);
75
76
77 /* Rewind the fastq file.
78  *
79  * The FILE passed to fastq_create must be seekable for this to work.
80  */
81 void fastq_rewind(fastq_t* f);
82
83
84 /* Print a fastq entry. */
85 void fastq_print(FILE* fout, const seq_t* seq);
86
87
88 #endif
89