-
Notifications
You must be signed in to change notification settings - Fork 13
Using py‐ard in R
Pradeep Bashyal edited this page Oct 2, 2023
·
1 revision
py-ard
requires Python 3.8 or higher. Install Python using your package manager or from Python Homepage.
You can create a virtual environment with:
cd <your-project-dir>
python3 -m venv venv
source venv/bin/activate
The R library reticulate
allows calling Python packages from R.
install.packages('reticulate')
Load reticulate
library in R.
library(reticulate)
If using virtual environments, call use_virtualenv
function to point to the virtual environment you created.
use_virtualenv('venv/')
Verify your Python environment
py_config()
This should show you the Python installation that reticulate
is using.
Install py-ard
in the Python environment
py_install('py-ard')
Import pyard
library and get the ARD
python object.
pyard <- import('pyard')
ard <- pyard$init()
reduced_alleles <- ard$redux('A*01:01:01/A*01:AB', 'lgx')
Produces:
> reduced_alleles
[1] "A*01:01/A*01:01/A*01:02"
Available reduction modes are G
, lg
, lgx
, W
and exon
.
Methods can be called on the ard
object using the $
operator. Eg. can call expand_mac
to get back a vector of expanded alleleles for a MAC code.
> ard$expand_mac("A*03:AAAUY")
[1] "A*03:01" "A*03:01N" "A*03:20" "A*03:21N" "A*03:26" "A*03:37" "A*03:45" "A*03:78"
[9] "A*03:112" "A*03:118" "A*03:129N" "A*03:132" "A*03:134" "A*03:162N" "A*03:182"