Last active
January 18, 2016 04:35
-
-
Save dnbaker/ebfe8551293ccd8d8c93 to your computer and use it in GitHub Desktop.
Decode kmer from 64-bit integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef KMER2STR_H | |
#define KMER2STR_H | |
#include "stdint.h" | |
#ifndef num2nuc | |
# ifndef NUM2NUC_STR | |
# define NUM2NUC_STR "ACGTN" | |
# endif | |
# define num2nuc(x) NUM2NUC_STR[(uint8_t)x] | |
#endif | |
/* | |
*Fill a buffer with the string for a kmer of a given k. | |
*For performance, since the string length will be constant during | |
*execution, you must null-terminate your string appropriately beforehand | |
*so that you don't have to add it every single time. | |
*/ | |
inline void kmer2str(uint64_t kmer, int k, char *buf) { | |
buf += k; | |
while(k) *--buf = num2nuc((kmer >> (2 * --k)) & 0x3u); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment