# Path: hgvs/extras/babelfish.py
# class Babelfish:
#     def __init__(self, hdp, assembly_name):
#         self.hdp = hdp
#         self.hn = hgvs.normalizer.Normalizer(hdp,
#                                              cross_boundaries=False,
#                                              shuffle_direction=5,
#                                              validate=False)
#         self.ac_to_chr_name_map = {
#             sr["refseq_ac"]: sr["name"]
#             for sr in bioutils.assemblies.get_assembly("GRCh38")["sequences"]}
# 
# 
# 
#     def hgvs_to_vcf(self, var_g):
#         """**EXPERIMENTAL**
# 
#         converts a single hgvs allele to (chr, pos, ref, alt) using
#         the given assembly_name. The chr name uses official chromosome
#         name (i.e., without a "chr" prefix).
# 
#         Returns None for non-variation (e.g., NC_000006.12:g.49949407=)
# 
#         """
# 
#         if var_g.type != "g":
#             raise RuntimeError("Expected g. variant, got {var_g}".format(var_g=var_g))
# 
#         vleft = self.hn.normalize(var_g)
# 
#         (start_i, end_i) = _as_interbase(vleft.posedit)
# 
#         chr = self.ac_to_chr_name_map[vleft.ac]
# 
#         typ = vleft.posedit.edit.type
# 
#         if typ == "dup":
#             start_i -= 1
#             alt = self.hdp.seqfetcher.fetch_seq(vleft.ac, start_i, end_i)
#             ref = alt[0]
#             end_i = start_i
#             return (chr, start_i + 1, ref, alt, typ)
# 
#         if vleft.posedit.edit.ref == vleft.posedit.edit.alt:
#             return None
# 
#         alt = vleft.posedit.edit.alt or ""
# 
#         if end_i - start_i == 1 and vleft.posedit.length_change == 0:
#             # SNVs aren't left anchored
#             ref = vleft.posedit.edit.ref
# 
#         else:
#             # everything else is left-anchored
#             start_i -= 1
#             ref = self.hdp.seqfetcher.fetch_seq(vleft.ac, start_i, end_i)
#             alt = ref[0] + alt
# 
#         return (chr, start_i + 1, ref, alt, typ)


import os
import pytest
import hgvs.easy
from hgvs.extras.babelfish import Babelfish
from support import CACHE
hgvs.easy.hdp = hgvs.dataproviders.uta.connect(mode=os.environ.get("HGVS_CACHE_MODE", "run"), cache=CACHE)


@pytest.fixture(scope="session", autouse=True)
def parser():
    return hgvs.easy.parser


@pytest.fixture(scope="session")
def am37():
    return hgvs.easy.am37


@pytest.fixture(scope="session")
def am38():
    return hgvs.easy.am38


@pytest.fixture(scope="session")
def hdp():
    return hgvs.easy.hdp


@pytest.fixture(scope="session")
def babelfish38(hdp):
    return Babelfish(hdp, assembly_name="GRCh38")



@pytest.fixture(scope="class")

# Path: hgvs/extras/babelfish.py
# class Babelfish:
#     def __init__(self, hdp, assembly_name):
#         self.hdp = hdp
#         self.hn = hgvs.normalizer.Normalizer(hdp,
#                                              cross_boundaries=False,
#                                              shuffle_direction=5,
#                                              validate=False)
#         self.ac_to_chr_name_map = {
#             sr["refseq_ac"]: sr["name"]
#             for sr in bioutils.assemblies.get_assembly("GRCh38")["sequences"]}
# 
# 
# 
#     def hgvs_to_vcf(self, var_g):
#         """**EXPERIMENTAL**
# 
#         converts a single hgvs allele to (chr, pos, ref, alt) using
#         the given assembly_name. The chr name uses official chromosome
#         name (i.e., without a "chr" prefix).
# 
#         Returns None for non-variation (e.g., NC_000006.12:g.49949407=)
# 
#         """
# 
#         if var_g.type != "g":
#             raise RuntimeError("Expected g. variant, got {var_g}".format(var_g=var_g))
# 
#         vleft = self.hn.normalize(var_g)
# 
#         (start_i, end_i) = _as_interbase(vleft.posedit)
# 
#         chr = self.ac_to_chr_name_map[vleft.ac]
# 
#         typ = vleft.posedit.edit.type
# 
#         if typ == "dup":
#             start_i -= 1
#             alt = self.hdp.seqfetcher.fetch_seq(vleft.ac, start_i, end_i)
#             ref = alt[0]
#             end_i = start_i
#             return (chr, start_i + 1, ref, alt, typ)
# 
#         if vleft.posedit.edit.ref == vleft.posedit.edit.alt:
#             return None
# 
#         alt = vleft.posedit.edit.alt or ""
# 
#         if end_i - start_i == 1 and vleft.posedit.length_change == 0:
#             # SNVs aren't left anchored
#             ref = vleft.posedit.edit.ref
# 
#         else:
#             # everything else is left-anchored
#             start_i -= 1
#             ref = self.hdp.seqfetcher.fetch_seq(vleft.ac, start_i, end_i)
#             alt = ref[0] + alt
# 
#         return (chr, start_i + 1, ref, alt, typ)


# Path: tests/conftest.py
import os
import pytest
import hgvs.easy
from hgvs.extras.babelfish import Babelfish
from support import CACHE

hgvs.easy.hdp = hgvs.dataproviders.uta.connect(mode=os.environ.get("HGVS_CACHE_MODE", "run"), cache=CACHE)


@pytest.fixture(scope="session", autouse=True)
def parser():
    return hgvs.easy.parser


@pytest.fixture(scope="session")
def am37():
    return hgvs.easy.am37


@pytest.fixture(scope="session")
def am38():
    return hgvs.easy.am38


@pytest.fixture(scope="session")
def hdp():
    return hgvs.easy.hdp


@pytest.fixture(scope="session")
def babelfish38(hdp):
    return Babelfish(hdp, assembly_name="GRCh38")



@pytest.fixture(scope="class")

def kitchen_sink_setup(request, hdp, parser, am37, am38):