File: main.c

package info (click to toggle)
fastq-pair 1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 804 kB
  • sloc: ansic: 289; sh: 38; makefile: 5
file content (80 lines) | stat: -rw-r--r-- 2,294 bytes parent folder | download | duplicates (2)
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
#include "fastq_pair.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 < 3) {
        help(argv[0]);
        exit(0);
    }

    struct options *opt;
    opt = malloc(sizeof(struct options));

    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], "-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);
    }

    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-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");

}