Skip to content

Commit a383c9e

Browse files
committed
Fix missed VCF regions
Awaits the merge of samtools/htslib#1624 Resolves #1918
1 parent 6735518 commit a383c9e

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

consensus.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static void init_region(args_t *args, char *line)
324324
{
325325
char *ss, *se = line;
326326
while ( *se && !isspace(*se) && *se!=':' ) se++;
327-
int from = 0, to = 0;
327+
hts_pos_t from = 0, to = 0;
328328
char tmp = 0, *tmp_ptr = NULL;
329329
if ( *se )
330330
{
@@ -356,7 +356,14 @@ static void init_region(args_t *args, char *line)
356356
args->fa_frz_mod = -1;
357357
args->fa_case = -1;
358358
args->vcf_rbuf.n = 0;
359-
bcf_sr_seek(args->files,line,args->fa_ori_pos);
359+
360+
kstring_t str = {0,0,0};
361+
if ( from==0 ) from = 1;
362+
if ( to==0 ) to = HTS_POS_MAX;
363+
ksprintf(&str,"%s:%"PRIhts_pos"-%"PRIhts_pos,line,from,to);
364+
bcf_sr_set_regions(args->files,line,0);
365+
free(str.s);
366+
360367
if ( tmp_ptr ) *tmp_ptr = tmp;
361368
fprintf(args->fp_out,">%s%s\n",args->chr_prefix?args->chr_prefix:"",line);
362369
if ( args->chain_fname )

test/consensus.21.fa

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
>17
2+
ACGTACGT
3+
>18
4+
ACGTACGT
5+
>19
6+
ACGTACGT

test/consensus.21.vcf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
##fileformat=VCFv4.2
2+
##reference=file://some/path/human_g1k_v37.fasta
3+
##contig=<ID=17>
4+
##contig=<ID=18>
5+
##contig=<ID=19>
6+
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
7+
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT a
8+
19 2 . C A . . . GT 0/0
9+
19 3 . G C . . . GT 0/0
10+
19 4 . T C . . . GT 0/1
11+
19 5 . A C . . . GT 1/1

test/consensus21.1.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
>17
2+
ACGTACGT
3+
>18
4+
ACGTACGT
5+
>19
6+
ACGYCCGT

test/test.pl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@
811811
run_test(\&test_vcf_consensus,$opts,in=>'consensus.20',out=>'consensus20.2.out',fa=>'consensus.20.fa',args=>'');
812812
run_test(\&test_vcf_consensus,$opts,in=>'consensus.20',out=>'consensus20.3.out',fa=>'consensus.20.fa',args=>'-M . -s b');
813813
run_test(\&test_vcf_consensus,$opts,in=>'consensus.20',out=>'consensus20.4.out',fa=>'consensus.20.fa',args=>'-M . -s a');
814+
run_test(\&test_vcf_consensus,$opts,in=>'consensus.21',out=>'consensus21.1.out',fa=>'consensus.21.fa',args=>'');
814815
run_test(\&test_mpileup,$opts,in=>[qw(mpileup.1 mpileup.2 mpileup.3)],out=>'mpileup/mpileup.1.out',args=>q[-r17:100-150],test_list=>1);
815816
run_test(\&test_mpileup,$opts,in=>[qw(mpileup.1 mpileup.2 mpileup.3)],out=>'mpileup/mpileup.2.out',args=>q[-a DP,DV -r17:100-600]); # test files from samtools mpileup test suite
816817
run_test(\&test_mpileup,$opts,in=>[qw(mpileup.1)],out=>'mpileup/mpileup.3.out',args=>q[-B --ff 0x14 -r17:1050-1060]); # test file converted to vcf from samtools mpileup test suite
@@ -1174,6 +1175,18 @@ sub bgzip_tabix_vcf
11741175
my ($opts,$file) = @_;
11751176
bgzip_tabix($opts,file=>$file,suffix=>'vcf',args=>'-p vcf');
11761177
}
1178+
sub bgzip_index_bcf
1179+
{
1180+
my ($opts,$file) = @_;
1181+
if ( !-e "$$opts{tmp}/$file.bcf" or is_file_newer("$$opts{path}/$file.vcf","$$opts{tmp}/$file.bcf") )
1182+
{
1183+
cmd("$$opts{bin}/bcftools view -Ob $$opts{path}/$file.vcf -o $$opts{tmp}/$file.bcf");
1184+
}
1185+
if ( !-e "$$opts{tmp}/$file.bcf.csi" or is_file_newer("$$opts{tmp}/$file.bcf","$$opts{tmp}/$file.bcf.csi") )
1186+
{
1187+
cmd("$$opts{bin}/bcftools index -f $$opts{tmp}/$file.bcf");
1188+
}
1189+
}
11771190
11781191
11791192
# The tests --------------------------
@@ -1755,10 +1768,12 @@ sub test_vcf_consensus
17551768
{
17561769
my ($opts,%args) = @_;
17571770
bgzip_tabix_vcf($opts,$args{in});
1771+
bgzip_index_bcf($opts,$args{in});
17581772
$args{args} =~ s/{PATH}/$$opts{path}/g;
17591773
my $mask = $args{mask} ? "-m $$opts{path}/$args{mask}" : '';
17601774
my $chain = $args{chain} ? "-c $$opts{tmp}/$args{chain}" : '';
17611775
test_cmd($opts,%args,cmd=>"$$opts{bin}/bcftools consensus $$opts{tmp}/$args{in}.vcf.gz -f $$opts{path}/$args{fa} $args{args} $mask $chain");
1776+
test_cmd($opts,%args,cmd=>"$$opts{bin}/bcftools consensus $$opts{tmp}/$args{in}.bcf -f $$opts{path}/$args{fa} $args{args} $mask $chain");
17621777
}
17631778
sub test_vcf_consensus_chain
17641779
{

0 commit comments

Comments
 (0)