Skip to content

Instantly share code, notes, and snippets.

@endrebak
Last active December 21, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endrebak/a4b276abc7fae187bc85298fdb01fa15 to your computer and use it in GitHub Desktop.
Save endrebak/a4b276abc7fae187bc85298fdb01fa15 to your computer and use it in GitHub Desktop.
import pyranges as pr
gr = pr.PyRanges(chromosomes=["chr1"] * 2 + ["chr2"] * 2, starts=[0, 100, 200, 300], ends=[50, 150, 250, 350], strands=["+", "+", "-", "-"])
gr.spliced_subsequence(0, -75, by="gene")
+--------------+-----------+-----------+--------------+------------+
| Chromosome | Start | End | Strand | gene |
| (category) | (int64) | (int32) | (category) | (object) |
|--------------+-----------+-----------+--------------+------------|
| chr1 | 0 | 25 | + | 1 |
| chr2 | 325 | 350 | - | 2 |
+--------------+-----------+-----------+--------------+------------+
Stranded PyRanges object has 2 rows and 5 columns from 2 chromosomes.
For printing, the PyRanges was sorted on Chromosome and Strand.
gr.spliced_subsequence(-80, -10, by="gene")
+--------------+-----------+-----------+--------------+------------+
| Chromosome | Start | End | Strand | gene |
| (category) | (int64) | (int32) | (category) | (object) |
|--------------+-----------+-----------+--------------+------------|
| chr1 | 20 | 50 | + | 1 |
| chr1 | 100 | 140 | + | 1 |
| chr2 | 210 | 250 | - | 2 |
| chr2 | 300 | 330 | - | 2 |
+--------------+-----------+-----------+--------------+------------+
Stranded PyRanges object has 4 rows and 5 columns from 2 chromosomes.
For printing, the PyRanges was sorted on Chromosome and Strand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment