|
3 | 3 | import logging |
4 | 4 | from collections.abc import Callable |
5 | 5 | from enum import Enum |
| 6 | +from functools import cache |
6 | 7 | from pathlib import Path |
7 | 8 | from typing import NamedTuple |
8 | 9 |
|
@@ -53,8 +54,8 @@ def __init__( |
53 | 54 | the `wags-tails documentation <https://wags-tails.readthedocs.io/>`_ for more info. |
54 | 55 | * If ``chainfile`` arg is provided, all other args are ignored. |
55 | 56 |
|
56 | | - :param from_assembly: Assembly name, e.g. ``<Assembly.HG19>`` |
57 | | - :param to_assembly: database name, e.g. ``"hg38"``. |
| 57 | + :param from_assembly: Name of assembly being lifted over from |
| 58 | + :param to_assembly: Name of assembly to lift over to |
58 | 59 | :param chainfile: Path to chainfile |
59 | 60 | :raise ValueError: if required arguments are not passed or are invalid |
60 | 61 | :raise FileNotFoundError: if unable to open corresponding chainfile |
@@ -178,3 +179,17 @@ def convert_coordinate( |
178 | 179 | LiftoverResult(result[0], lifted_over_start, lifted_over_end, strand) |
179 | 180 | ) |
180 | 181 | return formatted_results |
| 182 | + |
| 183 | + |
| 184 | +@cache |
| 185 | +def get_converter(from_assembly: Assembly, to_assembly: Assembly) -> Converter: |
| 186 | + """Get a converter to lift from one assembly to another. |
| 187 | +
|
| 188 | + This function wraps converter initialization with ``functools.cache``, so successive |
| 189 | + calls should return the same converter instance. |
| 190 | +
|
| 191 | + :param from_assembly: Name of assembly being lifted over from |
| 192 | + :param to_assembly: Name of assembly to lift over to |
| 193 | + :return: Converter instance |
| 194 | + """ |
| 195 | + return Converter(from_assembly=from_assembly, to_assembly=to_assembly) |
0 commit comments