-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.hpp
339 lines (285 loc) · 14.2 KB
/
options.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#pragma once
#include <filesystem>
#include <string>
#include <seqan/arg_parse.h>
enum class genotyping_model
{
multi,
ad,
va,
presence,
va_old,
joint
};
/* Option handling */
struct LRCOptions
{
std::string bam;
seqan::CharString bam2;
std::string faFile = "genome.fa";
std::string vcfInFile;
std::string vcfOutFile;
seqan::CharString genotypingModel = "multi";
bool dynamicWSize = false;
size_t wSize = 500; // Window Size,
size_t maxBARcount = 200; // maximum number of reads to use for a variant
bool verbose = false;
bool genotypeRightBreakpoint = false;
double logScaleFactor = 2.0;
size_t bandedAlignmentPercent = 40;
int match = 1;
int mismatch = -1;
int gapOpen = -1;
int gapExtend = -1;
bool mask = false;
bool cropRead = true;
bool outputRefAlt = false; // For debug purposes
size_t maxSoftClipped = 500; // Read cannot be softclipped at invariant end
double maxAlignBits = 10.0; // needs to be added as option
size_t overlapBits = 10; // needs to be added as option
size_t varWindow = 100; // How far
size_t maxReadLenForCropping = 200000; // Should not be needed
size_t minMapQ = 30; // minimum std::mapQ for a read to be used
size_t minDelIns = 6; // minum number of consecutive bp to be deleted or inserted to count it
size_t minPresent = 30; // minum number of del/ins for a variant to be considered present
// Fraction of deletion/insertion length that can be deleted/inserted but still called ref
double refThreshFraction = 1.0 / 10.0;
// Fraction of deletion/insertion length that needs to be deleted/inserted to call alt
double altThreshFraction = 1.0 / 2.0;
// Fraction of deletion/insertion length can be at most be observed to be deleted/inserted to call alt
double altThreshFractionMax = 100.0;
genotyping_model gtModel = genotyping_model::multi;
size_t nThreads = std::thread::hardware_concurrency();
bool cacheDataInTmp = false; // whether to copy BAM and BAI to /tmp at start
std::filesystem::path cacheDir; // where to store cache
};
inline int parseLRCArguments(int argc, char const ** argv, LRCOptions & O)
{
seqan::ArgumentParser parser("LRcaller");
setVersion(parser, LRCALLER_VERSION);
setDate(parser, __DATE__);
addUsageLine(parser, "[\\fIOPTIONS\\fP] \"\\fIBAMFILE\\fP\" \"\\fIVCF_FILE_IN\\fP\" \"\\fIVCF_FILE_OUT\\fP\" ");
addDescription(parser, "Genotypes variants using long reads\n in bam file/file of bam files ");
addArgument(parser, seqan::ArgParseArgument(seqan::ArgParseArgument::STRING, "BAMFILE bam file/file of bam files"));
addArgument(parser, seqan::ArgParseArgument(seqan::ArgParseArgument::STRING, "VCF_FILE_IN - input vcf file"));
addArgument(parser,
seqan::ArgParseArgument(seqan::ArgParseArgument::STRING, "VCF_FILE_OUT - output genotyped vcf file"));
addOption(parser, seqan::ArgParseOption("fa", "fa", "Fastafile", seqan::ArgParseArgument::STRING, "FA"));
addOption(
parser,
seqan::ArgParseOption(
"b2",
"bam2",
"Second bam file/file of bam files, use if you want to use multiple basecallings/mappings for the same reads",
seqan::ArgParseArgument::STRING,
"b2"));
hideOption(parser, "bam2");
addOption(parser,
seqan::ArgParseOption("gtm",
"genotyper",
"Genotyper used joint/ad/va/multi (default joint).",
seqan::ArgParseArgument::STRING,
"GENOTYPER"));
addOption(parser,
seqan::ArgParseOption("faA",
"faA",
"Fasta file alt, used when VCF file refers to an alternate fasta file",
seqan::ArgParseArgument::STRING,
"FAA"));
addOption(parser, seqan::ArgParseOption("v", "verbose", "Verbose output"));
addOption(parser,
seqan::ArgParseOption("rb",
"right_breakpoint",
"Genotype right breakpoint, left breakpoint genotyped by default"));
addOption(parser, seqan::ArgParseOption("ora", "get_ref_alt", "Output ref and alt allele, for debugging purposes"));
addOption(
parser,
seqan::ArgParseOption("A", "match", "Match score for alignment", seqan::ArgParseArgument::INTEGER, "INT"));
addOption(
parser,
seqan::ArgParseOption("B", "mismatch", "Error penalty for alignment.", seqan::ArgParseArgument::INTEGER, "INT"));
addOption(
parser,
seqan::ArgParseOption("O", "gap_open", "Gap open for alignment", seqan::ArgParseArgument::INTEGER, "INT"));
addOption(
parser,
seqan::ArgParseOption("E", "gap_extend", "Gap extend for alignment", seqan::ArgParseArgument::INTEGER, "INT"));
addOption(parser,
seqan::ArgParseOption("w", "window_size", "Window size", seqan::ArgParseArgument::INTEGER, "INT"));
addOption(parser, seqan::ArgParseOption("", "dyn-w-size", "Dynamically adjust window size to allele length."));
addOption(
parser,
seqan::ArgParseOption("", "cache-data-in-tmp", "Copy reads and index to (local) tmp directory before run."));
addOption(
parser,
seqan::ArgParseOption("", "mask", "Reduce stretches of the same base to a single base before alignment."));
seqan::hideOption(parser, "mask"); // THIS IS CURRENTLY NOT EXPOSED TO THE USER
setDefaultValue(parser, "A", O.match);
setDefaultValue(parser, "B", O.mismatch);
setDefaultValue(parser, "O", O.gapOpen);
setDefaultValue(parser, "E", O.gapExtend);
hideOption(parser, "A");
hideOption(parser, "B");
hideOption(parser, "O");
hideOption(parser, "E");
setDefaultValue(parser, "w", O.wSize);
addOption(
parser,
seqan::ArgParseOption("ab", "align_bits", "Max bits for alignment", seqan::ArgParseArgument::DOUBLE, "DOUBLE"));
setDefaultValue(parser, "ab", O.maxAlignBits);
addOption(parser,
seqan::ArgParseOption("ob",
"overlap_bits",
"Score for overlap (log_2)",
seqan::ArgParseArgument::INTEGER,
"INT"));
setDefaultValue(parser, "ob", O.overlapBits);
addOption(
parser,
seqan::ArgParseOption("nt", "number_of_threads", "Number of threads", seqan::ArgParseArgument::INTEGER, "INT"));
setDefaultValue(parser, "nt", O.nThreads);
addOption(parser,
seqan::ArgParseOption("vw",
"var_window",
"Var window size, look for del/ins inside this window",
seqan::ArgParseArgument::INTEGER,
"INT"));
setDefaultValue(parser, "vw", O.varWindow);
addOption(
parser,
seqan::ArgParseOption("mapQ", "read_mapq", "Minimum read std::mapQ", seqan::ArgParseArgument::INTEGER, "INT"));
setDefaultValue(parser, "mapQ", O.minMapQ);
addOption(parser,
seqan::ArgParseOption("di",
"min_del_ins",
"Minimum del/ins in cigar to consider",
seqan::ArgParseArgument::INTEGER,
"INT"));
setDefaultValue(parser, "di", O.minDelIns);
addOption(parser,
seqan::ArgParseOption("mp",
"min_present",
"Minimum del/ins var a variant to be considered present",
seqan::ArgParseArgument::INTEGER,
"INT"));
setDefaultValue(parser, "mp", O.minPresent);
addOption(parser,
seqan::ArgParseOption("",
"max-alignments",
"Maximum alignments per variant to consider",
seqan::ArgParseArgument::INTEGER,
"INT"));
setDefaultValue(parser, "max-alignments", O.maxBARcount);
addOption(parser,
seqan::ArgParseOption("rt",
"ref_thresh_fraction",
"Threshold for fraction of del/ins bp to be considered ref",
seqan::ArgParseArgument::DOUBLE,
"DOUBLE"));
setDefaultValue(parser, "rt", O.refThreshFraction);
addOption(parser,
seqan::ArgParseOption("at",
"alt_thresh_fraction",
"Threshold for fraction of del/ins bp to be considered alt",
seqan::ArgParseArgument::DOUBLE,
"DOUBLE"));
setDefaultValue(parser, "at", O.altThreshFraction);
addOption(parser,
seqan::ArgParseOption("am",
"alt_thresh_fraction_max",
"Max threshold for fraction of del/ins bp to be considered alt",
seqan::ArgParseArgument::DOUBLE,
"DOUBLE"));
setDefaultValue(parser, "am", O.altThreshFractionMax);
addOption(parser,
seqan::ArgParseOption("lsf",
"logScaleFactor",
"Log scale factor for comparing alignment scores",
seqan::ArgParseArgument::DOUBLE,
"DOUBLE"));
addOption(parser,
seqan::ArgParseOption("",
"band",
"Percentage of window size to use as band in alignment (100 == no band).",
seqan::ArgParseArgument::INTEGER,
"INTEGER"));
setDefaultValue(parser, "band", O.bandedAlignmentPercent);
setDefaultValue(parser, "fa", O.faFile);
setDefaultValue(parser, "b2", O.bam2);
setValidValues(parser, "genotyper", "joint ad va multi");
setDefaultValue(parser, "genotyper", "joint");
setDefaultValue(parser, "logScaleFactor", O.logScaleFactor);
seqan::ArgumentParser::ParseResult res = parse(parser, argc, argv);
// Only extract options if the program will continue after parseCommandLine()
if (res != seqan::ArgumentParser::PARSE_OK)
return res;
getArgumentValue(O.bam, parser, 0);
getArgumentValue(O.vcfInFile, parser, 1);
getArgumentValue(O.vcfOutFile, parser, 2);
if (isSet(parser, "align_bits"))
getOptionValue(O.maxAlignBits, parser, "align_bits");
if (isSet(parser, "overlap_bits"))
getOptionValue(O.overlapBits, parser, "overlap_bits");
if (isSet(parser, "fa"))
getOptionValue(O.faFile, parser, "fa");
if (isSet(parser, "number_of_threads"))
getOptionValue(O.nThreads, parser, "number_of_threads");
if (isSet(parser, "var_window"))
getOptionValue(O.varWindow, parser, "var_window");
if (isSet(parser, "read_mapq"))
getOptionValue(O.minMapQ, parser, "read_mapq");
if (isSet(parser, "min_del_ins"))
getOptionValue(O.minDelIns, parser, "min_del_ins");
if (isSet(parser, "min_present"))
getOptionValue(O.minPresent, parser, "min_present");
if (isSet(parser, "max-alignments"))
getOptionValue(O.maxBARcount, parser, "max-alignments");
if (isSet(parser, "ref_thresh_fraction"))
getOptionValue(O.refThreshFraction, parser, "ref_thresh_fraction");
if (isSet(parser, "alt_thresh_fraction"))
getOptionValue(O.altThreshFraction, parser, "alt_thresh_fraction");
if (isSet(parser, "alt_thresh_fraction_max"))
getOptionValue(O.altThreshFractionMax, parser, "alt_thresh_fraction_max");
if (isSet(parser, "match"))
getOptionValue(O.match, parser, "match");
if (isSet(parser, "mismatch"))
getOptionValue(O.mismatch, parser, "mismatch");
if (isSet(parser, "gap_open"))
getOptionValue(O.gapOpen, parser, "gap_open");
if (isSet(parser, "gap_extend"))
getOptionValue(O.gapExtend, parser, "gap_extend");
if (isSet(parser, "mismatch") || isSet(parser, "match") || isSet(parser, "gap_open") || isSet(parser, "gap_extend"))
std::cerr << "Setting customs scores is deprecated and will be removed in the future.\n";
if (isSet(parser, "window_size"))
getOptionValue(O.wSize, parser, "window_size");
if (isSet(parser, "bam2"))
throw std::runtime_error{"Setting -bam2 is no longer supported; instead create a joined filelist."};
if (isSet(parser, "band"))
getOptionValue(O.bandedAlignmentPercent, parser, "band");
seqan::CharString gtModelName;
if (isSet(parser, "genotyper"))
getOptionValue(gtModelName, parser, "genotyper");
if (gtModelName == "multi")
O.gtModel = genotyping_model::multi;
else if (gtModelName == "ad")
O.gtModel = genotyping_model::ad;
else if (gtModelName == "va")
O.gtModel = genotyping_model::va;
else if (gtModelName == "va2")
O.gtModel = genotyping_model::va_old;
else if (gtModelName == "p")
O.gtModel = genotyping_model::presence;
else if (gtModelName == "joint")
O.gtModel = genotyping_model::joint;
if (isSet(parser, "logScaleFactor"))
getOptionValue(O.logScaleFactor, parser, "logScaleFactor");
// O.cropRead = isSet(parser, "cropread");
O.verbose = isSet(parser, "verbose");
O.genotypeRightBreakpoint = isSet(parser, "right_breakpoint");
O.outputRefAlt = isSet(parser, "get_ref_alt");
O.cacheDataInTmp = isSet(parser, "cache-data-in-tmp");
O.dynamicWSize = isSet(parser, "dyn-w-size");
O.mask = isSet(parser, "mask");
// get options
return res;
}