aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-10-02 21:38:43 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-10-02 21:38:43 -0400
commitf47ce6202d2bb6425638a9142bbbebd7d44fb64f (patch)
tree612415c474b838247fe187eb1a68a9f9805d19e0
parent45628e09b8f2e496a8766c442626dd6a13465286 (diff)
use an external iterator so that we can skip over anything in range of an errorw
-rw-r--r--Makefile2
-rw-r--r--kmer_frequency_per_sequence.c5
-rw-r--r--kmer_frequency_per_sequence.h1
-rw-r--r--kmer_total_count.c9
-rw-r--r--kmer_total_count.h1
-rw-r--r--kmer_utils.c13
-rw-r--r--kmer_utils.h2
7 files changed, 20 insertions, 13 deletions
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 <math.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
#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 <math.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
#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);