7 Piping PyRanges

The PyRanges API supports chaining operations out of the box.

To set a new column in a PyRanges you would use the assign method and for subsetting you would use the subset method.

import pyranges as pr
import pandas as pd
exons = pr.data.exons()
cpg = pr.data.cpg()
cpg.join(exons.unstrand()).subset(lambda df: df.CpG > 25)[["CpG"]].assign("CpGDecile", lambda df: df.CpG % 10)["chrX"].slack(500)