aboutsummaryrefslogtreecommitdiff
path: root/kmer_utils.c
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-11-11 13:30:12 -0500
committerCalvin Morrison <mutantturkey@gmail.com>2013-11-11 13:30:12 -0500
commit7b69badc405e4a3c7572c1428da27be891b306d4 (patch)
tree2a47a113cf79c9efa2feb064cc02aca2c26eaab5 /kmer_utils.c
parentd2db15836b836696dfff747a54d0b442e368b5b4 (diff)
index to kmerfunction
Diffstat (limited to 'kmer_utils.c')
-rw-r--r--kmer_utils.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/kmer_utils.c b/kmer_utils.c
index 0f5f6d6..2a739d6 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -18,6 +18,8 @@ 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};
+const char reverse_alpha[4] = { 'A', 'C', 'G', 'T' };
+
inline unsigned long long pow_four(unsigned long long x) {
return (unsigned long long)1 << (x * 2);
}
@@ -46,6 +48,36 @@ inline unsigned long num_to_index(const char *str, const int kmer, const long er
return out;
}
+// convert an index back into a kmer string
+char *index_to_kmer(unsigned long long index, long kmer) {
+
+ int num_array[64];
+ char *ret = malloc(64);
+ if(ret == NULL)
+ exit(EXIT_FAILURE);
+
+ int i = 0;
+ int j = 0;
+
+ while (index != 0) {
+ num_array[i] = index % 4;
+ index /= 4;
+ i++;
+ }
+
+ ret[i] = '\0';
+ i--;
+
+ for(j = 0; j < (kmer - i -1); j++)
+ ret[j] = 'A';
+
+ for(; i>=0; i--) {
+ ret[i+j] = reverse_alpha[num_array[i]];
+ }
+
+ return ret;
+}
+
// Strip out any character 'c' from char array 's' into a destination dest (you
// need to allocate that) and copy only len characters.
char *strnstrip(const char *s, char *dest, int c, unsigned long long len) {