1 /*
2  * Copyright (c) 2004-2005, 2007 Genome Research Ltd.
3  * Author(s): James Bonfield
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *    1. Redistributions of source code must retain the above copyright notice,
9  *       this list of conditions and the following disclaimer.
10  *
11  *    2. Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *
16  *    3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
17  *    Institute nor the names of its contributors may be used to endorse
18  *    or promote products derived from this software without specific
19  *    prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS
22  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH
25  * LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Author(s): Simon Dear, James Bonfield, Rodger Staden
36  *
37  * Copyright (c) 1994-1998, 2001-2002 MEDICAL RESEARCH COUNCIL
38  * All rights reserved
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are met:
42  *
43  *    1 Redistributions of source code must retain the above copyright notice,
44  *      this list of conditions and the following disclaimer.
45  *
46  *    2 Redistributions in binary form must reproduce the above copyright
47  *      notice, this list of conditions and the following disclaimer in
48  *      the documentation and/or other materials provided with the
49  *      distribution.
50  *
51  *    3 Neither the name of the MEDICAL RESEARCH COUNCIL, THE LABORATORY OF
52  *      MOLECULAR BIOLOGY nor the names of its contributors may be used
53  *      to endorse or promote products derived from this software without
54  *      specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
57  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
60  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
66  * POSSIBILITY OF SUCH DAMAGE.
67  */
68 
69 /*
70  * Copyright (c) Medical Research Council 1994. All rights reserved.
71  *
72  * Permission to use, copy, modify and distribute this software and its
73  * documentation for any purpose is hereby granted without fee, provided that
74  * this copyright and notice appears in all copies.
75  *
76  * This file was written by James Bonfield, Simon Dear, Rodger Staden,
77  * as part of the Staden Package at the MRC Laboratory of Molecular
78  * Biology, Hills Road, Cambridge, CB2 2QH, United Kingdom.
79  *
80  * MRC disclaims all warranties with regard to this software.
81  */
82 
83 /*
84  * File: expFileIO.h
85  * Version:
86  *
87  * Description:
88  *
89  * Created:
90  * Updated:
91  *
92  */
93 
94 #ifndef _EXPFILEIO_H_
95 #define _EXPFILEIO_H_
96 
97 #include <stdio.h>
98 
99 #include "io_lib/mFILE.h"
100 #include "io_lib/array.h"
101 #include "io_lib/os.h"
102 
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
107 /*
108  * Definitions
109  */
110 #define MAXIMUM_EFLT_LENGTH     4
111 #define MAXIMUM_EFLTS          60
112 #define EFLT_FILE_LINE_LENGTH 128
113 #define EXP_FILE_LINE_LENGTH  128
114 
115 typedef Array Exp_entries;
116 
117 typedef struct {
118     Array entries[MAXIMUM_EFLTS]; /* array of array of entries */
119     int Nentries[MAXIMUM_EFLTS];
120     mFILE *fp;
121 } Exp_info;
122 
123 #define NULL_Exp_info ( (Exp_info *) NULL )
124 
125 
126 
127 #define exp_Nentries(E,I) ((E)->Nentries[I]) /* get last entry for line I */
128 
129 #define exp_get_entry(E,I) (arr(char *,(E)->entries[I],(E)->Nentries[I] - 1)) /* get last entry for line I */
130 
131 /*
132  * Allocate an set a new experiment file entry
133  */
134 extern char *exp_set_entry(Exp_info *e, int eflt, char *str);
135 
136 
137 
138 /*************************************************************
139  * Experiment file line types
140  *************************************************************/
141 
142 extern char eflt_feature_ids[MAXIMUM_EFLTS][MAXIMUM_EFLT_LENGTH+1];
143 
144 #define EFLT_CF  0
145 #define EFLT_CN  1
146 #define EFLT_CS  2
147 #define EFLT_CV  3
148 #define EFLT_DR  4
149 #define EFLT_DT  5
150 #define EFLT_EN  6
151 #define EFLT_EX  7
152 #define EFLT_FM  8
153 #define EFLT_LN  9
154 #define EFLT_LT 10
155 #define EFLT_MC 11
156 #define EFLT_MN 12
157 #define EFLT_MT 13
158 #define EFLT_OP 14
159 #define EFLT_PN 15
160 #define EFLT_QR 16
161 #define EFLT_SC 17
162 #define EFLT_SF 18
163 #define EFLT_SI 19
164 #define EFLT_SL 20
165 #define EFLT_SP 21
166 #define EFLT_SQ 22
167 #define EFLT_SR 23
168 #define EFLT_ST 24
169 #define EFLT_SV 25
170 #define EFLT_TN 26
171 #define EFLT_QL 27
172 #define EFLT_PS 28
173 #define EFLT_CC 29
174 #define EFLT_SS 30
175 #define EFLT_TG 31
176 #define EFLT_ID 32
177 #define EFLT_AQ 33
178 #define EFLT_PR 34
179 #define EFLT_LI 35
180 #define EFLT_LE 36
181 #define EFLT_TC 37
182 #define EFLT_AC 38
183 #define EFLT_BC 39
184 #define EFLT_ON 40
185 #define EFLT_AV 41
186 #define EFLT_PC 42
187 #define EFLT_SE 43
188 #define EFLT_CL 44
189 #define EFLT_CR 45
190 #define EFLT_AP 46
191 #define EFLT_CH 47
192 #define EFLT_PD 48
193 #define EFLT_WT 49
194 #define EFLT_NT 50
195 #define EFLT_GD 51
196 #define EFLT_WL 52
197 #define EFLT_WR 53
198 #define EFLT_FT 54
199 #define EFLT_LG 55
200 
201 
202 /*************************************************************************************/
203 
204 
205 /*
206  * Creates a string of 'range format' from the start and end points.
207  * The string (of form start..end) is also returned.
208  */
209 extern char *exp_create_range(char *str, int start, int end);
210 
211 /*
212  * Extracts the start and end points from a range string.
213  * Returns 0 for success and -1 for failure.
214  */
215 extern int exp_extract_range(char *str, int *start, int *end);
216 
217 /*
218  * Output an experiment file line
219  */
220 extern int exp_print_line(mFILE *fp, Exp_info *e, int eflt, int i);
221 
222 /*
223  * Output an experiment file multi-line
224  */
225 extern int exp_print_mline(mFILE *fp, Exp_info *e, int eflt, int i);
226 
227 extern int exp_print_seq(mFILE *fp, Exp_info *e, int eflt, int i);
228 /*
229  * Output an experiment file multi line
230  */
231 
232 
233 
234 extern int exp_get_feature_index(char *e);
235 
236 extern void exp_destroy_info(Exp_info *e);
237 /*
238  * Destroy experiment file information
239  */
240 
241 
242 
243 extern Exp_info *exp_create_info(void);
244 /*
245  * Allocate space for new experiment file information
246  */
247 
248 
249 
250 
251 
252 
253 
254 extern Exp_info *exp_fread_info(FILE *fp);
255 extern Exp_info *exp_mfread_info(mFILE *fp);
256 extern Exp_info *exp_read_info(char *file);
257 /*
258  * Read in an experiment file and return handle
259  */
260 
261 
262 char *opos2str(int2 *opos, int len, char *buf);
263 int   str2opos(int2 *opos, int len, char *buf);
264 char *conf2str(int1 *conf, int len, char *buf);
265 int   str2conf(int1 *conf, int len, char *buf);
266 
267 extern int exp_get_int(Exp_info *e, int id, int *val);
268 /*
269  * Get the integer for entry id
270  * returns:
271  *    0 - success
272  *    1 - no entry
273  */
274 
275 
276 extern int exp_get_rng(Exp_info *e, int id, int *from, int *to);
277 /*
278  * Get the integer pair for entry id
279  * returns:
280  *    0 - success
281  *    1 - no entry
282  */
283 
284 
285 extern int exp_get_str(Exp_info *e, int id, char *s, f_implicit s_l);
286 /*
287  * Get the string for entry id
288  * returns:
289  *    0 - success
290  *    1 - no entry
291  */
292 
293 
294 extern int exp_put_int(Exp_info *e, int id, int *val);
295 /*
296  * Append the integer for entry id to the experiment file
297  * returns:
298  *    0 - success
299  *    1 - no update
300  */
301 
302 
303 extern int exp_put_rng(Exp_info *e, int id, int *from, int *to);
304 /*
305  * Append the integer pair for entry id to the experiment file
306  * returns:
307  *    0 - success
308  *    1 - no update
309  */
310 
311 
312 
313 extern int exp_put_str(Exp_info *e, int id, char *s, f_implicit s_l);
314 /*
315  * Append the string for entry id to the experiment file
316  * returns:
317  *    0 - success
318  *    1 - no update
319  */
320 
321 
322 extern void exp_close(Exp_info *e);
323 /*
324  * Closes an experiment file (if open), but does not free it.
325  */
326 
327 /*
328  * FORTRAN INTERFACE
329  */
330 
331 
332 
333 extern f_int expopn_(char *fn, f_implicit fn_l);
334 /*
335  * FORTRAN interface to exp_open_file()
336  */
337 
338 extern f_proc_ret expkil_(f_int *le);
339 /*
340  * FORTRAN interface to exp_destroy_info
341  */
342 
343 extern f_int expri_(f_int *le, f_int *id, f_int *val);
344 /*
345  * FORTRAN interface to exp_get_int
346  */
347 
348 
349 extern f_int exprr_(f_int *le, f_int *id, f_int *from, f_int *to);
350 /*
351  * FORTRAN interface to exp_get_rng
352  */
353 
354 
355 extern f_int exprsa_(f_int *le, f_int *id, char *s, f_int *max_len, f_implicit s_l);
356 /*
357  * FORTRAN interface to exp_get_str workalike
358  * NOTE: for use with FORTRAN CHARACTER arrays instead CHARACTER strings
359  */
360 
361 extern f_int exprs_(f_int *le, f_int *id, char *s, f_implicit s_l);
362 /*
363  * FORTRAN interface to exp_get_str workalike
364  * NOTE: for use with FORTRAN CHARACTER strings instead CHARACTER arrays
365  */
366 
367 extern f_int expwi_(f_int *le, f_int *id, f_int *val);
368 /*
369  * FORTRAN interface to exp_put_int
370  */
371 
372 
373 extern f_int expwr_(f_int *le, f_int *id, f_int *from, f_int *to);
374 /*
375  * FORTRAN interface to exp_put_rng
376  */
377 
378 
379 
380 extern f_int expwsa_(f_int *le, f_int *id, char *s, f_int *max_len, f_implicit s_l);
381 /*
382  * FORTRAN interface to exp_put_str workalike
383  * NOTE: for use with FORTRAN CHARACTER arrays instead CHARACTER strings
384  */
385 
386 
387 
388 extern f_int expws_(f_int *le, f_int *id, char *s, f_implicit s_l);
389 /*
390  * FORTRAN interface to exp_put_str workalike
391  * NOTE: for use with FORTRAN CHARACTER strings instead CHARACTER arrays
392  */
393 
394 
395 extern void exp_print_file(FILE *fp, Exp_info *e);
396 extern void exp_print_mfile(mFILE *fp, Exp_info *e);
397 
398 /*
399  * FORTRAN interface to exp_create_range()
400  */
401 extern void expcr_(char *str, f_int *start, f_int *end, f_implicit str_l);
402 
403 /*
404  * FORTRAN interface to exp_extract_range()
405  */
406 extern f_int exper_(char *str, f_int *start, f_int *end, f_implicit str_l);
407 
408 #ifdef __cplusplus
409 }
410 #endif
411 
412 #endif /* _EXPFILEIO_H_ */
413 
414