// Copyright 2013 Calvin Morrison #include #include #include #include #include #include #include "kmer_utils.h" int main(int argc, char **argv) { char *line = NULL; size_t len = 0; ssize_t read; long i = 0; unsigned int kmer = 0; unsigned long width = 0; unsigned long long *counts; if(argc != 3) { printf("Please supply a filename and a kmer\n"); exit(EXIT_FAILURE); } FILE *fh = fopen(argv[1], "r" ); if(fh == NULL) { fprintf(stderr, "Couldn't open: %s\n", argv[1]); exit(EXIT_FAILURE); } // second argument is the kmer kmer = atoi(argv[2]); // width is 4^kmer width = (int)pow(4, kmer); // malloc our counts matrix counts = malloc((width+ 1) * sizeof(unsigned long long)); if(counts == NULL) exit(EXIT_FAILURE); while ((read = getline(&line, &len, fh)) != -1) { if(line[0] != '>') { convert_kmer_to_num(line, read); for(i = 0; i < read - kmer; i++) { counts[num_to_index(&line[i],kmer, width)]++; } } } for(i = 0; i < width; i++) printf("%llu\n", counts[i]); return EXIT_SUCCESS; }