aboutsummaryrefslogtreecommitdiff
path: root/src/c/multifasta_to_otu.c
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 /src/c/multifasta_to_otu.c
parentf251dc46c40501704bfebf2d778577b1f1dc3484 (diff)
allow for kmer inference and fix memory leak in get_fasta_files_from_file
Diffstat (limited to 'src/c/multifasta_to_otu.c')
-rw-r--r--src/c/multifasta_to_otu.c15
1 files changed, 7 insertions, 8 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;