# Path: hgvs/location.py
# class Interval(object):
#     start = attr.ib(default=None)
#     end = attr.ib(default=None)
#     uncertain = attr.ib(default=False)
# 
#     def validate(self):
#         if self.start:
#             (res, msg) = self.start.validate()
#             if res != ValidationLevel.VALID:
#                 return (res, msg)
#         if self.end:
#             (res, msg) = self.end.validate()
#             if res != ValidationLevel.VALID:
#                 return (res, msg)
#         # Check start less than or equal to end
#         if not self.start or not self.end:
#             return (ValidationLevel.VALID, None)
#         try:
#             if self.start <= self.end:
#                 return (ValidationLevel.VALID, None)
#             else:
#                 return (ValidationLevel.ERROR, "base start position must be <= end position")
#         except HGVSUnsupportedOperationError as err:
#             return (ValidationLevel.WARNING, str(err))
# 
#     def format(self, conf=None):
#         if self.start is None:
#             return ""
#         if self.end is None or self.start == self.end:
#             return self.start.format(conf)
#         iv = self.start.format(conf) + "_" + self.end.format(conf)
#         return "(" + iv + ")" if self.uncertain else iv
# 
#     __str__ = format
# 
#     def __repr__(self):
#         return "{0}({1})".format(
#             self.__class__.__name__, ", ".join(
#                 (a.name + "=" + str(getattr(self, a.name))) for a in self.__attrs_attrs__))
# 
#     def _set_uncertain(self):
#         "mark this interval as uncertain and return reference to self; this is called during parsing (see hgvs.ometa)"
#         self.uncertain = True
#         return self
# 
#     def _length(self):
#         return 1 if self.end is None else self.end - self.start + 1
# 
#     @property
#     def is_uncertain(self):
#         """return True if the position is marked uncertain or undefined"""
#         return self.uncertain or self.start.is_uncertain or self.end.is_uncertain
# 
# class SimplePosition(object):
#     base = attr.ib(default=None)
#     uncertain = attr.ib(default=False)
# 
#     def __str__(self):
#         self.validate()
#         s = "?" if self.base is None else str(self.base)
#         return "(" + s + ")" if self.uncertain else s
# 
#     def format(self, conf):
#         return str(self)
# 
#     def __repr__(self):
#         return "{0}({1})".format(
#             self.__class__.__name__, ", ".join(
#                 (a.name + "=" + str(getattr(self, a.name))) for a in self.__attrs_attrs__))
# 
#     @property
#     def is_uncertain(self):
#         """return True if the position is marked uncertain or undefined"""
#         return self.uncertain or self.base is None
# 
#     def _set_uncertain(self):
#         "mark this location as uncertain and return reference to self; this is called during parsing (see hgvs.ometa)"
#         self.uncertain = True
#         return self
# 
#     def validate(self):
#         if self.base is not None and self.base < 1:
#             return (ValidationLevel.ERROR, "Position base must be >= 1")
#         return (ValidationLevel.VALID, None)
# 
#     def __sub__(lhs, rhs):
#         assert type(lhs) == type(rhs), "Cannot substract coordinates of different representations"
#         return lhs.base - rhs.base
# 
#     def __eq__(lhs, rhs):
#         assert type(lhs) == type(rhs), "Cannot compare coordinates of different representations"
#         if lhs.uncertain or rhs.uncertain:
#             raise HGVSUnsupportedOperationError("Cannot compare coordinates of uncertain positions")
#         return lhs.base == rhs.base
# 
#     def __lt__(lhs, rhs):
#         assert type(lhs) == type(rhs), "Cannot compare coordinates of different representations"
#         if lhs.uncertain or rhs.uncertain:
#             raise HGVSUnsupportedOperationError("Cannot compare coordinates of uncertain positions")
#         return lhs.base < rhs.base


import re
from bioutils.sequences import complement
from ..location import Interval, SimplePosition
from six.moves import range
    from uta_align.align.algorithms import align, cigar_alignment
        var_c = am.n_to_c(var_n)
    elif var.type == 'c':
        var_c = var
        var_g = am.c_to_g(var_c)
        var_n = am.c_to_n(var_c)
    var_p = am.c_to_p(var_c)
    return {'g': var_g, 'c': var_c, 'n': var_n, 'p': var_p}


# def variant_context(am, var, margin=20):
#     span = _span(var, margin)
#     span_g = _ival_to_span(fh['g'])
#     span_g[0] -= margin
#     span_g[1] += margin
#     return '\n'.join([
#         seq_line_fmt(var=var,
#                      span=span,
#                      content=am.hdp.get_seq(var.ac, *span),
#                      post=''), pointer_line(var, span)
#     ])


def variant_context_w_alignment(am, var, margin=20, tx_ac=None):
    """This module is experimental. It requires the uta_align package from pypi."""

    fh = full_house(am, var, tx_ac=tx_ac)
    tm = am._fetch_AlignmentMapper(fh['n'].ac, fh['g'].ac, am.alt_aln_method)
    strand = tm.strand
    span_g = _ival_to_span(fh['g'].posedit.pos)
    span_g = (span_g[0] - margin, span_g[1] + margin)

# Path: hgvs/location.py
# class Interval(object):
#     start = attr.ib(default=None)
#     end = attr.ib(default=None)
#     uncertain = attr.ib(default=False)
# 
#     def validate(self):
#         if self.start:
#             (res, msg) = self.start.validate()
#             if res != ValidationLevel.VALID:
#                 return (res, msg)
#         if self.end:
#             (res, msg) = self.end.validate()
#             if res != ValidationLevel.VALID:
#                 return (res, msg)
#         # Check start less than or equal to end
#         if not self.start or not self.end:
#             return (ValidationLevel.VALID, None)
#         try:
#             if self.start <= self.end:
#                 return (ValidationLevel.VALID, None)
#             else:
#                 return (ValidationLevel.ERROR, "base start position must be <= end position")
#         except HGVSUnsupportedOperationError as err:
#             return (ValidationLevel.WARNING, str(err))
# 
#     def format(self, conf=None):
#         if self.start is None:
#             return ""
#         if self.end is None or self.start == self.end:
#             return self.start.format(conf)
#         iv = self.start.format(conf) + "_" + self.end.format(conf)
#         return "(" + iv + ")" if self.uncertain else iv
# 
#     __str__ = format
# 
#     def __repr__(self):
#         return "{0}({1})".format(
#             self.__class__.__name__, ", ".join(
#                 (a.name + "=" + str(getattr(self, a.name))) for a in self.__attrs_attrs__))
# 
#     def _set_uncertain(self):
#         "mark this interval as uncertain and return reference to self; this is called during parsing (see hgvs.ometa)"
#         self.uncertain = True
#         return self
# 
#     def _length(self):
#         return 1 if self.end is None else self.end - self.start + 1
# 
#     @property
#     def is_uncertain(self):
#         """return True if the position is marked uncertain or undefined"""
#         return self.uncertain or self.start.is_uncertain or self.end.is_uncertain
# 
# class SimplePosition(object):
#     base = attr.ib(default=None)
#     uncertain = attr.ib(default=False)
# 
#     def __str__(self):
#         self.validate()
#         s = "?" if self.base is None else str(self.base)
#         return "(" + s + ")" if self.uncertain else s
# 
#     def format(self, conf):
#         return str(self)
# 
#     def __repr__(self):
#         return "{0}({1})".format(
#             self.__class__.__name__, ", ".join(
#                 (a.name + "=" + str(getattr(self, a.name))) for a in self.__attrs_attrs__))
# 
#     @property
#     def is_uncertain(self):
#         """return True if the position is marked uncertain or undefined"""
#         return self.uncertain or self.base is None
# 
#     def _set_uncertain(self):
#         "mark this location as uncertain and return reference to self; this is called during parsing (see hgvs.ometa)"
#         self.uncertain = True
#         return self
# 
#     def validate(self):
#         if self.base is not None and self.base < 1:
#             return (ValidationLevel.ERROR, "Position base must be >= 1")
#         return (ValidationLevel.VALID, None)
# 
#     def __sub__(lhs, rhs):
#         assert type(lhs) == type(rhs), "Cannot substract coordinates of different representations"
#         return lhs.base - rhs.base
# 
#     def __eq__(lhs, rhs):
#         assert type(lhs) == type(rhs), "Cannot compare coordinates of different representations"
#         if lhs.uncertain or rhs.uncertain:
#             raise HGVSUnsupportedOperationError("Cannot compare coordinates of uncertain positions")
#         return lhs.base == rhs.base
# 
#     def __lt__(lhs, rhs):
#         assert type(lhs) == type(rhs), "Cannot compare coordinates of different representations"
#         if lhs.uncertain or rhs.uncertain:
#             raise HGVSUnsupportedOperationError("Cannot compare coordinates of uncertain positions")
#         return lhs.base < rhs.base


# Path: hgvs/utils/context.py
import re
from bioutils.sequences import complement
from ..location import Interval, SimplePosition
from six.moves import range
    from uta_align.align.algorithms import align, cigar_alignment

        var_c = am.n_to_c(var_n)
    elif var.type == 'c':
        var_c = var
        var_g = am.c_to_g(var_c)
        var_n = am.c_to_n(var_c)
    var_p = am.c_to_p(var_c)
    return {'g': var_g, 'c': var_c, 'n': var_n, 'p': var_p}


# def variant_context(am, var, margin=20):
#     span = _span(var, margin)
#     span_g = _ival_to_span(fh['g'])
#     span_g[0] -= margin
#     span_g[1] += margin
#     return '\n'.join([
#         seq_line_fmt(var=var,
#                      span=span,
#                      content=am.hdp.get_seq(var.ac, *span),
#                      post=''), pointer_line(var, span)
#     ])


def variant_context_w_alignment(am, var, margin=20, tx_ac=None):
    """This module is experimental. It requires the uta_align package from pypi."""

    fh = full_house(am, var, tx_ac=tx_ac)
    tm = am._fetch_AlignmentMapper(fh['n'].ac, fh['g'].ac, am.alt_aln_method)
    strand = tm.strand
    span_g = _ival_to_span(fh['g'].posedit.pos)
    span_g = (span_g[0] - margin, span_g[1] + margin)

    ival_g = Interval(SimplePosition(span_g[0]), SimplePosition(span_g[1]))