Python implementation of the IRanges Bioconductor package.
An IRanges holds a start position and a width, and is typically used to represent coordinates along a genomic sequence. The interpretation of the start position depends on the application; for sequences, the start is usually a 1-based position, but other use cases may allow zero or even negative values, e.g., circular genomes.
IRanges uses nested containment lists under the hood to perform fast overlap and search based operations.
Note
These classes follow a functional paradigm for accessing or setting properties, with further details discussed in functional paradigm section.
An IRanges holds a start position and a width, and is most typically used to represent coordinates along some genomic sequence. The interpretation of the start position depends on the application; for sequences, the start is usually a 1-based position, but other use cases may allow zero or even negative values (e.g. circular genomes).
Properties can be accessed directly from the object:
print("Number of intervals:", len(ir))print("start positions:", ir.get_start())print("width of each interval:", ir.get_width())print("end positions:", ir.get_end())
Number of intervals: 8
start positions: [-2 6 9 -4 1 0 -6 10]
width of each interval: [5 0 6 1 4 3 2 3]
end positions: [ 3 6 15 -3 5 3 -4 13]
Tip
Just like BiocFrame, these classes offer both functional-style and property-based getters and setters.
print("start positions:", ir.start)print("width of each interval:", ir.width)print("end positions:", ir.end)
Other range transformation methods include narrow, resize, flank, reflect and restrict. For example narrow supports the adjustment of start, end and width values, which should be relative to each range.
IRanges object with 3 ranges and 0 metadata columns
start end width
<ndarray[int32]> <ndarray[int32]> <ndarray[int32]>
[0] 7 9 2
[1] 4 7 3
[2] 9 12 3
flank returns ranges of a specified width that flank, to the left (default) or right, each input range. One use case of this is forming promoter regions for a set of genes.