From 3c48c960903dfbe900755f0ab4f3b679b2bd32d0 Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Mon, 28 Aug 2023 11:02:10 +1000 Subject: [PATCH 01/11] no timestamp check for index_load_with --- .../low_level_api/slow5_idx_load_with.md | 8 +++--- src/slow5_idx.c | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/docs/slow5_api/low_level_api/slow5_idx_load_with.md b/docs/slow5_api/low_level_api/slow5_idx_load_with.md index 34d853e..f852f5a 100755 --- a/docs/slow5_api/low_level_api/slow5_idx_load_with.md +++ b/docs/slow5_api/low_level_api/slow5_idx_load_with.md @@ -1,15 +1,13 @@ # slow5_idx_load_with ## NAME -slow5_idx_load_with - loads the index file for a SLOW5 file given a file path for the index +slow5_idx_load_with - loads the index file for a SLOW5 file for a user specified file path for the index ## SYNOPSYS -`int slow5_idx_load_with(slow5_with_file_t *s5p, const char *pathname)` +`int slow5_idx_load_with(slow5_file_t *s5p, const char *pathname)` ## DESCRIPTION -`slow5_idx_load_with()` loads an index file for a SLOW5 file pointed by *s5p* into the memory from the disk and associates the index with *s5p*. If the index file is not found, the index is first created and written to the disk. - -`slow5_idx_load_with()` could be called instead of `slow5_idx_load_with()` when the index file is at a custom location. +`slow5_idx_load_with()` loads an index file located at *pathname* for a SLOW5 file pointed by *s5p* into the memory from the disk and associates the index with *s5p*. If the index file is not found, it will error out. ## RETURN VALUE Upon successful completion, `slow5_idx_load_with()` returns a non-negative integer. Otherwise, a negative value is returned. diff --git a/src/slow5_idx.c b/src/slow5_idx.c index 36f5979..f300ed9 100644 --- a/src/slow5_idx.c +++ b/src/slow5_idx.c @@ -31,17 +31,23 @@ static inline struct slow5_idx *slow5_idx_init_empty(void) { return index; } -static inline int slow5_idx_load_fp(struct slow5_idx *index, struct slow5_file *s5p, FILE *index_fp) { +static inline int slow5_idx_load_fp(struct slow5_idx *index, struct slow5_file *s5p, FILE *index_fp, int8_t check_ts) { index->fp = index_fp; - int err; - if (slow5_filestamps_cmp(index->pathname, s5p->meta.pathname, &err) < 0.0) { - SLOW5_WARNING("Index file '%s' is older than slow5 file '%s'.", - index->pathname, s5p->meta.pathname); - } - if (err == -1) { - return -1; + + if(check_ts){ + int err; + if (slow5_filestamps_cmp(index->pathname, s5p->meta.pathname, &err) < 0.0) { + SLOW5_WARNING("Index file '%s' is older than slow5 file '%s'.", + index->pathname, s5p->meta.pathname); + } + if (err == -1) { + return -1; + } + } else { + SLOW5_INFO("Custom index file '%s' is being used. Time stamps not checked.", index->pathname); } + if (slow5_idx_read(index) != 0) { return -1; } @@ -79,7 +85,7 @@ struct slow5_idx *slow5_idx_init_with(struct slow5_file *s5p, const char *pathna slow5_idx_free(index); return NULL; } else { - if (slow5_idx_load_fp(index, s5p, index_fp) != 0) { + if (slow5_idx_load_fp(index, s5p, index_fp, 0) != 0) { slow5_idx_free(index); return NULL; } @@ -127,7 +133,7 @@ struct slow5_idx *slow5_idx_init(struct slow5_file *s5p) { fclose(index->fp); index->fp = NULL; } else { - if (slow5_idx_load_fp(index, s5p, index_fp) != 0) { + if (slow5_idx_load_fp(index, s5p, index_fp, 1) != 0) { slow5_idx_free(index); return NULL; } From a8a5afe5b938c6cfbf997b018804f0250356c7d1 Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Wed, 20 Sep 2023 16:14:34 +1000 Subject: [PATCH 02/11] add slow5_batch_encode --- include/slow5/slow5_mt.h | 1 + src/slow5_mt.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/slow5/slow5_mt.h b/include/slow5/slow5_mt.h index a444662..2a75ee4 100644 --- a/include/slow5/slow5_mt.h +++ b/include/slow5/slow5_mt.h @@ -51,6 +51,7 @@ slow5_batch_t* slow5_init_batch(int batch_capacity); int slow5_get_next_batch(slow5_mt_t *mt, slow5_batch_t *read_batch, int batch_size); int slow5_get_batch(slow5_mt_t *mt, slow5_batch_t *read_batch, char **rid, int num_rid); int slow5_write_batch(slow5_mt_t *mt, slow5_batch_t *read_batch, int batch_size); +int slow5_encode_batch(slow5_mt_t *core, slow5_batch_t *db, int batch_size); void slow5_free_batch(slow5_batch_t *read_batch); void slow5_free_mt(slow5_mt_t *mt); diff --git a/src/slow5_mt.c b/src/slow5_mt.c index f7b9849..cfa3341 100644 --- a/src/slow5_mt.c +++ b/src/slow5_mt.c @@ -361,6 +361,11 @@ int slow5_get_next_batch(slow5_mt_t *core, slow5_batch_t *db, int batch_size){ return num_read; } +int slow5_encode_batch(slow5_mt_t *core, slow5_batch_t *db, int batch_size){ + db->n_rec = batch_size; + slow5_work_db(core,db,slow5_work_per_single_read3); + return db->n_rec; +} int slow5_write_batch(slow5_mt_t *core, slow5_batch_t *db, int batch_size){ @@ -501,6 +506,10 @@ int slow5_get_batch(slow5_mt_t *mt, slow5_batch_t *read_batch, char **rid, int n fprintf(stderr,"slow5lib has not been compiled with lazy multithreading support\n"); exit(EXIT_FAILURE); } +int slow5_encode_batch(slow5_mt_t *core, slow5_batch_t *db, int batch_size){ + fprintf(stderr,"slow5lib has not been compiled with lazy multithreading support\n"); + exit(EXIT_FAILURE); +} int slow5_write_batch(slow5_mt_t *mt, slow5_batch_t *read_batch, int batch_size){ fprintf(stderr,"slow5lib has not been compiled with lazy multithreading support\n"); exit(EXIT_FAILURE); From df3aaf4c149556d5820a1ccf199956e4d9417f0c Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Sat, 23 Sep 2023 11:25:58 +1000 Subject: [PATCH 03/11] expose two internal functions --- src/slow5_idx.c | 8 ++++---- src/slow5_idx.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/slow5_idx.c b/src/slow5_idx.c index f300ed9..d9aa270 100644 --- a/src/slow5_idx.c +++ b/src/slow5_idx.c @@ -14,11 +14,11 @@ extern enum slow5_exit_condition_opt slow5_exit_condition; #define BUF_INIT_CAP (20*1024*1024) #define SLOW5_INDEX_BUF_INIT_CAP (64) // 2^6 TODO is this too little? -static inline struct slow5_idx *slow5_idx_init_empty(void); + static int slow5_idx_build(struct slow5_idx *index, struct slow5_file *s5p); -static int slow5_idx_read(struct slow5_idx *index); +int slow5_idx_read(struct slow5_idx *index); -static inline struct slow5_idx *slow5_idx_init_empty(void) { +struct slow5_idx *slow5_idx_init_empty(void) { struct slow5_idx *index = (struct slow5_idx *) calloc(1, sizeof *index); if(!index){ @@ -404,7 +404,7 @@ int slow5_idx_write(struct slow5_idx *index, struct slow5_version version) { return 0; } -static int slow5_idx_read(struct slow5_idx *index) { +int slow5_idx_read(struct slow5_idx *index) { struct slow5_version max_supported = SLOW5_VERSION_ARRAY; const char magic[] = SLOW5_INDEX_MAGIC_NUMBER; diff --git a/src/slow5_idx.h b/src/slow5_idx.h index 740729e..05a328e 100644 --- a/src/slow5_idx.h +++ b/src/slow5_idx.h @@ -47,6 +47,8 @@ struct slow5_idx { struct slow5_idx *slow5_idx_init(struct slow5_file *s5p); struct slow5_idx *slow5_idx_init_with(struct slow5_file *s5p, const char *pathname); +struct slow5_idx *slow5_idx_init_empty(void); +int slow5_idx_read(struct slow5_idx *index); /** * Create the index file for slow5 file. From d6e36bccd8c1d009c246ec075dd6d87da4332fe2 Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Sat, 23 Sep 2023 11:26:26 +1000 Subject: [PATCH 04/11] update docs --- docs/slow5_api/slow5_internal.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/slow5_api/slow5_internal.md b/docs/slow5_api/slow5_internal.md index ed70444..3090837 100755 --- a/docs/slow5_api/slow5_internal.md +++ b/docs/slow5_api/slow5_internal.md @@ -40,6 +40,9 @@ DO NOT USE. * slow5_hdr_set * slow5_hdr_add_rg_data +* slow5_idx_init_empty (used in slow5curl) +* slow5_idx_read (used in slow5curl) +