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 --- kmer_total_count.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'kmer_total_count.c') 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.1