1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-12 05:42:18 +02:00

(v2.1.1.9126) implemented WISCA! Also added top_n_microorganisms() and fixed Python wrapper

This commit is contained in:
2025-01-26 23:01:17 +01:00
parent 92c4fc0f94
commit 66833b4f5a
46 changed files with 1786 additions and 1842 deletions

View File

@ -47,6 +47,7 @@ GREEN = '\033[32m'
RESET = '\033[0m'
import os
import sys
from rpy2 import robjects
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr, isinstalled
@ -54,7 +55,7 @@ import pandas as pd
import importlib.metadata as metadata
# Get the path to the virtual environment
venv_path = os.getenv('VIRTUAL_ENV') # Path to the active virtual environment
venv_path = sys.prefix
# Define R library path within the venv
r_lib_path = os.path.join(venv_path, "R_libs")
@ -63,10 +64,12 @@ os.makedirs(r_lib_path, exist_ok=True)
# Set the R library path in .libPaths
base = importr('base')
base._libPaths(r_lib_path)
r_amr_lib_path = base._libPaths()[0]
# Check if the AMR package is installed in R
if not isinstalled('AMR'):
if not isinstalled('AMR', lib_loc = r_amr_lib_path):
utils = importr('utils')
print(f"{BLUE}AMR:{RESET} Installing AMR package to {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
# Python package version of AMR
@ -81,7 +84,7 @@ r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_li
# Compare R and Python package versions
if r_amr_version != python_amr_version:
try:
print(f"{BLUE}AMR:{RESET} Updating package version{RESET}", flush=True)
print(f"{BLUE}AMR:{RESET} Updating AMR package in {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
utils = importr('utils')
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
except Exception as e: