Skip to content

Commit b23579b

Browse files
committed
Fix three bugs in vcfconvert.c
1. _set_chrom_pos_ref_alt (~line 207): The while/if conditions checked isspace_c(*tsv->se) (the constant end pointer) instead of !isspace_c(*se) (the advancing scan pointer), causing the ALT allele scan to terminate immediately or never advance. 2. bgzf_thread_pool calls (~lines 1084, 1234): Added NULL check for hout before calling bgzf_thread_pool, preventing a crash when hap output is suppressed by passing '.' as the filename. 3. sample_compressed assignment (~lines 923, 1048, 1197): Changed `sample_compressed = 0` to `sample_compressed = 1` so that .gz sample filenames actually enable compressed output.
1 parent db17826 commit b23579b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

vcfconvert.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ static int _set_chrom_pos_ref_alt(tsv_t *tsv, bcf1_t *rec, void *usr)
204204
if ( *se!='_' ) return -1;
205205
kputsn(ss,se-ss,&args->str);
206206
ss = ++se;
207-
while ( se < tsv->se && *se!='_' && isspace_c(*tsv->se) ) se++;
208-
if ( se < tsv->se && *se!='_' && isspace_c(*tsv->se) ) return -1;
207+
while ( se < tsv->se && *se!='_' && !isspace_c(*se) ) se++;
208+
if ( se < tsv->se && *se!='_' && !isspace_c(*se) ) return -1;
209209
kputc(',',&args->str);
210210
kputsn(ss,se-ss,&args->str);
211211

@@ -920,7 +920,7 @@ static void vcf_to_gensample(args_t *args)
920920
free(files);
921921

922922
if ( gen_fname && (strlen(gen_fname)<3 || strcasecmp(".gz",gen_fname+strlen(gen_fname)-3)) ) gen_compressed = 0;
923-
if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0;
923+
if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 1;
924924

925925
if (gen_fname) fprintf(stderr, "Gen file: %s\n", gen_fname);
926926
if (sample_fname) fprintf(stderr, "Sample file: %s\n", sample_fname);
@@ -1045,7 +1045,7 @@ static void vcf_to_haplegendsample(args_t *args)
10451045

10461046
if ( hap_fname && (strlen(hap_fname)<3 || strcasecmp(".gz",hap_fname+strlen(hap_fname)-3)) ) hap_compressed = 0;
10471047
if ( legend_fname && (strlen(legend_fname)<3 || strcasecmp(".gz",legend_fname+strlen(legend_fname)-3)) ) legend_compressed = 0;
1048-
if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0;
1048+
if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 1;
10491049

10501050
if (hap_fname) fprintf(stderr, "Hap file: %s\n", hap_fname);
10511051
if (legend_fname) fprintf(stderr, "Legend file: %s\n", legend_fname);
@@ -1081,7 +1081,7 @@ static void vcf_to_haplegendsample(args_t *args)
10811081

10821082
// open haps and legend outputs
10831083
BGZF *hout = hap_fname ? bgzf_open(hap_fname, hap_compressed ? "wg" : "wu") : NULL;
1084-
if ( hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize);
1084+
if ( hout && hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize);
10851085
BGZF *lout = legend_fname ? bgzf_open(legend_fname, legend_compressed ? "wg" : "wu") : NULL;
10861086
if (legend_fname) {
10871087
str.l = 0;
@@ -1194,7 +1194,7 @@ static void vcf_to_hapsample(args_t *args)
11941194
free(files);
11951195

11961196
if ( hap_fname && (strlen(hap_fname)<3 || strcasecmp(".gz",hap_fname+strlen(hap_fname)-3)) ) hap_compressed = 0;
1197-
if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0;
1197+
if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 1;
11981198

11991199
if (hap_fname) fprintf(stderr, "Hap file: %s\n", hap_fname);
12001200
if (sample_fname) fprintf(stderr, "Sample file: %s\n", sample_fname);
@@ -1232,7 +1232,7 @@ static void vcf_to_hapsample(args_t *args)
12321232

12331233
// open haps output
12341234
BGZF *hout = hap_fname ? bgzf_open(hap_fname, hap_compressed ? "wg" : "wu") : NULL;
1235-
if ( hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize);
1235+
if ( hout && hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize);
12361236

12371237
int no_alt = 0, non_biallelic = 0, filtered = 0, nok = 0;
12381238
while ( bcf_sr_next_line(args->files) )

0 commit comments

Comments
 (0)