aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-09-12 16:56:58 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-09-12 16:56:58 -0400
commitdc659709ec94c9d414df8b04f62322f74e1e4a0d (patch)
treea6e25fe80bd246b1e25cb00b7425434448ca3e43
parentd74c19c8fceac333f9420a898b85ad0b1a8a85ff (diff)
don't use strtol
-rw-r--r--kmer_utils.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/kmer_utils.c b/kmer_utils.c
index 7647965..e737346 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -16,34 +16,35 @@
// long kmer - how long of a index value you want to return
// long error_pos - what index to return for a non ACGT character
//
-inline long convert_kmer_to_index(char *str, unsigned long kmer, long error_pos) {
+inline long convert_kmer_to_index(const char *str, long kmer, long error_pos) {
- char **ptr = NULL;
- char vals[kmer];
- unsigned long i = 0;
+ long i = 0;
+ long out = 0;
+ long multiply = 1;
- for(i = 0; i < kmer; i++) {
+ for(i = kmer - 1; i >= 0; i--){
switch(str[i]) {
case 'a':
case 'A':
- vals[i] = '0';
break;
case 'c':
case 'C':
- vals[i] = '1';
+ out += 1 * multiply;
break;
case 'g':
case 'G':
- vals[i] = '2';
+ out += 2 * multiply;
break;
case 't':
case 'T':
- vals[i] = '3';
+ out += 3 * multiply;
break;
default:
return error_pos;
}
+
+ multiply = multiply << 2;
}
- return strtol(vals, ptr, 4);
+ return out;
}