]> git.donarmstrong.com Git - fastq-tools.git/blob - src/parse.h
Sort by gc content and mean quality score, and seededing of random sort.
[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 /* Set the seed to use for seq_hash. Different seeds result in different hash
49  * functions. */
50 void seq_hash_set_seed(uint32_t seed);
51
52
53 /* Internal data for the fastq parser. */
54 typedef struct fastq_t_ fastq_t;
55
56
57 /* Create a new fastq parser object.
58  *
59  * Args:
60  *   file: A file that has been opened for reading.
61  */
62 fastq_t* fastq_create(FILE* file);
63
64
65 /* Free memory associated with a fastq_t object. */
66 void fastq_free(fastq_t*);
67
68
69 /* Read one fastq entry.
70  *
71  * Args:
72  *   f: A fastq_t parser object.
73  *   seq: A seq_t object that has been allocated with seq_create.
74  *
75  * Returns:
76  *   True if an entry was read, false if end-of-file was reached.
77  */
78 bool fastq_read(fastq_t* f, seq_t* seq);
79
80
81 /* Rewind the fastq file.
82  *
83  * The FILE passed to fastq_create must be seekable for this to work.
84  */
85 void fastq_rewind(fastq_t* f);
86
87
88 /* Print a fastq entry. */
89 void fastq_print(FILE* fout, const seq_t* seq);
90
91
92 #endif
93