@@ -62,6 +62,7 @@ void write_bcf(char *fname)
6262 bcf_hdr_append (hdr , "##phasing=partial" );
6363 bcf_hdr_append (hdr , "##INFO=<ID=NS,Number=1,Type=Integer,Description=\"Number of Samples With Data\">" );
6464 bcf_hdr_append (hdr , "##INFO=<ID=DP,Number=1,Type=Integer,Description=\"Total Depth\">" );
65+ bcf_hdr_append (hdr , "##INFO=<ID=NEG,Number=.,Type=Integer,Description=\"Test Negative Numbers\">" );
6566 bcf_hdr_append (hdr , "##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele Frequency\">" );
6667 bcf_hdr_append (hdr , "##INFO=<ID=AA,Number=1,Type=String,Description=\"Ancestral Allele\">" );
6768 bcf_hdr_append (hdr , "##INFO=<ID=DB,Number=0,Type=Flag,Description=\"dbSNP membership, build 129\">" );
@@ -82,7 +83,7 @@ void write_bcf(char *fname)
8283
8384
8485 // Add a record
85- // 20 14370 rs6054257 G A 29 PASS NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,.
86+ // 20 14370 rs6054257 G A 29 PASS NS=3;DP=14;NEG=-127; AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,.
8687 // .. CHROM
8788 rec -> rid = bcf_hdr_name2id (hdr , "20" );
8889 // .. POS
@@ -101,6 +102,8 @@ void write_bcf(char *fname)
101102 bcf_update_info_int32 (hdr , rec , "NS" , & tmpi , 1 );
102103 tmpi = 14 ;
103104 bcf_update_info_int32 (hdr , rec , "DP" , & tmpi , 1 );
105+ tmpi = -127 ;
106+ bcf_update_info_int32 (hdr , rec , "NEG" , & tmpi , 1 );
104107 float tmpf = 0.5 ;
105108 bcf_update_info_float (hdr , rec , "AF" , & tmpf , 1 );
106109 bcf_update_info_flag (hdr , rec , "DB" , NULL , 1 );
@@ -133,7 +136,7 @@ void write_bcf(char *fname)
133136 bcf_update_format_string (hdr , rec , "TS" , (const char * * )tmp_str , 3 );
134137 if ( bcf_write1 (fp , hdr , rec )!= 0 ) error ("Failed to write to %s\n" , fname );
135138
136- // 20 1110696 . A G,T 67 . NS=2;DP=10;AF=0.333,.;AA=T;DB GT 2 1 ./.
139+ // 20 1110696 . A G,T 67 . NS=2;DP=10;NEG=-128; AF=0.333,.;AA=T;DB GT 2 1 ./.
137140 bcf_clear1 (rec );
138141 rec -> rid = bcf_hdr_name2id (hdr , "20" );
139142 rec -> pos = 1110695 ;
@@ -143,6 +146,8 @@ void write_bcf(char *fname)
143146 bcf_update_info_int32 (hdr , rec , "NS" , & tmpi , 1 );
144147 tmpi = 10 ;
145148 bcf_update_info_int32 (hdr , rec , "DP" , & tmpi , 1 );
149+ tmpi = -128 ;
150+ bcf_update_info_int32 (hdr , rec , "NEG" , & tmpi , 1 );
146151 float * tmpfa = (float * )malloc (2 * sizeof (float ));
147152 tmpfa [0 ] = 0.333 ;
148153 bcf_float_set_missing (tmpfa [1 ]);
@@ -291,6 +296,7 @@ void test_get_info_values(const char *fname)
291296 while (bcf_read (fp , hdr , line ) == 0 )
292297 {
293298 float * afs = 0 ;
299+ int32_t * negs = NULL ;
294300 int count = 0 ;
295301 int ret = bcf_get_info_float (hdr , line , "AF" , & afs , & count );
296302
@@ -312,6 +318,21 @@ void test_get_info_values(const char *fname)
312318 }
313319
314320 free (afs );
321+
322+ int32_t expected = (line -> pos == 14369 )? -127 : -128 ;
323+ count = 0 ;
324+ ret = bcf_get_info_int32 (hdr , line , "NEG" , & negs , & count );
325+ if (ret != 1 || negs [0 ] != expected )
326+ {
327+ if (ret < 0 )
328+ fprintf (stderr , "NEG should be %d, got error ret=%d\n" , expected , ret );
329+ else if (ret == 0 )
330+ fprintf (stderr , "NEG should be %d, got no entries\n" , expected );
331+ else
332+ fprintf (stderr , "NEG should be %d, got %d entries (first is %d)\n" , expected , ret , negs [0 ]);
333+ exit (1 );
334+ }
335+ free (negs );
315336 }
316337
317338 bcf_destroy (line );
0 commit comments