aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kmer_total_count.c35
-rw-r--r--kmer_utils.c1
-rw-r--r--kmer_utils.h1
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