Skip to content

Commit

Permalink
Add FORMAT field to records (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin authored Jan 29, 2025
1 parent cd98d31 commit d8ed6cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export default class VCFParser {
const alt = ALT === '.' ? undefined : ALT!.split(',')
const qual = QUAL === '.' ? undefined : +QUAL!
const filter = FILTER === '.' ? undefined : FILTER!.split(';')
const format = fields[8]

if (this.strict && !fields[7]) {
throw new Error(
Expand Down Expand Up @@ -335,6 +336,7 @@ export default class VCFParser {
filter && filter.length === 1 && filter[0] === 'PASS' ? 'PASS' : filter,
ID: id,
QUAL: qual,
FORMAT: format,
SAMPLES: () => this.parseSamples(fields[8] ?? '', rest),
GENOTYPES: () => this.parseGenotypesOnly(fields[8] ?? '', rest),
}
Expand Down
43 changes: 43 additions & 0 deletions test/__snapshots__/parse.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ exports[`can parse a line from the VCF spec 1`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": [
"rs6054257",
Expand Down Expand Up @@ -681,6 +682,7 @@ exports[`can parse a line from the VCF spec Y chrom (haploid)) 1`] = `
],
"CHROM": "Y",
"FILTER": "PASS",
"FORMAT": "GT:CN:CNL:CNP:CNQ:GP:GQ:PL",
"GENOTYPES": [Function],
"ID": [
"CNV_Y_14483990_15232198",
Expand Down Expand Up @@ -827,6 +829,7 @@ exports[`can parse a line from the VCF spec Y chrom (haploid)) 3`] = `
],
"CHROM": "Y",
"FILTER": "PASS",
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": [
"rs11575897",
Expand Down Expand Up @@ -907,6 +910,7 @@ exports[`can parse a line with minimal entries 1`] = `
],
"CHROM": "20",
"FILTER": undefined,
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {},
Expand Down Expand Up @@ -942,6 +946,7 @@ exports[`can parse breakends 1`] = `
],
"CHROM": "11",
"FILTER": "PASS",
"FORMAT": "PR:SR",
"GENOTYPES": [Function],
"ID": [
"MantaBND:0:2:3:0:0:0:1",
Expand Down Expand Up @@ -981,6 +986,7 @@ exports[`can parse breakends 1`] = `
],
"CHROM": "11",
"FILTER": "PASS",
"FORMAT": "PR",
"GENOTYPES": [Function],
"ID": [
"MantaDEL:0:1:2:0:0:0",
Expand Down Expand Up @@ -1016,6 +1022,7 @@ exports[`can parse breakends 1`] = `
],
"CHROM": "11",
"FILTER": "PASS",
"FORMAT": "PR:SR",
"GENOTYPES": [Function],
"ID": [
"MantaBND:0:0:1:0:0:0:0",
Expand Down Expand Up @@ -1577,6 +1584,7 @@ exports[`parses a line with a breakend ALT 1`] = `
],
"CHROM": "2",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_W",
Expand All @@ -1602,6 +1610,7 @@ exports[`parses a line with mix of multiple breakends and non breakends 1`] = `
],
"CHROM": "13",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_U",
Expand Down Expand Up @@ -2027,6 +2036,7 @@ exports[`shortcut parsing with 1000 genomes 1`] = `
],
"CHROM": "Y",
"FILTER": "PASS",
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": [
"rs11575897",
Expand Down Expand Up @@ -2081,6 +2091,7 @@ exports[`shortcut parsing with 1000 genomes 1`] = `
],
"CHROM": "Y",
"FILTER": "PASS",
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -2138,6 +2149,7 @@ exports[`shortcut parsing with vcf 4.3 bnd example 1`] = `
],
"CHROM": "2",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_W",
Expand All @@ -2158,6 +2170,7 @@ exports[`shortcut parsing with vcf 4.3 bnd example 1`] = `
],
"CHROM": "2",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_V",
Expand All @@ -2178,6 +2191,7 @@ exports[`shortcut parsing with vcf 4.3 bnd example 1`] = `
],
"CHROM": "13",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_U",
Expand All @@ -2198,6 +2212,7 @@ exports[`shortcut parsing with vcf 4.3 bnd example 1`] = `
],
"CHROM": "13",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_X",
Expand All @@ -2218,6 +2233,7 @@ exports[`shortcut parsing with vcf 4.3 bnd example 1`] = `
],
"CHROM": "17",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_Y",
Expand All @@ -2238,6 +2254,7 @@ exports[`shortcut parsing with vcf 4.3 bnd example 1`] = `
],
"CHROM": "17",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"bnd_Z",
Expand All @@ -2262,6 +2279,7 @@ exports[`sniffles vcf 1`] = `
],
"CHROM": "8",
"FILTER": "PASS",
"FORMAT": "GT:DR:DV",
"GENOTYPES": [Function],
"ID": [
"28329_0",
Expand Down Expand Up @@ -2345,6 +2363,7 @@ exports[`snippet from VCF 4.3 spec 1`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": [
"rs6054257",
Expand Down Expand Up @@ -2375,6 +2394,7 @@ exports[`snippet from VCF 4.3 spec 1`] = `
"FILTER": [
"q10",
],
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand All @@ -2400,6 +2420,7 @@ exports[`snippet from VCF 4.3 spec 1`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": [
"rs6040355",
Expand Down Expand Up @@ -2429,6 +2450,7 @@ exports[`snippet from VCF 4.3 spec 1`] = `
"ALT": undefined,
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand All @@ -2454,6 +2476,7 @@ exports[`snippet from VCF 4.3 spec 1`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP",
"GENOTYPES": [Function],
"ID": [
"microsat1",
Expand Down Expand Up @@ -2761,6 +2784,7 @@ exports[`vcf lines with weird info field and missing format/genotypes 1`] = `
],
"CHROM": "lcl|Scaffald_1",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"rs118266897",
Expand Down Expand Up @@ -2788,6 +2812,7 @@ exports[`vcf lines with weird info field and missing format/genotypes 1`] = `
],
"CHROM": "lcl|Scaffald_1",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"rs118269296",
Expand Down Expand Up @@ -2815,6 +2840,7 @@ exports[`vcf lines with weird info field and missing format/genotypes 1`] = `
],
"CHROM": "lcl|Scaffald_1",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"rs118218236",
Expand Down Expand Up @@ -2842,6 +2868,7 @@ exports[`vcf lines with weird info field and missing format/genotypes 1`] = `
],
"CHROM": "lcl|Scaffald_1",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"rs118264755",
Expand Down Expand Up @@ -2869,6 +2896,7 @@ exports[`vcf lines with weird info field and missing format/genotypes 1`] = `
],
"CHROM": "lcl|Scaffald_1",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"rs118223336",
Expand Down Expand Up @@ -2896,6 +2924,7 @@ exports[`vcf lines with weird info field and missing format/genotypes 1`] = `
],
"CHROM": "lcl|Scaffald_1",
"FILTER": "PASS",
"FORMAT": undefined,
"GENOTYPES": [Function],
"ID": [
"rs118217257",
Expand Down Expand Up @@ -3285,6 +3314,7 @@ exports[`x simple spec 2`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": [
"rs6054257",
Expand Down Expand Up @@ -3361,6 +3391,7 @@ exports[`x simple spec 2`] = `
"FILTER": [
"q10",
],
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -3428,6 +3459,7 @@ exports[`x simple spec 2`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": [
"rs6040355",
Expand Down Expand Up @@ -3499,6 +3531,7 @@ exports[`x simple spec 2`] = `
"ALT": undefined,
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP:HQ",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -3566,6 +3599,7 @@ exports[`x simple spec 2`] = `
],
"CHROM": "20",
"FILTER": "PASS",
"FORMAT": "GT:GQ:DP",
"GENOTYPES": [Function],
"ID": [
"microsat1",
Expand Down Expand Up @@ -3985,6 +4019,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand All @@ -4009,6 +4044,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -4042,6 +4078,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": [
"delbp1",
Expand Down Expand Up @@ -4071,6 +4108,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": [
"delbp2",
Expand Down Expand Up @@ -4100,6 +4138,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -4133,6 +4172,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand All @@ -4157,6 +4197,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -4191,6 +4232,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down Expand Up @@ -4227,6 +4269,7 @@ exports[`x vcf44 spec 2`] = `
],
"CHROM": "chrA",
"FILTER": undefined,
"FORMAT": "GT",
"GENOTYPES": [Function],
"ID": undefined,
"INFO": {
Expand Down

0 comments on commit d8ed6cd

Please sign in to comment.