mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 08:46:12 +01:00
add Python package to repo
This commit is contained in:
parent
f424c39474
commit
87271d261a
@ -35,3 +35,4 @@
|
|||||||
^vignettes/WHONET\.Rmd$
|
^vignettes/WHONET\.Rmd$
|
||||||
^logo.svg$
|
^logo.svg$
|
||||||
^CRAN-SUBMISSION$
|
^CRAN-SUBMISSION$
|
||||||
|
^PythonPackage$
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,4 +26,3 @@ data-raw/country_analysis_url_token.R
|
|||||||
data-raw/country_analysis2.R
|
data-raw/country_analysis2.R
|
||||||
data-raw/taxonomy.csv
|
data-raw/taxonomy.csv
|
||||||
data-raw/WHONET/*
|
data-raw/WHONET/*
|
||||||
data-raw/python_wrapper/*
|
|
||||||
|
213
PythonPackage/AMR/AMR.egg-info/PKG-INFO
Normal file
213
PythonPackage/AMR/AMR.egg-info/PKG-INFO
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
Metadata-Version: 2.1
|
||||||
|
Name: AMR
|
||||||
|
Version: 2.1.1.9103
|
||||||
|
Summary: A Python wrapper for the AMR R package
|
||||||
|
Home-page: https://github.com/msberends/AMR
|
||||||
|
Author: Dr. Matthijs Berends
|
||||||
|
Author-email: m.s.berends@umcg.nl
|
||||||
|
License: GPL 2
|
||||||
|
Project-URL: Bug Tracker, https://github.com/msberends/AMR/issues
|
||||||
|
Classifier: Programming Language :: Python :: 3
|
||||||
|
Classifier: Operating System :: OS Independent
|
||||||
|
Requires-Python: >=3.6
|
||||||
|
Description-Content-Type: text/markdown
|
||||||
|
Requires-Dist: rpy2
|
||||||
|
Requires-Dist: numpy
|
||||||
|
Requires-Dist: pandas
|
||||||
|
|
||||||
|
---
|
||||||
|
title: "AMR for Python"
|
||||||
|
output:
|
||||||
|
rmarkdown::html_vignette:
|
||||||
|
toc: true
|
||||||
|
toc_depth: 3
|
||||||
|
vignette: >
|
||||||
|
%\VignetteIndexEntry{AMR for Python}
|
||||||
|
%\VignetteEncoding{UTF-8}
|
||||||
|
%\VignetteEngine{knitr::rmarkdown}
|
||||||
|
editor_options:
|
||||||
|
chunk_output_type: console
|
||||||
|
---
|
||||||
|
|
||||||
|
```{r setup, include = FALSE, results = 'markup'}
|
||||||
|
knitr::opts_chunk$set(
|
||||||
|
warning = FALSE,
|
||||||
|
collapse = TRUE,
|
||||||
|
comment = "#>",
|
||||||
|
fig.width = 7.5,
|
||||||
|
fig.height = 5
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
|
||||||
|
The `AMR` package for R is a powerful tool for antimicrobial resistance (AMR) analysis. It provides extensive features for handling microbial and antimicrobial data. However, for those who work primarily in Python, we now have a more intuitive option available: the [`AMR` Python Package Index](https://pypi.org/project/AMR/).
|
||||||
|
|
||||||
|
This Python package is a wrapper round the `AMR` R package. It uses the `rpy2` package internally. Despite the need to have R installed, Python users can now easily work with AMR data directly through Python code.
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
1. Since the Python package is available on the official [Python Package Index](https://pypi.org/project/AMR/), you can just run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install AMR
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Make sure you have R installed. There is **no need to install the `AMR` R package**, as it will be installed automatically.
|
||||||
|
|
||||||
|
For Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu / Debian
|
||||||
|
sudo apt install r-base
|
||||||
|
# Fedora:
|
||||||
|
sudo dnf install R
|
||||||
|
# CentOS/RHEL
|
||||||
|
sudo yum install R
|
||||||
|
```
|
||||||
|
|
||||||
|
For macOS (using [Homebrew](https://brew.sh)):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install r
|
||||||
|
```
|
||||||
|
|
||||||
|
For Windows, visit the [CRAN download page](https://cran.r-project.org) to download and install R.
|
||||||
|
|
||||||
|
# Examples of Usage
|
||||||
|
|
||||||
|
## Cleaning Taxonomy
|
||||||
|
|
||||||
|
Here’s an example that demonstrates how to clean microorganism and drug names using the `AMR` Python package:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pandas as pd
|
||||||
|
import AMR
|
||||||
|
|
||||||
|
# Sample data
|
||||||
|
data = {
|
||||||
|
"MOs": ['E. coli', 'ESCCOL', 'esco', 'Esche coli'],
|
||||||
|
"Drug": ['Cipro', 'CIP', 'J01MA02', 'Ciproxin']
|
||||||
|
}
|
||||||
|
df = pd.DataFrame(data)
|
||||||
|
|
||||||
|
# Use AMR functions to clean microorganism and drug names
|
||||||
|
df['MO_clean'] = AMR.mo_name(df['MOs'])
|
||||||
|
df['Drug_clean'] = AMR.ab_name(df['Drug'])
|
||||||
|
|
||||||
|
# Display the results
|
||||||
|
print(df)
|
||||||
|
```
|
||||||
|
|
||||||
|
| MOs | Drug | MO_clean | Drug_clean |
|
||||||
|
|-------------|-----------|--------------------|---------------|
|
||||||
|
| E. coli | Cipro | Escherichia coli | Ciprofloxacin |
|
||||||
|
| ESCCOL | CIP | Escherichia coli | Ciprofloxacin |
|
||||||
|
| esco | J01MA02 | Escherichia coli | Ciprofloxacin |
|
||||||
|
| Esche coli | Ciproxin | Escherichia coli | Ciprofloxacin |
|
||||||
|
|
||||||
|
### Explanation
|
||||||
|
|
||||||
|
* **mo_name:** This function standardises microorganism names. Here, different variations of *Escherichia coli* (such as "E. coli", "ESCCOL", "esco", and "Esche coli") are all converted into the correct, standardised form, "Escherichia coli".
|
||||||
|
|
||||||
|
* **ab_name**: Similarly, this function standardises antimicrobial names. The different representations of ciprofloxacin (e.g., "Cipro", "CIP", "J01MA02", and "Ciproxin") are all converted to the standard name, "Ciprofloxacin".
|
||||||
|
|
||||||
|
|
||||||
|
## Taxonomic Data Sets Now in Python!
|
||||||
|
|
||||||
|
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antibiotics`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
|
||||||
|
|
||||||
|
```python
|
||||||
|
AMR.microorganisms
|
||||||
|
```
|
||||||
|
|
||||||
|
| mo | fullname | status | kingdom | gbif | gbif_parent | gbif_renamed_to | prevalence |
|
||||||
|
|--------------|------------------------------------|----------|----------|-----------|-------------|-----------------|------------|
|
||||||
|
| B_GRAMN | (unknown Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_GRAMP | (unknown Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ANAER-NEG | (unknown anaerobic Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ANAER-POS | (unknown anaerobic Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ANAER | (unknown anaerobic bacteria) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||||
|
| B_ZYMMN_POMC | Zymomonas pomaceae | accepted | Bacteria | 10744418 | 3221412 | None | 2.0 |
|
||||||
|
| B_ZYMPH | Zymophilus | synonym | Bacteria | None | 9475166 | None | 2.0 |
|
||||||
|
| B_ZYMPH_PCVR | Zymophilus paucivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ZYMPH_RFFN | Zymophilus raffinosivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||||
|
| F_ZYZYG | Zyzygomyces | unknown | Fungi | None | 7581 | None | 2.0 |
|
||||||
|
|
||||||
|
```python
|
||||||
|
AMR.antibiotics
|
||||||
|
```
|
||||||
|
|
||||||
|
| ab | cid | name | group | oral_ddd | oral_units | iv_ddd | iv_units |
|
||||||
|
|-----|-------------|----------------------|----------------------------|----------|------------|--------|----------|
|
||||||
|
| AMA | 4649.0 | 4-aminosalicylic acid| Antimycobacterials | 12.00 | g | NaN | None |
|
||||||
|
| ACM | 6450012.0 | Acetylmidecamycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||||
|
| ASP | 49787020.0 | Acetylspiramycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||||
|
| ALS | 8954.0 | Aldesulfone sodium | Other antibacterials | 0.33 | g | NaN | None |
|
||||||
|
| AMK | 37768.0 | Amikacin | Aminoglycosides | NaN | None | 1.0 | g |
|
||||||
|
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||||
|
| VIR | 11979535.0 | Virginiamycine | Other antibacterials | NaN | None | NaN | None |
|
||||||
|
| VOR | 71616.0 | Voriconazole | Antifungals/antimycotics | 0.40 | g | 0.4 | g |
|
||||||
|
| XBR | 72144.0 | Xibornol | Other antibacterials | NaN | None | NaN | None |
|
||||||
|
| ZID | 77846445.0 | Zidebactam | Other antibacterials | NaN | None | NaN | None |
|
||||||
|
| ZFD | NaN | Zoliflodacin | None | NaN | None | NaN | None |
|
||||||
|
|
||||||
|
|
||||||
|
## Calculating AMR
|
||||||
|
|
||||||
|
```python
|
||||||
|
import AMR
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
df = AMR.example_isolates
|
||||||
|
result = AMR.resistance(df["AMX"])
|
||||||
|
print(result)
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
[0.59555556]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Generating Antibiograms
|
||||||
|
|
||||||
|
One of the core functions of the `AMR` package is generating an antibiogram, a table that summarises the antimicrobial susceptibility of bacterial isolates. Here’s how you can generate an antibiogram from Python:
|
||||||
|
|
||||||
|
```python
|
||||||
|
result2a = AMR.antibiogram(df[["mo", "AMX", "CIP", "TZP"]])
|
||||||
|
print(result2a)
|
||||||
|
```
|
||||||
|
|
||||||
|
| Pathogen | Amoxicillin | Ciprofloxacin | Piperacillin/tazobactam |
|
||||||
|
|-----------------|-----------------|-----------------|--------------------------|
|
||||||
|
| CoNS | 7% (10/142) | 73% (183/252) | 30% (10/33) |
|
||||||
|
| E. coli | 50% (196/392) | 88% (399/456) | 94% (393/416) |
|
||||||
|
| K. pneumoniae | 0% (0/58) | 96% (53/55) | 89% (47/53) |
|
||||||
|
| P. aeruginosa | 0% (0/30) | 100% (30/30) | None |
|
||||||
|
| P. mirabilis | None | 94% (34/36) | None |
|
||||||
|
| S. aureus | 6% (8/131) | 90% (171/191) | None |
|
||||||
|
| S. epidermidis | 1% (1/91) | 64% (87/136) | None |
|
||||||
|
| S. hominis | None | 80% (56/70) | None |
|
||||||
|
| S. pneumoniae | 100% (112/112) | None | 100% (112/112) |
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
result2b = AMR.antibiogram(df[["mo", "AMX", "CIP", "TZP"]], mo_transform = "gramstain")
|
||||||
|
print(result2b)
|
||||||
|
```
|
||||||
|
|
||||||
|
| Pathogen | Amoxicillin | Ciprofloxacin | Piperacillin/tazobactam |
|
||||||
|
|----------------|-----------------|------------------|--------------------------|
|
||||||
|
| Gram-negative | 36% (226/631) | 91% (621/684) | 88% (565/641) |
|
||||||
|
| Gram-positive | 43% (305/703) | 77% (560/724) | 86% (296/345) |
|
||||||
|
|
||||||
|
|
||||||
|
In this example, we generate an antibiogram by selecting various antibiotics.
|
||||||
|
|
||||||
|
# Conclusion
|
||||||
|
|
||||||
|
With the `AMR` Python package, Python users can now effortlessly call R functions from the `AMR` R package. This eliminates the need for complex `rpy2` configurations and provides a clean, easy-to-use interface for antimicrobial resistance analysis. The examples provided above demonstrate how this can be applied to typical workflows, such as standardising microorganism and antimicrobial names or calculating resistance.
|
||||||
|
|
||||||
|
By just running `import AMR`, users can seamlessly integrate the robust features of the R `AMR` package into Python workflows.
|
||||||
|
|
||||||
|
Whether you're cleaning data or analysing resistance patterns, the `AMR` Python package makes it easy to work with AMR data in Python.
|
10
PythonPackage/AMR/AMR.egg-info/SOURCES.txt
Normal file
10
PythonPackage/AMR/AMR.egg-info/SOURCES.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
README.md
|
||||||
|
setup.py
|
||||||
|
AMR/__init__.py
|
||||||
|
AMR/datasets.py
|
||||||
|
AMR/functions.py
|
||||||
|
AMR.egg-info/PKG-INFO
|
||||||
|
AMR.egg-info/SOURCES.txt
|
||||||
|
AMR.egg-info/dependency_links.txt
|
||||||
|
AMR.egg-info/requires.txt
|
||||||
|
AMR.egg-info/top_level.txt
|
1
PythonPackage/AMR/AMR.egg-info/dependency_links.txt
Normal file
1
PythonPackage/AMR/AMR.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
3
PythonPackage/AMR/AMR.egg-info/requires.txt
Normal file
3
PythonPackage/AMR/AMR.egg-info/requires.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
rpy2
|
||||||
|
numpy
|
||||||
|
pandas
|
1
PythonPackage/AMR/AMR.egg-info/top_level.txt
Normal file
1
PythonPackage/AMR/AMR.egg-info/top_level.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
AMR
|
201
PythonPackage/AMR/AMR/__init__.py
Normal file
201
PythonPackage/AMR/AMR/__init__.py
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
from .datasets import example_isolates
|
||||||
|
from .datasets import microorganisms
|
||||||
|
from .datasets import antibiotics
|
||||||
|
from .datasets import clinical_breakpoints
|
||||||
|
from .functions import ab_from_text
|
||||||
|
from .functions import ab_name
|
||||||
|
from .functions import ab_cid
|
||||||
|
from .functions import ab_synonyms
|
||||||
|
from .functions import ab_tradenames
|
||||||
|
from .functions import ab_group
|
||||||
|
from .functions import ab_atc
|
||||||
|
from .functions import ab_atc_group1
|
||||||
|
from .functions import ab_atc_group2
|
||||||
|
from .functions import ab_loinc
|
||||||
|
from .functions import ab_ddd
|
||||||
|
from .functions import ab_ddd_units
|
||||||
|
from .functions import ab_info
|
||||||
|
from .functions import ab_url
|
||||||
|
from .functions import ab_property
|
||||||
|
from .functions import add_custom_antimicrobials
|
||||||
|
from .functions import clear_custom_antimicrobials
|
||||||
|
from .functions import add_custom_microorganisms
|
||||||
|
from .functions import clear_custom_microorganisms
|
||||||
|
from .functions import age
|
||||||
|
from .functions import age_groups
|
||||||
|
from .functions import antibiogram
|
||||||
|
from .functions import ab_class
|
||||||
|
from .functions import ab_selector
|
||||||
|
from .functions import aminoglycosides
|
||||||
|
from .functions import aminopenicillins
|
||||||
|
from .functions import antifungals
|
||||||
|
from .functions import antimycobacterials
|
||||||
|
from .functions import betalactams
|
||||||
|
from .functions import carbapenems
|
||||||
|
from .functions import cephalosporins
|
||||||
|
from .functions import cephalosporins_1st
|
||||||
|
from .functions import cephalosporins_2nd
|
||||||
|
from .functions import cephalosporins_3rd
|
||||||
|
from .functions import cephalosporins_4th
|
||||||
|
from .functions import cephalosporins_5th
|
||||||
|
from .functions import fluoroquinolones
|
||||||
|
from .functions import glycopeptides
|
||||||
|
from .functions import lincosamides
|
||||||
|
from .functions import lipoglycopeptides
|
||||||
|
from .functions import macrolides
|
||||||
|
from .functions import nitrofurans
|
||||||
|
from .functions import oxazolidinones
|
||||||
|
from .functions import penicillins
|
||||||
|
from .functions import polymyxins
|
||||||
|
from .functions import quinolones
|
||||||
|
from .functions import rifamycins
|
||||||
|
from .functions import streptogramins
|
||||||
|
from .functions import tetracyclines
|
||||||
|
from .functions import trimethoprims
|
||||||
|
from .functions import ureidopenicillins
|
||||||
|
from .functions import administrable_per_os
|
||||||
|
from .functions import administrable_iv
|
||||||
|
from .functions import not_intrinsic_resistant
|
||||||
|
from .functions import as_ab
|
||||||
|
from .functions import is_ab
|
||||||
|
from .functions import as_av
|
||||||
|
from .functions import is_av
|
||||||
|
from .functions import as_disk
|
||||||
|
from .functions import is_disk
|
||||||
|
from .functions import as_mic
|
||||||
|
from .functions import is_mic
|
||||||
|
from .functions import rescale_mic
|
||||||
|
from .functions import as_mo
|
||||||
|
from .functions import is_mo
|
||||||
|
from .functions import mo_uncertainties
|
||||||
|
from .functions import mo_renamed
|
||||||
|
from .functions import mo_failures
|
||||||
|
from .functions import mo_reset_session
|
||||||
|
from .functions import mo_cleaning_regex
|
||||||
|
from .functions import as_sir
|
||||||
|
from .functions import is_sir
|
||||||
|
from .functions import is_sir_eligible
|
||||||
|
from .functions import sir_interpretation_history
|
||||||
|
from .functions import atc_online_property
|
||||||
|
from .functions import atc_online_groups
|
||||||
|
from .functions import atc_online_ddd
|
||||||
|
from .functions import atc_online_ddd_units
|
||||||
|
from .functions import av_from_text
|
||||||
|
from .functions import av_name
|
||||||
|
from .functions import av_cid
|
||||||
|
from .functions import av_synonyms
|
||||||
|
from .functions import av_tradenames
|
||||||
|
from .functions import av_group
|
||||||
|
from .functions import av_atc
|
||||||
|
from .functions import av_loinc
|
||||||
|
from .functions import av_ddd
|
||||||
|
from .functions import av_ddd_units
|
||||||
|
from .functions import av_info
|
||||||
|
from .functions import av_url
|
||||||
|
from .functions import av_property
|
||||||
|
from .functions import availability
|
||||||
|
from .functions import bug_drug_combinations
|
||||||
|
from .functions import count_resistant
|
||||||
|
from .functions import count_susceptible
|
||||||
|
from .functions import count_S
|
||||||
|
from .functions import count_SI
|
||||||
|
from .functions import count_I
|
||||||
|
from .functions import count_IR
|
||||||
|
from .functions import count_R
|
||||||
|
from .functions import count_all
|
||||||
|
from .functions import n_sir
|
||||||
|
from .functions import count_df
|
||||||
|
from .functions import custom_eucast_rules
|
||||||
|
from .functions import eucast_rules
|
||||||
|
from .functions import eucast_dosage
|
||||||
|
from .functions import export_ncbi_biosample
|
||||||
|
from .functions import first_isolate
|
||||||
|
from .functions import filter_first_isolate
|
||||||
|
from .functions import g_test
|
||||||
|
from .functions import is_new_episode
|
||||||
|
from .functions import ggplot_pca
|
||||||
|
from .functions import ggplot_sir
|
||||||
|
from .functions import geom_sir
|
||||||
|
from .functions import theme_sir
|
||||||
|
from .functions import labels_sir_count
|
||||||
|
from .functions import guess_ab_col
|
||||||
|
from .functions import italicise_taxonomy
|
||||||
|
from .functions import italicize_taxonomy
|
||||||
|
from .functions import inner_join_microorganisms
|
||||||
|
from .functions import left_join_microorganisms
|
||||||
|
from .functions import right_join_microorganisms
|
||||||
|
from .functions import full_join_microorganisms
|
||||||
|
from .functions import semi_join_microorganisms
|
||||||
|
from .functions import anti_join_microorganisms
|
||||||
|
from .functions import key_antimicrobials
|
||||||
|
from .functions import all_antimicrobials
|
||||||
|
from .functions import antimicrobials_equal
|
||||||
|
from .functions import kurtosis
|
||||||
|
from .functions import like
|
||||||
|
from .functions import mdro
|
||||||
|
from .functions import custom_mdro_guideline
|
||||||
|
from .functions import brmo
|
||||||
|
from .functions import mrgn
|
||||||
|
from .functions import mdr_tb
|
||||||
|
from .functions import mdr_cmi2012
|
||||||
|
from .functions import eucast_exceptional_phenotypes
|
||||||
|
from .functions import mean_amr_distance
|
||||||
|
from .functions import amr_distance_from_row
|
||||||
|
from .functions import mo_matching_score
|
||||||
|
from .functions import mo_name
|
||||||
|
from .functions import mo_fullname
|
||||||
|
from .functions import mo_shortname
|
||||||
|
from .functions import mo_subspecies
|
||||||
|
from .functions import mo_species
|
||||||
|
from .functions import mo_genus
|
||||||
|
from .functions import mo_family
|
||||||
|
from .functions import mo_order
|
||||||
|
from .functions import mo_class
|
||||||
|
from .functions import mo_phylum
|
||||||
|
from .functions import mo_kingdom
|
||||||
|
from .functions import mo_domain
|
||||||
|
from .functions import mo_type
|
||||||
|
from .functions import mo_status
|
||||||
|
from .functions import mo_pathogenicity
|
||||||
|
from .functions import mo_gramstain
|
||||||
|
from .functions import mo_is_gram_negative
|
||||||
|
from .functions import mo_is_gram_positive
|
||||||
|
from .functions import mo_is_yeast
|
||||||
|
from .functions import mo_is_intrinsic_resistant
|
||||||
|
from .functions import mo_oxygen_tolerance
|
||||||
|
from .functions import mo_is_anaerobic
|
||||||
|
from .functions import mo_snomed
|
||||||
|
from .functions import mo_ref
|
||||||
|
from .functions import mo_authors
|
||||||
|
from .functions import mo_year
|
||||||
|
from .functions import mo_lpsn
|
||||||
|
from .functions import mo_mycobank
|
||||||
|
from .functions import mo_gbif
|
||||||
|
from .functions import mo_rank
|
||||||
|
from .functions import mo_taxonomy
|
||||||
|
from .functions import mo_synonyms
|
||||||
|
from .functions import mo_current
|
||||||
|
from .functions import mo_group_members
|
||||||
|
from .functions import mo_info
|
||||||
|
from .functions import mo_url
|
||||||
|
from .functions import mo_property
|
||||||
|
from .functions import pca
|
||||||
|
from .functions import resistance
|
||||||
|
from .functions import susceptibility
|
||||||
|
from .functions import sir_confidence_interval
|
||||||
|
from .functions import proportion_R
|
||||||
|
from .functions import proportion_IR
|
||||||
|
from .functions import proportion_I
|
||||||
|
from .functions import proportion_SI
|
||||||
|
from .functions import proportion_S
|
||||||
|
from .functions import proportion_df
|
||||||
|
from .functions import sir_df
|
||||||
|
from .functions import random_mic
|
||||||
|
from .functions import random_disk
|
||||||
|
from .functions import random_sir
|
||||||
|
from .functions import resistance_predict
|
||||||
|
from .functions import sir_predict
|
||||||
|
from .functions import ggplot_sir_predict
|
||||||
|
from .functions import skewness
|
||||||
|
from .functions import reset_AMR_locale
|
||||||
|
from .functions import translate_AMR
|
73
PythonPackage/AMR/AMR/datasets.py
Normal file
73
PythonPackage/AMR/AMR/datasets.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
BLUE = '\033[94m'
|
||||||
|
GREEN = '\033[32m'
|
||||||
|
RESET = '\033[0m'
|
||||||
|
|
||||||
|
print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
from rpy2 import robjects
|
||||||
|
from rpy2.robjects import pandas2ri
|
||||||
|
from rpy2.robjects.packages import importr, isinstalled
|
||||||
|
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
|
||||||
|
if not venv_path:
|
||||||
|
raise EnvironmentError("No virtual environment detected. Please activate your Python virtual environment.")
|
||||||
|
|
||||||
|
# Define R library path within the venv
|
||||||
|
r_lib_path = os.path.join(venv_path, "R_libs")
|
||||||
|
# Ensure the R library path exists
|
||||||
|
os.makedirs(r_lib_path, exist_ok=True)
|
||||||
|
# Set the R library path in .libPaths
|
||||||
|
base = importr('base')
|
||||||
|
base._libPaths(r_lib_path)
|
||||||
|
|
||||||
|
# Check if the AMR package is installed in R
|
||||||
|
if not isinstalled('AMR'):
|
||||||
|
utils = importr('utils')
|
||||||
|
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
|
||||||
|
|
||||||
|
# Python package version of AMR
|
||||||
|
try:
|
||||||
|
python_amr_version = metadata.version('AMR')
|
||||||
|
except metadata.PackageNotFoundError:
|
||||||
|
python_amr_version = None
|
||||||
|
|
||||||
|
# R package version of AMR
|
||||||
|
r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_lib_path}"))')[0]
|
||||||
|
|
||||||
|
# Compare R and Python package versions
|
||||||
|
if python_amr_version and r_amr_version != python_amr_version:
|
||||||
|
try:
|
||||||
|
utils = importr('utils')
|
||||||
|
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True)
|
||||||
|
|
||||||
|
# Activate the automatic conversion between R and pandas DataFrames
|
||||||
|
pandas2ri.activate()
|
||||||
|
|
||||||
|
# example_isolates
|
||||||
|
example_isolates = pandas2ri.rpy2py(robjects.r('''
|
||||||
|
df <- AMR::example_isolates
|
||||||
|
df[] <- lapply(df, function(x) {
|
||||||
|
if (inherits(x, c("Date", "POSIXt", "factor"))) {
|
||||||
|
as.character(x)
|
||||||
|
} else {
|
||||||
|
x
|
||||||
|
}
|
||||||
|
})
|
||||||
|
df <- df[, !sapply(df, is.list)]
|
||||||
|
df
|
||||||
|
'''))
|
||||||
|
example_isolates['date'] = pd.to_datetime(example_isolates['date'])
|
||||||
|
|
||||||
|
# microorganisms
|
||||||
|
microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR::microorganisms, is.list)]'))
|
||||||
|
antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]'))
|
||||||
|
clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]'))
|
||||||
|
|
||||||
|
print(f"{BLUE}AMR:{RESET} {GREEN}Done.{RESET}", flush=True)
|
629
PythonPackage/AMR/AMR/functions.py
Normal file
629
PythonPackage/AMR/AMR/functions.py
Normal file
@ -0,0 +1,629 @@
|
|||||||
|
import rpy2.robjects as robjects
|
||||||
|
from rpy2.robjects.packages import importr
|
||||||
|
from rpy2.robjects.vectors import StrVector, FactorVector, IntVector, FloatVector, DataFrame
|
||||||
|
from rpy2.robjects import pandas2ri
|
||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Activate automatic conversion between R data frames and pandas data frames
|
||||||
|
pandas2ri.activate()
|
||||||
|
|
||||||
|
# Import the AMR R package
|
||||||
|
amr_r = importr('AMR')
|
||||||
|
|
||||||
|
def convert_to_python(r_output):
|
||||||
|
# Check if it's a StrVector (R character vector)
|
||||||
|
if isinstance(r_output, StrVector):
|
||||||
|
return list(r_output) # Convert to a Python list of strings
|
||||||
|
|
||||||
|
# Check if it's a FactorVector (R factor)
|
||||||
|
elif isinstance(r_output, FactorVector):
|
||||||
|
return list(r_output) # Convert to a list of integers (factor levels)
|
||||||
|
|
||||||
|
# Check if it's an IntVector or FloatVector (numeric R vectors)
|
||||||
|
elif isinstance(r_output, (IntVector, FloatVector)):
|
||||||
|
return list(r_output) # Convert to a Python list of integers or floats
|
||||||
|
|
||||||
|
# Check if it's a pandas-compatible R data frame
|
||||||
|
elif isinstance(r_output, pd.DataFrame):
|
||||||
|
return r_output # Return as pandas DataFrame (already converted by pandas2ri)
|
||||||
|
elif isinstance(r_output, DataFrame):
|
||||||
|
return pandas2ri.rpy2py(r_output) # Return as pandas DataFrame
|
||||||
|
|
||||||
|
# Check if the input is a NumPy array and has a string data type
|
||||||
|
if isinstance(r_output, np.ndarray) and np.issubdtype(r_output.dtype, np.str_):
|
||||||
|
return r_output.tolist() # Convert to a regular Python list
|
||||||
|
|
||||||
|
# Fall-back
|
||||||
|
return r_output
|
||||||
|
def ab_from_text(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_from_text(*args, **kwargs))
|
||||||
|
def ab_name(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_name(x, *args, **kwargs))
|
||||||
|
def ab_cid(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_cid(x, *args, **kwargs))
|
||||||
|
def ab_synonyms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_synonyms(x, *args, **kwargs))
|
||||||
|
def ab_tradenames(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_tradenames(x, *args, **kwargs))
|
||||||
|
def ab_group(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_group(x, *args, **kwargs))
|
||||||
|
def ab_atc(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_atc(x, *args, **kwargs))
|
||||||
|
def ab_atc_group1(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_atc_group1(x, *args, **kwargs))
|
||||||
|
def ab_atc_group2(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_atc_group2(x, *args, **kwargs))
|
||||||
|
def ab_loinc(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_loinc(x, *args, **kwargs))
|
||||||
|
def ab_ddd(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_ddd(x, *args, **kwargs))
|
||||||
|
def ab_ddd_units(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_ddd_units(x, *args, **kwargs))
|
||||||
|
def ab_info(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_info(x, *args, **kwargs))
|
||||||
|
def ab_url(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_url(x, *args, **kwargs))
|
||||||
|
def ab_property(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_property(x, *args, **kwargs))
|
||||||
|
def add_custom_antimicrobials(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.add_custom_antimicrobials(x))
|
||||||
|
def clear_custom_antimicrobials(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.clear_custom_antimicrobials(*args, **kwargs))
|
||||||
|
def add_custom_microorganisms(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.add_custom_microorganisms(x))
|
||||||
|
def clear_custom_microorganisms(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.clear_custom_microorganisms(*args, **kwargs))
|
||||||
|
def age(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.age(x, *args, **kwargs))
|
||||||
|
def age_groups(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.age_groups(x, *args, **kwargs))
|
||||||
|
def antibiogram(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.antibiogram(*args, **kwargs))
|
||||||
|
def ab_class(ab_class, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_class(ab_class, *args, **kwargs))
|
||||||
|
def ab_selector(filter, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ab_selector(filter, *args, **kwargs))
|
||||||
|
def aminoglycosides(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.aminoglycosides(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def aminopenicillins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.aminopenicillins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def antifungals(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.antifungals(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def antimycobacterials(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.antimycobacterials(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def betalactams(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.betalactams(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def carbapenems(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.carbapenems(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def cephalosporins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.cephalosporins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def cephalosporins_1st(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.cephalosporins_1st(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def cephalosporins_2nd(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.cephalosporins_2nd(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def cephalosporins_3rd(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.cephalosporins_3rd(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def cephalosporins_4th(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.cephalosporins_4th(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def cephalosporins_5th(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.cephalosporins_5th(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def fluoroquinolones(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.fluoroquinolones(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def glycopeptides(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.glycopeptides(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def lincosamides(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.lincosamides(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def lipoglycopeptides(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.lipoglycopeptides(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def macrolides(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.macrolides(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def nitrofurans(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.nitrofurans(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def oxazolidinones(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.oxazolidinones(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def penicillins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.penicillins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def polymyxins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.polymyxins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def quinolones(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.quinolones(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def rifamycins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.rifamycins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def streptogramins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.streptogramins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def tetracyclines(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.tetracyclines(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def trimethoprims(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.trimethoprims(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def ureidopenicillins(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ureidopenicillins(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def administrable_per_os(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.administrable_per_os(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def administrable_iv(only_sir_columns = False, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.administrable_iv(only_sir_columns = False, *args, **kwargs))
|
||||||
|
def not_intrinsic_resistant(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.not_intrinsic_resistant(*args, **kwargs))
|
||||||
|
def as_ab(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.as_ab(x, *args, **kwargs))
|
||||||
|
def is_ab(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_ab(x))
|
||||||
|
def as_av(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.as_av(x, *args, **kwargs))
|
||||||
|
def is_av(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_av(x))
|
||||||
|
def as_disk(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.as_disk(x, *args, **kwargs))
|
||||||
|
def is_disk(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_disk(x))
|
||||||
|
def as_mic(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.as_mic(x, *args, **kwargs))
|
||||||
|
def is_mic(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_mic(x))
|
||||||
|
def rescale_mic(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.rescale_mic(x, *args, **kwargs))
|
||||||
|
def as_mo(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.as_mo(*args, **kwargs))
|
||||||
|
def is_mo(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_mo(x))
|
||||||
|
def mo_uncertainties(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_uncertainties(*args, **kwargs))
|
||||||
|
def mo_renamed(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_renamed(*args, **kwargs))
|
||||||
|
def mo_failures(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_failures(*args, **kwargs))
|
||||||
|
def mo_reset_session(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_reset_session(*args, **kwargs))
|
||||||
|
def mo_cleaning_regex(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_cleaning_regex(*args, **kwargs))
|
||||||
|
def as_sir(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.as_sir(x, *args, **kwargs))
|
||||||
|
def is_sir(x):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_sir(x))
|
||||||
|
def is_sir_eligible(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_sir_eligible(x, *args, **kwargs))
|
||||||
|
def sir_interpretation_history(clean):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.sir_interpretation_history(clean))
|
||||||
|
def atc_online_property(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.atc_online_property(*args, **kwargs))
|
||||||
|
def atc_online_groups(atc_code, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.atc_online_groups(atc_code, *args, **kwargs))
|
||||||
|
def atc_online_ddd(atc_code, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.atc_online_ddd(atc_code, *args, **kwargs))
|
||||||
|
def atc_online_ddd_units(atc_code, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.atc_online_ddd_units(atc_code, *args, **kwargs))
|
||||||
|
def av_from_text(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_from_text(*args, **kwargs))
|
||||||
|
def av_name(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_name(x, *args, **kwargs))
|
||||||
|
def av_cid(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_cid(x, *args, **kwargs))
|
||||||
|
def av_synonyms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_synonyms(x, *args, **kwargs))
|
||||||
|
def av_tradenames(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_tradenames(x, *args, **kwargs))
|
||||||
|
def av_group(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_group(x, *args, **kwargs))
|
||||||
|
def av_atc(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_atc(x, *args, **kwargs))
|
||||||
|
def av_loinc(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_loinc(x, *args, **kwargs))
|
||||||
|
def av_ddd(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_ddd(x, *args, **kwargs))
|
||||||
|
def av_ddd_units(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_ddd_units(x, *args, **kwargs))
|
||||||
|
def av_info(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_info(x, *args, **kwargs))
|
||||||
|
def av_url(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_url(x, *args, **kwargs))
|
||||||
|
def av_property(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.av_property(x, *args, **kwargs))
|
||||||
|
def availability(tbl, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.availability(tbl, *args, **kwargs))
|
||||||
|
def bug_drug_combinations(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.bug_drug_combinations(x, *args, **kwargs))
|
||||||
|
def count_resistant(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_resistant(*args, **kwargs))
|
||||||
|
def count_susceptible(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_susceptible(*args, **kwargs))
|
||||||
|
def count_S(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_S(*args, **kwargs))
|
||||||
|
def count_SI(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_SI(*args, **kwargs))
|
||||||
|
def count_I(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_I(*args, **kwargs))
|
||||||
|
def count_IR(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_IR(*args, **kwargs))
|
||||||
|
def count_R(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_R(*args, **kwargs))
|
||||||
|
def count_all(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_all(*args, **kwargs))
|
||||||
|
def n_sir(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.n_sir(*args, **kwargs))
|
||||||
|
def count_df(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.count_df(*args, **kwargs))
|
||||||
|
def custom_eucast_rules(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.custom_eucast_rules(*args, **kwargs))
|
||||||
|
def eucast_rules(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.eucast_rules(*args, **kwargs))
|
||||||
|
def eucast_dosage(ab, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.eucast_dosage(ab, *args, **kwargs))
|
||||||
|
def export_ncbi_biosample(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.export_ncbi_biosample(*args, **kwargs))
|
||||||
|
def first_isolate(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.first_isolate(*args, **kwargs))
|
||||||
|
def filter_first_isolate(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.filter_first_isolate(*args, **kwargs))
|
||||||
|
def g_test(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.g_test(x, *args, **kwargs))
|
||||||
|
def is_new_episode(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.is_new_episode(x, *args, **kwargs))
|
||||||
|
def ggplot_pca(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ggplot_pca(*args, **kwargs))
|
||||||
|
def ggplot_sir(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ggplot_sir(*args, **kwargs))
|
||||||
|
def geom_sir(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.geom_sir(*args, **kwargs))
|
||||||
|
def theme_sir(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.theme_sir(*args, **kwargs))
|
||||||
|
def labels_sir_count(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.labels_sir_count(*args, **kwargs))
|
||||||
|
def guess_ab_col(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.guess_ab_col(*args, **kwargs))
|
||||||
|
def italicise_taxonomy(string, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.italicise_taxonomy(string, *args, **kwargs))
|
||||||
|
def italicize_taxonomy(string, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.italicize_taxonomy(string, *args, **kwargs))
|
||||||
|
def inner_join_microorganisms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.inner_join_microorganisms(x, *args, **kwargs))
|
||||||
|
def left_join_microorganisms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.left_join_microorganisms(x, *args, **kwargs))
|
||||||
|
def right_join_microorganisms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.right_join_microorganisms(x, *args, **kwargs))
|
||||||
|
def full_join_microorganisms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.full_join_microorganisms(x, *args, **kwargs))
|
||||||
|
def semi_join_microorganisms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.semi_join_microorganisms(x, *args, **kwargs))
|
||||||
|
def anti_join_microorganisms(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.anti_join_microorganisms(x, *args, **kwargs))
|
||||||
|
def key_antimicrobials(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.key_antimicrobials(*args, **kwargs))
|
||||||
|
def all_antimicrobials(x = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.all_antimicrobials(x = None, *args, **kwargs))
|
||||||
|
def antimicrobials_equal(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.antimicrobials_equal(*args, **kwargs))
|
||||||
|
def kurtosis(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.kurtosis(x, *args, **kwargs))
|
||||||
|
def like(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.like(x, *args, **kwargs))
|
||||||
|
def mdro(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mdro(*args, **kwargs))
|
||||||
|
def custom_mdro_guideline(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.custom_mdro_guideline(*args, **kwargs))
|
||||||
|
def brmo(x = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.brmo(x = None, *args, **kwargs))
|
||||||
|
def mrgn(x = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mrgn(x = None, *args, **kwargs))
|
||||||
|
def mdr_tb(x = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mdr_tb(x = None, *args, **kwargs))
|
||||||
|
def mdr_cmi2012(x = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mdr_cmi2012(x = None, *args, **kwargs))
|
||||||
|
def eucast_exceptional_phenotypes(x = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.eucast_exceptional_phenotypes(x = None, *args, **kwargs))
|
||||||
|
def mean_amr_distance(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mean_amr_distance(x, *args, **kwargs))
|
||||||
|
def amr_distance_from_row(amr_distance, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.amr_distance_from_row(amr_distance, *args, **kwargs))
|
||||||
|
def mo_matching_score(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_matching_score(x, *args, **kwargs))
|
||||||
|
def mo_name(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_name(*args, **kwargs))
|
||||||
|
def mo_fullname(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_fullname(*args, **kwargs))
|
||||||
|
def mo_shortname(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_shortname(*args, **kwargs))
|
||||||
|
def mo_subspecies(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_subspecies(*args, **kwargs))
|
||||||
|
def mo_species(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_species(*args, **kwargs))
|
||||||
|
def mo_genus(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_genus(*args, **kwargs))
|
||||||
|
def mo_family(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_family(*args, **kwargs))
|
||||||
|
def mo_order(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_order(*args, **kwargs))
|
||||||
|
def mo_class(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_class(*args, **kwargs))
|
||||||
|
def mo_phylum(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_phylum(*args, **kwargs))
|
||||||
|
def mo_kingdom(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_kingdom(*args, **kwargs))
|
||||||
|
def mo_domain(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_domain(*args, **kwargs))
|
||||||
|
def mo_type(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_type(*args, **kwargs))
|
||||||
|
def mo_status(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_status(*args, **kwargs))
|
||||||
|
def mo_pathogenicity(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_pathogenicity(*args, **kwargs))
|
||||||
|
def mo_gramstain(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_gramstain(*args, **kwargs))
|
||||||
|
def mo_is_gram_negative(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_is_gram_negative(*args, **kwargs))
|
||||||
|
def mo_is_gram_positive(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_is_gram_positive(*args, **kwargs))
|
||||||
|
def mo_is_yeast(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_is_yeast(*args, **kwargs))
|
||||||
|
def mo_is_intrinsic_resistant(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_is_intrinsic_resistant(*args, **kwargs))
|
||||||
|
def mo_oxygen_tolerance(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_oxygen_tolerance(*args, **kwargs))
|
||||||
|
def mo_is_anaerobic(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_is_anaerobic(*args, **kwargs))
|
||||||
|
def mo_snomed(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_snomed(*args, **kwargs))
|
||||||
|
def mo_ref(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_ref(*args, **kwargs))
|
||||||
|
def mo_authors(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_authors(*args, **kwargs))
|
||||||
|
def mo_year(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_year(*args, **kwargs))
|
||||||
|
def mo_lpsn(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_lpsn(*args, **kwargs))
|
||||||
|
def mo_mycobank(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_mycobank(*args, **kwargs))
|
||||||
|
def mo_gbif(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_gbif(*args, **kwargs))
|
||||||
|
def mo_rank(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_rank(*args, **kwargs))
|
||||||
|
def mo_taxonomy(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_taxonomy(*args, **kwargs))
|
||||||
|
def mo_synonyms(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_synonyms(*args, **kwargs))
|
||||||
|
def mo_current(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_current(x, *args, **kwargs))
|
||||||
|
def mo_group_members(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_group_members(*args, **kwargs))
|
||||||
|
def mo_info(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_info(*args, **kwargs))
|
||||||
|
def mo_url(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_url(*args, **kwargs))
|
||||||
|
def mo_property(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.mo_property(*args, **kwargs))
|
||||||
|
def pca(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.pca(*args, **kwargs))
|
||||||
|
def resistance(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.resistance(*args, **kwargs))
|
||||||
|
def susceptibility(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.susceptibility(*args, **kwargs))
|
||||||
|
def sir_confidence_interval(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.sir_confidence_interval(*args, **kwargs))
|
||||||
|
def proportion_R(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.proportion_R(*args, **kwargs))
|
||||||
|
def proportion_IR(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.proportion_IR(*args, **kwargs))
|
||||||
|
def proportion_I(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.proportion_I(*args, **kwargs))
|
||||||
|
def proportion_SI(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.proportion_SI(*args, **kwargs))
|
||||||
|
def proportion_S(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.proportion_S(*args, **kwargs))
|
||||||
|
def proportion_df(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.proportion_df(*args, **kwargs))
|
||||||
|
def sir_df(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.sir_df(*args, **kwargs))
|
||||||
|
def random_mic(size = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.random_mic(size = None, *args, **kwargs))
|
||||||
|
def random_disk(size = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.random_disk(size = None, *args, **kwargs))
|
||||||
|
def random_sir(size = None, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.random_sir(size = None, *args, **kwargs))
|
||||||
|
def resistance_predict(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.resistance_predict(*args, **kwargs))
|
||||||
|
def sir_predict(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.sir_predict(*args, **kwargs))
|
||||||
|
def ggplot_sir_predict(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.ggplot_sir_predict(*args, **kwargs))
|
||||||
|
def skewness(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.skewness(x, *args, **kwargs))
|
||||||
|
def reset_AMR_locale(*args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.reset_AMR_locale(*args, **kwargs))
|
||||||
|
def translate_AMR(x, *args, **kwargs):
|
||||||
|
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
|
||||||
|
return convert_to_python(amr_r.translate_AMR(x, *args, **kwargs))
|
196
PythonPackage/AMR/README.md
Executable file
196
PythonPackage/AMR/README.md
Executable file
@ -0,0 +1,196 @@
|
|||||||
|
---
|
||||||
|
title: "AMR for Python"
|
||||||
|
output:
|
||||||
|
rmarkdown::html_vignette:
|
||||||
|
toc: true
|
||||||
|
toc_depth: 3
|
||||||
|
vignette: >
|
||||||
|
%\VignetteIndexEntry{AMR for Python}
|
||||||
|
%\VignetteEncoding{UTF-8}
|
||||||
|
%\VignetteEngine{knitr::rmarkdown}
|
||||||
|
editor_options:
|
||||||
|
chunk_output_type: console
|
||||||
|
---
|
||||||
|
|
||||||
|
```{r setup, include = FALSE, results = 'markup'}
|
||||||
|
knitr::opts_chunk$set(
|
||||||
|
warning = FALSE,
|
||||||
|
collapse = TRUE,
|
||||||
|
comment = "#>",
|
||||||
|
fig.width = 7.5,
|
||||||
|
fig.height = 5
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
|
||||||
|
The `AMR` package for R is a powerful tool for antimicrobial resistance (AMR) analysis. It provides extensive features for handling microbial and antimicrobial data. However, for those who work primarily in Python, we now have a more intuitive option available: the [`AMR` Python Package Index](https://pypi.org/project/AMR/).
|
||||||
|
|
||||||
|
This Python package is a wrapper round the `AMR` R package. It uses the `rpy2` package internally. Despite the need to have R installed, Python users can now easily work with AMR data directly through Python code.
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
1. Since the Python package is available on the official [Python Package Index](https://pypi.org/project/AMR/), you can just run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install AMR
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Make sure you have R installed. There is **no need to install the `AMR` R package**, as it will be installed automatically.
|
||||||
|
|
||||||
|
For Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu / Debian
|
||||||
|
sudo apt install r-base
|
||||||
|
# Fedora:
|
||||||
|
sudo dnf install R
|
||||||
|
# CentOS/RHEL
|
||||||
|
sudo yum install R
|
||||||
|
```
|
||||||
|
|
||||||
|
For macOS (using [Homebrew](https://brew.sh)):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install r
|
||||||
|
```
|
||||||
|
|
||||||
|
For Windows, visit the [CRAN download page](https://cran.r-project.org) to download and install R.
|
||||||
|
|
||||||
|
# Examples of Usage
|
||||||
|
|
||||||
|
## Cleaning Taxonomy
|
||||||
|
|
||||||
|
Here’s an example that demonstrates how to clean microorganism and drug names using the `AMR` Python package:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pandas as pd
|
||||||
|
import AMR
|
||||||
|
|
||||||
|
# Sample data
|
||||||
|
data = {
|
||||||
|
"MOs": ['E. coli', 'ESCCOL', 'esco', 'Esche coli'],
|
||||||
|
"Drug": ['Cipro', 'CIP', 'J01MA02', 'Ciproxin']
|
||||||
|
}
|
||||||
|
df = pd.DataFrame(data)
|
||||||
|
|
||||||
|
# Use AMR functions to clean microorganism and drug names
|
||||||
|
df['MO_clean'] = AMR.mo_name(df['MOs'])
|
||||||
|
df['Drug_clean'] = AMR.ab_name(df['Drug'])
|
||||||
|
|
||||||
|
# Display the results
|
||||||
|
print(df)
|
||||||
|
```
|
||||||
|
|
||||||
|
| MOs | Drug | MO_clean | Drug_clean |
|
||||||
|
|-------------|-----------|--------------------|---------------|
|
||||||
|
| E. coli | Cipro | Escherichia coli | Ciprofloxacin |
|
||||||
|
| ESCCOL | CIP | Escherichia coli | Ciprofloxacin |
|
||||||
|
| esco | J01MA02 | Escherichia coli | Ciprofloxacin |
|
||||||
|
| Esche coli | Ciproxin | Escherichia coli | Ciprofloxacin |
|
||||||
|
|
||||||
|
### Explanation
|
||||||
|
|
||||||
|
* **mo_name:** This function standardises microorganism names. Here, different variations of *Escherichia coli* (such as "E. coli", "ESCCOL", "esco", and "Esche coli") are all converted into the correct, standardised form, "Escherichia coli".
|
||||||
|
|
||||||
|
* **ab_name**: Similarly, this function standardises antimicrobial names. The different representations of ciprofloxacin (e.g., "Cipro", "CIP", "J01MA02", and "Ciproxin") are all converted to the standard name, "Ciprofloxacin".
|
||||||
|
|
||||||
|
|
||||||
|
## Taxonomic Data Sets Now in Python!
|
||||||
|
|
||||||
|
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antibiotics`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
|
||||||
|
|
||||||
|
```python
|
||||||
|
AMR.microorganisms
|
||||||
|
```
|
||||||
|
|
||||||
|
| mo | fullname | status | kingdom | gbif | gbif_parent | gbif_renamed_to | prevalence |
|
||||||
|
|--------------|------------------------------------|----------|----------|-----------|-------------|-----------------|------------|
|
||||||
|
| B_GRAMN | (unknown Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_GRAMP | (unknown Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ANAER-NEG | (unknown anaerobic Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ANAER-POS | (unknown anaerobic Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ANAER | (unknown anaerobic bacteria) | unknown | Bacteria | None | None | None | 2.0 |
|
||||||
|
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||||
|
| B_ZYMMN_POMC | Zymomonas pomaceae | accepted | Bacteria | 10744418 | 3221412 | None | 2.0 |
|
||||||
|
| B_ZYMPH | Zymophilus | synonym | Bacteria | None | 9475166 | None | 2.0 |
|
||||||
|
| B_ZYMPH_PCVR | Zymophilus paucivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||||
|
| B_ZYMPH_RFFN | Zymophilus raffinosivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||||
|
| F_ZYZYG | Zyzygomyces | unknown | Fungi | None | 7581 | None | 2.0 |
|
||||||
|
|
||||||
|
```python
|
||||||
|
AMR.antibiotics
|
||||||
|
```
|
||||||
|
|
||||||
|
| ab | cid | name | group | oral_ddd | oral_units | iv_ddd | iv_units |
|
||||||
|
|-----|-------------|----------------------|----------------------------|----------|------------|--------|----------|
|
||||||
|
| AMA | 4649.0 | 4-aminosalicylic acid| Antimycobacterials | 12.00 | g | NaN | None |
|
||||||
|
| ACM | 6450012.0 | Acetylmidecamycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||||
|
| ASP | 49787020.0 | Acetylspiramycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||||
|
| ALS | 8954.0 | Aldesulfone sodium | Other antibacterials | 0.33 | g | NaN | None |
|
||||||
|
| AMK | 37768.0 | Amikacin | Aminoglycosides | NaN | None | 1.0 | g |
|
||||||
|
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||||
|
| VIR | 11979535.0 | Virginiamycine | Other antibacterials | NaN | None | NaN | None |
|
||||||
|
| VOR | 71616.0 | Voriconazole | Antifungals/antimycotics | 0.40 | g | 0.4 | g |
|
||||||
|
| XBR | 72144.0 | Xibornol | Other antibacterials | NaN | None | NaN | None |
|
||||||
|
| ZID | 77846445.0 | Zidebactam | Other antibacterials | NaN | None | NaN | None |
|
||||||
|
| ZFD | NaN | Zoliflodacin | None | NaN | None | NaN | None |
|
||||||
|
|
||||||
|
|
||||||
|
## Calculating AMR
|
||||||
|
|
||||||
|
```python
|
||||||
|
import AMR
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
df = AMR.example_isolates
|
||||||
|
result = AMR.resistance(df["AMX"])
|
||||||
|
print(result)
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
[0.59555556]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Generating Antibiograms
|
||||||
|
|
||||||
|
One of the core functions of the `AMR` package is generating an antibiogram, a table that summarises the antimicrobial susceptibility of bacterial isolates. Here’s how you can generate an antibiogram from Python:
|
||||||
|
|
||||||
|
```python
|
||||||
|
result2a = AMR.antibiogram(df[["mo", "AMX", "CIP", "TZP"]])
|
||||||
|
print(result2a)
|
||||||
|
```
|
||||||
|
|
||||||
|
| Pathogen | Amoxicillin | Ciprofloxacin | Piperacillin/tazobactam |
|
||||||
|
|-----------------|-----------------|-----------------|--------------------------|
|
||||||
|
| CoNS | 7% (10/142) | 73% (183/252) | 30% (10/33) |
|
||||||
|
| E. coli | 50% (196/392) | 88% (399/456) | 94% (393/416) |
|
||||||
|
| K. pneumoniae | 0% (0/58) | 96% (53/55) | 89% (47/53) |
|
||||||
|
| P. aeruginosa | 0% (0/30) | 100% (30/30) | None |
|
||||||
|
| P. mirabilis | None | 94% (34/36) | None |
|
||||||
|
| S. aureus | 6% (8/131) | 90% (171/191) | None |
|
||||||
|
| S. epidermidis | 1% (1/91) | 64% (87/136) | None |
|
||||||
|
| S. hominis | None | 80% (56/70) | None |
|
||||||
|
| S. pneumoniae | 100% (112/112) | None | 100% (112/112) |
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
result2b = AMR.antibiogram(df[["mo", "AMX", "CIP", "TZP"]], mo_transform = "gramstain")
|
||||||
|
print(result2b)
|
||||||
|
```
|
||||||
|
|
||||||
|
| Pathogen | Amoxicillin | Ciprofloxacin | Piperacillin/tazobactam |
|
||||||
|
|----------------|-----------------|------------------|--------------------------|
|
||||||
|
| Gram-negative | 36% (226/631) | 91% (621/684) | 88% (565/641) |
|
||||||
|
| Gram-positive | 43% (305/703) | 77% (560/724) | 86% (296/345) |
|
||||||
|
|
||||||
|
|
||||||
|
In this example, we generate an antibiogram by selecting various antibiotics.
|
||||||
|
|
||||||
|
# Conclusion
|
||||||
|
|
||||||
|
With the `AMR` Python package, Python users can now effortlessly call R functions from the `AMR` R package. This eliminates the need for complex `rpy2` configurations and provides a clean, easy-to-use interface for antimicrobial resistance analysis. The examples provided above demonstrate how this can be applied to typical workflows, such as standardising microorganism and antimicrobial names or calculating resistance.
|
||||||
|
|
||||||
|
By just running `import AMR`, users can seamlessly integrate the robust features of the R `AMR` package into Python workflows.
|
||||||
|
|
||||||
|
Whether you're cleaning data or analysing resistance patterns, the `AMR` Python package makes it easy to work with AMR data in Python.
|
BIN
PythonPackage/AMR/dist/AMR-2.1.1.9103-py3-none-any.whl
vendored
Normal file
BIN
PythonPackage/AMR/dist/AMR-2.1.1.9103-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
PythonPackage/AMR/dist/amr-2.1.1.9103.tar.gz
vendored
Normal file
BIN
PythonPackage/AMR/dist/amr-2.1.1.9103.tar.gz
vendored
Normal file
Binary file not shown.
27
PythonPackage/AMR/setup.py
Normal file
27
PythonPackage/AMR/setup.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='AMR',
|
||||||
|
version='2.1.1.9103',
|
||||||
|
packages=find_packages(),
|
||||||
|
install_requires=[
|
||||||
|
'rpy2',
|
||||||
|
'numpy',
|
||||||
|
'pandas',
|
||||||
|
],
|
||||||
|
author='Dr. Matthijs Berends',
|
||||||
|
author_email='m.s.berends@umcg.nl',
|
||||||
|
description='A Python wrapper for the AMR R package',
|
||||||
|
long_description=open('README.md').read(),
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
|
url='https://github.com/msberends/AMR',
|
||||||
|
project_urls={
|
||||||
|
'Bug Tracker': 'https://github.com/msberends/AMR/issues',
|
||||||
|
},
|
||||||
|
license='GPL 2',
|
||||||
|
classifiers=[
|
||||||
|
'Programming Language :: Python :: 3',
|
||||||
|
'Operating System :: OS Independent',
|
||||||
|
],
|
||||||
|
python_requires='>=3.6',
|
||||||
|
)
|
24
R/sir.R
24
R/sir.R
@ -970,6 +970,7 @@ as_sir_method <- function(method_short,
|
|||||||
warning_("The following animal host(s) could not be coerced: ", vector_and(host.bak[is.na(host) & !is.na(host.bak)]), immediate = TRUE)
|
warning_("The following animal host(s) could not be coerced: ", vector_and(host.bak[is.na(host) & !is.na(host.bak)]), immediate = TRUE)
|
||||||
message() # new line
|
message() # new line
|
||||||
}
|
}
|
||||||
|
# TODO add a switch to turn this off? In interactive sessions perhaps ask the user. Default should be On.
|
||||||
if (breakpoint_type == "animal" && message_not_thrown_before("as.sir", "host_missing_breakpoints")) {
|
if (breakpoint_type == "animal" && message_not_thrown_before("as.sir", "host_missing_breakpoints")) {
|
||||||
if (guideline_coerced %like% "CLSI") {
|
if (guideline_coerced %like% "CLSI") {
|
||||||
message_("Please note that in the absence of specific veterinary breakpoints for certain animal hosts, the CLSI guideline VET09 will be applied where possible.\n\n")
|
message_("Please note that in the absence of specific veterinary breakpoints for certain animal hosts, the CLSI guideline VET09 will be applied where possible.\n\n")
|
||||||
@ -1053,6 +1054,8 @@ as_sir_method <- function(method_short,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# TODO set uti to specimen column here
|
||||||
|
|
||||||
|
|
||||||
if (length(ab) == 1 && ab %like% paste0("as.", method_short)) {
|
if (length(ab) == 1 && ab %like% paste0("as.", method_short)) {
|
||||||
stop_("No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.sir.", call = FALSE)
|
stop_("No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.sir.", call = FALSE)
|
||||||
@ -1238,6 +1241,8 @@ as_sir_method <- function(method_short,
|
|||||||
new_sir <- rep(NA_sir_, length(rows))
|
new_sir <- rep(NA_sir_, length(rows))
|
||||||
|
|
||||||
# find different mo properties, as fast as possible
|
# find different mo properties, as fast as possible
|
||||||
|
# TODO in case of VET09, we need to keep E. coli, also when users have Proteus in their data set
|
||||||
|
# TODO look up which species, at least E. coli - also Staph or Strep?
|
||||||
mo_current_genus <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$genus[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
|
mo_current_genus <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$genus[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
|
||||||
mo_current_family <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$family[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
|
mo_current_family <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$family[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
|
||||||
mo_current_order <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$order[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
|
mo_current_order <- AMR_env$MO_lookup$mo[match(AMR_env$MO_lookup$order[match(mo_current, AMR_env$MO_lookup$mo)], AMR_env$MO_lookup$fullname)]
|
||||||
@ -1262,6 +1267,7 @@ as_sir_method <- function(method_short,
|
|||||||
)
|
)
|
||||||
|
|
||||||
# gather all available breakpoints for current MO
|
# gather all available breakpoints for current MO
|
||||||
|
# TODO for VET09 do not filter out E. coli and such
|
||||||
breakpoints_current <- breakpoints %pm>%
|
breakpoints_current <- breakpoints %pm>%
|
||||||
subset(ab == ab_current) %pm>%
|
subset(ab == ab_current) %pm>%
|
||||||
subset(mo %in% c(
|
subset(mo %in% c(
|
||||||
@ -1271,14 +1277,17 @@ as_sir_method <- function(method_short,
|
|||||||
mo_current_other
|
mo_current_other
|
||||||
))
|
))
|
||||||
|
|
||||||
|
# TODO are operators considered??
|
||||||
|
# This seems to not work well: as.sir(as.mic(c(4, ">4", ">=4", 8, ">8", ">=8")), ab = "AMC", mo = "E. coli", breakpoint_type = "animal", host = "dogs", guideline = "CLSI 2024")
|
||||||
|
|
||||||
## fall-back methods for veterinary guidelines ----
|
## fall-back methods for veterinary guidelines ----
|
||||||
if (breakpoint_type == "animal" && !host_current %in% breakpoints_current$host) {
|
if (breakpoint_type == "animal" && !host_current %in% breakpoints_current$host) {
|
||||||
if (guideline_coerced %like% "CLSI") {
|
if (guideline_coerced %like% "CLSI") {
|
||||||
# VET09 says that staph/strep/enterococcus BP can be extrapolated to all Gr+ cocci except for intrinsic resistance, so take all Gr+ cocci:
|
# VET09 says that staph/strep/enterococcus BP can be extrapolated to all Gr+ cocci except for intrinsic resistance, so take all Gr+ cocci:
|
||||||
all_gram_pos_genera <- c("B_STPHY", "B_STRPT", "B_PPTST", "B_AERCC", "B_MCRCCC", "B_TRPRL")
|
gram_plus_cocci_vet09 <- microorganisms$mo[microorganisms$genus %in% c("Staphylococcus", "Streptococcus", "Peptostreptococcus", "Aerococcus", "Micrococcus") & microorganisms$rank == "genus"] # TODO should probably include genera that were either of these before
|
||||||
|
|
||||||
# HUMAN SUBSTITUTES
|
# HUMAN SUBSTITUTES
|
||||||
if (ab_current == "AZM" && mo_current_genus %in% all_gram_pos_genera && host_current %in% c("dogs", "cats", "horse")) {
|
if (ab_current == "AZM" && mo_current_genus %in% gram_plus_cocci_vet09 && host_current %in% c("dogs", "cats", "horse")) {
|
||||||
# azithro can take human breakpoints for these agents
|
# azithro can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Gram-positive cocci based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Gram-positive cocci based on CLSI VET09."))
|
||||||
@ -1290,7 +1299,7 @@ as_sir_method <- function(method_short,
|
|||||||
# cefta can take human breakpoints for these agents
|
# cefta can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Enterobacterales and ", font_italic("P. aeruginosa"), " based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Enterobacterales and ", font_italic("P. aeruginosa"), " based on CLSI VET09."))
|
||||||
} else if (ab_current == "ERY" && mo_current_genus %in% all_gram_pos_genera && host_current %in% c("dogs", "cats", "horse")) {
|
} else if (ab_current == "ERY" && mo_current_genus %in% gram_plus_cocci_vet09 && host_current %in% c("dogs", "cats", "horse")) {
|
||||||
# erythro can take human breakpoints for these agents
|
# erythro can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Gram-positive cocci based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Gram-positive cocci based on CLSI VET09."))
|
||||||
@ -1298,7 +1307,7 @@ as_sir_method <- function(method_short,
|
|||||||
# imipenem can take human breakpoints for these agents
|
# imipenem can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Enterobacterales and ", font_italic("P. aeruginosa"), " based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Enterobacterales and ", font_italic("P. aeruginosa"), " based on CLSI VET09."))
|
||||||
} else if (ab_current == "LNZ" && mo_current_genus %in% all_gram_pos_genera && host_current %in% c("dogs", "cats")) {
|
} else if (ab_current == "LNZ" && mo_current_genus %in% gram_plus_cocci_vet09 && host_current %in% c("dogs", "cats")) {
|
||||||
# linezolid can take human breakpoints for these agents
|
# linezolid can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in staphylococci/enterococci based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in staphylococci/enterococci based on CLSI VET09."))
|
||||||
@ -1306,11 +1315,11 @@ as_sir_method <- function(method_short,
|
|||||||
# nitro can take human breakpoints for these agents
|
# nitro can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " based on CLSI VET09."))
|
||||||
} else if (ab_current == "PEN" && mo_current_genus %in% all_gram_pos_genera && host_current %in% c("dogs", "cats")) {
|
} else if (ab_current == "PEN" && mo_current_genus %in% gram_plus_cocci_vet09 && host_current %in% c("dogs", "cats")) {
|
||||||
# penicillin can take human breakpoints for these agents
|
# penicillin can take human breakpoints for these agents
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Gram-positive cocci based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in Gram-positive cocci based on CLSI VET09."))
|
||||||
} else if (ab_current == "RIF" && mo_current_genus %in% all_gram_pos_genera && host_current %in% c("dogs", "cats")) {
|
} else if (ab_current == "RIF" && mo_current_genus %in% gram_plus_cocci_vet09 && host_current %in% c("dogs", "cats")) {
|
||||||
# rifampicin can take human breakpoints for staphylococci
|
# rifampicin can take human breakpoints for staphylococci
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in staphylococci based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", ab_formatted, " in staphylococci based on CLSI VET09."))
|
||||||
@ -1325,7 +1334,8 @@ as_sir_method <- function(method_short,
|
|||||||
|
|
||||||
} else if (host_current %in% c("dogs", "cats") && (mo_current_genus %in% c("B_AMYCS", "B_NOCRD", "B_CMPYL", "B_CRYNB", "B_ENTRC", "B_MYCBC", "B_PSDMN", "B_AERMN") | mo_current_class == "B_[CLS]_BTPRTBCT" | mo_current == "B_LISTR_MNCY")) {
|
} else if (host_current %in% c("dogs", "cats") && (mo_current_genus %in% c("B_AMYCS", "B_NOCRD", "B_CMPYL", "B_CRYNB", "B_ENTRC", "B_MYCBC", "B_PSDMN", "B_AERMN") | mo_current_class == "B_[CLS]_BTPRTBCT" | mo_current == "B_LISTR_MNCY")) {
|
||||||
# dog breakpoints if no canine/feline
|
# dog breakpoints if no canine/feline
|
||||||
breakpoints_current <- breakpoints_current %pm>% subset(host == "human")
|
# TODO do we still have dogs breakpoints at this point???
|
||||||
|
breakpoints_current <- breakpoints_current %pm>% subset(host == "human") # WRONG
|
||||||
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", mo_formatted, " based on CLSI VET09."))
|
notes_current <- c(notes_current, paste0("Using ", font_bold("human"), " breakpoints for ", mo_formatted, " based on CLSI VET09."))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,13 +30,15 @@
|
|||||||
# ==================================================================== #
|
# ==================================================================== #
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
rm -rf python_wrapper/AMR/*
|
rm -rf ../PythonPackage/AMR/*
|
||||||
mkdir -p python_wrapper/AMR/AMR
|
mkdir -p ../PythonPackage/AMR/AMR
|
||||||
|
|
||||||
# Output Python file
|
# Output Python file
|
||||||
functions_file="python_wrapper/AMR/AMR/functions.py"
|
setup_file="../PythonPackage/AMR/setup.py"
|
||||||
datasets_file="python_wrapper/AMR/AMR/datasets.py"
|
functions_file="../PythonPackage/AMR/AMR/functions.py"
|
||||||
init_file="python_wrapper/AMR/AMR/__init__.py"
|
datasets_file="../PythonPackage/AMR/AMR/datasets.py"
|
||||||
|
init_file="../PythonPackage/AMR/AMR/__init__.py"
|
||||||
|
|
||||||
|
|
||||||
# Write header to the datasets Python file, including the convert_to_python function
|
# Write header to the datasets Python file, including the convert_to_python function
|
||||||
cat <<EOL > "$datasets_file"
|
cat <<EOL > "$datasets_file"
|
||||||
@ -46,31 +48,48 @@ RESET = '\033[0m'
|
|||||||
|
|
||||||
print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True)
|
print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
from rpy2 import robjects
|
from rpy2 import robjects
|
||||||
from rpy2.robjects import pandas2ri
|
from rpy2.robjects import pandas2ri
|
||||||
from rpy2.robjects.packages import importr, isinstalled
|
from rpy2.robjects.packages import importr, isinstalled
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
# import importlib.metadata as metadata
|
import importlib.metadata as metadata
|
||||||
|
|
||||||
# Check if AMR package is installed in R
|
# Get the path to the virtual environment
|
||||||
|
venv_path = os.getenv('VIRTUAL_ENV') # Path to the active virtual environment
|
||||||
|
if not venv_path:
|
||||||
|
raise EnvironmentError("No virtual environment detected. Please activate your Python virtual environment.")
|
||||||
|
|
||||||
|
# Define R library path within the venv
|
||||||
|
r_lib_path = os.path.join(venv_path, "R_libs")
|
||||||
|
# Ensure the R library path exists
|
||||||
|
os.makedirs(r_lib_path, exist_ok=True)
|
||||||
|
# Set the R library path in .libPaths
|
||||||
|
base = importr('base')
|
||||||
|
base._libPaths(r_lib_path)
|
||||||
|
|
||||||
|
# Check if the AMR package is installed in R
|
||||||
if not isinstalled('AMR'):
|
if not isinstalled('AMR'):
|
||||||
utils = importr('utils')
|
utils = importr('utils')
|
||||||
utils.install_packages('AMR', repos='https://msberends.r-universe.dev')
|
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
|
||||||
|
|
||||||
# Python package version of AMR
|
# Python package version of AMR
|
||||||
python_amr_version = metadata.version('AMR')
|
try:
|
||||||
|
python_amr_version = metadata.version('AMR')
|
||||||
|
except metadata.PackageNotFoundError:
|
||||||
|
python_amr_version = None
|
||||||
|
|
||||||
# R package version of AMR
|
# R package version of AMR
|
||||||
# r_amr_version = robjects.r('packageVersion("AMR")')[0]
|
r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_lib_path}"))')[0]
|
||||||
|
|
||||||
# Compare R and Python package versions
|
# Compare R and Python package versions
|
||||||
# if r_amr_version != python_amr_version:
|
if python_amr_version and r_amr_version != python_amr_version:
|
||||||
# print(f"{BLUE}AMR:{RESET} Version mismatch detected. Updating AMR R package version to {python_amr_version}...", flush=True)
|
try:
|
||||||
# try:
|
utils = importr('utils')
|
||||||
# # Re-install the specific version of AMR in R
|
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
|
||||||
# utils = importr('utils')
|
except Exception as e:
|
||||||
# utils.install_packages('AMR', repos='https://msberends.r-universe.dev')
|
print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True)
|
||||||
# except Exception as e:
|
|
||||||
# print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True)
|
|
||||||
|
|
||||||
# Activate the automatic conversion between R and pandas DataFrames
|
# Activate the automatic conversion between R and pandas DataFrames
|
||||||
pandas2ri.activate()
|
pandas2ri.activate()
|
||||||
@ -237,22 +256,20 @@ done
|
|||||||
echo "Python wrapper functions generated in $functions_file."
|
echo "Python wrapper functions generated in $functions_file."
|
||||||
echo "Python wrapper functions listed in $init_file."
|
echo "Python wrapper functions listed in $init_file."
|
||||||
|
|
||||||
cp ../vignettes/AMR_for_Python.Rmd python_wrapper/AMR/README.md
|
cp ../vignettes/AMR_for_Python.Rmd ../PythonPackage/AMR/README.md
|
||||||
sed -i '1,/^# Introduction$/d' python_wrapper/AMR/README.md
|
sed -i '1,/^# Introduction$/d' ../PythonPackage/AMR/README.md
|
||||||
echo "README copied"
|
echo "README copied"
|
||||||
|
|
||||||
|
|
||||||
# Path to your DESCRIPTION file
|
# Path to your DESCRIPTION file
|
||||||
description_file="../DESCRIPTION"
|
description_file="../DESCRIPTION"
|
||||||
|
|
||||||
# Output setup.py file
|
|
||||||
functions_file="python_wrapper/AMR/setup.py"
|
|
||||||
|
|
||||||
# Extract the relevant fields from DESCRIPTION
|
# Extract the relevant fields from DESCRIPTION
|
||||||
version=$(grep "^Version:" "$description_file" | awk '{print $2}')
|
version=$(grep "^Version:" "$description_file" | awk '{print $2}')
|
||||||
|
|
||||||
# Write the setup.py file
|
# Write the setup.py file
|
||||||
cat <<EOL > "$functions_file"
|
cat <<EOL > "$setup_file"
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
@ -283,8 +300,10 @@ setup(
|
|||||||
EOL
|
EOL
|
||||||
|
|
||||||
# Output completion message
|
# Output completion message
|
||||||
echo "setup.py has been generated in $functions_file."
|
echo "setup.py has been generated in $setup_file."
|
||||||
|
|
||||||
cd python_wrapper/AMR
|
cd ../PythonPackage/AMR
|
||||||
python3 setup.py sdist bdist_wheel
|
pip3 install build
|
||||||
|
python3 -m build
|
||||||
|
# python3 setup.py sdist bdist_wheel
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user