From f47ce6202d2bb6425638a9142bbbebd7d44fb64f Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Wed, 2 Oct 2013 21:38:43 -0400 Subject: use an external iterator so that we can skip over anything in range of an errorw --- Makefile | 2 +- kmer_frequency_per_sequence.c | 5 ++--- kmer_frequency_per_sequence.h | 1 + kmer_total_count.c | 9 ++++----- kmer_total_count.h | 1 + kmer_utils.c | 13 ++++++++++--- kmer_utils.h | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 kmer_frequency_per_sequence.h create mode 100644 kmer_total_count.h diff --git a/Makefile b/Makefile index a009094..55b4805 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFLAGS = -O3 -s -mtune=native -Wall -lm -DVERSION=$(VERSION) -Wextra all: libkmer.so kmer_total_count kmer_frequency_per_sequence libkmer.so: - $(CC) kmer_utils.c -o libkmer.so $(CFLAGS) -shared -FPIC + $(CC) kmer_utils.c -o libkmer.so $(CFLAGS) -shared -FPIC -DSHARED=0 kmer_total_count: $(CC) kmer_total_count.c kmer_utils.c -o kmer_total_count $(CFLAGS) kmer_frequency_per_sequence: diff --git a/kmer_frequency_per_sequence.c b/kmer_frequency_per_sequence.c index ae15bd2..9cda533 100644 --- a/kmer_frequency_per_sequence.c +++ b/kmer_frequency_per_sequence.c @@ -1,13 +1,12 @@ // Copyright 2013 Calvin Morrison #include -#include #include #include -#include -#include #include "kmer_utils.h" +long position = 0; + int main(int argc, char **argv) { char *line = NULL; diff --git a/kmer_frequency_per_sequence.h b/kmer_frequency_per_sequence.h new file mode 100644 index 0000000..e782906 --- /dev/null +++ b/kmer_frequency_per_sequence.h @@ -0,0 +1 @@ +extern long position; diff --git a/kmer_total_count.c b/kmer_total_count.c index 3a418ed..e953d88 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -1,13 +1,12 @@ // Copyright 2013 Calvin Morrison #include -#include #include #include -#include -#include #include "kmer_utils.h" +long position = 0; + int main(int argc, char **argv) { char *line = NULL; @@ -43,8 +42,8 @@ int main(int argc, char **argv) { if(line[0] != '>' && read > kmer) { convert_kmer_to_num(line, read); - for(i = 0; i < (read - kmer); i++) { - counts[num_to_index(&line[i],kmer, width)]++; + for(position = 0; position < (read - kmer); position++) { + counts[num_to_index(&line[position],kmer, width)]++; } } } diff --git a/kmer_total_count.h b/kmer_total_count.h new file mode 100644 index 0000000..e782906 --- /dev/null +++ b/kmer_total_count.h @@ -0,0 +1 @@ +extern long position; diff --git a/kmer_utils.c b/kmer_utils.c index f63caef..f4f8d2f 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -1,6 +1,8 @@ +#include "kmer_total_count.h" + // convert a string of k-mer size base-4 values into a // base-10 index -long num_to_index(const char *str, const int kmer, const long error_pos) { +unsigned long num_to_index(const char *str, const int kmer, const long error_pos) { int i = 0; unsigned long out = 0; @@ -8,8 +10,13 @@ long num_to_index(const char *str, const int kmer, const long error_pos) { for(i = kmer - 1; i >= 0; i--){ - if(str[i] >> 2) - return error_pos; + if(str[i] >> 2) { + #ifndef SHARED + position += i; + #endif + return error_pos; + } + out += str[i] * multiply; multiply = multiply << 2; diff --git a/kmer_utils.h b/kmer_utils.h index b7bfb1a..f1a84b6 100644 --- a/kmer_utils.h +++ b/kmer_utils.h @@ -1,2 +1,2 @@ void convert_kmer_to_num(char *str, const unsigned long length); -long num_to_index(const char *str, const int kmer, const long error_pos); +unsigned long num_to_index(const char *str, const int kmer, const long error_pos); -- cgit v1.2.3