Coverage for src/python/ensembl/vep/corpus/exporter/formats/file/fasta.py: 100%

15 statements  

« 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"""FASTA rendering for corpora.""" 

15 

16from __future__ import annotations 

17 

18from collections.abc import Iterator, Sequence 

19 

20from ensembl.vep.corpus.base import Corpus 

21 

22__all__ = ["FASTA_NAME", "fasta_lines"] 

23 

24FASTA_NAME = "corpus.fa" 

25 

26_LINE_WIDTH = 60 

27 

28 

29def fasta_lines(corpora: Sequence[Corpus]) -> Iterator[str]: 

30 """Yield one FASTA record per corpus chromosome, wrapped to a fixed width.""" 

31 for corpus in corpora: 

32 for sequence_region in corpus.sequence_regions: 

33 sequence = sequence_region.seq 

34 if not sequence: 

35 raise ValueError(f"No sequence for {sequence_region.seq_region_name}") 

36 yield f">{sequence_region.seq_region_name}" 

37 for offset in range(0, len(sequence), _LINE_WIDTH): 

38 yield sequence[offset : offset + _LINE_WIDTH]