aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kmer_counts_per_sequence.c4
-rw-r--r--kmer_total_count.c8
-rw-r--r--kmer_utils.c16
-rw-r--r--kmer_utils.h13
4 files changed, 20 insertions, 21 deletions
diff --git a/kmer_counts_per_sequence.c b/kmer_counts_per_sequence.c
index 6557d5d..6ff815d 100644
--- a/kmer_counts_per_sequence.c
+++ b/kmer_counts_per_sequence.c
@@ -46,11 +46,11 @@ int main(int argc, char **argv) {
memset(counts, 0, width * sizeof(unsigned long long));
for(i = 0; i < read - kmer; i++) {
- line[i] = alpha[(int)line[i]];
+ line[i] = kmer_alpha[(int)line[i]];
}
for(i = 0; i < read - kmer; i++) {
- counts[num_to_index(&line[i],kmer, width)]++;
+ counts[kmer_num_to_index(&line[i],kmer, width)]++;
}
for(i = 0; i < width; i++)
diff --git a/kmer_total_count.c b/kmer_total_count.c
index 5dbb50d..2f944d8 100644
--- a/kmer_total_count.c
+++ b/kmer_total_count.c
@@ -80,9 +80,9 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
- width = pow_four(kmer);
+ width = kmer_pow_four(kmer);
- unsigned long long *counts = get_kmer_counts_from_file(fh, kmer);
+ unsigned long long *counts = kmer_counts_from_file(fh, kmer);
// If nonzero is set, only print non zeros
if(nonzero) {
@@ -90,7 +90,7 @@ int main(int argc, char **argv) {
if(label) {
for(i = 0; i < width; i++)
if(counts[i] != 0) {
- char *kmer_str = index_to_kmer(i, kmer);
+ char *kmer_str = kmer_index_to_kmer(i, kmer);
fprintf(stdout, "%s\t%llu\n", kmer_str, counts[i]);
free(kmer_str);
}
@@ -106,7 +106,7 @@ int main(int argc, char **argv) {
if(label) {
for(i = 0; i < width; i++) {
if(counts[i] != 0) {
- char *kmer_str = index_to_kmer(i, kmer);
+ char *kmer_str = kmer_index_to_kmer(i, kmer);
fprintf(stdout, "%s\t%llu\n", kmer_str, counts[i]);
free(kmer_str);
}
diff --git a/kmer_utils.c b/kmer_utils.c
index ce0aa81..51129ee 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -6,7 +6,7 @@
#include "kmer_total_count.h"
-const unsigned char alpha[256] =
+const unsigned char kmer_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, 5, 5, 5, 5,
@@ -26,13 +26,13 @@ const unsigned char alpha[256] =
static const char reverse_alpha[4] = { 'A', 'C', 'G', 'T' };
-unsigned long long pow_four(unsigned long long x) {
+unsigned long long kmer_pow_four(unsigned long long x) {
return (unsigned long long)1 << (x * 2);
}
// convert a string of k-mer size base-4 values into a
// base-10 index
-unsigned long num_to_index(const char *str, const int kmer, const long error_pos) {
+unsigned long kmer_num_to_index(const char *str, const int kmer, const long error_pos) {
int i = 0;
unsigned long out = 0;
unsigned long multiply = 1;
@@ -54,7 +54,7 @@ unsigned long num_to_index(const char *str, const int kmer, const long error_pos
}
// convert an index back into a kmer string
-char *index_to_kmer(unsigned long long index, long kmer) {
+char *kmer_index_to_kmer(unsigned long long index, long kmer) {
int i = 0;
int j = 0;
char *num_array = calloc(kmer, sizeof(char));
@@ -97,7 +97,7 @@ char *index_to_kmer(unsigned long long index, long kmer) {
// 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) {
+static char *strnstrip(const char *s, char *dest, int c, unsigned long long len) {
unsigned long long i = 0;
unsigned long long j = 0;
@@ -113,7 +113,7 @@ char *strnstrip(const char *s, char *dest, int c, unsigned long long len) {
return dest;
}
-unsigned long long *get_kmer_counts_from_file(FILE *fh, const unsigned int kmer) {
+unsigned long long *kmer_counts_from_file(FILE *fh, const unsigned int kmer) {
char *line = NULL;
size_t len = 0;
ssize_t read;
@@ -123,7 +123,7 @@ unsigned long long *get_kmer_counts_from_file(FILE *fh, const unsigned int kmer)
// width is 4^kmer
// there's a sneaky bitshift to avoid pow dependency
- const unsigned long width = pow_four(kmer);
+ const unsigned long width = kmer_pow_four(kmer);
// malloc our return array
unsigned long long * counts = calloc((width+ 1), sizeof(unsigned long long));
@@ -170,7 +170,7 @@ unsigned long long *get_kmer_counts_from_file(FILE *fh, const unsigned int kmer)
// relace A, C, G and T with 0, 1, 2, 3 respectively
// everything else is 5
for(i = 0; i < seq_length; i++) {
- str[i] = alpha[(int)str[i]];
+ str[i] = kmer_alpha[(int)str[i]];
}
// loop through our string to process each k-mer
diff --git a/kmer_utils.h b/kmer_utils.h
index 9f4d34f..5932316 100644
--- a/kmer_utils.h
+++ b/kmer_utils.h
@@ -1,11 +1,10 @@
// Kmer functions
-void convert_kmer_to_num(char *str, unsigned long length);
-unsigned long num_to_index(const char *str, const int kmer, long error_pos);
-char *index_to_kmer(unsigned long long index, long kmer);
-unsigned long long * get_kmer_counts_from_file(FILE *fh, int kmer);
+void kmer_convert_kmer_to_num(char *str, unsigned long length);
+unsigned long kmer_num_to_index(const char *str, const int kmer, long error_pos);
+char *kmer_index_to_kmer(unsigned long long index, long kmer);
+unsigned long long * kmer_counts_from_file(FILE *fh, int kmer);
// Utility functions
-char *strnstrip(const char *s, char *dest, int c, int len);
-unsigned long long pow_four(unsigned long long x);
+unsigned long long kmer_pow_four(unsigned long long x);
-extern const unsigned char alpha[256];
+extern const unsigned char kmer_alpha[256];