From f5e6c210a95a98a4381e6142ad599e1ec3f8eff6 Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 15 May 2013 11:38:31 -0400 Subject: add some error checking --- src/c/quikr.c | 18 +++++++++++++++++- src/c/quikr_train.c | 13 +++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/c/quikr.c b/src/c/quikr.c index bb21093..e0ba77e 100644 --- a/src/c/quikr.c +++ b/src/c/quikr.c @@ -112,7 +112,6 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - if(verbose) { printf("kmer: %d\n", kmer); printf("lambda: %d\n", lambda); @@ -121,11 +120,28 @@ int main(int argc, char **argv) { printf("sensing database fasta: %s\n", sensing_fasta_filename); printf("output: %s\n", output_filename); } + + if(access (sensing_matrix_filename, F_OK) == -1) { + fprintf(stderr, "Error: could not find %s\n", sensing_matrix_filename); + exit(EXIT_FAILURE); + } + if(access (sensing_fasta_filename, F_OK) == -1) { + fprintf(stderr, "Error: could not find %s\n", sensing_fasta_filename); + exit(EXIT_FAILURE); + } + if(access (input_fasta_filename, F_OK) == -1) { + fprintf(stderr, "Error: could not find %s\n", input_fasta_filename); + exit(EXIT_FAILURE); + } + // 4 "ACGT" ^ Kmer gives us the size of output rows width = pow(4, kmer); width = width + 1; sequences = count_sequences(sensing_fasta_filename); + if(sequences == 0) { + fprintf(stderr, "Error: %s contains 0 fasta sequences\n", sensing_fasta_filename); + } if(verbose) { printf("width: %d\nsequences %d\n", width, sequences); diff --git a/src/c/quikr_train.c b/src/c/quikr_train.c index f19a554..1585629 100644 --- a/src/c/quikr_train.c +++ b/src/c/quikr_train.c @@ -22,7 +22,7 @@ int main(int argc, char **argv) { int c; - int kmer = 0; + int kmer = 6; char *fasta_file = NULL; char *output_file = NULL; @@ -88,15 +88,17 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - if(kmer == 0) - kmer = 6; - if(verbose) { printf("kmer size: %d\n", kmer); printf("fasta file: %s\n", fasta_file); printf("output file: %s\n", output_file); } + if(access (fasta_file, F_OK) == -1) { + fprintf(stderr, "Error: could not find %s\n", fasta_file); + exit(EXIT_FAILURE); + } + if(strcmp(&output_file[strlen(output_file) - 3], ".gz") != 0) { char *temp = malloc(sizeof(strlen(output_file) + 4)); sprintf(temp, "%s.gz", output_file); @@ -107,6 +109,9 @@ int main(int argc, char **argv) { // 4 ^ Kmer gives us the width, or the number of permutations of ACTG with kmer length int width = pow(4, kmer); int sequences = count_sequences(fasta_file); + if(sequences == 0) { + fprintf(stderr, "Error: %s contains 0 fasta sequences\n", fasta_file); + } if(verbose) printf("sequences: %d\nwidth: %d\n", sequences, width); -- cgit v1.2.3