Skip to content

Commit c2001ab

Browse files
committed
New -H, --header-line option
This is a convenience option that allows to pass a header line on command line, and complements the existing `-h, --header-lines` option which requires a file with header lines
1 parent b46e7cd commit c2001ab

File tree

4 files changed

+150
-57
lines changed

4 files changed

+150
-57
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,13 @@ prob1_h = prob1.h $(htslib_vcf_h) $(call_h)
230230
smpl_ilist_h = smpl_ilist.h $(htslib_vcf_h)
231231
vcfbuf_h = vcfbuf.h $(htslib_vcf_h)
232232
abuf_h = abuf.h $(htslib_vcf_h)
233+
dbuf_h = dbuf.h $(htslib_vcf_h)
233234
bam2bcf_h = bam2bcf.h $(htslib_hts_h) $(htslib_vcf_h)
234235
bam_sample_h = bam_sample.h $(htslib_sam_h)
235236

236237
str_finder.o: str_finder.h utlist.h
237238
main.o: main.c $(htslib_hts_h) config.h version.h $(bcftools_h)
238-
vcfannotate.o: vcfannotate.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) $(bcftools_h) vcmp.h $(filter_h) $(convert_h) $(smpl_ilist_h) regidx.h $(htslib_khash_h)
239+
vcfannotate.o: vcfannotate.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) $(bcftools_h) vcmp.h $(filter_h) $(convert_h) $(smpl_ilist_h) regidx.h $(htslib_khash_h) $(dbuf_h)
239240
vcfplugin.o: vcfplugin.c config.h $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) $(bcftools_h) vcmp.h $(filter_h)
240241
vcfcall.o: vcfcall.c $(htslib_vcf_h) $(htslib_kfunc_h) $(htslib_synced_bcf_reader_h) $(htslib_khash_str2int_h) $(bcftools_h) $(call_h) $(prob1_h) $(ploidy_h) $(gvcf_h) regidx.h $(vcfbuf_h)
241242
vcfconcat.o: vcfconcat.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_bgzf_h) $(htslib_tbx_h) $(htslib_thread_pool_h) $(bcftools_h)

dbuf.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* The MIT License
2+
3+
Copyright (c) 2022 Genome Research Ltd.
4+
5+
Author: Petr Danecek <pd3@sanger.ac.uk>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
*/
26+
27+
/*
28+
Simple data buffer
29+
*/
30+
31+
#ifndef __DBUF_H__
32+
#define __DBUF_H__
33+
34+
#include <htslib/hts.h>
35+
36+
typedef struct
37+
{
38+
size_t n,m;
39+
void **dat;
40+
}
41+
dbuf_t;
42+
43+
static inline dbuf_t *dbuf_push(dbuf_t *buf, void *ptr)
44+
{
45+
if ( !buf ) buf = calloc(1,sizeof(dbuf_t));
46+
buf->n++;
47+
hts_expand(void*,buf->n,buf->m,buf->dat);
48+
buf->dat[buf->n-1] = ptr;
49+
return buf;
50+
}
51+
52+
static inline void *dbuf_ith(dbuf_t *buf, int i)
53+
{
54+
return buf->dat[i];
55+
}
56+
57+
static inline size_t dbuf_n(dbuf_t *buf)
58+
{
59+
return buf->n;
60+
}
61+
62+
static inline void dbuf_destroy_free(dbuf_t *buf)
63+
{
64+
int i;
65+
for (i=0; i<buf->n; i++) free(buf->dat[i]);
66+
free(buf->dat);
67+
free(buf);
68+
}
69+
70+
#endif
71+

test/test.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@
448448
test_vcf_annotate($opts,in=>'annotate14',out=>'annotate25.out',args=>'-x FILTER/XX,INFO/XX --force');
449449
test_vcf_annotate($opts,in=>'annotate15',tab=>'annotate15',out=>'annotate26.out',args=>'-s SAMPLE1 -c CHROM,FROM,TO,FMT/FOO,BAR');
450450
test_vcf_annotate($opts,in=>'annotate15',tab=>'annotate15',out=>'annotate27.out',args=>'-s SAMPLE2 -c CHROM,FROM,TO,FMT/FOO,BAR');
451+
test_vcf_annotate($opts,in=>'annotate15',tab=>'annotate15',out=>'annotate27.out',args=>q[-s SAMPLE2 -c CHROM,FROM,TO,FMT/FOO,BAR -H '##FORMAT=<ID=FOO,Number=1,Type=String,Description="Some description">' -H '##INFO=<ID=BAR,Number=1,Type=Integer,Description="Some description">']);
451452
test_vcf_annotate($opts,in=>'annotate16',out=>'annotate28.out',args=>'-x FILTER');
452453
test_vcf_annotate($opts,in=>'annotate17.1',tab=>'annotate17.1',out=>'annotate17.1.out',args=>'-c CHROM,BEG,END,A,B -l A:append,B:append');
453454
test_vcf_annotate($opts,in=>'annotate17.2',tab=>'annotate17.1',out=>'annotate17.2.out',args=>'-c CHROM,BEG,END,A,B -l A:append,B:append');
@@ -1514,7 +1515,7 @@ sub test_vcf_annotate
15141515
bgzip_tabix($opts,file=>$args{tab},suffix=>'tab',args=>'-s1 -b2 -e2');
15151516
$annot_fname = "-a $$opts{tmp}/$args{tab}.tab.gz";
15161517
$in_fname = "$$opts{path}/$args{in}.vcf";
1517-
$hdr = -e "$$opts{path}/$args{in}.hdr" ? "-h $$opts{path}/$args{in}.hdr" : '';
1518+
$hdr = (-e "$$opts{path}/$args{in}.hdr" && !($args{args}=~/-H/) && !($args{args}=~/--header-line\s/)) ? "-h $$opts{path}/$args{in}.hdr" : '';
15181519
}
15191520
elsif ( exists($args{vcf}) )
15201521
{

0 commit comments

Comments
 (0)