A thin wrapper around rpy2 with strong opinions on how data types should be converted.
Project description
rwrap
A thin wrapper around rpy2 with strong opinions on how data types should be converted. This enables easy usage of R packages from Python with no boilerplate code.
Warning: still work-in-progress, issues and PRs welcome
Installation
pip install rwrap
Usage
For example, accessing Bioconductor's biomaRt package can be as simple as follows:
from rwrap import biomaRt
biomaRt
## <module 'biomaRt' from '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/biomaRt'>
snp_list = ["rs7329174", "rs4948523", "rs479445"]
ensembl = biomaRt.useMart("ENSEMBL_MART_SNP", dataset="hsapiens_snp")
df = biomaRt.getBM(
attributes=["refsnp_id", "chr_name", "chrom_start", "consequence_type_tv"],
filters="snp_filter", values=snp_list, mart=ensembl
)
print(df) # pandas.DataFrame
## refsnp_id chr_name chrom_start consequence_type_tv
## 1 rs479445 1 60875960 intron_variant
## 2 rs479445 1 60875960 NMD_transcript_variant
## 3 rs4948523 10 58579338 intron_variant
## 4 rs7329174 13 40983974 intron_variant
Check the tests/
directory for more examples showing how to rewrite R scripts in Python.
Tests
A comprehensive test suite aims at providing stability and avoiding regressions.
The examples in tests/
are validated using pytest
.
Run tests as follows:
$ pytest tests/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rwrap-0.1.2.tar.gz
(5.7 kB
view hashes)
Built Distribution
rwrap-0.1.2-py3-none-any.whl
(6.0 kB
view hashes)