aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-09-09 17:49:37 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2014-09-09 17:49:37 -0400
commitc0838b7286f3da6ba1d0962b78df24b80c4a8d1d (patch)
tree0047614ecfe318e711b5875977992683a47641b4
parentf251dc46c40501704bfebf2d778577b1f1dc3484 (diff)
allow for kmer inference and fix memory leak in get_fasta_files_from_file
-rw-r--r--src/c/multifasta_to_otu.c15
-rw-r--r--src/c/quikr.c12
-rw-r--r--src/c/quikr_functions.c8
3 files changed, 17 insertions, 18 deletions
diff --git a/src/c/multifasta_to_otu.c b/src/c/multifasta_to_otu.c
index d5021fa..3c4850b 100644
--- a/src/c/multifasta_to_otu.c
+++ b/src/c/multifasta_to_otu.c
@@ -63,10 +63,8 @@ char **get_fasta_files_from_file(char *fn) {
files = malloc(sizeof(char **));
while ((read = getline(&line, &len, fh)) != -1) {
- char *file = malloc(sizeof(char) * (strlen(line)));
- if(file == NULL) {
- exit(EXIT_FAILURE);
- }
+ char *file = malloc(sizeof(char) * (strlen(line) + 1));
+ check_malloc(file, NULL);
strncpy(file, line, strlen(line) + 1 );
file[strlen(file)- 1] = '\0';
@@ -94,7 +92,7 @@ char **get_fasta_files_from_file(char *fn) {
fprintf(stderr, "could not realloc keys\n");
exit(EXIT_FAILURE);
}
- files[files_count] = NULL;
+ files[files_count - 1] = NULL;
fclose(fh);
return files;
@@ -311,9 +309,11 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ struct matrix *sensing_matrix = load_sensing_matrix(sensing_matrix_filename, kmer);
+
if(kmer == 0) {
- fprintf(stderr, "Error: zero is not a valid kmer\n");
- exit(EXIT_FAILURE);
+ fprintf(stdout, "Warning: zero is not a valid kmer, inferring kmer from sensing matrix (%d)\n", sensing_matrix->kmer);
+ kmer = sensing_matrix->kmer;
}
// load filenames
@@ -334,7 +334,6 @@ int main(int argc, char **argv) {
// 4 "ACGT" ^ Kmer gives us the size of output rows
width = pow(4, kmer);
- struct matrix *sensing_matrix = load_sensing_matrix(sensing_matrix_filename, kmer);
double *sensing_matrix_ptr = sensing_matrix->matrix;
unsigned long long sequences = sensing_matrix->sequences;
diff --git a/src/c/quikr.c b/src/c/quikr.c
index de1f39a..5ed72b0 100644
--- a/src/c/quikr.c
+++ b/src/c/quikr.c
@@ -131,25 +131,23 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ // load sensing matrix
+ struct matrix *sensing_matrix = load_sensing_matrix(sensing_matrix_filename, kmer);
+
if(kmer == 0) {
- fprintf(stderr, "Error: zero is not a valid kmer\n");
- exit(EXIT_FAILURE);
+ fprintf(stdout, "Warning: zero is not a valid kmer, inferring kmer from sensing matrix\n");
+ kmer = sensing_matrix->kmer;
}
-
// 4 "ACGT" ^ Kmer gives us the size of output rows
width = pow_four(kmer);
- // load sensing matrix
- struct matrix *sensing_matrix = load_sensing_matrix(sensing_matrix_filename, kmer);
-
if(verbose) {
printf("width: %llu\n", width);
printf("sequences: %llu\n", sensing_matrix->sequences);
}
-
// load counts matrix
double *count_matrix = malloc(width * sizeof(double));
check_malloc(count_matrix, NULL);
diff --git a/src/c/quikr_functions.c b/src/c/quikr_functions.c
index 5715024..8156a19 100644
--- a/src/c/quikr_functions.c
+++ b/src/c/quikr_functions.c
@@ -317,9 +317,10 @@ struct matrix *load_sensing_matrix(const char *filename, unsigned int target_kme
}
lineno++;
- if(kmer != target_kmer) {
- fprintf(stderr, "The sensing_matrix was trained with a different kmer than your requested kmer\n");
- exit(EXIT_FAILURE);
+ // if passed kmer in is zero, just use whatever the matrix is trained as.
+ if(target_kmer != 0 && kmer != target_kmer ) {
+ fprintf(stderr, "The sensing_matrix was trained with a different kmer than your requested kmer\n");
+ exit(EXIT_FAILURE);
}
width = pow_four(kmer);
@@ -344,6 +345,7 @@ struct matrix *load_sensing_matrix(const char *filename, unsigned int target_kme
read = gzgetline(&buf, &len, fh);
if(read == 0) {
fprintf(stderr, "Error parsing sensing matrix, could not read header\n");
+ fprintf(stderr, "%s\n", buf);
exit(EXIT_FAILURE);
}