Use HELMshaker from R¶
HELMshaker is a Python package. Call it from R through reticulate, which runs Python in-process and converts values between the two languages.
Prerequisites¶
- Python 3.10 or later, and the path to its executable
- R
Set up the environment¶
Install reticulate and point it at your Python:
Create a virtual environment and install HELMshaker into it:
virtualenv_create("helmshaker")
use_virtualenv("helmshaker", required = TRUE)
py_install("helmshaker", envname = "helmshaker")
Add the extras you need in the same call, quoting them so the shell does not expand the brackets:
Read a molecule¶
HELMshaker ships no monomers, so supply a library. See Why a monomer library is mandatory.
hs <- import("helmshaker")
library_ <- hs$MonomerLibrary()
library_$load_from_file("monomers.json")
molecule <- hs$Molecule$from_helm(
"RNA1{[moe](A)[sp].[moe](U)[sp].[moe](G)}$$$$V2.0",
monomer_library = library_
)
molecule$to_fasta()
Note the trailing underscore in library_: library is a base R function, so
shadowing it makes for confusing scripts.
Things that differ from Python¶
| Python | R via reticulate |
|---|---|
obj.method() |
obj$method() |
Class.classmethod() |
Class$classmethod() |
keyword argument x=1 |
x = 1 |
integer 5 |
5L, since R numerics are doubles by default |
None |
NULL |
Positional integer arguments are the usual snag. replace_monomer_at("RNA1",
position = 5, ...) needs position = 5L, or reticulate passes a float and the
call fails.
Related¶
- Get started for the Python equivalents
Moleculefor the full API