From e2291efb098885e6d7a18abed8babb59e0a2fb49 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 10 Oct 2013 19:44:15 -0400 Subject: don't use the num_to_index function for more speeeeed --- Makefile | 2 +- kmer_frequency_per_sequence.c | 1 - kmer_total_count.c | 24 ++++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index adabfb2..92719d7 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: libkmer.so kmer_total_count kmer_frequency_per_sequence libkmer.so: $(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) + $(CC) kmer_total_count.c -o kmer_total_count $(CFLAGS) kmer_frequency_per_sequence: $(CC) kmer_frequency_per_sequence.c kmer_utils.c -o kmer_frequency_per_sequence $(CFLAGS) diff --git a/kmer_frequency_per_sequence.c b/kmer_frequency_per_sequence.c index 62b98cb..f2aa112 100644 --- a/kmer_frequency_per_sequence.c +++ b/kmer_frequency_per_sequence.c @@ -1,6 +1,5 @@ // Copyright 2013 Calvin Morrison #include -#include #include #include #include diff --git a/kmer_total_count.c b/kmer_total_count.c index 345bceb..795b5dc 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -1,14 +1,10 @@ // Copyright 2013 Calvin Morrison #include -#include #include #include #include #include "kmer_utils.h" - -unsigned long position = 0; - const unsigned char alpha[256] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, @@ -27,6 +23,7 @@ int main(int argc, char **argv) { size_t len = 0; ssize_t read; long i = 0; + long posistion = 0; if(argc != 3) { printf("Please supply a filename and a kmer\n"); @@ -58,8 +55,23 @@ int main(int argc, char **argv) { line[i] = alpha[line[i]]; } - for(position = 0; position < (read - kmer); position++) { - counts[num_to_index(&line[position],kmer, width)]++; + for(posistion = 0; posistion < (read - kmer); posistion++) { + unsigned long out = 0; + unsigned long multiply = 1; + + + for(i = posistion + kmer - 1; i >= posistion; i--){ + if(line[i] >> 2) { + out = width; + posistion = i; + goto next; + } + + out += line[i] * multiply; + multiply = multiply << 2; + } + next: + counts[out]++; } } } -- cgit v1.2.3