diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-10-16 13:43:38 -0400 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-10-16 13:43:38 -0400 |
commit | b5618d07a51ed431b9710c7f35ae7f4cc8d4e0a3 (patch) | |
tree | 8281b2d66c5fad40154cb3639db16c798d49f28c | |
parent | b43c4ae35d7996c18f13911e6c21d389b84fc6c5 (diff) |
reorder kmer_utils.h, actually take a kmer value as argv[2] for frequency, error check kmer
-rw-r--r-- | kmer_frequency_per_sequence.c | 9 | ||||
-rw-r--r-- | kmer_total_count.c | 8 | ||||
-rw-r--r-- | kmer_utils.h | 2 |
3 files changed, 15 insertions, 4 deletions
diff --git a/kmer_frequency_per_sequence.c b/kmer_frequency_per_sequence.c index d3e21a1..7c1bf9b 100644 --- a/kmer_frequency_per_sequence.c +++ b/kmer_frequency_per_sequence.c @@ -10,7 +10,6 @@ unsigned long position = 0; int main(int argc, char **argv) { char *line = NULL; - long kmer = 6; size_t len = 0; ssize_t read; @@ -25,6 +24,12 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } + unsigned long kmer = atoi(argv[2]); + if(kmer == 0) { + fprintf(stderr, "Error: invalid kmer.\n"); + exit(EXIT_FAILURE); + } + const unsigned long width = (unsigned long)1 << (kmer * 2); unsigned long long *counts = malloc((width+ 1) * sizeof(unsigned long long)); @@ -41,7 +46,7 @@ int main(int argc, char **argv) { memset(counts, 0, width); for(i = 0; i < read - kmer; i++) { - line[i] = alpha[line[i]]; + line[i] = alpha[(int)line[i]]; } for(i = 0; i < read - kmer; i++) { diff --git a/kmer_total_count.c b/kmer_total_count.c index 34abfa0..ec9a3f8 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -11,10 +11,16 @@ int main(int argc, char **argv) { unsigned long long i = 0; if(argc != 3) { - printf("Please supply a filename and a kmer\n"); + fprintf(stderr, "Please supply a filename and a kmer\n"); exit(EXIT_FAILURE); } + unsigned long kmer = atoi(argv[2]); + if(kmer == 0) { + fprintf(stderr, "Error: invalid kmer.\n"); + exit(EXIT_FAILURE); + } + unsigned long long *counts = get_kmer_counts_from_file(argv[1], atoi(argv[2])); // print out our counts arrray diff --git a/kmer_utils.h b/kmer_utils.h index 11506b3..4ed5928 100644 --- a/kmer_utils.h +++ b/kmer_utils.h @@ -1,4 +1,4 @@ -// kmer functions +// Kmer functions void convert_kmer_to_num(char *str, const unsigned long length); unsigned long num_to_index(const char *str, const int kmer, const long error_pos); unsigned long long * get_kmer_counts_from_file(const char *fn, const int kmer); |