diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-10-10 19:44:15 -0400 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-10-10 19:44:15 -0400 |
commit | e2291efb098885e6d7a18abed8babb59e0a2fb49 (patch) | |
tree | bce3858df100cc2ce360141d7313731bd7e54546 | |
parent | 5ca66675b8cacf42a1dde84a267dc10a4752a370 (diff) |
don't use the num_to_index function for more speeeeed
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | kmer_frequency_per_sequence.c | 1 | ||||
-rw-r--r-- | kmer_total_count.c | 24 |
3 files changed, 19 insertions, 8 deletions
@@ -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 <errno.h> -#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> 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 <errno.h> -#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #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]++; } } } |