2 Copyright (C) 2017 Genome Research Ltd.
4 Author: Petr Danecek <pd3@sanger.ac.uk>
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 Test bcf synced reader allele pairing
34 #include <htslib/synced_bcf_reader.h>
36 void error(const char *format
, ...)
40 vfprintf(stderr
, format
, ap
);
47 fprintf(stderr
, "Usage: test-bcf-sr [OPTIONS] vcf-list.txt\n");
48 fprintf(stderr
, "Options:\n");
49 fprintf(stderr
, " -p, --pair <logic[+ref]> logic: snps,indels,both,snps+ref,indels+ref,both+ref,exact,some,all\n");
50 fprintf(stderr
, "\n");
54 int main(int argc
, char *argv
[])
56 static struct option loptions
[] =
58 {"help",no_argument
,NULL
,'h'},
59 {"pair",required_argument
,NULL
,'p'},
64 while ((c
= getopt_long(argc
, argv
, "p:h", loptions
, NULL
)) >= 0)
69 if ( !strcmp(optarg
,"snps") ) pair
|= BCF_SR_PAIR_SNPS
;
70 else if ( !strcmp(optarg
,"snp+ref") ) pair
|= BCF_SR_PAIR_SNPS
|BCF_SR_PAIR_SNP_REF
;
71 else if ( !strcmp(optarg
,"snps+ref") ) pair
|= BCF_SR_PAIR_SNPS
|BCF_SR_PAIR_SNP_REF
;
72 else if ( !strcmp(optarg
,"indels") ) pair
|= BCF_SR_PAIR_INDELS
;
73 else if ( !strcmp(optarg
,"indel+ref") ) pair
|= BCF_SR_PAIR_INDELS
|BCF_SR_PAIR_INDEL_REF
;
74 else if ( !strcmp(optarg
,"indels+ref") ) pair
|= BCF_SR_PAIR_INDELS
|BCF_SR_PAIR_INDEL_REF
;
75 else if ( !strcmp(optarg
,"both") ) pair
|= BCF_SR_PAIR_BOTH
;
76 else if ( !strcmp(optarg
,"both+ref") ) pair
|= BCF_SR_PAIR_BOTH_REF
;
77 else if ( !strcmp(optarg
,"any") ) pair
|= BCF_SR_PAIR_ANY
;
78 else if ( !strcmp(optarg
,"all") ) pair
|= BCF_SR_PAIR_ANY
;
79 else if ( !strcmp(optarg
,"some") ) pair
|= BCF_SR_PAIR_SOME
;
80 else if ( !strcmp(optarg
,"exact") ) pair
= BCF_SR_PAIR_EXACT
;
81 else error("The --pair logic \"%s\" not recognised.\n", optarg
);
86 if ( !pair
) pair
= BCF_SR_PAIR_EXACT
;
87 if ( optind
== argc
) usage();
90 char **vcf
= hts_readlist(argv
[optind
], 1, &nvcf
);
91 if ( !vcf
) error("Could not parse %s\n", argv
[optind
]);
93 bcf_srs_t
*sr
= bcf_sr_init();
94 bcf_sr_set_opt(sr
, BCF_SR_PAIR_LOGIC
, pair
);
95 bcf_sr_set_opt(sr
, BCF_SR_REQUIRE_IDX
);
96 for (i
=0; i
<nvcf
; i
++)
97 if ( !bcf_sr_add_reader(sr
,vcf
[i
]) ) error("Failed to open %s: %s\n", vcf
[i
],bcf_sr_strerror(sr
->errnum
));
99 kstring_t str
= {0,0,0};
100 while ( (n
=bcf_sr_next_line(sr
)) )
102 for (i
=0; i
<sr
->nreaders
; i
++)
104 if ( !bcf_sr_has_line(sr
,i
) ) continue;
105 bcf1_t
*rec
= bcf_sr_get_line(sr
, i
);
106 printf("%s:%d", bcf_seqname(bcf_sr_get_header(sr
,i
),rec
),rec
->pos
+1);
110 for (i
=0; i
<sr
->nreaders
; i
++)
114 if ( !bcf_sr_has_line(sr
,i
) )
121 bcf1_t
*rec
= bcf_sr_get_line(sr
, i
);
122 kputs(rec
->n_allele
> 1 ? rec
->d
.allele
[1] : ".", &str
);
123 for (j
=2; j
<rec
->n_allele
; j
++)
126 kputs(rec
->d
.allele
[j
], &str
);
135 for (i
=0; i
<nvcf
; i
++)