Skip to content

Commit f794342

Browse files
committed
Add --regions/--targets-overlap pos|record|variant mnemonic options
Introduce parse_overlap_option() for parsing the argument to these options, and accept "pos"/"record"/"variant" as more mnemonic equivalents of the existing 0/1/2. Document these in the Common Options section, and mention the difference between record/1 and variant/2.
1 parent 9a29657 commit f794342

25 files changed

+97
-167
lines changed

bcftools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const char *hts_bcf_wmode2(int file_type, const char *fname);
5555
void set_wmode(char dst[8], int file_type, const char *fname, int compression_level); // clevel: 0-9 with or zb type, -1 unset
5656
char *init_tmp_prefix(const char *prefix);
5757
int read_AF(bcf_sr_regions_t *tgt, bcf1_t *line, double *alt_freq);
58+
int parse_overlap_option(const char *arg);
5859

5960
void *smalloc(size_t size); // safe malloc
6061

csq.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,16 +4340,12 @@ int main_csq(int argc, char *argv[])
43404340
case 't': targets_list = optarg; break;
43414341
case 'T': targets_list = optarg; targets_is_file = 1; break;
43424342
case 4 :
4343-
if ( !strcasecmp(optarg,"0") ) regions_overlap = 0;
4344-
else if ( !strcasecmp(optarg,"1") ) regions_overlap = 1;
4345-
else if ( !strcasecmp(optarg,"2") ) regions_overlap = 2;
4346-
else error("Could not parse: --regions-overlap %s\n",optarg);
4343+
regions_overlap = parse_overlap_option(optarg);
4344+
if ( regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
43474345
break;
43484346
case 5 :
4349-
if ( !strcasecmp(optarg,"0") ) targets_overlap = 0;
4350-
else if ( !strcasecmp(optarg,"1") ) targets_overlap = 1;
4351-
else if ( !strcasecmp(optarg,"2") ) targets_overlap = 2;
4352-
else error("Could not parse: --targets-overlap %s\n",optarg);
4347+
targets_overlap = parse_overlap_option(optarg);
4348+
if ( targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
43534349
break;
43544350
case 'h':
43554351
case '?': error("%s",usage());

doc/bcftools.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ specific commands to see if they apply.
210210
This option requires indexed VCF/BCF files. Note that *-R* cannot be used
211211
in combination with *-r*.
212212

213-
*--regions-overlap* '0'|'1'|'2'::
213+
*--regions-overlap* 'pos'|'record'|'variant'|'0'|'1'|'2'::
214214
This option controls how overlapping records are determined:
215-
set to *0* if the VCF record has to have POS inside a region
215+
set to *pos* or *0* if the VCF record has to have POS inside a region
216216
(this corresponds to the default behavior of *-t/-T*);
217-
set to *1* if also overlapping records with POS outside a region
218-
should be included (this is the default behavior of *-r/-R*); or set
219-
to *2* to include only true overlapping variation (compare
217+
set to *record* or *1* if also overlapping records with POS outside a region
218+
should be included (this is the default behavior of *-r/-R*, and includes indels
219+
with POS at the end of a region, which are technically outside the region); or set
220+
to *variant* or *2* to include only true overlapping variation (compare
220221
the full VCF representation "`TA>T-`" vs the true sequence variation "`A>-`").
221222

222223
*-s, --samples* \[^]'LIST'::
@@ -274,7 +275,8 @@ The program ignores the first column and the last indicates sex (1=male, 2=femal
274275
indicates that sequences X, Y and MT should be skipped.
275276
Yet another difference between the *-t/-T* and *-r/-R* is that *-r/-R* checks for
276277
proper overlaps and considers both POS and the end position of an indel, while *-t/-T*
277-
considers the POS coordinate only. Note that *-t* cannot be used in combination with *-T*.
278+
considers the POS coordinate only (by default; see also *--regions-overlap* and *--targets-overlap*).
279+
Note that *-t* cannot be used in combination with *-T*.
278280

279281
*-T, --targets-file* \[^]'FILE'::
280282
Same *-t, --targets*, but reads regions from a file. Note that *-T*
@@ -289,7 +291,7 @@ Such a file can be easily created from a VCF using:
289291
bcftools query -f'%CHROM\t%POS\t%REF,%ALT\n' file.vcf | bgzip -c > als.tsv.gz && tabix -s1 -b2 -e2 als.tsv.gz
290292
----
291293

292-
*--targets-overlap* '0'|'1'|'2'::
294+
*--targets-overlap* 'pos'|'record'|'variant'|'0'|'1'|'2'::
293295
Same as *--regions-overlap* but for *-t/-T*.
294296

295297
*--threads* 'INT'::

plugins/contrast.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,16 +515,12 @@ int run(int argc, char **argv)
515515
}
516516
break;
517517
case 3 :
518-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
519-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
520-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
521-
else error("Could not parse: --regions-overlap %s\n",optarg);
518+
args->regions_overlap = parse_overlap_option(optarg);
519+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
522520
break;
523521
case 4 :
524-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
525-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
526-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
527-
else error("Could not parse: --targets-overlap %s\n",optarg);
522+
args->targets_overlap = parse_overlap_option(optarg);
523+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
528524
break;
529525
case 'h':
530526
case '?':

plugins/scatter.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,14 @@ int run(int argc, char **argv)
373373
case 'r': args->region = optarg; break;
374374
case 'R': args->region = optarg; args->region_is_file = 1; break;
375375
case 3 :
376-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
377-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
378-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
379-
else error("Could not parse: --regions-overlap %s\n",optarg);
376+
args->regions_overlap = parse_overlap_option(optarg);
377+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
380378
break;
381379
case 't': args->target = optarg; break;
382380
case 'T': args->target = optarg; args->target_is_file = 1; break;
383381
case 4 :
384-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
385-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
386-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
387-
else error("Could not parse: --targets-overlap %s\n",optarg);
382+
args->targets_overlap = parse_overlap_option(optarg);
383+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
388384
break;
389385
case 'n':
390386
args->nsites = strtod(optarg, &tmp);

plugins/split-vep.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,16 +1120,12 @@ int run(int argc, char **argv)
11201120
}
11211121
break;
11221122
case 3 :
1123-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
1124-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
1125-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
1126-
else error("Could not parse: --regions-overlap %s\n",optarg);
1123+
args->regions_overlap = parse_overlap_option(optarg);
1124+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
11271125
break;
11281126
case 4 :
1129-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
1130-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
1131-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
1132-
else error("Could not parse: --targets-overlap %s\n",optarg);
1127+
args->targets_overlap = parse_overlap_option(optarg);
1128+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
11331129
break;
11341130
case 'h':
11351131
case '?':

plugins/split.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,16 +683,12 @@ int run(int argc, char **argv)
683683
}
684684
break;
685685
case 2 :
686-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
687-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
688-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
689-
else error("Could not parse: --regions-overlap %s\n",optarg);
686+
args->regions_overlap = parse_overlap_option(optarg);
687+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
690688
break;
691689
case 3 :
692-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
693-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
694-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
695-
else error("Could not parse: --targets-overlap %s\n",optarg);
690+
args->targets_overlap = parse_overlap_option(optarg);
691+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
696692
break;
697693
case 'h':
698694
case '?':

plugins/trio-dnm2.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,16 +1593,12 @@ int run(int argc, char **argv)
15931593
case 12 : args->record_cmd_line = 0; break;
15941594
case 13 : args->with_pad = 1; break;
15951595
case 14 :
1596-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
1597-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
1598-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
1599-
else error("Could not parse: --regions-overlap %s\n",optarg);
1596+
args->regions_overlap = parse_overlap_option(optarg);
1597+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
16001598
break;
16011599
case 15 :
1602-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
1603-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
1604-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
1605-
else error("Could not parse: --targets-overlap %s\n",optarg);
1600+
args->targets_overlap = parse_overlap_option(optarg);
1601+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
16061602
break;
16071603
case 'X': args->chrX_list_str = optarg; break;
16081604
case 'u': set_option(args,optarg); break;

polysomy.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,16 +693,12 @@ int main_polysomy(int argc, char *argv[])
693693
case 1 : args->ra_rr_scaling = 0; break;
694694
case 2 : args->force_cn = atoi(optarg); break;
695695
case 3 :
696-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
697-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
698-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
699-
else error("Could not parse: --regions-overlap %s\n",optarg);
696+
args->regions_overlap = parse_overlap_option(optarg);
697+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
700698
break;
701699
case 4 :
702-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
703-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
704-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
705-
else error("Could not parse: --targets-overlap %s\n",optarg);
700+
args->targets_overlap = parse_overlap_option(optarg);
701+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
706702
break;
707703
case 'n': args->nbins = atoi(optarg); break;
708704
case 'S': args->smooth = atoi(optarg); break;

vcfannotate.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,10 +3397,8 @@ int main_vcfannotate(int argc, char *argv[])
33973397
else error("The --pair-logic string \"%s\" not recognised.\n", optarg);
33983398
break;
33993399
case 3 :
3400-
if ( !strcasecmp(optarg,"0") ) regions_overlap = 0;
3401-
else if ( !strcasecmp(optarg,"1") ) regions_overlap = 1;
3402-
else if ( !strcasecmp(optarg,"2") ) regions_overlap = 2;
3403-
else error("Could not parse: --regions-overlap %s\n",optarg);
3400+
regions_overlap = parse_overlap_option(optarg);
3401+
if ( regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
34043402
break;
34053403
case 9 : args->n_threads = strtol(optarg, 0, 0); break;
34063404
case 8 : args->record_cmd_line = 0; break;

vcfcall.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,8 @@ int main_vcfcall(int argc, char *argv[])
10711071
case 9 : args.n_threads = strtol(optarg, 0, 0); break;
10721072
case 8 : args.record_cmd_line = 0; break;
10731073
case 4 :
1074-
if ( !strcasecmp(optarg,"0") ) args.regions_overlap = 0;
1075-
else if ( !strcasecmp(optarg,"1") ) args.regions_overlap = 1;
1076-
else if ( !strcasecmp(optarg,"2") ) args.regions_overlap = 2;
1077-
else error("Could not parse: --regions-overlap %s\n",optarg);
1074+
args.regions_overlap = parse_overlap_option(optarg);
1075+
if ( args.regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
10781076
break;
10791077
default: usage(&args);
10801078
}

vcfcnv.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,16 +1379,12 @@ int main_vcfcnv(int argc, char *argv[])
13791379
case 'r': args->regions_list = optarg; break;
13801380
case 'R': args->regions_list = optarg; regions_is_file = 1; break;
13811381
case 3 :
1382-
if ( !strcasecmp(optarg,"0") ) regions_overlap = 0;
1383-
else if ( !strcasecmp(optarg,"1") ) regions_overlap = 1;
1384-
else if ( !strcasecmp(optarg,"2") ) regions_overlap = 2;
1385-
else error("Could not parse: --regions-overlap %s\n",optarg);
1382+
regions_overlap = parse_overlap_option(optarg);
1383+
if ( regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
13861384
break;
13871385
case 4 :
1388-
if ( !strcasecmp(optarg,"0") ) targets_overlap = 0;
1389-
else if ( !strcasecmp(optarg,"1") ) targets_overlap = 1;
1390-
else if ( !strcasecmp(optarg,"2") ) targets_overlap = 2;
1391-
else error("Could not parse: --targets-overlap %s\n",optarg);
1386+
targets_overlap = parse_overlap_option(optarg);
1387+
if ( targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
13921388
break;
13931389
case 'h':
13941390
case '?': usage(args); break;

vcfconcat.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,8 @@ int main_vcfconcat(int argc, char *argv[])
10141014
case 8 : args->record_cmd_line = 0; break;
10151015
case 7 : args->naive_concat = 1; args->naive_concat_trust_headers = 1; break;
10161016
case 12 :
1017-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
1018-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
1019-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
1020-
else error("Could not parse: --regions-overlap %s\n",optarg);
1017+
args->regions_overlap = parse_overlap_option(optarg);
1018+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
10211019
break;
10221020
case 'v':
10231021
args->verbose = strtol(optarg, 0, 0);

vcfconvert.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,16 +1646,12 @@ int main_vcfconvert(int argc, char *argv[])
16461646
case 11 : args->sex_fname = optarg; break;
16471647
case 12 : args->keep_duplicates = 1; break;
16481648
case 13 :
1649-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
1650-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
1651-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
1652-
else error("Could not parse: --regions-overlap %s\n",optarg);
1649+
args->regions_overlap = parse_overlap_option(optarg);
1650+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
16531651
break;
16541652
case 14 :
1655-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
1656-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
1657-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
1658-
else error("Could not parse: --targets-overlap %s\n",optarg);
1653+
args->targets_overlap = parse_overlap_option(optarg);
1654+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
16591655
break;
16601656
case '?': usage(); break;
16611657
default: error("Unknown argument: %s\n", optarg);

vcffilter.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,16 +610,12 @@ int main_vcffilter(int argc, char *argv[])
610610
case 9 : args->n_threads = strtol(optarg, 0, 0); break;
611611
case 8 : args->record_cmd_line = 0; break;
612612
case 3 :
613-
if ( !strcasecmp(optarg,"0") ) regions_overlap = 0;
614-
else if ( !strcasecmp(optarg,"1") ) regions_overlap = 1;
615-
else if ( !strcasecmp(optarg,"2") ) regions_overlap = 2;
616-
else error("Could not parse: --regions-overlap %s\n",optarg);
613+
regions_overlap = parse_overlap_option(optarg);
614+
if ( regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
617615
break;
618616
case 4 :
619-
if ( !strcasecmp(optarg,"0") ) targets_overlap = 0;
620-
else if ( !strcasecmp(optarg,"1") ) targets_overlap = 1;
621-
else if ( !strcasecmp(optarg,"2") ) targets_overlap = 2;
622-
else error("Could not parse: --targets-overlap %s\n",optarg);
617+
targets_overlap = parse_overlap_option(optarg);
618+
if ( targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
623619
break;
624620
case 10 : args->mask_list = optarg; break;
625621
case 'M' : args->mask_list = optarg; args->mask_is_file = 1; break;

vcfgtcheck.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,16 +1214,12 @@ int main_vcfgtcheck(int argc, char *argv[])
12141214
case 't': args->targets = optarg; break;
12151215
case 'T': args->targets = optarg; args->targets_is_file = 1; break;
12161216
case 7 :
1217-
if ( !strcasecmp(optarg,"0") ) args->regions_overlap = 0;
1218-
else if ( !strcasecmp(optarg,"1") ) args->regions_overlap = 1;
1219-
else if ( !strcasecmp(optarg,"2") ) args->regions_overlap = 2;
1220-
else error("Could not parse: --regions-overlap %s\n",optarg);
1217+
args->regions_overlap = parse_overlap_option(optarg);
1218+
if ( args->regions_overlap < 0 ) error("Could not parse: --regions-overlap %s\n",optarg);
12211219
break;
12221220
case 8 :
1223-
if ( !strcasecmp(optarg,"0") ) args->targets_overlap = 0;
1224-
else if ( !strcasecmp(optarg,"1") ) args->targets_overlap = 1;
1225-
else if ( !strcasecmp(optarg,"2") ) args->targets_overlap = 2;
1226-
else error("Could not parse: --targets-overlap %s\n",optarg);
1221+
args->targets_overlap = parse_overlap_option(optarg);
1222+
if ( args->targets_overlap < 0 ) error("Could not parse: --targets-overlap %s\n",optarg);
12271223
break;
12281224
case 'h':
12291225
case '?': usage(); break;

0 commit comments

Comments
 (0)