-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.c
100 lines (82 loc) · 3.2 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "fastq_pair.h"
#include "is_gzipped.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
long long get_time_ms()
{
struct timeval te;
gettimeofday(&te, NULL);
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000;
return milliseconds;
}
void help(char *s);
int main(int argc, char* argv[]) {
if (argc == 2 && (strcmp(argv[1], "-V") == 0)) {
fprintf(stdout, "%s version %0.1f\n", argv[0], 0.3);
exit(0);
}
if (argc < 3) {
help(argv[0]);
exit(0);
}
struct options *opt;
opt = malloc(sizeof(struct options));
opt->splitspace = true;
opt->tablesize = 100003;
opt->print_table_counts = false;
opt->verbose = false;
char *left_file = NULL;
char *right_file = NULL;
// access from unistd.h is a method to check whether a file exists.
// we use this to parse the file name and see if it is a valid file.
for (int i=1; i<argc; i++) {
if (strcmp(argv[i], "-t") == 0)
opt->tablesize = atoi(argv[++i]);
else if (strcmp(argv[i], "-p") == 0)
opt->print_table_counts = true;
else if (strcmp(argv[i], "-s") == 0)
opt->verbose = false;
else if (strcmp(argv[i], "-v") == 0)
opt->verbose = true;
else if (access(argv[i], F_OK) != -1 && left_file == NULL)
left_file = argv[i];
else if (access(argv[i], F_OK) != -1 && right_file == NULL)
right_file = argv[i];
else
fprintf(stderr, "\n\nERROR: Not sure what parameter %s is\n", argv[i]);
}
if (left_file == NULL || right_file == NULL) {
fprintf(stderr, "\n\nERROR: We could not find the files you specified.\n");
help(argv[0]);
exit(-1);
}
//if (test_gzip(left_file) || test_gzip(right_file)) {
if (test_gzip(left_file) || test_gzip(right_file)) {
fprintf(stderr, "ERROR: It appears that your files are compressed with gzip.\n");
fprintf(stderr, "At this time we can't handle gzipped files because we use random access reading of the data stream.\n");
fprintf(stderr, "Please either uncompress the files, or check these alternatives: https://edwards.sdsu.edu/research/sorting-and-paring-fastq-files/\n");
exit(-1);
}
long long start_time, end_time, overhead_time;
start_time = get_time_ms();
end_time = get_time_ms();
overhead_time = end_time - start_time;
start_time = get_time_ms();
int success = pair_files(left_file, right_file, opt);
end_time = get_time_ms();
if (opt->verbose)
printf ("Elapsed time = %lld (ms)\n", end_time - start_time - overhead_time);
return success;
}
void help(char *s) {
fprintf(stdout, "\n%s [options] [fastq file 1] [fastq file 2]\n", s);
fprintf(stdout, "\nOPTIONS\n");
fprintf(stdout, "-s do not split sequence IDs on spaces. See issue #14 for more details");
fprintf(stdout, "-t table size (default 100003)\n");
fprintf(stdout, "-p print the number of elements in each bucket in the table\n");
fprintf(stdout, "-v verbose output. This is mainly for debugging\n");
fprintf(stdout, "-V print the current version number and exit\n");
}