From d8578f338104287b4af59cbadb01f0e45843962d Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Wed, 9 Apr 2014 17:12:09 -0400 Subject: MERGE sparse trunk into master --- kmer_counts_per_sequence.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'kmer_counts_per_sequence.c') diff --git a/kmer_counts_per_sequence.c b/kmer_counts_per_sequence.c index 2b2dbef..e9ca812 100644 --- a/kmer_counts_per_sequence.c +++ b/kmer_counts_per_sequence.c @@ -30,7 +30,43 @@ void help() { "dna-utils. Drexel University, Philadelphia USA, 2014;\n" "software available at www.github.com/EESI/dna-utils/\n"); } +static void inc(kmer_map *map, size_t index) { + (*map)[index]++; +} + +static void inc(unsigned long long *counts, size_t index) { + counts[index]++; +} + +template +void count_sequence(const char *seq, const size_t seq_length, const unsigned int kmer, array_type *counts) { + long long position; + long long i; + + // loop through our seq to process each k-mer + for(position = 0; position < (signed)(seq_length - kmer + 1); position++) { + unsigned long long mer = 0; + unsigned long long multiply = 1; + + // for each char in the k-mer check if it is an error char + for(i = position + kmer - 1; i >= position; i--){ + if(seq[i] == 5) { + position = i; + goto next; + } + // multiply this char in the mer by the multiply + // and bitshift the multiply for the next round + mer += seq[i] * multiply; + multiply = multiply << 2; + } + // bump up the mer value in the counts array + inc(counts, mer); + + // skip count if error + next: ; + } +} int main(int argc, char **argv) { @@ -135,8 +171,10 @@ int main(int argc, char **argv) { width = pow_four(kmer); if(specific_mers) { - desired_indicies = malloc((width) * sizeof(size_t)); - check_null_ptr(desired_indicies, NULL); + sparse = false; + desired_indicies = (size_t *) malloc((width) * sizeof(size_t)); + if(desired_indicies == NULL) + exit(EXIT_FAILURE); num_desired_indicies = load_specific_mers_from_file(mer_fn, kmer, width, desired_indicies); if(num_desired_indicies == 0) { fprintf(stderr, "Error: no mers loaded from file\n"); @@ -145,7 +183,7 @@ int main(int argc, char **argv) { } - unsigned long long *counts = malloc((width+ 1) * sizeof(unsigned long long)); + unsigned long long *counts = (unsigned long long *) malloc((width+ 1) * sizeof(unsigned long long)); if(counts == NULL) { fprintf(stderr, "%s\n", strerror(errno)); exit(EXIT_FAILURE); -- cgit v1.2.3