-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathargument_parser.hpp
161 lines (149 loc) · 4.87 KB
/
argument_parser.hpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* MALVA - genotyping by Mapping-free ALternate-allele detection of known VAriants
* Copyright (C) 2019 Giulia Bernardini, Luca Denti, Marco Previtali
*
* This file is part of MALVA.
*
* MALVA is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MALVA is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MALVA; see the file LICENSE. If not, see
* <https://www.gnu.org/licenses/>.
**/
#ifndef _MALVAARGUMENT_PARSER_HPP_
#define _MALVAARGUMENT_PARSER_HPP_
#include <sstream>
#include <getopt.h>
using namespace std;
static const char *USAGE_MESSAGE =
"Usage: malva-geno [-k KMER-SIZE] [-r REF-KMER-SIZE] [-c MAX-COV] "
"<reference.fa> <variants.vcf> <kmc_output_prefix>\n"
"\n"
"Top notch description of this tool\n"
"\n"
" -h, --help display this help and exit\n"
" -k, --kmer-size size of the kmers to index (default:35)\n"
" -r, --ref-kmer-size size of the reference kmers to index (default:43)\n"
" -e, --error-rate expected sample error rate (default:0.001)\n"
" -s, --samples file containing the list of (VCF) samples to consider (default:-, i.e. all samples)\n"
" -f, --freq-key a priori frequency key in the INFO column of the input VCF (default:AF)\n"
" -c, --max-coverage maximum coverage for variant alleles (default:200)\n"
" -b, --bf-size bloom filter size in GB (default:4)\n"
" -p, --strip-chr strip \"chr\" from sequence names (default:false)\n"
" -u, --uniform use uniform a priori probabilities (default:false)\n"
" -v, --verbose output COVS and GTS in INFO column (default: false)\n"
" -1, --haploid run MALVA in haploid mode (default: false)\n"
"\n";
namespace opt
{
static uint k = 35;
static uint ref_k = 43;
static float error_rate = 0.001;
static string samples = "-";
static string freq_key = "AF";
static uint max_coverage = 200;
static uint64_t bf_size = ((uint64_t)0b1 << 35);
static bool strip_chr = false;
static bool uniform = false;
static bool verbose = false;
static bool haploid = false;
static string fasta_path;
static string vcf_path;
static string kmc_sample_path;
}
static const char *shortopts = "k:r:e:s:f:c:b:hpuv1";
static const struct option longopts[] = {
{"kmer-size", required_argument, NULL, 'k'},
{"ref-kmer-size", required_argument, NULL, 'r'},
{"error-rate", required_argument, NULL, 'e'},
{"freq-key", required_argument, NULL, 'f'},
{"samples", required_argument, NULL, 's'},
{"max-coverage", required_argument, NULL, 'c'},
{"bf-size", required_argument, NULL, 'b'},
{"strip-chr", required_argument, NULL, 'p'},
{"uniform", required_argument, NULL, 'u'},
{"verbose", no_argument, NULL, 'v'},
{"haplod", no_argument, NULL, '1'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};
void parse_arguments(int argc, char **argv)
{
bool die = false;
for (char c;
(c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;)
{
istringstream arg(optarg != NULL ? optarg : "");
switch (c)
{
case 'p':
opt::strip_chr = true;
break;
case 'u':
opt::uniform = true;
break;
case 'k':
arg >> opt::k;
break;
case 'r':
arg >> opt::ref_k;
break;
case 'e':
arg >> opt::error_rate;
break;
case 's':
arg >> opt::samples;
break;
case 'f':
arg >> opt::freq_key;
break;
case 'c':
arg >> opt::max_coverage;
break;
case 'b':
// Let's consider this as GB
arg >> opt::bf_size;
opt::bf_size = opt::bf_size * ((uint64_t)0b1 << 33);
break;
case 'v':
opt::verbose = true;
break;
case '1':
opt::haploid = true;
break;
case '?':
die = true;
break;
case 'h':
cout << USAGE_MESSAGE;
exit(EXIT_SUCCESS);
}
}
if (argc - optind < 3)
{
cerr << "malva : missing arguments\n";
die = true;
}
else if (argc - optind > 3)
{
cerr << "malva : too many arguments\n";
die = true;
}
if (die)
{
cerr << "\n"
<< USAGE_MESSAGE;
exit(EXIT_FAILURE);
}
opt::fasta_path = argv[optind++];
opt::vcf_path = argv[optind++];
opt::kmc_sample_path = argv[optind++];
}
#endif