biocantor.location.location

Module Contents

Classes

Location

Abstract location with respect to a coordinate system

class biocantor.location.location.Location

Bases: inscripta.biocantor.AbstractLocation, abc.ABC

Abstract location with respect to a coordinate system

__slots__ = []
parent_to_relative_location(parent_location: Location, optimize_blocks: bool = True) Location

Converts a Location on the parent to a Location relative to this Location.

Parameters
  • parent_location – Location with the same parent as this Location. Both parents can be None.

  • optimize_blocks – Run optimize_blocks on the resulting location?

Returns

Return type

New Location relative to this Location.

location_relative_to(other: Location, optimize_blocks: bool = True) Location

Converts this Location to a Location relative to another Location. The Locations must overlap. The returned value represents the relative location of the overlap within the other Location.

If optimize_blocks is True, the resulting Location will not have any adjacent or overlapping intervals. This is often desirable, because the output of this function can have weird coordinates when the locations are overlapping or adjacent. However, there are some cases where it is desirable to retain the original block structure. One such example are CDS where adjacent blocks or overlapping blocks are used to model frameshifts or indels.

scan_windows(window_size: int, step_size: int, start_pos: int = 0) Iterator[Location]

Returns an iterator over fixed size windows within this Location. Windows represent sub-regions of this Location and are with respect to the same parent as this Location. The final window returned is the last one that fits completely within this Location. Returned windows are in order according to relative position within this Location; i.e., corresponding to the strand of this Location.

Parameters
  • window_size

  • step_size

  • start_pos – 0-based relative start position of first window relative to this Location

first_ancestor_of_type(sequence_type: Union[str, inscripta.biocantor.parent.SequenceType]) inscripta.biocantor.parent.Parent

Returns the Parent object representing the closest ancestor (parent, parent of parent, etc.) of this location which has the given sequence type. Raises NoSuchAncestorException if no ancestor with the given type exists.

has_ancestor_of_type(sequence_type: Union[str, inscripta.biocantor.parent.SequenceType]) bool

Returns True if some ancestor (parent, parent of parent, etc.) of of this location has the given sequence type, or False otherwise.

lift_over_to_first_ancestor_of_type(sequence_type: Union[str, inscripta.biocantor.parent.SequenceType]) Location

Returns a new Location representing the liftover of this Location to its closest ancestor sequence (parent, parent of parent, etc.) which has the given sequence type. If the immediate parent has the given type, returns this Location. Raises NoSuchAncestorException if no ancestor with the given type exists.

has_ancestor_sequence(sequence: inscripta.biocantor.sequence.Sequence) bool

Returns True iff this Location has some ancestor (parent, parent of parent, etc.) whose sequence attribute is equal to the given sequence

lift_over_to_sequence(sequence: inscripta.biocantor.sequence.Sequence) Location

Returns a new Location representing the liftover of this Location to the given sequence. The given sequence must be equal to the sequence attribute of some Parent in the ancestor hierarchy of this Location; otherwise, raises NoSuchAncestorException.

contains(other: Location, match_strand: bool = False, full_span: bool = False, strict_parent_compare: bool = False) bool

Returns True iff this location contains the other. If full_span is True, the full span of both locations are compared.

Parameters
  • other – Other location

  • match_strand – If set to True, automatically return EmptyLocation() if other Location has a different Strand than this Location

  • full_span – If set to True, compare the full span of this Location to the full span of the other Location.

  • strict_parent_compare – Raise MismatchedParentException if parents do not match