Coverage for src/python/ensembl/vep/output/factory/write/json.py: 100%
15 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
1# See the NOTICE file distributed with this work for additional information
2# regarding copyright ownership.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""JSON-lines annotated-variant output."""
16from __future__ import annotations
18import json
19from collections.abc import Sequence
21from ensembl.vep.output.factory.base import AnnotatedVariant
22from ensembl.vep.output.factory.stream.json import JSONStreamFactory
24__all__ = ["JSONOutputWriter"]
27class JSONOutputWriter:
28 """Ensembl VEP-schema JSON-lines serializer."""
30 def __init__(self, stream_factory: JSONStreamFactory | None = None) -> None:
31 """Initialize the writer.
33 Args:
34 stream_factory (JSONStreamFactory | None): The record mapper, or None for the default.
35 """
36 self.stream_factory = stream_factory or JSONStreamFactory()
38 def headers(self, input_headers: Sequence[str] = ()) -> list[str]:
39 """Return no headers for JSON lines."""
40 del input_headers
41 return []
43 def line(self, variant: AnnotatedVariant) -> str:
44 """Return one compact JSON object for an annotated variant."""
45 record = self.stream_factory.record(variant)
46 return json.dumps(record, separators=(",", ":"), ensure_ascii=False)