Skip to content

Commit 527c48e

Browse files
committed
Merge branch 'master' into dev
2 parents 9887f49 + 9792c31 commit 527c48e

File tree

12 files changed

+134
-55
lines changed

12 files changed

+134
-55
lines changed

.github/workflows/c-cpp.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ jobs:
105105
run: make clean && make CC=icc -j8 zstd=1
106106
- name: test zstd
107107
run: make test zstd=1 CC=icc
108-
os_x_10:
109-
name: OSX 10
110-
runs-on: macos-10.15
108+
os_x_11:
109+
name: OSX 11
110+
runs-on: macos-11
111111
steps:
112112
- uses: actions/checkout@v2
113113
- name: build
@@ -116,9 +116,9 @@ jobs:
116116
run: make test
117117
- name: examples
118118
run: make examples
119-
os_x_10_zstd:
120-
name: OSX 10 zstd
121-
runs-on: macos-10.15
119+
os_x_11_zstd:
120+
name: OSX 11 zstd
121+
runs-on: macos-11
122122
steps:
123123
- uses: actions/checkout@v2
124124
- name: install packages

docs/slow5_api/slow5_aux_get.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ Upon successful completion, `slow5_aux_get_<primitive_datatype>()` returns the r
4040
In case of an error, `slow5_errno` or the non zero error code is set in *err* (unless *err* is NULL) are as follows.
4141

4242

43-
`SLOW5_ERR_NOFLD`
43+
* `SLOW5_ERR_NOFLD`
4444
&nbsp;&nbsp;&nbsp;&nbsp; The requested field was not found.
45-
`SLOW5_ERR_NOAUX`
45+
* `SLOW5_ERR_NOAUX`
4646
&nbsp;&nbsp;&nbsp;&nbsp; Auxiliary hash map for the record was not found (see notes below).
47-
`SLOW5_ERR_ARG`
47+
* `SLOW5_ERR_ARG`
4848
&nbsp;&nbsp;&nbsp;&nbsp; Invalid argument - read or field is NULL.
49-
`SLOW5_ERR_TYPE`
49+
* `SLOW5_ERR_TYPE`
5050
&nbsp;&nbsp;&nbsp;&nbsp; Type conversion was not possible - an array data type field cannot be converted to a primitive type.
5151

5252

docs/slow5_api/slow5_aux_get_array.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ Upon successful completion, `slow5_aux_get_<array_datatype>()` returns a pointer
4040

4141
In case of an error, `slow5_errno` or the non zero error code is set in *err* (unless *err* is NULL) are as follows.
4242

43-
`SLOW5_ERR_NOFLD`
43+
* `SLOW5_ERR_NOFLD`
4444
&nbsp;&nbsp;&nbsp;&nbsp; The requested field was not found.
45-
`SLOW5_ERR_NOAUX`
45+
* `SLOW5_ERR_NOAUX`
4646
&nbsp;&nbsp;&nbsp;&nbsp; Auxiliary hash map for the record was not found.
47-
`SLOW5_ERR_ARG`
47+
* `SLOW5_ERR_ARG`
4848
&nbsp;&nbsp;&nbsp;&nbsp; Invalid argument - read or field is NULL
49-
`SLOW5_ERR_TYPE`
49+
* `SLOW5_ERR_TYPE`
5050
&nbsp;&nbsp;&nbsp;&nbsp; Type conversion was not possible - a primitives data type field cannot be converted to an array type.
5151

5252
## NOTES

examples/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# slow5lib Examples
2+
3+
This directory contains following examples.
4+
- *sequential_read.c* demonstrates how to read a slow5/blow5 file, sequentially from start to end.
5+
- *random_read.c* demonstrates how to fetch a given read ID from a slow5/blow5 file.
6+
- *header_attribute.c* demonstrates how to fetch a header data attribute from a slow5/blow5 file.
7+
- *auxiliary_field.c* demonstrates how to fetch a auxiliary field from a slow5/blow5 file.
8+
- *random_read_pthreads.c* demonstrates how to fetch given read IDs in parallel from a slow5/blow5 file using *pthreads*.
9+
- *random_read_openmp.c* demonstrates how to fetch given read IDs in parallel from a slow5/blow5 file using openMP.
10+
- *write.c* demonstrate how to write a new slow5/blow5 file.
11+
- *append.c* demonstrates how to append to an existing slow5/blow5 file.
12+
13+
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.
14+
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.

examples/append.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ read_1 0 4096 4 12 4000 12 0,1,2
1616

1717
int main(){
1818

19+
//open the SLOW5 file for appending
1920
slow5_file_t *sp = slow5_open(FILE_PATH, "a");
2021
if(sp==NULL){
2122
fprintf(stderr,"Error opening file!\n");
@@ -81,13 +82,16 @@ int main(){
8182
exit(EXIT_FAILURE);
8283
}
8384

85+
//append the record to the file
8486
if(slow5_write(slow5_record, sp) < 0){
8587
fprintf(stderr,"Error writing record to file\n");
8688
exit(EXIT_FAILURE);
8789
}
8890

91+
//free the slow5 record
8992
slow5_rec_free(slow5_record);
9093

94+
//close the SLOW5 file
9195
slow5_close(sp);
9296

9397
return 0;

examples/auxiliary_field.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// an example programme that uses slow5lib to obtain auxiliary field from a slow5/blow5 file
2+
13
#include <stdio.h>
24
#include <stdlib.h>
35
#include <slow5/slow5.h>
@@ -6,50 +8,73 @@
68

79
int main(){
810

11+
//open the SLOW5 file
912
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
1013
if(sp==NULL){
1114
fprintf(stderr,"Error in opening file\n");
1215
exit(EXIT_FAILURE);
1316
}
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
1622
ret = slow5_get_next(&rec,sp);
1723
if(ret<0){
1824
fprintf(stderr,"Error in slow5_get_next. Error code %d\n",ret);
1925
exit(EXIT_FAILURE);
2026
}
2127

2228
//------------------------------------------------------------------------
23-
// get auxiliary values with primitive datatype
29+
// getting auxiliary fields whose values are primitive datatypes
2430
//------------------------------------------------------------------------
25-
ret=0;
31+
32+
//median_before auxiliary field - double data type
2633
double median_before = slow5_aux_get_double(rec,"median_before",&ret);
2734
if(ret!=0){
2835
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);
2936
exit(EXIT_FAILURE);
3037
}
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+
}
3243

44+
//start_time auxiliary field - uint64 data type
3345
uint64_t start_time = slow5_aux_get_uint64(rec, "start_time", &ret);
3446
if(ret!=0){
3547
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);
3648
exit(EXIT_FAILURE);
3749
}
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+
}
3955

4056
//------------------------------------------------------------------------
41-
// get auxiliary values with array datatype
57+
// getting auxiliary fields whose values are array datatypes
4258
//------------------------------------------------------------------------
4359

44-
uint64_t len;
60+
//channel_number auxiliary field - string (char *) datatype
61+
uint64_t len; //length of the array
4562
char* channel_number = slow5_aux_get_string(rec, "channel_number", &len, &ret);
4663
if(ret!=0){
4764
fprintf(stderr,"Error in getting auxiliary attribute from the file. Error code %d\n",ret);
4865
exit(EXIT_FAILURE);
4966
}
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+
}
5172

73+
//free the SLOW5 record
5274
slow5_rec_free(rec);
75+
76+
//close the SLOW5 file
5377
slow5_close(sp);
5478

79+
return 0;
5580
}

examples/header_attribute.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// an example programme that uses slow5lib to obtain a slow5 header attribute
2+
// an example programme that uses slow5lib to obtain a slow5 header data attribute
33

44
#include <stdio.h>
55
#include <stdlib.h>
@@ -9,18 +9,22 @@
99

1010
int main(){
1111

12+
//open the SLOW5 file
1213
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
1314
if(sp==NULL){
1415
fprintf(stderr,"Error in opening file\n");
1516
exit(EXIT_FAILURE);
1617
}
17-
const slow5_hdr_t* header = sp->header;
18+
19+
const slow5_hdr_t* header = sp->header; //pointer to the SLOW5 header
1820
int read_group = 0;
19-
char* read_group_0_run_id_value = slow5_hdr_get("run_id", read_group, header);
20-
if(read_group_0_run_id_value != NULL ){
21+
char* read_group_0_run_id_value = slow5_hdr_get("run_id", read_group, header); //get the value of the attribute "run_id" in the read group 0
22+
if(read_group_0_run_id_value != NULL ){ //check if the attribute exists and print the value
2123
printf("%s\n",read_group_0_run_id_value);
2224
}
2325

26+
//close the SLOW5 file
2427
slow5_close(sp);
2528

29+
return 0;
2630
}

examples/random_read.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,48 @@
1010

1111
int main(){
1212

13+
//open the SLOW5 file
1314
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
1415
if(sp==NULL){
1516
fprintf(stderr,"Error in opening file\n");
1617
exit(EXIT_FAILURE);
1718
}
18-
slow5_rec_t *rec = NULL;
19-
int ret=0;
2019

20+
slow5_rec_t *rec = NULL; //slow5 record to be read
21+
int ret=0; //for return value
22+
23+
//load the SLOW5 index (will be built if not present)
2124
ret = slow5_idx_load(sp);
2225
if(ret<0){
2326
fprintf(stderr,"Error in loading index\n");
2427
exit(EXIT_FAILURE);
2528
}
2629

30+
//fetch the read with read_id "r3"
2731
ret = slow5_get("r3", &rec, sp);
28-
if(ret < 0){
32+
if(ret<0){
2933
fprintf(stderr,"Error in when fetching the read\n");
3034
}
3135
else{
3236
printf("%s\t",rec->read_id);
3337
uint64_t len_raw_signal = rec->len_raw_signal;
34-
for(uint64_t i=0;i<len_raw_signal;i++){
38+
for(uint64_t i=0;i<len_raw_signal;i++){ //iterate through the raw signal and print in picoamperes
3539
double pA = TO_PICOAMPS(rec->raw_signal[i],rec->digitisation,rec->offset,rec->range);
3640
printf("%f ",pA);
3741
}
3842
printf("\n");
3943
}
4044

45+
//..... fetch any other read using slow5_get (as above)
46+
47+
//free the SLOW5 record
4148
slow5_rec_free(rec);
4249

50+
//free the SLOW5 index
4351
slow5_idx_unload(sp);
4452

53+
//close the SLOW5 file
4554
slow5_close(sp);
4655

56+
return 0;
4757
}

examples/random_read_openmp.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// an example programme that uses slow5lib to randmly access records in a SLOW5 file using multiple threads (openMP)
2+
// an example programme that uses slow5lib to randomly access records in a SLOW5 file using multiple threads (openMP)
33
#include <omp.h>
44
#include <stdio.h>
55
#include <stdlib.h>
@@ -12,13 +12,16 @@ char * read_id_list[READ_LIST_SIZE] = {"r4", "r1", "r3", "r4"};
1212

1313
int main(){
1414

15+
//open the SLOW5 file
1516
slow5_file_t *sp = slow5_open(FILE_PATH,"r");
1617
if(sp==NULL){
1718
fprintf(stderr,"Error in opening file\n");
1819
exit(EXIT_FAILURE);
1920
}
2021

21-
int ret=0;
22+
int ret=0; //for return value
23+
24+
//load the SLOW5 index (will be built if not present)
2225
ret = slow5_idx_load(sp);
2326
if (ret < 0) {
2427
fprintf(stderr, "Error in loading index\n");
@@ -27,18 +30,21 @@ int main(){
2730

2831
#pragma omp parallel for
2932
for(int32_t i=0; i<READ_LIST_SIZE; i++) {
30-
slow5_rec_t *rec = NULL;
31-
ret = slow5_get(read_id_list[i], &rec, sp);
33+
slow5_rec_t *rec = NULL; //slow5 record to be read
34+
ret = slow5_get(read_id_list[i], &rec, sp); //fetch the read
3235
if (ret < 0) {
3336
fprintf(stderr, "Error in when fetching the read %s\n",read_id_list[i]);
3437
} else {
3538
fprintf(stderr, "Successfully fetched the read %s with %ld raw signal samples\n", rec->read_id, rec->len_raw_signal);
3639
}
37-
slow5_rec_free(rec);
40+
slow5_rec_free(rec); //free the SLOW5 record
3841
}
3942

43+
//free the SLOW5 index
4044
slow5_idx_unload(sp);
4145

46+
//close the SLOW5 file
4247
slow5_close(sp);
4348

49+
return 0;
4450
}

0 commit comments

Comments
 (0)