Example #1
0
def _make_position(location_string, offset=0):
    """Turn a Swiss location position into a SeqFeature position object (PRIVATE).

    An offset of -1 is used with a start location to make it pythonic.
    """
    if location_string == "?":
        return SeqFeature.UnknownPosition()
    #Hack so that feature from 0 to 0 becomes 0 to 0, not -1 to 0.
    try:
        return SeqFeature.ExactPosition(max(0, offset + int(location_string)))
    except ValueError:
        pass
    if location_string.startswith("<"):
        try:
            return SeqFeature.BeforePosition(
                max(0, offset + int(location_string[1:])))
        except ValueError:
            pass
    elif location_string.startswith(">"):  # e.g. ">13"
        try:
            return SeqFeature.AfterPosition(
                max(0, offset + int(location_string[1:])))
        except ValueError:
            pass
    elif location_string.startswith("?"):  # e.g. "?22"
        try:
            return SeqFeature.UncertainPosition(
                max(0, offset + int(location_string[1:])))
        except ValueError:
            pass
    raise NotImplementedError("Cannot parse location '%s'" % location_string)
Example #2
0
 def _parse_position(element, offset=0):
     try:
         position = int(element.attrib['position']) + offset
     except KeyError as err:
         position = None
     status = element.attrib.get('status', '')
     if status == 'unknown':
         assert position is None
         return SeqFeature.UnknownPosition()
     elif not status:
         return SeqFeature.ExactPosition(position)
     elif status == 'greater than':
         return SeqFeature.AfterPosition(position)
     elif status == 'less than':
         return SeqFeature.BeforePosition(position)
     elif status == 'uncertain':
         return SeqFeature.UncertainPosition(position)
     else:
         raise NotImplementedError("Position status %r" % status)