aboutsummaryrefslogtreecommitdiff
path: root/kmer_total_count.c
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-10-10 19:44:15 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-10-10 19:44:15 -0400
commite2291efb098885e6d7a18abed8babb59e0a2fb49 (patch)
treebce3858df100cc2ce360141d7313731bd7e54546 /kmer_total_count.c
parent5ca66675b8cacf42a1dde84a267dc10a4752a370 (diff)
don't use the num_to_index function for more speeeeed
Diffstat (limited to 'kmer_total_count.c')
-rw-r--r--kmer_total_count.c24
1 files changed, 18 insertions, 6 deletions
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]++;
}
}
}