-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspose.c
More file actions
82 lines (64 loc) · 1.86 KB
/
Copy pathtranspose.c
File metadata and controls
82 lines (64 loc) · 1.86 KB
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
#include <argp.h>
#include <stdio.h>
#include "geno.h"
static const char usage_documentation[] = "Transpose a genotype between a packed ancestry map format and a transpose packed format or vice versa.";
static struct argp_option options[] = {
{"low-mem", 'm', 0, 0, "Do not allocate memory for the full genotype file. This will substantially reduce memory requirements but will be much slower." },
{ 0 }
};
static char args_doc[] = "input_genotype_file output_genotype_file";
struct arguments
{
char *input_file;
char *output_file;
int low_mem;
};
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = state->input;
switch (key){
case 'm':
arguments->low_mem = 1;
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 2) // too many arguments
argp_usage (state);
else if (state->arg_num == 0)
arguments->input_file = arg;
else if (state->arg_num == 1)
arguments->output_file = arg;
break;
case ARGP_KEY_END:
if(state->arg_num < 2)
argp_usage(state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Our argp parser. */
static struct argp argp = { options, parse_opt, args_doc, usage_documentation };
int main(int argc, char **argv){
struct arguments arguments;
// default
arguments.low_mem = 0;
argp_parse (&argp, argc, argv, 0, 0, &arguments);
genotype_matrix geno;
printf("reading %s\n", arguments.input_file);
genotype_matrix_initialize(&geno);
int result;
if (arguments.low_mem){
result = genotype_matrix_read_file(&geno, arguments.input_file, 0, NULL, NULL);
} else{
result = genotype_matrix_read_file_full(&geno, arguments.input_file, 0, NULL, NULL);
}
if (result < 0){
printf("Error %d", result);
return result;
}
genotype_matrix_write_packed_file(&geno, arguments.output_file, !geno.transpose);
genotype_matrix_destructor(&geno);
return 0;
}