comparison srf2fastq/io_lib-1.12.2/io_lib/scf.h @ 0:d901c9f41a6a default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author dawe
date Tue, 07 Jun 2011 17:48:05 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d901c9f41a6a
1 /*
2 * Copyright (c) Medical Research Council 1994. All rights reserved.
3 *
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * this copyright and notice appears in all copies.
7 *
8 * This file was written by James Bonfield, Simon Dear, Rodger Staden,
9 * as part of the Staden Package at the MRC Laboratory of Molecular
10 * Biology, Hills Road, Cambridge, CB2 2QH, United Kingdom.
11 *
12 * MRC disclaims all warranties with regard to this software.
13 */
14
15 /*
16 * File: scf.h
17 * Version: 3.00
18 *
19 * Description: file structure definitions for SCF file
20 *
21 * Created: 19 November 1992
22 *
23 */
24
25 #ifndef _SCF_H_
26 #define _SCF_H_
27
28 #include <stdio.h>
29 #include <sys/types.h>
30
31 #include "io_lib/mFILE.h"
32 #include "io_lib/os.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /*
39 *-----------------------------------------------------------------------------
40 * Macros
41 *-----------------------------------------------------------------------------
42 */
43
44 /* The SCF magic number */
45 #define SCF_MAGIC (((((uint_4)'.'<<8)+(uint_4)'s'<<8)+(uint_4)'c'<<8)+(uint_4)'f')
46
47 /* prior to this was a different format */
48 #define SCF_VERSION_OLDEST 2.00
49 #define SCF_VERSION_OLD 2.02
50
51 /* The current SCF format level */
52 #define SCF_VERSION 3.00
53
54 /* Uncertainty code sets supported */
55 #define CSET_DEFAULT 0 /* {A,C,G,T,-} */
56 #define CSET_STADEN 1
57 #define CSET_NC_IUB 2 /* Pharmacia A.L.F. */
58 #define CSET_ALF 3 /* extended NC_IUB */
59 #define CSET_ABI 4 /* {A,C,G,T,N} */
60 #define CSET_IBI 5 /* IBI/Pustell */
61 #define CSET_DNASTAR 6 /* DNA* */
62 #define CSET_DNASIS 7
63 #define CSET_PCGENE 8 /* IG/PC-Gene */
64 #define CSET_GENIE 9 /* MicroGenie */
65
66 /* define samples to delta_delta values */
67 #define DELTA_IT 1
68
69 /* What components to read */
70 #define READ_BASES (1<<0)
71 #define READ_SAMPLES (1<<1)
72 #define READ_COMMENTS (1<<2)
73 #define READ_ALL (READ_BASES | READ_SAMPLES | READ_COMMENTS)
74
75 /*
76 *-----------------------------------------------------------------------------
77 * Structures and typedefs
78 *-----------------------------------------------------------------------------
79 */
80
81 /*
82 * Type definition for the Header structure
83 */
84 typedef struct {
85 uint_4 magic_number; /* SCF_MAGIC */
86 uint_4 samples; /* Number of elements in Samples matrix */
87 uint_4 samples_offset; /* Byte offset from start of file */
88 uint_4 bases; /* Number of bases in Bases matrix */
89 uint_4 bases_left_clip; /* OBSOLETE: No. bases in left clip (vector) */
90 uint_4 bases_right_clip; /* OBSOLETE: No. bases in right clip (qual) */
91 uint_4 bases_offset; /* Byte offset from start of file */
92 uint_4 comments_size; /* Number of bytes in Comment section */
93 uint_4 comments_offset; /* Byte offset from start of file */
94 char version[4]; /* "version.revision" */
95 uint_4 sample_size; /* precision of samples (in bytes) */
96 uint_4 code_set; /* uncertainty codes used */
97 uint_4 private_size; /* size of private data, 0 if none */
98 uint_4 private_offset; /* Byte offset from start of file */
99 uint_4 spare[18]; /* Unused */
100 } Header;
101
102 /*
103 * Header.sample_size == 1.
104 */
105 typedef struct {
106 uint_1 sample_A; /* Sample for A trace */
107 uint_1 sample_C; /* Sample for C trace */
108 uint_1 sample_G; /* Sample for G trace */
109 uint_1 sample_T; /* Sample for T trace */
110 } Samples1;
111
112 /*
113 * Header.sample_size == 2.
114 */
115 typedef struct {
116 uint_2 sample_A; /* Sample for A trace */
117 uint_2 sample_C; /* Sample for C trace */
118 uint_2 sample_G; /* Sample for G trace */
119 uint_2 sample_T; /* Sample for T trace */
120 } Samples2;
121
122 /*
123 * Type definition for the sequence data
124 */
125 typedef struct {
126 uint_4 peak_index; /* Index into Samples matrix for base position */
127 uint_1 prob_A; /* Probability of it being an A */
128 uint_1 prob_C; /* Probability of it being an C */
129 uint_1 prob_G; /* Probability of it being an G */
130 uint_1 prob_T; /* Probability of it being an T */
131 char base; /* Base called */
132 uint_1 spare[3]; /* Spare */
133 } Bases;
134
135
136 /*
137 * Type definition for the comments
138 */
139 typedef char Comments; /* Zero terminated list of \n separated entries */
140
141
142 /*
143 * All of the above structs in a single scf format.
144 */
145 typedef struct {
146 Header header;
147 union Samples {
148 Samples1 *samples1;
149 Samples2 *samples2;
150 } samples;
151 Bases *bases;
152 Comments *comments;
153 char *private_data;
154 } Scf;
155
156 /*
157 *-----------------------------------------------------------------------------
158 * Function prototypes
159 *-----------------------------------------------------------------------------
160 */
161
162 /*
163 * Reading SCF Files
164 * -----------------
165 */
166
167 /*
168 * Read the Header struct.
169 * Returns:
170 * 0 - success
171 * -1 - failure
172 */
173 int read_scf_header(mFILE *fp, Header *h);
174
175 /*
176 * Read a single 8bit sample
177 * Returns:
178 * 0 - success
179 * -1 - failure
180 */
181 int read_scf_sample1(mFILE *fp, Samples1 *s);
182
183 /*
184 * Read several 8bit samples
185 * Returns:
186 * 0 - success
187 * -1 - failure
188 */
189 int read_scf_samples1(mFILE *fp, Samples1 *s, size_t num_samples);
190
191 /*
192 * Read several 8bit samples in delta_delta format
193 * Returns:
194 * 0 - success
195 * -1 - failure
196 */
197 int read_scf_samples31(mFILE *fp, Samples1 *s, size_t num_samples);
198
199 /*
200 * Read a single 16bit sample
201 * Returns:
202 * 0 - success
203 * -1 - failure
204 */
205 int read_scf_sample2(mFILE *fp, Samples2 *s);
206
207 /*
208 * Read several 16bit samples
209 * Returns:
210 * 0 - success
211 * -1 - failure
212 */
213 int read_scf_samples2(mFILE *fp, Samples2 *s, size_t num_samples);
214
215 /*
216 * Read several 16bit samples in delta_delta format
217 * Returns:
218 * 0 - success
219 * -1 - failure
220 */
221 int read_scf_samples32(mFILE *fp, Samples2 *s, size_t num_samples);
222
223 /*
224 * Read a single Bases structure
225 * Returns:
226 * 0 - success
227 * -1 - failure
228 */
229 int read_scf_base(mFILE *fp, Bases *b);
230
231 /*
232 * Read several Bases structures consecutively
233 * Returns:
234 * 0 - success
235 * -1 - failure
236 */
237 int read_scf_bases(mFILE *fp, Bases *b, size_t num_bases);
238
239 /*
240 * Read Bases, peak_indexes and probs
241 * Returns:
242 * 0 - success
243 * -1 - failure
244 */
245 int read_scf_bases3(mFILE *fp, Bases *b, size_t num_bases);
246
247 /*
248 * Read the SCF Comments.
249 * Returns:
250 * 0 - success
251 * -1 - failure
252 */
253 int read_scf_comment(mFILE *fp, Comments *c, size_t l);
254
255 /*
256 * Reads a whole SCF file into a Scf structure. This memory for this
257 * structure is allocated by this routine. To free this memory use
258 * scf_deallocate().
259 * Returns:
260 * Scf * - Success, the Scf structure read.
261 * NULL - Failure.
262 * On failure NULL is returned, otherwise the Scf struct.
263 */
264 Scf *read_scf(char *fn);
265 Scf *fread_scf(FILE *fp);
266 Scf *mfread_scf(mFILE *fp);
267
268
269 /*
270 * Writing SCF Files
271 * -----------------
272 */
273
274 /*
275 * Write the Header struct.
276 * Returns:
277 * 0 - success
278 * -1 - failure
279 */
280 int write_scf_header(mFILE *fp, Header *h);
281
282 /*
283 * Write a single 8bit sample
284 * Returns:
285 * 0 - success
286 * -1 - failure
287 */
288 int write_scf_sample1(mFILE *fp, Samples1 *s);
289
290 /*
291 * Write several 8bit samples
292 * Returns:
293 * 0 - success
294 * -1 - failure
295 */
296 int write_scf_samples1(mFILE *fp, Samples1 *s, size_t num_samples);
297
298 /*
299 * Write several 8bit samples in delta_delta format
300 * Returns:
301 * 0 - success
302 * -1 - failure
303 */
304 int write_scf_samples31(mFILE *fp, Samples1 *s, size_t num_samples);
305
306 /*
307 * Write 16bit samples
308 * Returns:
309 * 0 - success
310 * -1 - failure
311 */
312 int write_scf_sample2(mFILE *fp, Samples2 *s);
313
314 /*
315 * Write several 16bit samples
316 * Returns:
317 * 0 - success
318 * -1 - failure
319 */
320 int write_scf_samples2(mFILE *fp, Samples2 *s, size_t num_samples);
321
322 /*
323 * Write several 16bit samples in delta_delta format
324 * Returns:
325 * 0 - success
326 * -1 - failure
327 */
328 int write_scf_samples32(mFILE *fp, Samples2 *s, size_t num_samples);
329
330 /*
331 * Write the Bases structure
332 * Returns:
333 * 0 - success
334 * -1 - failure
335 */
336 int write_scf_base(mFILE *fp, Bases *b);
337
338 /*
339 * Write the several Bases structures consecutively
340 * Returns:
341 * 0 - success
342 * -1 - failure
343 */
344 int write_scf_bases(mFILE *fp, Bases *b, size_t num_bases);
345
346 /*
347 * Write the bases, then peak indexes, then probs
348 * Returns:
349 * 0 - success
350 * -1 - failure
351 */
352 int write_scf_bases3(mFILE *fp, Bases *b, size_t num_bases);
353
354 /*
355 * Write the SCF Comments.
356 * Returns:
357 * 0 - success
358 * -1 - failure
359 */
360 int write_scf_comment(mFILE *fp, Comments *c, size_t l);
361
362
363 /*
364 * Writes a whole Scf structure to filename "fn".
365 * This initialises several fields in the Header struct for you. These are:
366 * samples_offset
367 * bases_offset
368 * comments_offset
369 * magic_number
370 *
371 * All other fields are assumed to be correctly set.
372 *
373 * Returns:
374 * 0 for success
375 * -1 for failure
376 */
377 int write_scf(Scf *scf, char *fn);
378 int fwrite_scf(Scf *scf, FILE *fp);
379 int mfwrite_scf(Scf *scf, mFILE *fp);
380
381 /*
382 * Request which (major) version of scf to use when writing.
383 * Defaults to the latest. Currently suitable fields are
384 * 2 and 3.
385 *
386 * Returns 0 for success, -1 for failure.
387 */
388 int set_scf_version(int version);
389
390
391 /*
392 * Miscellaneous SCF utilities
393 * ---------------------------
394 */
395
396 /*
397 * Converts an SCF version string (eg "2.00") to a float
398 */
399 float scf_version_str2float(char version[]);
400
401 /*
402 * Converts an SCF version float (eg 2.00) to a string
403 * Returns:
404 * A statically allocated 5 character string.
405 */
406 char *scf_version_float2str(float f);
407
408 /*
409 * Allocates memory for the scf elements based upon arguments passed.
410 * Returns;
411 * Scf * - Success. The scf structure and it's samples, bases,
412 * and comments fields have been allocated.
413 * NULL - Failure.
414 */
415 Scf *scf_allocate(int num_samples, int sample_size, int num_bases,
416 int comment_size, int private_size);
417
418 /*
419 * Frees memory allocated by scf_allocate.
420 */
421 void scf_deallocate(Scf *scf);
422
423 /*
424 * Checks to see if the file with name "fn" is in SCF format.
425 * Returns:
426 * 1 - is in SCF format
427 * 0 - is not in SCF format
428 * -1 - failure
429 */
430 int is_scf(char *fn);
431
432 /*
433 * Change sample points to delta_delta values for uint1
434 */
435 void scf_delta_samples1 ( int1 samples[], int num_samples, int job);
436
437 /*
438 * Change sample points to delta_delta values for uint2
439 */
440 void scf_delta_samples2 ( uint2 samples[], int num_samples, int job);
441
442 #ifdef __cplusplus
443 }
444 #endif
445
446 #endif /*_SCF_H_*/
447