diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-11-15 13:47:23 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-11-15 13:47:23 -0500 |
commit | cdb94d95429edf6d1f68ee3954cb2feb843f02e2 (patch) | |
tree | c00f05f7ba425a1cc7f6909df40081e7f894ef14 | |
parent | 2af65dca1f84acfe320753d5e8fa17133788015b (diff) | |
parent | 5d12ff8c86fc82b2800063ecd14008a5e34fd946 (diff) |
Merge branch 'master' of github.com:mutantturkey/dna-utils
-rw-r--r-- | kmer_total_count.c | 35 | ||||
-rw-r--r-- | kmer_utils.c | 1 | ||||
-rw-r--r-- | kmer_utils.h | 1 |
3 files changed, 23 insertions, 14 deletions
diff --git a/kmer_total_count.c b/kmer_total_count.c index 8310e00..57d4fcc 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -13,7 +13,7 @@ int main(int argc, char **argv) { char *filename = NULL; - unsigned int kmer = NULL; + unsigned int kmer = 0; bool nonzero = 0; bool label = 0; @@ -21,9 +21,7 @@ int main(int argc, char **argv) { unsigned long long width = 0; - unsigned long long i = 0; - - long long j = 0; + unsigned long long i = 0; static struct option long_options[] = { {"input", required_argument, 0, 'i'}, @@ -69,7 +67,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: filename (-i) must be supplied\n"); exit(EXIT_FAILURE); } - if(kmer == NULL && !kmer_set) { + if(kmer == 0 && !kmer_set) { fprintf(stderr, "Error: kmer (-k) must be supplied\n"); exit(EXIT_FAILURE); } @@ -87,26 +85,35 @@ int main(int argc, char **argv) { // if labels is set, print out our labels if(label) { for(i = 0; i < width; i++) - if(counts[i] != 0) - fprintf(stdout, "%s\t%llu\n", index_to_kmer(i, kmer), counts[i]); - + if(counts[i] != 0) { + char *kmer_str = index_to_kmer(i, kmer); + fprintf(stdout, "%s\t%llu\n", kmer_str, counts[i]); + free(kmer_str); + } + } else { for(i = 0; i < width; i++) if(counts[i] != 0) fprintf(stdout, "%llu\t%llu\n", i, counts[i]); - + } } // If we aren't printing nonzeros print everything else { if(label) { - for(i = 0; i < width; i++) - fprintf(stdout, "%s\t%llu\n", index_to_kmer(i, kmer), counts[i]); - } + for(i = 0; i < width; i++) { + if(counts[i] != 0) { + char *kmer_str = index_to_kmer(i, kmer); + fprintf(stdout, "%s\t%llu\n", kmer_str, counts[i]); + free(kmer_str); + } + } + } else { - for(i = 0; i < width; i=i+4) - fprintf(stdout, "%llu\n%llu\n%llu\n%llu\n", counts[i], counts[i+1], counts[i+2], counts[i+3]); + for(i = 0; i < width; i=i+4) { + fprintf(stdout, "%llu\n%llu\n%llu\n%llu\n", counts[i], counts[i+1], counts[i+2], counts[i+3]); + } } } return EXIT_SUCCESS; diff --git a/kmer_utils.c b/kmer_utils.c index a517c39..b29cd24 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -185,5 +185,6 @@ unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned in } } + free(line); return counts; } diff --git a/kmer_utils.h b/kmer_utils.h index 4ed5928..762c20c 100644 --- a/kmer_utils.h +++ b/kmer_utils.h @@ -1,6 +1,7 @@ // 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); +char *index_to_kmer(unsigned long long index, long kmer); unsigned long long * get_kmer_counts_from_file(const char *fn, const int kmer); // Utility functions |