Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idx #81

Merged
merged 5 commits into from
Nov 16, 2023
Merged

Idx #81

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions docs/slow5_api/low_level_api/slow5_idx_load_with.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions docs/slow5_api/slow5_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!--
int slow5_hdr_fwrite(FILE *fp, struct slow5_hdr *header, enum slow5_fmt format, slow5_press_method_t comp)
int slow5_rec_fwrite(FILE *fp, struct slow5_rec *read, struct slow5_aux_meta *aux_meta, enum slow5_fmt format, struct slow5_press *compress)
Expand Down
1 change: 1 addition & 0 deletions include/slow5/slow5_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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);

Expand Down
34 changes: 20 additions & 14 deletions src/slow5_idx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -398,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;
Expand Down
2 changes: 2 additions & 0 deletions src/slow5_idx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/slow5_mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){

Expand Down Expand Up @@ -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);
Expand Down
Loading