Debian Codegraph @

easel/esl_sqio.h

raw symbols SCIP
1 /* sqio: unaligned sequence file i/o.
2 *
3 * To do:
4 * :: esl_sqio_* vs. esl_sqfile_* prefixing is inconsistent,
5 * for historical reasons. Fix.
6 *
7 * :: Write tests for bad format detection, making sure that
8 * linenumber report is correct.
9 */
10 #ifndef eslSQIO_INCLUDED
11 #define eslSQIO_INCLUDED
12 #include <esl_config.h>
13
14 #include <stdio.h>
15
16 #include "easel.h"
17 #include "esl_alphabet.h"
18 #include "esl_msa.h"
19 #include "esl_msafile.h"
20 #include "esl_sq.h"
21 #include "esl_sqio_ascii.h"
22 #include "esl_sqio_ncbi.h"
23
24 /*::cexcerpt::sq_sqio_data::begin::*/
25 /* ESL_SQDATA:
26 * Data for different sequence formats.
27 */
28 typedef union {
29 ESL_SQASCII_DATA ascii;
30 ESL_SQNCBI_DATA ncbi;
31 } ESL_SQDATA;
32 /*::cexcerpt::sq_sqio_data::end::*/
33
34 /* ESL_SQFILE:
35 * An open sequence file for reading.
36 */
37 typedef struct esl_sqio_s {
38 char *filename; /* Name of file (for diagnostics) */
39
40 /* In digital mode, we have an alphabet ptr */
41 int do_digital; /* TRUE if we're reading in digital mode */
42 const ESL_ALPHABET *abc;
43
44 /* Format-specific configuration */
45 int format; /* Format code of this file */
46 ESL_DSQ inmap[128]; /* an input map, 0..127 */
47
48 /* function pointers to format specific routines */
49 int (*position) (struct esl_sqio_s *sqfp, off_t offset);
50 void (*close) (struct esl_sqio_s *sqfp);
51
52 int (*set_digital) (struct esl_sqio_s *sqfp, const ESL_ALPHABET *abc);
53 int (*guess_alphabet) (struct esl_sqio_s *sqfp, int *ret_type);
54
55 int (*read) (struct esl_sqio_s *sqfp, ESL_SQ *sq);
56 int (*read_info) (struct esl_sqio_s *sqfp, ESL_SQ *sq);
57 int (*read_seq) (struct esl_sqio_s *sqfp, ESL_SQ *sq);
58 int (*read_window) (struct esl_sqio_s *sqfp, int C, int W, ESL_SQ *sq);
59 int (*echo) (struct esl_sqio_s *sqfp, const ESL_SQ *sq, FILE *ofp);
60
61 int (*read_block) (struct esl_sqio_s *sqfp, ESL_SQ_BLOCK *sqBlock, int max_residues, int max_sequences, int max_init_window, int long_target);
62
63 int (*open_ssi) (struct esl_sqio_s *sqfp, const char *ssifile_hint);
64 int (*pos_by_key) (struct esl_sqio_s *sqfp, const char *key);
65 int (*pos_by_number) (struct esl_sqio_s *sqfp, int which);
66
67 int (*fetch) (struct esl_sqio_s *sqfp, const char *key, ESL_SQ *sq);
68 int (*fetch_info) (struct esl_sqio_s *sqfp, const char *key, ESL_SQ *sq);
69 int (*fetch_subseq) (struct esl_sqio_s *sqfp, const char *source, int64_t start, int64_t end, ESL_SQ *sq);
70
71 int (*is_rewindable) (const struct esl_sqio_s *sqfp);
72 const char *(*get_error) (const struct esl_sqio_s *sqfp);
73
74 ESL_SQDATA data; /* format specific data */
75 } ESL_SQFILE;
76
77 /* ESL_SQCACHE:
78 * A entire database cached into memory.
79 */
80 typedef struct esl_sqcache_s {
81 char *filename; /* Name of file (for diagnostics) */
82 int format; /* Format code of this file */
83
84 const ESL_ALPHABET *abc; /* alphabet for database */
85
86 uint32_t seq_count; /* number of sequences */
87 uint64_t res_count; /* number of residues */
88 uint32_t max_seq; /* longest sequence */
89
90 ESL_SQ *sq_list; /* list of cached sequences [0 .. seq_count-1] */
91
92 void *residue_mem; /* memory holding the residues */
93 void *header_mem; /* memory holding the header strings */
94
95 uint64_t res_size; /* size of residue memory allocation */
96 uint64_t hdr_size; /* size of header memory allocation */
97 } ESL_SQCACHE;
98
99 /*::cexcerpt::sq_sqio_format::begin::*/
100 /* Unaligned file format codes
101 * These codes are coordinated with the msa module.
102 * - 0 is an unknown/unassigned format (eslSQFILE_UNKNOWN, eslMSAFILE_UNKNOWN)
103 * - <=100 is reserved for sqio, for unaligned formats
104 * - >100 is reserved for msa, for aligned formats
105 */
106 #define eslSQFILE_UNKNOWN 0
107 #define eslSQFILE_FASTA 1 // FASTA format
108 #define eslSQFILE_EMBL 2 // EMBL DNA sequence
109 #define eslSQFILE_GENBANK 3 // Genbank DNA sequence
110 #define eslSQFILE_DDBJ 4 // DDBJ (currently identical to GenBank parser)
111 #define eslSQFILE_UNIPROT 5 // UniProt (currently identical to EMBL parser)
112 #define eslSQFILE_NCBI 6 // NCBI blast db, v4, single file
113 #define eslSQFILE_DAEMON 7 // Farrar format, hmmpgmd queries: fasta + // terminator
114 #define eslSQFILE_HMMPGMD 8 // Farrar hmmpgmd database format: fasta + # header
115 #define eslSQFILE_FMINDEX 9 // Pressed FM-index format used in HMMER
116 /*::cexcerpt::sq_sqio_format::end::*/
117
118
119 /* eslREADBUFSIZE is the fixed size of a block to bring in at one time,
120 * in character-based (fread()) parsers (like the FASTA parser).
121 */
122 #define eslREADBUFSIZE 4096
123
124 extern int esl_sqfile_Open(const char *seqfile, int fmt, const char *env, ESL_SQFILE **ret_sqfp);
125 extern void esl_sqfile_Close(ESL_SQFILE *sqfp);
126
127 extern int esl_sqfile_OpenDigital(const ESL_ALPHABET *abc, const char *filename, int format, const char *env, ESL_SQFILE **ret_sqfp);
128 extern int esl_sqfile_SetDigital(ESL_SQFILE *sqfp, const ESL_ALPHABET *abc);
129 extern int esl_sqfile_GuessAlphabet(ESL_SQFILE *sqfp, int *ret_type);
130
131 extern int esl_sqio_Read (ESL_SQFILE *sqfp, ESL_SQ *sq);
132 extern int esl_sqio_ReadInfo (ESL_SQFILE *sqfp, ESL_SQ *sq);
133 extern int esl_sqio_ReadWindow (ESL_SQFILE *sqfp, int C, int W, ESL_SQ *sq);
134 extern int esl_sqio_ReadSequence(ESL_SQFILE *sqfp, ESL_SQ *sq);
135 extern int esl_sqio_ReadBlock (ESL_SQFILE *sqfp, ESL_SQ_BLOCK *sqBlock, int max_residues, int max_sequences, int max_init_window, int long_target);
136 extern int esl_sqio_Parse (char *buffer, int size, ESL_SQ *s, int format);
137
138 extern int esl_sqio_Write (FILE *fp, ESL_SQ *s, int format, int update);
139 extern int esl_sqio_Echo (ESL_SQFILE *sqfp, const ESL_SQ *sq, FILE *ofp);
140
141 const char *esl_sqfile_GetErrorBuf(const ESL_SQFILE *sqfp);
142 extern int esl_sqfile_IsRewindable(const ESL_SQFILE *sqfp);
143 extern int esl_sqio_IsAlignment(int fmt);
144 extern int esl_sqio_EncodeFormat(char *fmtstring);
145 extern char *esl_sqio_DecodeFormat(int fmt);
146 extern int esl_sqfile_Position(ESL_SQFILE *sqfp, off_t offset);
147 extern int esl_sqio_Ignore(ESL_SQFILE *sqfp, const char *ignoredchars);
148 extern int esl_sqio_AcceptAs(ESL_SQFILE *sqfp, char *xchars, char readas);
149
150 extern int esl_sqfile_OpenSSI (ESL_SQFILE *sqfp, const char *ssifile_hint);
151 extern int esl_sqfile_PositionByKey (ESL_SQFILE *sqfp, const char *key);
152 extern int esl_sqfile_PositionByNumber(ESL_SQFILE *sqfp, int which);
153
154 extern int esl_sqio_Fetch (ESL_SQFILE *sqfp, const char *key, ESL_SQ *sq);
155 extern int esl_sqio_FetchInfo (ESL_SQFILE *sqfp, const char *key, ESL_SQ *sq);
156 extern int esl_sqio_FetchSubseq(ESL_SQFILE *sqfp, const char *source, int64_t start, int64_t end, ESL_SQ *sq);
157
158 extern int esl_sqfile_Cache(const ESL_ALPHABET *abc, const char *seqfile, int fmt, const char *env, ESL_SQCACHE **ret_sqcache);
159 extern void esl_sqfile_Free(ESL_SQCACHE *sqcache);
160
161 #endif /*eslSQIO_INCLUDED*/
162