py8rds (python ate RDS) provides pure-Python deserialization of R .rds files, allowing you to load R data directly into Python without requiring an R installation.
- Python 3.8+
Use pip to install directly from the repository.
pip install git+https://github.com/cellgeni/py8rds.gitimport py8rds
df = py8rds.as_data_frame('data_frame.rds')
adata = py8rds.as_anndata('seurat.rds')
robj = py8rds.parse_rds('data.rds')
robj.show()Please see the tutorial.
parse_rds is the base function that reads an RDS file into a Python Robj, which has a tree-like structure. Robj has two main methods:
show(level=1)shows the object structure to the specified level.get([inx1,key2])recursively subsets the object by the provided keys/indices. EachRobjhas values that are indexed by integers (shown as+Nbyshowfunction) and slots/attributes that are indexed by keys (shown as&/*<key>byshowfunction).
Amazing blog by Danielle Navarro helped us kick-start the project, other projects such as rds2cpp helped us move forward, R source code became the last resort after meeting with the R documentation, and at the very end, ChatGPT came to our rescue.
- rds2py, based on rds2cpp, cannot read functions so fails on complex objects such as Seurat
- pyreadr, focused on simple data types such as data.frames, cannot read complex objects such as Seurat.
- rdata in addition to reading rds files it can also save python objects into rds, but it fails to read Seurat objects.
So, none of the alternatives seem able (at least at the moment) to read Seurat objects (see this notebook).