Skip to content

Commit 80f99ab

Browse files
committed
document aux enum and add advanced examples
1 parent 527c48e commit 80f99ab

File tree

13 files changed

+474
-3
lines changed

13 files changed

+474
-3
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# slow5\_aux\_get\_enum
2+
3+
## NAME
4+
5+
slow5\_aux\_get\_enum - fetches an auxiliary field of type enum from a SLOW5 record
6+
7+
## SYNOPSYS
8+
9+
```
10+
uint8_t slow5_aux_get_enum(const slow5_rec_t *read, const char *field, int *err)
11+
```
12+
13+
14+
## DESCRIPTION
15+
16+
`slow5_aux_get_enum()` fetches the value of an auxiliary field of a enum datatype specified by the field name *field* from the slow5 record pointed by *read*.
17+
18+
The argument *err* is an address of an integer which will be set inside the function call to indicate an error. Unless *err* is NULL, `slow5_aux_get_enum()` sets a non zero error code in **err* in case of failure.
19+
20+
## RETURN VALUE
21+
22+
Upon successful completion, `slow5_aux_get_enum()` returns the requested enum field value as a uint8_t. Otherwise, the SLOW5 missing value representation for the enum datatype is returned (`SLOW5_ENUM_NULL`) and `slow5_errno` is set to indicate the error. See notes below.
23+
24+
25+
## ERRORS
26+
27+
In case of an error, `slow5_errno` or the non zero error code is set in *err* (unless *err* is NULL) are as follows.
28+
29+
* `SLOW5_ERR_NOFLD`
30+
     The requested field was not found.
31+
* `SLOW5_ERR_NOAUX`
32+
     Auxiliary hash map for the record was not found (see notes below).
33+
* `SLOW5_ERR_ARG`
34+
     Invalid argument - read or field is NULL.
35+
* `SLOW5_ERR_TYPE`
36+
     Type conversion was not possible - an array data type field cannot be converted to a primitive type.
37+
38+
39+
## NOTES
40+
41+
More error codes may be introduced in future. If the field value has been marked missing for an individual SLOW5 record ("." in SLOW5 ASCII and as `SLOW5_ENUM_NULL` in BLOW5), `SLOW5_ENUM_NULL` is returned and no error code is set (considered successful as the SLOW5 missing value representation is actually present in the file). This is typically the case when the field name is present in the SLOW5 header, but the field value for the particular record is missing. If the requested field is completely not present (not in the SLOW5 header as well), this is considered an error and `SLOW5_ERR_NOAUX` code is set.
42+
43+
The enum value returned by `slow5_aux_get_enum()` can be used to obtain the corresponding enum label by using using as the index for the list returned by `slow5_get_aux_enum_labels()`.
44+
45+
## EXAMPLES
46+
```
47+
#include <stdio.h>
48+
#include <stdlib.h>
49+
#include <slow5/slow5.h>
50+
51+
#define FILE_PATH "examples/adv/example3.blow5"
52+
53+
int main(){
54+
55+
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
56+
if(sp==NULL){
57+
fprintf(stderr,"Error in opening file\n");
58+
exit(EXIT_FAILURE);
59+
}
60+
slow5_rec_t *rec = NULL;
61+
int ret=0;
62+
ret = slow5_get_next(&rec,sp);
63+
if(ret<0){
64+
fprintf(stderr,"Error in slow5_get_next. Error code %d\n",ret);
65+
exit(EXIT_FAILURE);
66+
}
67+
68+
uint8_t num_label = 0;
69+
char **labels = slow5_get_aux_enum_labels(sp->header, "end_reason", &num_label);
70+
if(labels==NULL){
71+
fprintf(stderr,"Error in getting list of enum labels\n");
72+
exit(EXIT_FAILURE);
73+
}
74+
75+
uint8_t end_reason = slow5_aux_get_enum(rec,"end_reason",&ret);
76+
if(ret!=0){
77+
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);
78+
exit(EXIT_FAILURE);
79+
}
80+
if(end_reason != SLOW5_ENUM_NULL){
81+
printf("end_reason = %s\n", labels[end_reason]);
82+
} else{
83+
printf("end_reason is missing for the record\n");
84+
}
85+
86+
slow5_rec_free(rec);
87+
slow5_close(sp);
88+
89+
}
90+
```
91+
92+
## SEE ALSO
93+
[`slow5_get_aux_enum_labels()`](slow5_get_aux_enum_labels.md).
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# slow5_get_aux_enum_labels
2+
3+
## NAME
4+
5+
slow5_get_aux_enum_labels - gets the list of labels for an enum data type
6+
7+
## SYNOPSYS
8+
9+
`char **slow5_get_aux_enum_labels(const slow5_hdr_t *header, const char *field, uint8_t *n)`
10+
11+
## DESCRIPTION
12+
13+
`slow5_get_aux_enum_labels()` gets the list of enum labels for a auxiliary field specified by *field* from a SLOW5 file header pointed by *header*. The number of enum labels will be set on the address specified by *n*.
14+
15+
16+
## RETURN VALUE
17+
18+
`slow5_get_aux_enum_labels()` returns the list of enum labels as a *char*** pointer. On error NULL is returned and `slow5_errno` is set to indicate the error.
19+
20+
## ERRORS
21+
22+
In case of an error, `slow5_errno` is set as follows.
23+
24+
* `SLOW5_ERR_NOAUX`
25+
&nbsp;&nbsp;&nbsp;&nbsp; Auxiliary hash map for the record was not found.
26+
* `SLOW5_ERR_ARG`
27+
&nbsp;&nbsp;&nbsp;&nbsp; Invalid argument - header or field is NULL.
28+
* `SLOW5_ERR_TYPE`
29+
&nbsp;&nbsp;&nbsp;&nbsp; Field data type is not an enum type
30+
31+
32+
## NOTES
33+
34+
The returned pointer is from an internal data structure and must NOT be freed by user.
35+
The order of the enum labels corresponds to the enum value, that is, an enum value can be used as the index on the returned pointer to access the corresponding enum label.
36+
37+
## EXAMPLES
38+
39+
```
40+
#include <stdio.h>
41+
#include <stdlib.h>
42+
#include <slow5/slow5.h>
43+
44+
#define FILE_PATH "examples/adv/example3.blow5"
45+
46+
int main(){
47+
48+
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
49+
if(sp==NULL){
50+
fprintf(stderr,"Error in opening file\n");
51+
exit(EXIT_FAILURE);
52+
}
53+
slow5_rec_t *rec = NULL;
54+
int ret=0;
55+
ret = slow5_get_next(&rec,sp);
56+
if(ret<0){
57+
fprintf(stderr,"Error in slow5_get_next. Error code %d\n",ret);
58+
exit(EXIT_FAILURE);
59+
}
60+
61+
uint8_t num_label = 0;
62+
char **labels = slow5_get_aux_enum_labels(sp->header, "end_reason", &num_label);
63+
if(labels==NULL){
64+
fprintf(stderr,"Error in getting list of enum labels\n");
65+
exit(EXIT_FAILURE);
66+
}
67+
68+
uint8_t end_reason = slow5_aux_get_enum(rec,"end_reason",&ret);
69+
if(ret!=0){
70+
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);
71+
exit(EXIT_FAILURE);
72+
}
73+
if(end_reason != SLOW5_ENUM_NULL){
74+
printf("end_reason = %s\n", labels[end_reason]);
75+
} else{
76+
printf("end_reason is missing for the record\n");
77+
}
78+
79+
slow5_rec_free(rec);
80+
slow5_close(sp);
81+
82+
}
83+
```
84+
85+
## SEE ALSO
86+
[slow5_aux_get_enum()](slow5_aux_get_enum.md)

docs/slow5_api/slow5_aux_get.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int main(){
8181
//------------------------------------------------------------------------
8282
// get auxiliary values with primitive datatype
8383
//------------------------------------------------------------------------
84-
ret=0;
84+
8585
double median_before = slow5_aux_get_double(rec,"median_before",&ret);
8686
if(ret!=0){
8787
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);

docs/slow5_api/slow5_low_level_api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ Low-level API allows much more efficient access to BLOW5 files compared to the h
2626
&nbsp;&nbsp;&nbsp;&nbsp;fetches the raw record (without decompressing or parsing) at the current file pointer of a SLOW5 file
2727
* [slow5_decode](low_level_api/slow5_decode.md)<br/>
2828
&nbsp;&nbsp;&nbsp;&nbsp;decodes a slow5 record
29-
29+
* [slow5_aux_get_enum](low_level_api/slow5_aux_get_enum.md)<br/>
30+
&nbsp;&nbsp;&nbsp;&nbsp;fetches an auxiliary field of type enum from a SLOW5 record
31+
* [slow5_get_aux_enum_labels](low_level_api/slow5_get_aux_enum_labels.md)<br/>
32+
&nbsp;&nbsp;&nbsp;&nbsp;gets the list of labels for an enum data type
3033

3134
### Writing and editing
3235

examples/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ example_write_append.slow5
1616
example_write_aux.blow5
1717
write
1818
append
19+
adv/auxiliary_field_enum
20+
adv/sequential_read_pthreads
21+
adv/sequential_read_openmp
22+
adv/get_all_read_ids

examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ This directory contains following examples.
1212

1313
You can invoke [build.sh](build.sh) from slow5lib directory as `examples/build.sh` to compile the example programmes. Have a look at the script to see the commands used for compiling and linking. As an example, the command to compile [sequential_read.c](sequential_read.c) is `gcc -Wall -O2 -I include/ examples/sequential_read.c lib/libslow5.a -o examples/sequential_read -lm -lz`. Make sure that you first call `make` so that `lib/libslow5.a` becomes available to be linked with. If you compiled *slow5lib* with *zstd* support enabled (`make zstd=1`), make sure you append `-lzstd` to the compilation commands.
1414

15-
A public template repository is available at [https://github.com/hasindu2008/slow5-template] which you can directly use to setup your own repository that uses *slow5lib* to build a tool. Check the instructions and comments there.
15+
A public template repository is available at [https://github.com/hasindu2008/slow5-template] which you can directly use to setup your own repository that uses *slow5lib* to build a tool. Check the instructions and comments there.
16+
17+
Some advanced examples that uses low-level API are available [here](adv/).

examples/adv/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# slow5lib Advanced Examples
2+
3+
This directory contains following advanced examples that uses low-level API.
4+
- *auxiliary_field_enum.c* demonstrates how to fetch a auxiliary field of enum data type from a slow5/blow5 file.
5+
- *sequential_read_pthreads.c* demonstrates how to sequentially read raw SLOW5 records from a slow5/blow5 file using a single thread and then decode those in parallel using *pthreads*.
6+
- *sequential_read_openmp.c* demonstrates how to sequentially read raw SLOW5 records from a slow5/blow5 file using a single thread and then decode those in parallel using *openMP*.
7+
- *get_all_read_ids.c* demonstrates how to get the list of all read IDs from a slow5/blow5 file.
8+
9+
You can invoke [build.sh](build.sh) from slow5lib directory as `examples/adv/build.sh` to compile the example programmes. Have a look at the script to see the commands used for compiling and linking. Also make sure you get familiar with the basic examples first, before trying these advanced examples.
10+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// an example programme that uses slow5lib to obtain auxiliary field of enum type from a slow5/blow5 file
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <slow5/slow5.h>
6+
7+
#define FILE_PATH "examples/adv/example3.blow5"
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <slow5/slow5.h>
11+
12+
int main(){
13+
14+
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
15+
if(sp==NULL){
16+
fprintf(stderr,"Error in opening file\n");
17+
exit(EXIT_FAILURE);
18+
}
19+
slow5_rec_t *rec = NULL;
20+
int ret=0;
21+
ret = slow5_get_next(&rec,sp);
22+
if(ret<0){
23+
fprintf(stderr,"Error in slow5_get_next. Error code %d\n",ret);
24+
exit(EXIT_FAILURE);
25+
}
26+
27+
uint8_t num_label = 0;
28+
char **labels = slow5_get_aux_enum_labels(sp->header, "end_reason", &num_label);
29+
if(labels==NULL){
30+
fprintf(stderr,"Error in getting list of enum labels\n");
31+
exit(EXIT_FAILURE);
32+
}
33+
34+
uint8_t end_reason = slow5_aux_get_enum(rec,"end_reason",&ret);
35+
if(ret!=0){
36+
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);
37+
exit(EXIT_FAILURE);
38+
}
39+
if(end_reason != SLOW5_ENUM_NULL){
40+
printf("end_reason = %s\n", labels[end_reason]);
41+
} else{
42+
printf("end_reason is missing for the record\n");
43+
}
44+
45+
slow5_rec_free(rec);
46+
slow5_close(sp);
47+
48+
return 0;
49+
}

examples/adv/build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
#exit on error
4+
set -x
5+
#prints the command to the console
6+
set -e
7+
gcc -Wall -O2 -I include/ examples/adv/auxiliary_field_enum.c lib/libslow5.a -o examples/adv/auxiliary_field_enum -lm -lz
8+
gcc -Wall -O2 -I include/ examples/adv/sequential_read_openmp.c lib/libslow5.a -o examples/adv/sequential_read_openmp -lm -lz -fopenmp
9+
gcc -Wall -O2 -I include/ examples/adv/sequential_read_pthreads.c lib/libslow5.a -o examples/adv/sequential_read_pthreads -lm -lz -lpthread
10+
gcc -Wall -O2 -I include/ examples/adv/get_all_read_ids.c lib/libslow5.a -o examples/adv/get_all_read_ids -lm -lz
11+
12+
#append -lzstd to above commands if your slow5lib is built with zstd support

examples/adv/example3.blow5

690 KB
Binary file not shown.

0 commit comments

Comments
 (0)