Skip to content

Instantly share code, notes, and snippets.

@dnbaker
Last active January 18, 2016 04:35
Show Gist options
  • Save dnbaker/ebfe8551293ccd8d8c93 to your computer and use it in GitHub Desktop.
Save dnbaker/ebfe8551293ccd8d8c93 to your computer and use it in GitHub Desktop.
Decode kmer from 64-bit integer
#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