|
| 1 | +// an example programme that uses slow5lib to obtain auxiliary field from a slow5/blow5 file |
| 2 | + |
1 | 3 | #include <stdio.h> |
2 | 4 | #include <stdlib.h> |
3 | 5 | #include <slow5/slow5.h> |
|
6 | 8 |
|
7 | 9 | int main(){ |
8 | 10 |
|
| 11 | + //open the SLOW5 file |
9 | 12 | slow5_file_t *sp = slow5_open(FILE_PATH,"r"); |
10 | 13 | if(sp==NULL){ |
11 | 14 | fprintf(stderr,"Error in opening file\n"); |
12 | 15 | exit(EXIT_FAILURE); |
13 | 16 | } |
14 | | - slow5_rec_t *rec = NULL; |
15 | | - int ret=0; |
| 17 | + |
| 18 | + slow5_rec_t *rec = NULL; //slow5 record to be read |
| 19 | + int ret=0; //for return value |
| 20 | + |
| 21 | + //get the very first record |
16 | 22 | ret = slow5_get_next(&rec,sp); |
17 | 23 | if(ret<0){ |
18 | 24 | fprintf(stderr,"Error in slow5_get_next. Error code %d\n",ret); |
19 | 25 | exit(EXIT_FAILURE); |
20 | 26 | } |
21 | 27 |
|
22 | 28 | //------------------------------------------------------------------------ |
23 | | - // get auxiliary values with primitive datatype |
| 29 | + // getting auxiliary fields whose values are primitive datatypes |
24 | 30 | //------------------------------------------------------------------------ |
25 | | - ret=0; |
| 31 | + |
| 32 | + //median_before auxiliary field - double data type |
26 | 33 | double median_before = slow5_aux_get_double(rec,"median_before",&ret); |
27 | 34 | if(ret!=0){ |
28 | 35 | fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret); |
29 | 36 | exit(EXIT_FAILURE); |
30 | 37 | } |
31 | | - fprintf(stderr,"median_before = %f\n", median_before); |
| 38 | + if(!isnan(median_before)){ //SLOW5_DOUBLE_NULL is the generic NaN value returned by nan("""") and thus median_before != SLOW5_DOUBLE_NULL is not correct |
| 39 | + printf("median_before = %f\n", median_before); |
| 40 | + } else { |
| 41 | + printf("median_before is missing for the record\n"); |
| 42 | + } |
32 | 43 |
|
| 44 | + //start_time auxiliary field - uint64 data type |
33 | 45 | uint64_t start_time = slow5_aux_get_uint64(rec, "start_time", &ret); |
34 | 46 | if(ret!=0){ |
35 | 47 | fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret); |
36 | 48 | exit(EXIT_FAILURE); |
37 | 49 | } |
38 | | - fprintf(stderr,"start_time = %lu\n", start_time); |
| 50 | + if(start_time != SLOW5_UINT64_T_NULL){ //check if the field value is marked missing and print the value |
| 51 | + printf("start_time = %lu\n", start_time); |
| 52 | + } else{ |
| 53 | + printf("start_time is missing for the record\n"); |
| 54 | + } |
39 | 55 |
|
40 | 56 | //------------------------------------------------------------------------ |
41 | | - // get auxiliary values with array datatype |
| 57 | + // getting auxiliary fields whose values are array datatypes |
42 | 58 | //------------------------------------------------------------------------ |
43 | 59 |
|
44 | | - uint64_t len; |
| 60 | + //channel_number auxiliary field - string (char *) datatype |
| 61 | + uint64_t len; //length of the array |
45 | 62 | char* channel_number = slow5_aux_get_string(rec, "channel_number", &len, &ret); |
46 | 63 | if(ret!=0){ |
47 | 64 | fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret); |
48 | 65 | exit(EXIT_FAILURE); |
49 | 66 | } |
50 | | - fprintf(stderr,"channel_number = %s\n", channel_number); |
| 67 | + if (channel_number != NULL){ //check if the field value exists and print the value |
| 68 | + printf("channel_number = %s\n", channel_number); |
| 69 | + } else{ |
| 70 | + printf("channel_number is missing for the record\n"); |
| 71 | + } |
51 | 72 |
|
| 73 | + //free the SLOW5 record |
52 | 74 | slow5_rec_free(rec); |
| 75 | + |
| 76 | + //close the SLOW5 file |
53 | 77 | slow5_close(sp); |
54 | 78 |
|
| 79 | + return 0; |
55 | 80 | } |
0 commit comments