From 67fd78612f3d7be776e6a49c424f299bb839abae Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 6 Feb 2014 14:32:14 -0500 Subject: combine strnstrip with conversion, so no need to convert then strip. --- kmer_utils.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'kmer_utils.c') diff --git a/kmer_utils.c b/kmer_utils.c index 713ef90..d7ab808 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -191,24 +191,28 @@ unsigned long long * get_kmer_counts_from_file(FILE *fh, const unsigned int kmer seq = seq + 1; // strip out all other newlines to handle multiline sequences - strnstrip(seq, '\n', strlen(seq)); - seq_length = strlen(seq); // relace A, C, G and T with 0, 1, 2, 3 respectively // everything else is 5 - for(k = 0; k < seq_length; k++) - seq[k] = alpha[(int)seq[k]]; - + seq_length = strlen(seq); + + size_t j = 0; + for(k = 0; k < seq_length; k++) { + char c = alpha[(int)seq[k]]; + if(c != 5) { + seq[j] = c; + j++; + } + } + seq[j] = '\0'; + + seq_length = j; for(i = 0; i < (signed long long)(seq_length - kmer + 1); i++) { char *seq_h = &seq[i]; - unsigned int j = 0; - for(j = 0; j < kmer; j++) - if(seq_h[j] == 5) - continue; - - counts[(*mer_ptr)(seq_h)]++; - } + unsigned long long mer = (*mer_ptr)(seq_h); + counts[mer]++; + } } free(line); -- cgit v1.2.3