8 Printing PyRanges
There are 10 helper methods for printing PyRanges. These are p/print (regular print), mp (merged position print), sp (sorted print), msp (merged position sorted print) and rp (raw print).
Merged means that the information about Chromosome, Start, End and Strand (if applicable) are merged into one column for printing. Sorted means that the output is sorted on position and Strand. Regular print shows the + strand first and - strand second, so if you want to display interleaved intervals from both strands, sorted print is the way to do it.
Raw print (rp) just prints the underlying dict of dataframes.
All print methods except rp take an n-argument to control how many entries should be displayed.
The pc, mpc, spc, mspc and rpc also return the pyranges so that print methods can be used to display intermediate results in pipes.
import pyranges as pr
= pr.data.exons()
exons =2).mpc(n=8).sp() exons.pc(n
## +--------------+-----------+-----------+-------+
## | Chromosome | Start | End | +3 |
## | (category) | (int32) | (int32) | ... |
## |--------------+-----------+-----------+-------|
## | chrX | 135721701 | 135721963 | ... |
## | ... | ... | ... | ... |
## | chrY | 15467254 | 15467278 | ... |
## +--------------+-----------+-----------+-------+
## Stranded PyRanges object has 1,000 rows and 6 columns from 2 chromosomes.
## For printing, the PyRanges was sorted on Chromosome and Strand.
## 3 hidden columns: Name, Score, Strand
## +----------------------------+----------------------------------------+-----------+
## | - Position - | Name | Score |
## | (Multiple types) | (object) | (int64) |
## |----------------------------+----------------------------------------+-----------|
## | chrX 135721701-135721963 + | NR_038462_exon_0_0_chrX_135721702_f | 0 |
## | chrX 135574120-135574598 + | NM_001727_exon_2_0_chrX_135574121_f | 0 |
## | chrX 47868945-47869126 + | NM_205856_exon_4_0_chrX_47868946_f | 0 |
## | chrX 77294333-77294480 + | NM_000052_exon_17_0_chrX_77294334_f | 0 |
## | ... | ... | ... |
## | chrY 15409586-15409728 - | NR_047633_exon_3_0_chrY_15409587_r | 0 |
## | chrY 15478146-15478273 - | NR_047634_exon_18_0_chrY_15478147_r | 0 |
## | chrY 15360258-15361762 - | NR_047601_exon_0_0_chrY_15360259_r | 0 |
## | chrY 15467254-15467278 - | NM_001258270_exon_13_0_chrY_15467255_r | 0 |
## +----------------------------+----------------------------------------+-----------+
## Stranded PyRanges object has 1,000 rows and 6 columns from 2 chromosomes.
## For printing, the PyRanges was sorted on Chromosome and Strand.
## +--------------+-----------+-----------+-------+
## | Chromosome | Start | End | +3 |
## | (category) | (int32) | (int32) | ... |
## |--------------+-----------+-----------+-------|
## | chrX | 585078 | 585337 | ... |
## | chrX | 1393647 | 1393735 | ... |
## | chrX | 1393647 | 1393735 | ... |
## | chrX | 1404670 | 1404813 | ... |
## | chrX | 1407411 | 1407535 | ... |
## | chrX | 1407651 | 1407781 | ... |
## | chrX | 1414319 | 1414349 | ... |
## | chrX | 1419383 | 1419519 | ... |
## | chrX | 1424338 | 1424420 | ... |
## | chrX | 1424338 | 1424420 | ... |
## | chrX | 1475113 | 1475229 | ... |
## | chrX | 1510791 | 1511039 | ... |
## | chrX | 1553914 | 1553976 | ... |
## | chrX | 1554586 | 1554651 | ... |
## | chrX | 1734025 | 1734161 | ... |
## | ... | ... | ... | ... |
## | chrY | 25336491 | 25336631 | ... |
## | chrY | 26778138 | 26778263 | ... |
## | chrY | 26952215 | 26952307 | ... |
## | chrY | 26979966 | 26980276 | ... |
## | chrY | 26998146 | 26998238 | ... |
## | chrY | 26998798 | 26998850 | ... |
## | chrY | 26999286 | 26999350 | ... |
## | chrY | 27003422 | 27003494 | ... |
## | chrY | 27041834 | 27041906 | ... |
## | chrY | 27197822 | 27197945 | ... |
## | chrY | 27197822 | 27197945 | ... |
## | chrY | 27606238 | 27606322 | ... |
## | chrY | 27606238 | 27606322 | ... |
## | chrY | 59222126 | 59222216 | ... |
## | chrY | 59233166 | 59233257 | ... |
## +--------------+-----------+-----------+-------+
## Stranded PyRanges object has 1,000 rows and 6 columns from 2 chromosomes.
## For printing, the PyRanges was sorted on Chromosome, Start, End and Strand.
## 3 hidden columns: Name, Score, Strand
print(n=1,
exons.=False,
merge_position=True,
sort={"Start": "{:,}", "Name": "{:2.2}"},
formatting=False) chain
## +--------------+-----------+-----------+------------+-----------+--------------+
## | Chromosome | Start | End | Name | Score | Strand |
## | (category) | (int32) | (int32) | (object) | (int64) | (category) |
## |--------------+-----------+-----------+------------+-----------+--------------|
## | ... | ... | ... | ... | ... | ... |
## +--------------+-----------+-----------+------------+-----------+--------------+
## Stranded PyRanges object has 1,000 rows and 6 columns from 2 chromosomes.
## For printing, the PyRanges was sorted on Chromosome, Start, End and Strand.
= pr.data.f1()
f1 f1.rp()
## {('chr1', '+'): Chromosome Start End Name Score Strand
## 0 chr1 3 6 interval1 0 +
## 2 chr1 8 9 interval3 0 +, ('chr1', '-'): Chromosome Start End Name Score Strand
## 1 chr1 5 7 interval2 0 -}