Skip to content

Commit

Permalink
allow spaces in vcf header lines
Browse files Browse the repository at this point in the history
* allow spaces between keys and values when parsing in header lines
* these spaces will be dropped when writing out the header

e.g. `##reference=<ID=hs37d5 , Source=blah>` and `##reference=<ID=hs37d5, Source = blah >`
     will become `##reference=<ID=hs37d5,Source=blah>`

Fixes samtools/bcftools#266
  • Loading branch information
mcshane committed Jul 6, 2015
1 parent d8172f9 commit e085e20
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions vcf.c
Expand Up @@ -307,13 +307,16 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
while ( *q && *q!='\n' && nopen )
{
p = ++q;
while ( *q && *q==' ' ) { p++; q++; }
// ^[A-Za-z_][0-9A-Za-z_.]*$
if (p==q && *q && (isalpha(*q) || *q=='_'))
{
q++;
while ( *q && (isalnum(*q) || *q=='_' || *q=='.') ) q++;
}
n = q-p;
int m = 0;
while ( *q && *q==' ' ) { q++; m++; }
if ( *q!='=' || !n )
{
// wrong format
Expand All @@ -326,8 +329,9 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
bcf_hrec_destroy(hrec);
return NULL;
}
bcf_hrec_add_key(hrec, p, q-p);
bcf_hrec_add_key(hrec, p, q-p-m);
p = ++q;
while ( *q && *q==' ' ) { p++; q++; }
int quoted = *p=='"' ? 1 : 0;
if ( quoted ) p++, q++;
while (1)
Expand All @@ -343,7 +347,9 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
}
q++;
}
bcf_hrec_set_val(hrec, hrec->nkeys-1, p, q-p, quoted);
const char *r = q-1;
while ( *r && (*r==' ') ) r--;
bcf_hrec_set_val(hrec, hrec->nkeys-1, p, r-p+1, quoted);
if ( quoted ) q++;
if ( *q=='>' ) { nopen--; q++; }
}
Expand Down

0 comments on commit e085e20

Please sign in to comment.