Skip to content

Commit

Permalink
improve help msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonson Wong committed Apr 24, 2024
1 parent 6fe2b76 commit 99e1c11
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
12 changes: 10 additions & 2 deletions src_tool/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ extern "C" {
" -p, --iop INT number of I/O processes [" TO_STR(DEFAULT_NUM_PROCESSES) "]\n"

#define HELP_MSG_BATCH \
" -K, --batchsize INT number of records loaded to the memory at once [" TO_STR(DEFAULT_BATCH_SIZE) "]\n" \
" -K, --batchsize INT number of records loaded to the memory at once [" TO_STR(DEFAULT_BATCH_SIZE) "]\n"

#define HELP_MSG_RETRY \
" -r, --retry INT number of retries on a fetch before aborting the batch [" TO_STR(DEFAULT_NUM_RETRY) "]\n" \
" -w, --wait INT time (sec) to wait before the next fetch retry [" TO_STR(DEFAULT_RETRY_WAIT) "]\n"

#define HELP_MSG_CACHE \
" --cache FILE save the downloaded index to the specified file path [false]\n"

#define HELP_MSG_INDEX \
" --index FILE specify path to a custom slow5 index\n" \

#define HELP_MSG_HELP \
" -h, --help display this message and exit\n" \
" -h, --help display this message and exit\n\n"

#define HELP_FORMATS_METHODS \
"FORMAT:\n" \
Expand All @@ -70,6 +76,8 @@ extern "C" {
"SIG_MTD:\n" \
" none - no special signal compression\n" \
" svb-zd - StreamVByte with zig-zag delta \n\n" \

#define HELP_DOCS \
"See https://slow5.page.link/slow5curl for a detailed description of these command-line options.\n"

struct program_meta {
Expand Down
33 changes: 16 additions & 17 deletions src_tool/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@
#define USAGE_MSG "Usage: %s [OPTIONS] [SLOW5_FILE] [READ_ID]...\n"
#define HELP_LARGE_MSG \
"Display the read entry for each specified READ_ID from a blow5 file.\n" \
"If READ_ID is not specified, a newline separated list of read ids will be read from the standard input .\n" \
"If READ_ID is not specified, a newline separated list of read ids will be read from the standard input.\n" \
USAGE_MSG \
"\n" \
"OPTIONS:\n" \
" --to FORMAT specify output file format (slow5 or blow5)\n" \
" -o, --output [FILE] output contents to FILE (.slow5 or .blow5 extensions) [default: stdout]\n" \
HELP_MSG_INDEX \
HELP_MSG_CACHE \
HELP_MSG_PRESS \
HELP_MSG_THREADS \
HELP_MSG_BATCH \
" -l --list [FILE] list of read ids provided as a single-column text file with one read id per line.\n" \
" --skip warn and continue if a read_id was not found.\n" \
" --index [FILE] path to a custom slow5 index (experimental).\n" \
HELP_MSG_RETRY \
HELP_MSG_HELP \
HELP_FORMATS_METHODS
HELP_FORMATS_METHODS \
HELP_DOCS

typedef struct {
double fetch;
Expand Down Expand Up @@ -130,7 +132,7 @@ bool get_single(
if (core->benchmark == false) {
struct slow5_press* compress = slow5_press_init(core->press_method);
if (!compress) {
ERROR("Could not initialise the slow5 compression method%s","");
ERROR("%s","Could not initialise the slow5 compression method.");
exit(EXIT_FAILURE);
}
slow5_rec_fwrite(slow5_file_pointer, record, s5c->s5p->header->aux_meta, core->format_out, compress);
Expand Down Expand Up @@ -163,13 +165,13 @@ int get_main(int argc, char **argv, struct program_meta *meta) {
{"output", required_argument, NULL, 'o'}, //4
{"list", required_argument, NULL, 'l'}, //5
{"skip", no_argument, NULL, 0}, //6
{"threads", required_argument, NULL, 't' }, //7
{"help", no_argument, NULL, 'h' }, //8
{"benchmark", no_argument, NULL, 'e' }, //9
{"index", required_argument, NULL, 0 }, //10
{"cache", required_argument, NULL, 0 }, //11
{"retry", required_argument, NULL, 'r' }, //12
{"wait", required_argument, NULL, 'w' }, //13
{"threads", required_argument, NULL, 't'}, //7
{"help", no_argument, NULL, 'h'}, //8
{"benchmark", no_argument, NULL, 'e'}, //9
{"index", required_argument, NULL, 0}, //10
{"cache", required_argument, NULL, 0}, //11
{"retry", required_argument, NULL, 'r'}, //12
{"wait", required_argument, NULL, 'w'}, //13
{NULL, 0, NULL, 0 }
};

Expand Down Expand Up @@ -361,7 +363,7 @@ int get_main(int argc, char **argv, struct program_meta *meta) {
start = slow5_realtime();
s5curl_t *slow5curl = s5curl_open(f_in_name);
if (!slow5curl) {
ERROR("cannot open %s. \n", f_in_name);
ERROR("cannot open %s.\n", f_in_name);
return EXIT_FAILURE;
}
end = slow5_realtime();
Expand All @@ -385,23 +387,20 @@ int get_main(int argc, char **argv, struct program_meta *meta) {
ret_idx = s5curl_idx_load(slow5curl);
}
if (ret_idx < 0) {
ERROR("Error loading index file for %s\n", f_in_name);
ERROR("Error loading index file for %s.\n", f_in_name);
EXIT_MSG(EXIT_FAILURE, argv, meta);
return EXIT_FAILURE;
}

} else {
int ret_idx;

if (idx_cache_path != NULL) {
VERBOSE("Caching index to %s.", idx_cache_path);
ret_idx = s5curl_idx_load_with_and_cache(slow5curl, slow5_index, idx_cache_path);
} else {
ret_idx = s5curl_idx_load_with(slow5curl, slow5_index);
}

if (ret_idx < 0) {
ERROR("Error loading index file for %s from file path %s\n", f_in_name, slow5_index);
ERROR("Error loading index file for %s from file path %s.\n", f_in_name, slow5_index);
EXIT_MSG(EXIT_FAILURE, argv, meta);
return EXIT_FAILURE;
}
Expand Down
17 changes: 14 additions & 3 deletions src_tool/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
USAGE_MSG \
"\n" \
HELP_MSG_HELP \
HELP_DOCS

extern int slow5curl_verbosity_level;

Expand All @@ -30,6 +31,13 @@ int head_main(int argc, char **argv, struct program_meta *meta) {
// Debug: print arguments
print_args(argc,argv);

// No arguments given
if (argc <= 1) {
fprintf(stderr, HELP_LARGE_MSG, argv[0]);
EXIT_MSG(EXIT_FAILURE, argv, meta);
return EXIT_FAILURE;
}

static struct option long_opts[] = {
{"help", no_argument, NULL, 'h' }, //0
{NULL, 0, NULL, 0 }
Expand Down Expand Up @@ -68,7 +76,7 @@ int head_main(int argc, char **argv, struct program_meta *meta) {
}

if (argc - optind > 1){
ERROR("%s", "Too many arguments");
ERROR("%s", "Too many arguments.");
fprintf(stderr, HELP_SMALL_MSG, argv[0]);
EXIT_MSG(EXIT_FAILURE, argv, meta);
exit(EXIT_FAILURE);
Expand All @@ -80,9 +88,12 @@ int head_main(int argc, char **argv, struct program_meta *meta) {
return EXIT_FAILURE;
}

s5curl_t *slow5curl = s5curl_open(argv[optind]);
char *f_in_name = argv[optind];

VERBOSE("%s", "Loading remote BLOW5 file.");
s5curl_t *slow5curl = s5curl_open(f_in_name);
if (!slow5curl) {
ERROR("cannot open %s. \n", argv[optind]);
ERROR("cannot open %s.\n", f_in_name);
return EXIT_FAILURE;
}

Expand Down
21 changes: 14 additions & 7 deletions src_tool/reads.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"Prints the reads in a remote BLOW5 file. "\
USAGE_MSG \
"\n" \
HELP_MSG_CACHE \
HELP_MSG_INDEX \
HELP_MSG_HELP \
HELP_DOCS

extern int slow5curl_verbosity_level;

Expand All @@ -42,6 +45,13 @@ int reads_main(int argc, char **argv, struct program_meta *meta) {
// Debug: print arguments
print_args(argc,argv);

// No arguments given
if (argc <= 1) {
fprintf(stderr, HELP_LARGE_MSG, argv[0]);
EXIT_MSG(EXIT_FAILURE, argv, meta);
return EXIT_FAILURE;
}

static struct option long_opts[] = {
{"help", no_argument, NULL, 'h'}, //0
{"index", required_argument, NULL, 0}, //1
Expand Down Expand Up @@ -96,7 +106,7 @@ int reads_main(int argc, char **argv, struct program_meta *meta) {
}

if (argc - optind > 1){
ERROR("%s", "Too many arguments");
ERROR("%s\n", "Too many arguments.");
fprintf(stderr, HELP_SMALL_MSG, argv[0]);
EXIT_MSG(EXIT_FAILURE, argv, meta);
exit(EXIT_FAILURE);
Expand All @@ -113,7 +123,7 @@ int reads_main(int argc, char **argv, struct program_meta *meta) {
VERBOSE("%s", "Loading remote BLOW5 file.");
s5curl_t *slow5curl = s5curl_open(f_in_name);
if (!slow5curl) {
ERROR("cannot open %s. \n", f_in_name);
ERROR("cannot open %s.\n", f_in_name);
return EXIT_FAILURE;
}

Expand All @@ -127,23 +137,20 @@ int reads_main(int argc, char **argv, struct program_meta *meta) {
ret_idx = s5curl_idx_load(slow5curl);
}
if (ret_idx < 0) {
ERROR("Error loading index file for %s\n", f_in_name);
ERROR("Error loading index file for %s.\n", f_in_name);
EXIT_MSG(EXIT_FAILURE, argv, meta);
return EXIT_FAILURE;
}

} else {
int ret_idx;

if (idx_cache_path != NULL) {
VERBOSE("Caching index to %s.", idx_cache_path);
ret_idx = s5curl_idx_load_with_and_cache(slow5curl, slow5_index, idx_cache_path);
} else {
ret_idx = s5curl_idx_load_with(slow5curl, slow5_index);
}

if (ret_idx < 0) {
ERROR("Error loading index file for %s from file path %s\n", f_in_name, slow5_index);
ERROR("Error loading index file for %s from file path %s.\n", f_in_name, slow5_index);
EXIT_MSG(EXIT_FAILURE, argv, meta);
return EXIT_FAILURE;
}
Expand Down

0 comments on commit 99e1c11

Please sign in to comment.