bio-affy 0.1.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +32 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +33 -0
  7. data/Rakefile +77 -0
  8. data/VERSION +1 -0
  9. data/bin/bio-affy +80 -0
  10. data/bio-affy.gemspec +128 -0
  11. data/ext/DESCRIPTION +11 -0
  12. data/ext/HISTORY +3 -0
  13. data/ext/LICENSE +456 -0
  14. data/ext/NAMESPACE +2 -0
  15. data/ext/R/check.cdf.type.R +18 -0
  16. data/ext/R/read.cdffile.list.R +23 -0
  17. data/ext/R/read.celfile.R +11 -0
  18. data/ext/R/read.celfile.header.R +37 -0
  19. data/ext/R/read.probematrices.R +29 -0
  20. data/ext/README_BIOLIB +36 -0
  21. data/ext/aclocal.m4 +32 -0
  22. data/ext/configure +4898 -0
  23. data/ext/configure.in +51 -0
  24. data/ext/man/check.cdf.type.Rd +22 -0
  25. data/ext/man/read.cdffile.list.Rd +20 -0
  26. data/ext/man/read.celfile.Rd +23 -0
  27. data/ext/man/read.celfile.header.Rd +22 -0
  28. data/ext/man/read.celfile.probeintensity.matrices.Rd +31 -0
  29. data/ext/src/CMakeLists.txt +39 -0
  30. data/ext/src/Makevars.in +3 -0
  31. data/ext/src/Makevars.win +2 -0
  32. data/ext/src/Rakefile +43 -0
  33. data/ext/src/biolib_affyio.c +416 -0
  34. data/ext/src/biolib_affyio.h +132 -0
  35. data/ext/src/biolib_affyio.o +0 -0
  36. data/ext/src/fread_functions.c +871 -0
  37. data/ext/src/fread_functions.h +60 -0
  38. data/ext/src/fread_functions.o +0 -0
  39. data/ext/src/libaffyext.so +0 -0
  40. data/ext/src/mkrf.log +11 -0
  41. data/ext/src/mkrf_conf.rb +6 -0
  42. data/ext/src/read_abatch.c +5484 -0
  43. data/ext/src/read_abatch.h +63 -0
  44. data/ext/src/read_abatch.o +0 -0
  45. data/ext/src/read_bpmap.c +888 -0
  46. data/ext/src/read_bpmap.o +0 -0
  47. data/ext/src/read_cdf.h +347 -0
  48. data/ext/src/read_cdf_xda.c +1342 -0
  49. data/ext/src/read_cdf_xda.o +0 -0
  50. data/ext/src/read_cdffile2.c +1576 -0
  51. data/ext/src/read_cdffile2.o +0 -0
  52. data/ext/src/read_celfile_generic.c +2061 -0
  53. data/ext/src/read_celfile_generic.h +33 -0
  54. data/ext/src/read_celfile_generic.o +0 -0
  55. data/ext/src/read_clf.c +870 -0
  56. data/ext/src/read_clf.o +0 -0
  57. data/ext/src/read_generic.c +1446 -0
  58. data/ext/src/read_generic.h +144 -0
  59. data/ext/src/read_generic.o +0 -0
  60. data/ext/src/read_pgf.c +1337 -0
  61. data/ext/src/read_pgf.o +0 -0
  62. data/lib/bio-affy.rb +5 -0
  63. data/lib/bio/affy.rb +7 -0
  64. data/lib/bio/affyext.rb +23 -0
  65. data/lib/bio/libaffyext.so +0 -0
  66. data/spec/bio-affy_spec.rb +22 -0
  67. data/spec/spec_helper.rb +13 -0
  68. data/test/data/affy/GSM103328.CEL.gz +0 -0
  69. data/test/data/affy/GSM103329.CEL.gz +0 -0
  70. data/test/data/affy/GSM103330.CEL.gz +0 -0
  71. data/test/data/affy/MG_U74Av2.CDF.gz +0 -0
  72. metadata +190 -0
@@ -0,0 +1,132 @@
1
+ /*! \file biolib_affyio.h
2
+ *
3
+ * \ingroup affyio
4
+ *
5
+ * BIOLIB 'C' interface to affyio - for linking against the Bio* languages
6
+ *
7
+ * These functions provide access to Affymetrix probe values (CEL files) and
8
+ * the location description of each probe on the trip (CDF files). The underlying
9
+ * library parsing these files is Affyio by Ben Bolstad. The same that is used
10
+ * in R/Bioconductor.
11
+ *
12
+ * De pseudo-code for reading all PM's in a file is:
13
+ *
14
+ * \code
15
+ * cel = open_cel('celfile')
16
+ * cdf = open_cdf('cdffile')
17
+ * for probeset=0 ; probeset < cdf_num_probesets(cdf) do
18
+ * info = cdf_probeset_info(cdf,probeset)
19
+ * for probe=0; probe < info.probes ; do
20
+ * print cel_pm(cel,cdf,probeset,probe)
21
+ * \endcode
22
+ *
23
+ * \author Pjotr Prins 2008
24
+ *
25
+ * See the BioLib API or biolib_affyio.c for method descriptions. Some implementation
26
+ * info is available in ./src/clibs/affyio-ver/README_BIOLIB.
27
+ *
28
+ * @see open_celfile
29
+ * @see open_cdffile
30
+ *
31
+ */
32
+
33
+ /*@{*/
34
+
35
+ #ifdef __cplusplus
36
+ extern "C" {
37
+ #endif
38
+
39
+ #ifdef BIOLIB
40
+ #include <biolib_R_map.h>
41
+ #endif
42
+ #include <read_abatch.h>
43
+ #include <read_cdf.h>
44
+
45
+ /*! State object - keeps track of the opened CEL file */
46
+ typedef struct {
47
+ /// Should be '[CEL]'
48
+ char id[8];
49
+ /// Points to CEL array
50
+ CEL *cel;
51
+ /// Masked indices
52
+ short *masks;
53
+ /// Outlier indices
54
+ short *outliers;
55
+ } CELOBJECT;
56
+
57
+ int has_affyext(int start);
58
+ CELOBJECT *open_celfile(const char *celfilename);
59
+ void close_celfile(CELOBJECT *object);
60
+ unsigned long cel_num_cols(CELOBJECT *object);
61
+ unsigned long cel_num_rows(CELOBJECT *object);
62
+ unsigned long cel_size(CELOBJECT *object);
63
+ unsigned long cel_num_intensities(CELOBJECT *object);
64
+ unsigned long cel_num_masks(CELOBJECT *object);
65
+ unsigned long cel_num_outliers(CELOBJECT *object);
66
+ double cel_intensity(CELOBJECT *object, unsigned long index);
67
+ double cel_intensity_xy(CELOBJECT *object, unsigned long x, unsigned long y);
68
+ double *cel_intensities(CELOBJECT *object);
69
+ double cel_stddev(CELOBJECT *object, unsigned long index);
70
+ double *cel_stddevs(CELOBJECT *object);
71
+ unsigned int cel_mask(CELOBJECT *object, unsigned long index);
72
+ unsigned int cel_outlier(CELOBJECT *object, unsigned long index);
73
+
74
+ /*! Probe description */
75
+ typedef struct {
76
+ /// x coordinate on chip
77
+ unsigned int x;
78
+ /// y coordinate on chip
79
+ unsigned int y;
80
+ // unsigned int id; (unused - same as probeset name)
81
+ } CDFPROBE;
82
+
83
+ /*! Probeset description */
84
+ typedef struct {
85
+ /// Is quality control?
86
+ int isQC;
87
+ /// Number of pm probes
88
+ unsigned int pm_num;
89
+ /// Number of mm probes
90
+ unsigned int mm_num;
91
+ /// pm index array
92
+ CDFPROBE *pm;
93
+ /// mm index array (when available)
94
+ CDFPROBE *mm;
95
+ /// Name of probeset
96
+ char name[64];
97
+ } CDFPROBESET;
98
+
99
+ /*! State object - keeps track of opened CDF file */
100
+ typedef struct {
101
+ /// Should be '[CDF]'
102
+ char id[8];
103
+ /// Is this a textual file?
104
+ int isText;
105
+ /// Affyio internal reference
106
+ cdf_text text;
107
+ /// Affyio internal reference
108
+ cdf_xda xda;
109
+ /// Chip cols
110
+ unsigned int cols;
111
+ /// Chip rows
112
+ unsigned int rows;
113
+ /// Pointer to probeset info array
114
+ CDFPROBESET *probeset;
115
+ } CDFOBJECT;
116
+
117
+ CDFOBJECT *open_cdffile(const char *cdffilename);
118
+ void close_cdffile(CDFOBJECT *cdfobject);
119
+ unsigned long cdf_num_probesets(CDFOBJECT *cdfobject);
120
+ CDFPROBESET *cdf_probeset_info(CDFOBJECT *cdfobject, unsigned int probeset);
121
+ CDFPROBE *cdf_pmprobe_info(CDFOBJECT *cdfobject, unsigned int probeset, unsigned int probe);
122
+ CDFPROBE *cdf_mmprobe_info(CDFOBJECT *cdfobject, unsigned int probeset, unsigned int probe);
123
+ double cel_pm(CELOBJECT *celobject, CDFOBJECT *cdfobject, unsigned int probeset, unsigned int probe);
124
+ double cel_mm(CELOBJECT *celobject, CDFOBJECT *cdfobject, unsigned int probeset, unsigned int probe);
125
+
126
+ int check_cdf_xda(const char *filename);
127
+
128
+ #ifdef __cplusplus
129
+ }
130
+ #endif
131
+
132
+ /*@}*/
Binary file
@@ -0,0 +1,871 @@
1
+
2
+
3
+ #include <R.h>
4
+ #include <Rdefines.h>
5
+ #include <Rmath.h>
6
+ #include <Rinternals.h>
7
+
8
+ #include "stdlib.h"
9
+ #include "stdio.h"
10
+ #include "fread_functions.h"
11
+
12
+ #define HAVE_ZLIB 1
13
+
14
+ #if defined(HAVE_ZLIB)
15
+ #include <zlib.h>
16
+ #endif
17
+
18
+
19
+ /*************************************************************************
20
+ **
21
+ ** Code for reading from the binary files, doing bit flipping if
22
+ ** necessary (on big-endian machines)
23
+ **
24
+ **
25
+ ************************************************************************/
26
+
27
+
28
+ size_t fread_int32(int *destination, int n, FILE *instream){
29
+
30
+ size_t result;
31
+
32
+ result = fread(destination,sizeof(int),n,instream);
33
+
34
+ #ifdef WORDS_BIGENDIAN
35
+ while( n-- > 0 ){
36
+ /* bit flip since all Affymetrix binary files are little endian */
37
+
38
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
39
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
40
+ destination++;
41
+ }
42
+ #endif
43
+ return result;
44
+ }
45
+
46
+
47
+
48
+ size_t fread_uint32(unsigned int *destination, int n, FILE *instream){
49
+
50
+
51
+ size_t result;
52
+
53
+ result = fread(destination,sizeof(unsigned int),n,instream);
54
+
55
+
56
+ #ifdef WORDS_BIGENDIAN
57
+ while( n-- > 0 ){
58
+ /* bit flip since all Affymetrix binary files are little endian */
59
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
60
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
61
+ destination++;
62
+ }
63
+ #endif
64
+ return result;
65
+ }
66
+
67
+
68
+
69
+ size_t fread_int16(short *destination, int n, FILE *instream){
70
+ size_t result;
71
+
72
+ result = fread(destination,sizeof(short),n,instream);
73
+
74
+ #ifdef WORDS_BIGENDIAN
75
+ while( n-- > 0 ){
76
+ /* bit flip since all Affymetrix binary files are little endian */
77
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
78
+ destination++;
79
+ }
80
+ #endif
81
+ return result;
82
+
83
+ }
84
+
85
+
86
+ size_t fread_uint16(unsigned short *destination, int n, FILE *instream){
87
+ size_t result;
88
+
89
+ result = fread(destination,sizeof(unsigned short),n,instream);
90
+
91
+ #ifdef WORDS_BIGENDIAN
92
+ while( n-- > 0 ){
93
+ /* bit flip since all Affymetrix binary files are little endian */
94
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
95
+ destination++;
96
+ }
97
+ #endif
98
+ return result;
99
+
100
+ }
101
+
102
+
103
+
104
+
105
+
106
+ static void swap_float_4(float *tnf4) /* 4 byte floating point numbers */
107
+ {
108
+ unsigned char *cptr,tmp;
109
+
110
+ cptr = (unsigned char *)tnf4;
111
+ tmp = cptr[0];
112
+ cptr[0] = cptr[3];
113
+ cptr[3] =tmp;
114
+ tmp = cptr[1];
115
+ cptr[1] = cptr[2];
116
+ cptr[2] = tmp;
117
+
118
+ }
119
+
120
+
121
+ size_t fread_float32(float *destination, int n, FILE *instream){
122
+
123
+ size_t result;
124
+
125
+
126
+ result = fread(destination,sizeof(float),n,instream);
127
+
128
+ #ifdef WORDS_BIGENDIAN
129
+ while( n-- > 0 ){
130
+ swap_float_4(destination);
131
+ destination++;
132
+ }
133
+ #endif
134
+
135
+ return result;
136
+ }
137
+
138
+ size_t fread_char(char *destination, int n, FILE *instream){
139
+
140
+ size_t result;
141
+
142
+ result = fread(destination,sizeof(char),n,instream);
143
+
144
+ #ifdef WORDS_BIGENDIAN
145
+ /* Probably don't need to do anything for characters */
146
+
147
+ #endif
148
+
149
+ return result;
150
+
151
+ }
152
+
153
+
154
+ size_t fread_uchar(unsigned char *destination, int n, FILE *instream){
155
+
156
+
157
+ size_t result;
158
+
159
+ result = fread(destination,sizeof(unsigned char),n,instream);
160
+
161
+ #ifdef WORDS_BIGENDIAN
162
+ /* Probably don't need to do anything for characters */
163
+ /* destination = ~destination; */
164
+ #endif
165
+
166
+ return result;
167
+
168
+ }
169
+
170
+
171
+
172
+
173
+ static void swap_float_8(double *tnf8) /* 8 byte floating point numbers */
174
+ {
175
+ unsigned char *cptr,tmp;
176
+
177
+ cptr = (unsigned char *)tnf8;
178
+ tmp = cptr[0];
179
+ cptr[0] = cptr[7];
180
+ cptr[7] = tmp;
181
+ tmp = cptr[1];
182
+ cptr[1] = cptr[6];
183
+ cptr[6] = tmp;
184
+ tmp = cptr[2];
185
+ cptr[2] = cptr[5];
186
+ cptr[5] =tmp;
187
+ tmp = cptr[3];
188
+ cptr[3] = cptr[4];
189
+ cptr[4] = tmp;
190
+ }
191
+
192
+
193
+
194
+
195
+
196
+ size_t fread_double64(double *destination, int n, FILE *instream){
197
+
198
+ size_t result;
199
+
200
+
201
+ result = fread(destination,sizeof(double),n,instream);
202
+
203
+ #ifdef WORDS_BIGENDIAN
204
+ while( n-- > 0 ){
205
+ swap_float_8(destination);
206
+ destination++;
207
+ }
208
+ #endif
209
+
210
+ return result;
211
+ }
212
+
213
+ /*************************************************************************
214
+ **
215
+ ** Code for big endian data reading from the binary files, doing bit flipping if
216
+ ** necessary (on little-endian machines)
217
+ **
218
+ **
219
+ ************************************************************************/
220
+
221
+ size_t fread_be_int32(int *destination, int n, FILE *instream){
222
+
223
+ size_t result;
224
+
225
+ result = fread(destination,sizeof(int),n,instream);
226
+
227
+ #ifndef WORDS_BIGENDIAN
228
+ while (n-- > 0){
229
+ /* bit flip since on a little endian machine */
230
+
231
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
232
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
233
+ destination++;
234
+ }
235
+ #endif
236
+ return result;
237
+ }
238
+
239
+
240
+
241
+ size_t fread_be_uint32(unsigned int *destination, int n, FILE *instream){
242
+
243
+
244
+ size_t result;
245
+
246
+ result = fread(destination,sizeof(unsigned int),n,instream);
247
+
248
+
249
+ #ifndef WORDS_BIGENDIAN
250
+ while (n-- > 0){
251
+ /* bit flip since all Affymetrix binary files are little endian */
252
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
253
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
254
+ destination++;
255
+ }
256
+
257
+ #endif
258
+ return result;
259
+ }
260
+
261
+
262
+ size_t fread_be_int16(short *destination, int n, FILE *instream){
263
+ size_t result;
264
+
265
+ result = fread(destination,sizeof(short),n,instream);
266
+
267
+ #ifndef WORDS_BIGENDIAN
268
+ while (n-- > 0){
269
+ /* bit flip since all Affymetrix binary files are little endian */
270
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
271
+ destination++;
272
+ }
273
+ #endif
274
+ return result;
275
+
276
+ }
277
+
278
+
279
+
280
+
281
+ size_t fread_be_uint16(unsigned short *destination, int n, FILE *instream){
282
+ size_t result;
283
+
284
+ result = fread(destination,sizeof(unsigned short),n,instream);
285
+
286
+ #ifndef WORDS_BIGENDIAN
287
+ while( n-- > 0 ){
288
+ /* bit flip since all Affymetrix binary files are little endian */
289
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
290
+ destination++;
291
+ }
292
+ #endif
293
+ return result;
294
+
295
+ }
296
+
297
+
298
+
299
+
300
+ static void swap_uint_32(unsigned int *tni4) /* 4 byte integer numbers */
301
+ {
302
+
303
+ *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
304
+ ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));
305
+
306
+
307
+ }
308
+
309
+
310
+
311
+
312
+
313
+ size_t fread_be_float32(float *destination, int n, FILE *instream){
314
+
315
+ size_t result;
316
+
317
+
318
+
319
+ result = fread(destination,sizeof(float),n,instream);
320
+
321
+ #ifndef WORDS_BIGENDIAN
322
+ while( n-- > 0 ) {
323
+ swap_float_4(destination);
324
+ destination++;
325
+ }
326
+ #endif
327
+
328
+ return result;
329
+ }
330
+
331
+
332
+
333
+
334
+ size_t fread_be_char(char *destination, int n, FILE *instream){
335
+
336
+
337
+ size_t result;
338
+
339
+ result = fread(destination,sizeof(char),n,instream);
340
+
341
+ #ifndef WORDS_BIGENDIAN
342
+ /* Probably don't need to do anything for characters */
343
+
344
+ #endif
345
+
346
+ return result;
347
+
348
+ }
349
+
350
+ size_t fread_be_uchar(unsigned char *destination, int n, FILE *instream){
351
+
352
+
353
+ size_t result;
354
+
355
+ result = fread(destination,sizeof(unsigned char),n,instream);
356
+
357
+ #ifndef WORDS_BIGENDIAN
358
+ /* Probably don't need to do anything for characters */
359
+ /* destination = ~destination; */
360
+ #endif
361
+
362
+ return result;
363
+
364
+ }
365
+
366
+
367
+
368
+ size_t fread_be_wchar(wchar_t *destination, int n, FILE *instream){
369
+
370
+ size_t result;
371
+
372
+ result = fread(destination, sizeof(wchar_t), n, instream);
373
+
374
+ return result;
375
+
376
+ }
377
+
378
+
379
+ size_t fread_be_double64(double *destination, int n, FILE *instream){
380
+
381
+ size_t result;
382
+
383
+
384
+ result = fread(destination,sizeof(double),n,instream);
385
+
386
+ #ifndef WORDS_BIGENDIAN
387
+ while( n-- > 0 ){
388
+ swap_float_8(destination);
389
+ destination++;
390
+ }
391
+ #endif
392
+
393
+ return result;
394
+ }
395
+
396
+ #if defined(HAVE_ZLIB)
397
+
398
+
399
+
400
+
401
+ /*************************************************************************
402
+ **
403
+ ** Code for reading from the gzipped binary files, doing bit flipping if
404
+ ** necessary (on big-endian machines)
405
+ **
406
+ **
407
+ ************************************************************************/
408
+
409
+
410
+ size_t gzread_int32(int *destination, int n, gzFile *instream){
411
+
412
+ size_t result;
413
+
414
+ result = gzread(instream,destination,sizeof(int)*n);
415
+
416
+ //int gzread (gzFile file, voidp buf, unsigned int len);
417
+
418
+
419
+
420
+ #ifdef WORDS_BIGENDIAN
421
+ while( n-- > 0 ){
422
+ /* bit flip since all Affymetrix binary files are little endian */
423
+
424
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
425
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
426
+ destination++;
427
+ }
428
+ #endif
429
+ return result;
430
+ }
431
+
432
+
433
+
434
+ size_t gzread_uint32(unsigned int *destination, int n, gzFile *instream){
435
+
436
+
437
+ size_t result;
438
+
439
+ result = gzread(instream,destination,sizeof(unsigned int)*n);
440
+
441
+
442
+ #ifdef WORDS_BIGENDIAN
443
+ while( n-- > 0 ){
444
+ /* bit flip since all Affymetrix binary files are little endian */
445
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
446
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
447
+ destination++;
448
+ }
449
+ #endif
450
+ return result;
451
+ }
452
+
453
+
454
+
455
+ size_t gzread_int16(short *destination, int n, gzFile *instream){
456
+ size_t result;
457
+
458
+ result = gzread(instream,destination,sizeof(short)*n);
459
+
460
+ #ifdef WORDS_BIGENDIAN
461
+ while( n-- > 0 ){
462
+ /* bit flip since all Affymetrix binary files are little endian */
463
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
464
+ destination++;
465
+ }
466
+ #endif
467
+ return result;
468
+ }
469
+
470
+
471
+
472
+
473
+ size_t gzread_uint16(unsigned short *destination, int n, gzFile *instream){
474
+ size_t result;
475
+
476
+ result = gzread(instream,destination,sizeof(unsigned short)*n);
477
+
478
+ #ifdef WORDS_BIGENDIAN
479
+ while( n-- > 0 ){
480
+ /* bit flip since all Affymetrix binary files are little endian */
481
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
482
+ destination++;
483
+ }
484
+ #endif
485
+ return result;
486
+ }
487
+
488
+
489
+
490
+
491
+
492
+ size_t gzread_float32(float *destination, int n, gzFile *instream){
493
+
494
+ size_t result;
495
+
496
+
497
+ result = gzread(instream,destination,sizeof(float)*n);
498
+
499
+ #ifdef WORDS_BIGENDIAN
500
+ while( n-- > 0 ){
501
+ swap_float_4(destination);
502
+ destination++;
503
+ }
504
+ #endif
505
+
506
+ return result;
507
+ }
508
+
509
+ size_t gzread_char(char *destination, int n, gzFile *instream){
510
+
511
+ size_t result;
512
+
513
+ result = gzread(instream,destination,sizeof(char)*n);
514
+
515
+ #ifdef WORDS_BIGENDIAN
516
+ /* Probably don't need to do anything for characters */
517
+
518
+ #endif
519
+
520
+ return result;
521
+
522
+ }
523
+
524
+
525
+ size_t gzread_uchar(unsigned char *destination, int n, gzFile *instream){
526
+
527
+ size_t result;
528
+
529
+ result = gzread(instream,destination,sizeof(unsigned char)*n);
530
+
531
+ #ifdef WORDS_BIGENDIAN
532
+ /* Probably don't need to do anything for characters */
533
+
534
+ #endif
535
+
536
+ return result;
537
+
538
+ }
539
+
540
+
541
+
542
+
543
+ size_t gzread_double64(double *destination, int n, gzFile *instream){
544
+
545
+ size_t result;
546
+
547
+ result = gzread(instream, destination,sizeof(double)*n);
548
+
549
+ #ifdef WORDS_BIGENDIAN
550
+ while( n-- > 0 ){
551
+ swap_float_8(destination);
552
+ destination++;
553
+ }
554
+ #endif
555
+
556
+ return result;
557
+ }
558
+
559
+
560
+
561
+
562
+ /*************************************************************************
563
+ **
564
+ ** Code for reading from the gzipped binary files written in BE format, doing bit flipping if
565
+ ** necessary (on big-endian machines)
566
+ **
567
+ **
568
+ ************************************************************************/
569
+
570
+
571
+ size_t gzread_be_int32(int *destination, int n, gzFile *instream){
572
+
573
+ size_t result;
574
+
575
+ result = gzread(instream,destination,sizeof(int)*n);
576
+
577
+ //int gzread (gzFile file, voidp buf, unsigned int len);
578
+
579
+
580
+
581
+ #ifndef WORDS_BIGENDIAN
582
+ while( n-- > 0 ){
583
+ /* bit flip since all Affymetrix binary files are little endian */
584
+
585
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
586
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
587
+ destination++;
588
+ }
589
+ #endif
590
+ return result;
591
+ }
592
+
593
+
594
+
595
+ size_t gzread_be_uint32(unsigned int *destination, int n, gzFile *instream){
596
+
597
+
598
+ size_t result;
599
+
600
+ result = gzread(instream,destination,sizeof(unsigned int)*n);
601
+
602
+
603
+ #ifndef WORDS_BIGENDIAN
604
+ while( n-- > 0 ){
605
+ /* bit flip since all Affymetrix binary files are little endian */
606
+ *destination=(((*destination>>24)&0xff) | ((*destination&0xff)<<24) |
607
+ ((*destination>>8)&0xff00) | ((*destination&0xff00)<<8));
608
+ destination++;
609
+ }
610
+ #endif
611
+ return result;
612
+ }
613
+
614
+
615
+
616
+
617
+ size_t gzread_be_int16(short *destination, int n, gzFile *instream){
618
+ size_t result;
619
+
620
+ result = gzread(instream,destination,sizeof(short)*n);
621
+
622
+ #ifndef WORDS_BIGENDIAN
623
+ while( n-- > 0 ){
624
+ /* bit flip since all Affymetrix binary files are little endian */
625
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
626
+ destination++;
627
+ }
628
+ #endif
629
+ return result;
630
+ }
631
+
632
+
633
+ size_t gzread_be_uint16(unsigned short *destination, int n, gzFile *instream){
634
+ size_t result;
635
+
636
+ result = gzread(instream,destination,sizeof(unsigned short)*n);
637
+
638
+ #ifndef WORDS_BIGENDIAN
639
+ while( n-- > 0 ){
640
+ /* bit flip since all Affymetrix binary files are little endian */
641
+ *destination=(((*destination>>8)&0xff) | ((*destination&0xff)<<8));
642
+ destination++;
643
+ }
644
+ #endif
645
+ return result;
646
+ }
647
+
648
+
649
+
650
+
651
+ size_t gzread_be_float32(float *destination, int n, gzFile *instream){
652
+
653
+ size_t result;
654
+
655
+
656
+ result = gzread(instream,destination,sizeof(float)*n);
657
+
658
+ #ifndef WORDS_BIGENDIAN
659
+ while( n-- > 0 ){
660
+ swap_float_4(destination);
661
+ destination++;
662
+ }
663
+ #endif
664
+
665
+ return result;
666
+ }
667
+
668
+
669
+ size_t gzread_be_char(char *destination, int n, gzFile *instream){
670
+
671
+ size_t result;
672
+
673
+ result = gzread(instream,destination,sizeof(char)*n);
674
+
675
+ #ifndef WORDS_BIGENDIAN
676
+ /* Probably don't need to do anything for characters */
677
+
678
+ #endif
679
+
680
+ return result;
681
+
682
+ }
683
+
684
+
685
+
686
+ size_t gzread_be_uchar(unsigned char *destination, int n, gzFile *instream){
687
+
688
+ size_t result;
689
+
690
+ result = gzread(instream,destination,sizeof(unsigned char)*n);
691
+
692
+ #ifndef WORDS_BIGENDIAN
693
+ /* Probably don't need to do anything for characters */
694
+
695
+ #endif
696
+
697
+ return result;
698
+
699
+ }
700
+
701
+
702
+ size_t gzread_be_double64(double *destination, int n, gzFile *instream){
703
+
704
+ size_t result;
705
+
706
+ result = gzread(instream, destination,sizeof(double)*n);
707
+
708
+ #ifndef WORDS_BIGENDIAN
709
+ while( n-- > 0 ){
710
+ swap_float_8(destination);
711
+ destination++;
712
+ }
713
+ #endif
714
+
715
+ return result;
716
+ }
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+ #endif
726
+
727
+
728
+ void test_parsers_le(){
729
+ FILE* infile;
730
+ int i;
731
+
732
+ unsigned char my_uc;
733
+ char my_c;
734
+
735
+ unsigned short my_us;
736
+ short my_s;
737
+
738
+ unsigned int my_ui;
739
+ int my_i;
740
+
741
+ float my_f;
742
+
743
+ double my_d;
744
+
745
+ if ((infile = fopen("LittleEndianTest.bin", "rb")) == NULL)
746
+ {
747
+ printf("Unable to open the file\n");
748
+ return ;
749
+ }
750
+
751
+ for (i = 0; i < 255; i++){
752
+ fread_uchar(&my_uc,1, infile);
753
+ printf("Was : %d should be %d\n",my_uc,i);
754
+ }
755
+
756
+ for (i = -128; i < 127; i++){
757
+ fread_char(&my_c,1, infile);
758
+ printf("Was : %d should be %d\n",my_c,i);
759
+ }
760
+
761
+ for (i =0; i < 15; i++){
762
+ fread_uint16(&my_us,1,infile);
763
+ printf("Was : %d \n", my_us);
764
+ }
765
+
766
+ for (i=0; i < 15; i++){
767
+ fread_int16(&my_s,1,infile);
768
+ printf("Was : %d \n", my_s);
769
+ }
770
+
771
+ for (i=0; i < 31; i++){
772
+ fread_uint32(&my_ui,1,infile);
773
+ printf("uint32 Was : %d \n", my_ui);
774
+ }
775
+
776
+
777
+ for (i=0; i < 31; i++){
778
+ fread_int32(&my_i,1, infile);
779
+ printf("int32 Was : %d \n", my_i);
780
+ }
781
+
782
+
783
+ for (i = 0; i < 25; i++){
784
+ fread_float32(&my_f,1,infile);
785
+ printf("float32 Was : %e \n", my_f);
786
+ }
787
+ fread_float32(&my_f,1,infile);
788
+ printf("PI float32 Was : %f \n", my_f);
789
+
790
+
791
+ for (i = 0; i < 25; i++){
792
+ fread_double64(&my_d,1,infile);
793
+ printf("double64 Was : %le \n", my_d);
794
+ }
795
+ fread_double64(&my_d,1,infile);
796
+ printf("exp(1) double64 Was : %f \n", my_d);
797
+ }
798
+
799
+
800
+
801
+ void test_parsers_be(){
802
+ FILE* infile;
803
+ int i;
804
+
805
+ unsigned char my_uc;
806
+ char my_c;
807
+
808
+ unsigned short my_us;
809
+ short my_s;
810
+
811
+ unsigned int my_ui;
812
+ int my_i;
813
+
814
+ float my_f;
815
+
816
+ double my_d;
817
+
818
+ if ((infile = fopen("BigEndianTest.bin", "rb")) == NULL)
819
+ {
820
+ printf("Unable to open the file\n");
821
+ return ;
822
+ }
823
+
824
+ for (i = 0; i < 255; i++){
825
+ fread_be_uchar(&my_uc,1, infile);
826
+ printf("Was : %d should be %d\n",my_uc,i);
827
+ }
828
+
829
+ for (i = -128; i < 127; i++){
830
+ fread_be_char(&my_c,1, infile);
831
+ printf("Was : %d should be %d\n",my_c,i);
832
+ }
833
+
834
+ for (i =0; i < 15; i++){
835
+ fread_be_uint16(&my_us,1,infile);
836
+ printf("Was : %d \n", my_us);
837
+ }
838
+
839
+ for (i=0; i < 15; i++){
840
+ fread_be_int16(&my_s,1,infile);
841
+ printf("Was : %d \n", my_s);
842
+ }
843
+
844
+ for (i=0; i < 31; i++){
845
+ fread_be_uint32(&my_ui,1,infile);
846
+ printf("uint32 Was : %d \n", my_ui);
847
+ }
848
+
849
+
850
+ for (i=0; i < 31; i++){
851
+ fread_be_int32(&my_i,1, infile);
852
+ printf("int32 Was : %d \n", my_i);
853
+ }
854
+
855
+
856
+ for (i = 0; i < 25; i++){
857
+ fread_be_float32(&my_f,1,infile);
858
+ printf("float32 Was : %e \n", my_f);
859
+ }
860
+ fread_be_float32(&my_f,1,infile);
861
+ printf("PI float32 Was : %f \n", my_f);
862
+
863
+
864
+ for (i = 0; i < 25; i++){
865
+ fread_be_double64(&my_d,1,infile);
866
+ printf("double64 Was : %le \n", my_d);
867
+ }
868
+ fread_be_double64(&my_d,1,infile);
869
+ printf("exp(1) double64 Was : %f \n", my_d);
870
+ }
871
+