]> git.donarmstrong.com Git - fastq-tools.git/blob - src/parse.h
8500f0c832fc1fb6c7460afdaa0d7ee05ce4d891
[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 <stdlib.h>
16
17 /* A string structure to keep-track of a reserved space. */
18 typedef struct
19 {
20     char*  s;    /* null-terminated string */
21     size_t n;    /* length of s */
22     size_t size; /* bytes allocated for s */
23 } str_t;
24
25
26 /* A single fastq entry. */
27 typedef struct
28 {
29     str_t id1;
30     str_t seq;
31     str_t id2;
32     str_t qual;
33 } seq_t;
34
35
36 /* Allocate a new empty seq_t. */
37 seq_t* seq_create();
38
39
40 /* Free a seq allocated with seq_create. */
41 void seq_free(seq_t* seq);
42
43
44 /* Internal data for the fastq parser. */
45 typedef struct fastq_t_ fastq_t;
46
47
48 /* Create a new fastq parser object.
49  *
50  * Args:
51  *   file: A file that has been opened for reading.
52  */
53 fastq_t* fastq_create(FILE* file);
54
55
56 /* Free memory associated with a fastq_t object. */
57 void fastq_free(fastq_t*);
58
59
60 /* Read one fastq entry.
61  *
62  * Args:
63  *   f: A fastq_t parser object.
64  *   seq: A seq_t object that has been allocated with seq_create.
65  *
66  * Returns:
67  *   True if an entry was read, false if end-of-file was reached.
68  */
69 bool fastq_read(fastq_t* f, seq_t* seq);
70
71
72 /* Print a fastq entry. */
73 void fastq_print(FILE* fout, const seq_t* seq);
74
75
76 #endif
77