Skip to content

Commit

Permalink
Merge branch 'main' into fix/format_multi_missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dennishendriksen authored Jul 4, 2023
2 parents f9a6ef2 + 408fb0d commit f8cbb14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@molgenis/vip-report-vcf",
"version": "1.3.5",
"version": "1.4.0",
"description": "TypeScript VCF library with support for both reading and writing",
"scripts": {
"preinstall": "curl --no-progress-meter --location https://github.com/molgenis/vip-utils/releases/download/v1.1.3/field_metadata.json --create-dirs --output src/metadata/field_metadata.json",
"preinstall": "curl --no-progress-meter --location https://github.com/molgenis/vip-utils/releases/download/v1.3.0/field_metadata.json --create-dirs --output src/metadata/field_metadata.json",
"build": "tsc --build",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/VcfWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,16 @@ function writeString(value: string) {
}

function writeFormat(samples: RecordSample[]): string {
const keys = Object.keys(samples[0]);
const keys = Object.keys(samples[0]).filter((key) => key !== "VIAB");
return keys.length > 0 ? keys.map(writeString).join(":") : MISSING;
}

function writeSample(formatFields: FormatMetadataContainer, sample: RecordSample): string {
const vcf = [];
for (const [key, value] of Object.entries(sample)) {
vcf.push(writeSampleValue(formatFields[key], value));
if (key !== "VIAB") {
vcf.push(writeSampleValue(formatFields[key], value));
}
}
return vcf.join(":");
}
Expand Down
7 changes: 5 additions & 2 deletions src/__tests__/VcfWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ test("parse and write vcf: Samples filtered", () => {
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allelic depths for the ref and alt alleles in the order listed">
##contig=<ID=1,length=249250621,assembly=b37>
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tSAMPLE1\tSAMPLE2
1\t1\t.\tA\tG\t.\t.\t.\tGT:GQ:HQ\t0/1:.:4,5\t1/1
1\t1\t.\tA\tG\t.\t.\t.\tGT:AD:GQ:HQ\t0/1:20,80:.:4,5\t1/1
`;
expect(writeVcf(parseVcf(vcfSamples), { samples: ["SAMPLE1", "SAMPLE2"] })).toBe(expectedVcfSamples);
});
Expand All @@ -47,6 +48,7 @@ test("parse and write vcf: Samples none", () => {
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allelic depths for the ref and alt alleles in the order listed">
##contig=<ID=1,length=249250621,assembly=b37>
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO
1\t1\t.\tA\tG\t.\t.\t.
Expand Down Expand Up @@ -136,9 +138,10 @@ const vcfSamples = `##fileformat=VCFv4.2
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allelic depths for the ref and alt alleles in the order listed">
##contig=<ID=1,length=249250621,assembly=b37>
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tSAMPLE0\tSAMPLE1\tSAMPLE2
1\t1\t.\tA\tG\t.\t.\t.\tGT:GQ:HQ\t0|1:1:2,3\t0/1:.:4,5\t1/1
1\t1\t.\tA\tG\t.\t.\t.\tGT:AD:GQ:HQ\t0|1:1,50:1:2,3\t0/1:20,80:.:4,5\t1/1
`;

const vcfSamplesMissingValues = `##fileformat=VCFv4.2
Expand Down

0 comments on commit f8cbb14

Please sign in to comment.