aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororbitz <orbitz@gmail.com>2013-12-29 12:36:37 +0100
committerorbitz <orbitz@gmail.com>2013-12-29 12:36:37 +0100
commitc2dfccab8aa22f308dc572b18658036e9db01107 (patch)
tree9f9a89cbfe2f526d461dad629da5fe76aea10361
parentda0825a749c0879a6aff8731a7d6c716e68d89e8 (diff)
Refactor to pull opening the file out of the count function
-rw-r--r--kmer_total_count.c9
-rw-r--r--kmer_utils.c8
2 files changed, 9 insertions, 8 deletions
diff --git a/kmer_total_count.c b/kmer_total_count.c
index f15b69c..5ce7ee1 100644
--- a/kmer_total_count.c
+++ b/kmer_total_count.c
@@ -12,6 +12,7 @@ int main(int argc, char **argv) {
char *filename = NULL;
+ FILE *fh;
unsigned int kmer = 0;
@@ -76,9 +77,15 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ fh = fopen(filename, "r");
+ if(fh == NULL) {
+ fprintf(stderr, "Could not open %s\n", filename);
+ exit(EXIT_FAILURE);
+ }
+
width = pow_four(kmer);
- unsigned long long *counts = get_kmer_counts_from_file(filename, kmer);
+ unsigned long long *counts = get_kmer_counts_from_file(fh, kmer);
// If nonzero is set, only print non zeros
if(nonzero) {
diff --git a/kmer_utils.c b/kmer_utils.c
index e818a27..9e4bdd8 100644
--- a/kmer_utils.c
+++ b/kmer_utils.c
@@ -107,7 +107,7 @@ char *strnstrip(const char *s, char *dest, int c, unsigned long long len) {
return dest;
}
-unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned int kmer) {
+unsigned long long * get_kmer_counts_from_file(FILE *fh, const unsigned int kmer) {
char *line = NULL;
size_t len = 0;
ssize_t read;
@@ -115,12 +115,6 @@ unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned in
long long i = 0;
long long position = 0;
- FILE * const fh = fopen(fn, "r");
- if(fh == NULL) {
- fprintf(stderr, "Error opening %s - %s\n", fn, strerror(errno));
- exit(EXIT_FAILURE);
- }
-
// width is 4^kmer
// there's a sneaky bitshift to avoid pow dependency
const unsigned long width = pow_four(kmer);