ngs_tools.gtf.SegmentCollection
Module Contents
Classes
Class to represent a collection of integer interval segments, zero-indexed. |
- exception ngs_tools.gtf.SegmentCollection.SegmentCollectionError
Bases:
ExceptionCommon base class for all non-exit exceptions.
- class ngs_tools.gtf.SegmentCollection.SegmentCollection(segments: Optional[List[ngs_tools.gtf.Segment.Segment]] = None)
Class to represent a collection of integer interval segments, zero-indexed. The segments are always sorted and overlaps are collapsed.
- property segments: List[ngs_tools.gtf.Segment.Segment]
Get a list of
Segmentinstances
- property start: int
Leftmost value of all segments. 0 if there are no segments.
- property end: int
Rightmost value of all segments. 0 if there are no segments.
- add_segment(segment: ngs_tools.gtf.Segment.Segment)
Add a segment to the collection.
- Parameters:
segment – Segment to add
- add_collection(collection: SegmentCollection)
Add a collection of segments to the collection.
- Parameters:
collection – Collection to add
- __iter__()
- __getitem__(i)
- __len__()
- __bool__()
- __eq__(other: SegmentCollection)
Return self==value.
- invert(bounds: ngs_tools.gtf.Segment.Segment) SegmentCollection
Invert this
SegmentCollectionwithin the givenbounds.- Parameters:
bounds – The bounds to invert with respect to.
- Returns:
A new
SegmentCollectionthat is inverted- Raises:
SegmentCollectionError – If
boundsdoes not entirely contain this collection
- collapse()
Collapse the segments in this collection such that there are no overlapping segments. Any overlapping segments are merged into a single large segment.
- span_is_exclusive(collection: SegmentCollection) bool
Evaluate whether the span of this collection is exclusive of that of another collection.
- Parameters:
collection –
SegmentCollectionobject to check- Returns:
True or False
- is_overlapping(collection: SegmentCollection) bool
Evaluate whether this collection overlaps with another collection.
- Parameters:
collection –
SegmentCollectionobject to check- Returns:
True or False
- is_subset(collection: SegmentCollection) bool
Evaluate whether this collection is a subset of another collection.
- Parameters:
collection –
SegmentCollectionobject to check- Returns:
True or False
- is_superset(collection: SegmentCollection) bool
Evaluate whether this collection is a superset of another collection.
- Parameters:
collection –
SegmentCollectionobject to check- Returns:
True or False
- flank(l: int, left: Optional[int] = None, right: Optional[int] = None) SegmentCollection
Construct a new segment collection where all the segments have start and end flanks of length
l. Optionally, limit the span of the new segment collection. This is done by callingSegment.flank()on all the segments and initializing a newSegmentCollection. Any overlaps are collapsed.- Parameters:
l – Flank length
left – Clip the resulting collection’s start to this value. Defaults to None. If not provided, no clipping is performed.
right – Clip the resulting collection’s end to this value. Defaults to None. If not provided, no clipping is performed.
- Returns:
The new collection
- classmethod from_positions(positions: Union[List[int], Set[int]]) SegmentCollection
Initialize a new collection given a list or set of integer positions.
- Parameters:
positions – Integer positions to construct the collection from
- Returns:
The new collection
- classmethod from_collections(*collections: SegmentCollection) SegmentCollection
Initialize a new collection given an arbitrary number of collections.
- Parameters:
*collections – The collections to combine
- Returns:
The new collection
- __repr__()
Return repr(self).