Author SHA1 Message Date
github-actions[bot] 8e522cd988 Python wrapper update 2026-09-08 13:04:10 +00:00
49 changed files with 1886 additions and 3637 deletions

No files matched your search

-2
View File
@@ -1,2 +0,0 @@
^.*\.Rproj$
^\.Rproj\.user$
-5
View File
@@ -1,5 +0,0 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
AMR.Rproj
+254
View File
@@ -0,0 +1,254 @@
Metadata-Version: 2.4
Name: AMR
Version: 3.0.1.9091
Summary: A Python wrapper for the AMR R package
Home-page: https://github.com/msberends/AMR
Author: 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
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary
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](https://pypi.org/project/AMR/).
This Python package is a wrapper around 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.
# Prerequisites
This package was only tested with a [virtual environment (venv)](https://docs.python.org/3/library/venv.html). You can set up such an environment by running:
```python
# linux and macOS:
python -m venv /path/to/new/virtual/environment
# Windows:
python -m venv C:\path\to\new\virtual\environment
```
Then you can [activate the environment](https://docs.python.org/3/library/venv.html#how-venvs-work), after which the venv is ready to work with.
# Install AMR
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".
## 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.
## 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`, `antimicrobials`, `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.antimicrobials
```
| 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 |
# Installation Channels
## Stable Release (CRAN)
The default `AMR` Python package uses the latest stable version of the `AMR` R package, published on CRAN. After running `pip install AMR`, import it as usual:
```python
import AMR
AMR.example_isolates
```
## Development Version (GitHub)
To use the latest development version of the `AMR` R package (sourced directly from GitHub), import the `beta` sub-package and alias it as `AMR`:
```python
import AMR.beta as AMR
AMR.example_isolates
```
Aliasing with `as AMR` keeps all downstream code identical to the stable import. Switching between the stable release and the development version requires changing only the import line — nothing else in your script needs to change.
# SIR Classification with `as_sir()`
## Using `enforce_method`
The `as_sir()` function in R uses S3 method dispatch to select the correct calculation method based on the input class: `<mic>` for MIC values and `<disk>` for disk diffusion values. Because Python objects do not carry R class attributes through the `rpy2` bridge, this automatic dispatch may not resolve correctly.
To explicitly specify the input type, use the `enforce_method` argument:
```python
# Treat the column as MIC values — maps to R's as.sir.mic()
AMR.as_sir(df["MIC_col"], mo="E. coli", ab="AMX", guideline="EUCAST", enforce_method="mic")
# Treat the column as disk diffusion values — maps to R's as.sir.disk()
AMR.as_sir(df["disk_col"], mo="E. coli", ab="AMX", guideline="EUCAST", enforce_method="disk")
```
Without `enforce_method`, R falls back to class-based dispatch on the raw Python input, which may fail or return unexpected results. Always supply `enforce_method` when calling `as_sir()` from Python.
# 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.
+12
View File
@@ -0,0 +1,12 @@
README.md
setup.py
AMR/__init__.py
AMR/_engine.py
AMR/beta.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
View File
@@ -0,0 +1 @@
+3
View File
@@ -0,0 +1,3 @@
rpy2
numpy
pandas
+1
View File
@@ -0,0 +1 @@
AMR
+249
View File
@@ -0,0 +1,249 @@
import sys
_DATASETS = frozenset({
'example_isolates', 'microorganisms',
'antimicrobials', 'clinical_breakpoints'
})
class _AMRModule(type(sys.modules[__name__])):
"""Lazy-loading module: nothing runs until an attribute is accessed."""
def __getattr__(self, name):
if name in _DATASETS:
from .datasets import get
return get(name, source="cran")
try:
from . import functions
return getattr(functions, name)
except AttributeError:
raise AttributeError(
f"module 'AMR' has no attribute '{name}'")
sys.modules[__name__].__class__ = _AMRModule
from .functions import custom_eucast_rules
from .functions import ab_class
from .functions import ab_selector
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 all_sir
from .functions import all_sir_predictors
from .functions import all_mic
from .functions import all_mic_predictors
from .functions import all_disk
from .functions import all_disk_predictors
from .functions import step_mic_log2
from .functions import step_sir_numeric
from .functions import amr_course
from .functions import wisca
from .functions import antibiogram
from .functions import retrieve_wisca_parameters
from .functions import wisca_plot
from .functions import aminoglycosides
from .functions import aminopenicillins
from .functions import antifungals
from .functions import antimycobacterials
from .functions import betalactams
from .functions import betalactams_with_inhibitor
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 ionophores
from .functions import isoxazolylpenicillins
from .functions import lincosamides
from .functions import lipoglycopeptides
from .functions import macrolides
from .functions import monobactams
from .functions import nitrofurans
from .functions import oxazolidinones
from .functions import penicillins
from .functions import peptides
from .functions import phenicols
from .functions import phosphonics
from .functions import polymyxins
from .functions import quinolones
from .functions import rifamycins
from .functions import spiropyrimidinetriones
from .functions import streptogramins
from .functions import sulfonamides
from .functions import tetracyclines
from .functions import trimethoprims
from .functions import ureidopenicillins
from .functions import amr_class
from .functions import amr_selector
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 ab_reset_session
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 mic_p50
from .functions import mic_p90
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_interpretive_rules
from .functions import custom_mdro_guideline
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 guess_ab_col
from .functions import interpretive_rules
from .functions import eucast_rules
from .functions import clsi_rules
from .functions import eucast_dosage
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 kurtosis
from .functions import like
from .functions import mdro
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_morphology
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 theme_sir
from .functions import labels_sir_count
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 top_n_microorganisms
from .functions import reset_AMR_locale
from .functions import translate_AMR
+93
View File
@@ -0,0 +1,93 @@
import os
import sys
import importlib.metadata as metadata
# Get the path to the virtual environment
venv_path = sys.prefix
r_lib_path = os.path.join(venv_path, "R_libs")
os.makedirs(r_lib_path, exist_ok=True)
# Set environment variable before importing rpy2
os.environ['R_LIBS_SITE'] = r_lib_path
from rpy2 import robjects
from rpy2.robjects.vectors import StrVector
from rpy2.robjects.packages import importr, isinstalled
# Import base and utils once
base = importr('base')
utils = importr('utils')
# Silence R console output entirely
robjects.r('suppressMessages(suppressWarnings(sink(tempfile())))')
base._libPaths(r_lib_path)
_installed_source = None
def _r_version():
"""Return the currently installed AMR R package version, or None."""
try:
return str(robjects.r(
f'as.character(packageVersion("AMR", lib.loc = "{r_lib_path}"))')[0])
except Exception:
return None
def _py_version():
"""Return the Python AMR package version from metadata, or empty string."""
try:
return str(metadata.version('AMR'))
except metadata.PackageNotFoundError:
return ''
def _install_cran():
"""Install AMR from CRAN into the isolated library."""
print("AMR: Installing from CRAN...", flush=True)
utils.install_packages(
'AMR',
repos='https://cloud.r-project.org',
lib=r_lib_path,
quiet=True
)
def _install_github():
"""Install AMR development version from GitHub into the isolated library."""
print("AMR: Installing development version from GitHub...", flush=True)
utils.install_packages(
StrVector(['remotes', 'desc']),
repos='https://cloud.r-project.org',
lib=r_lib_path,
quiet=True
)
remotes = importr('remotes', lib_loc=r_lib_path)
remotes.install_github('msberends/AMR', lib=r_lib_path, quiet=True)
def ensure_amr(source="cran"):
"""Ensure AMR is installed from the requested source. Idempotent per source."""
global _installed_source
if _installed_source == source:
return
install_fn = _install_github if source == "github" else _install_cran
if not isinstalled('AMR', lib_loc=r_lib_path):
install_fn()
else:
# Check for version mismatch and update if needed
r_ver = _r_version()
py_ver = _py_version()
if r_ver != py_ver:
try:
install_fn()
except Exception as e:
print(f"AMR: Could not update ({e})", flush=True)
print(f"AMR: R package version {_r_version()} ready.", flush=True)
_installed_source = source
def restore_sink():
"""Restore R console output after setup is complete."""
try:
robjects.r('sink()')
except Exception:
pass
+22
View File
@@ -0,0 +1,22 @@
import sys
_DATASETS = frozenset({
'example_isolates', 'microorganisms',
'antimicrobials', 'clinical_breakpoints'
})
class _BetaModule(type(sys.modules[__name__])):
"""Lazy-loading module: installs AMR from GitHub on first access."""
def __getattr__(self, name):
if name in _DATASETS:
from .datasets import get
return get(name, source="github")
try:
from . import functions
return getattr(functions, name)
except AttributeError:
raise AttributeError(
f"module 'AMR.beta' has no attribute '{name}'")
sys.modules[__name__].__class__ = _BetaModule
+54
View File
@@ -0,0 +1,54 @@
import pandas as pd
from rpy2 import robjects
from rpy2.robjects.conversion import localconverter
from rpy2.robjects import default_converter, numpy2ri, pandas2ri
from ._engine import ensure_amr, restore_sink
_cache = {}
_loaded_source = None
def _load_datasets(source="cran"):
"""Load all AMR datasets into the module cache."""
global _loaded_source
if _cache and _loaded_source == source:
return
if _cache and _loaded_source != source:
_cache.clear()
ensure_amr(source)
with localconverter(default_converter + numpy2ri.converter + pandas2ri.converter):
_cache['example_isolates'] = _load_example_isolates()
_cache['microorganisms'] = robjects.r(
'AMR::microorganisms[, !sapply(AMR::microorganisms, is.list)]')
_cache['antimicrobials'] = robjects.r(
'AMR::antimicrobials[, !sapply(AMR::antimicrobials, is.list)]')
_cache['clinical_breakpoints'] = robjects.r(
'AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]')
restore_sink()
_loaded_source = source
def _load_example_isolates():
df = 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
''')
df['date'] = pd.to_datetime(df['date'])
return df
def get(name, source="cran"):
"""Retrieve a dataset by name, installing AMR if needed."""
_load_datasets(source)
return _cache[name]
+984
View File
@@ -0,0 +1,984 @@
import functools
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import StrVector, FactorVector, IntVector, FloatVector, DataFrame
from rpy2.robjects.conversion import localconverter
from rpy2.robjects import default_converter, numpy2ri, pandas2ri
import pandas as pd
import numpy as np
from ._engine import ensure_amr
# Ensure AMR is available before importing it in R
ensure_amr("cran")
amr_r = importr('AMR')
def convert_to_r(value):
"""Convert Python lists/tuples to typed R vectors.
rpy2's default_converter passes Python lists to R as R lists, not as
character/numeric vectors. This causes element-wise type-check functions
such as is.mic(), is.sir(), and is.disk() to return a logical vector
rather than a single logical, breaking R's scalar && operator.
This helper converts Python lists and tuples to the appropriate R vector
type based on the element types, so R always receives a proper vector."""
if isinstance(value, (list, tuple)):
if len(value) == 0:
return StrVector([])
# bool must be checked before int because bool is a subclass of int
if all(isinstance(v, bool) for v in value):
return robjects.vectors.BoolVector(value)
if all(isinstance(v, int) for v in value):
return IntVector(value)
if all(isinstance(v, float) for v in value):
return FloatVector(value)
if all(isinstance(v, str) for v in value):
return StrVector(value)
# Mixed types: coerce all to string
return StrVector([str(v) for v in value])
return value
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, DataFrame)):
return r_output # Return as pandas DataFrame (already converted by pandas2ri)
# 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 r_to_python(r_func):
"""Decorator that converts Python list/tuple inputs to typed R vectors,
runs the rpy2 function under a localconverter, and converts the output
to a Python type."""
@functools.wraps(r_func)
def wrapper(*args, **kwargs):
args = tuple(convert_to_r(a) for a in args)
kwargs = {k: convert_to_r(v) for k, v in kwargs.items()}
with localconverter(default_converter + numpy2ri.converter + pandas2ri.converter):
return convert_to_python(r_func(*args, **kwargs))
return wrapper
@r_to_python
def custom_eucast_rules(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.custom_eucast_rules(*args, **kwargs)
@r_to_python
def ab_class(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_class(*args, **kwargs)
@r_to_python
def ab_selector(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_selector(*args, **kwargs)
@r_to_python
def ab_from_text(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_from_text(*args, **kwargs)
@r_to_python
def ab_name(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_name(x, *args, **kwargs)
@r_to_python
def ab_cid(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_cid(x, *args, **kwargs)
@r_to_python
def ab_synonyms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_synonyms(x, *args, **kwargs)
@r_to_python
def ab_tradenames(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_tradenames(x, *args, **kwargs)
@r_to_python
def ab_group(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_group(x, *args, **kwargs)
@r_to_python
def ab_atc(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_atc(x, *args, **kwargs)
@r_to_python
def ab_atc_group1(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_atc_group1(x, *args, **kwargs)
@r_to_python
def ab_atc_group2(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_atc_group2(x, *args, **kwargs)
@r_to_python
def ab_loinc(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_loinc(x, *args, **kwargs)
@r_to_python
def ab_ddd(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_ddd(x, *args, **kwargs)
@r_to_python
def ab_ddd_units(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_ddd_units(x, *args, **kwargs)
@r_to_python
def ab_info(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_info(x, *args, **kwargs)
@r_to_python
def ab_url(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_url(x, *args, **kwargs)
@r_to_python
def ab_property(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_property(x, *args, **kwargs)
@r_to_python
def add_custom_antimicrobials(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.add_custom_antimicrobials(x)
@r_to_python
def clear_custom_antimicrobials(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.clear_custom_antimicrobials(*args, **kwargs)
@r_to_python
def add_custom_microorganisms(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.add_custom_microorganisms(x)
@r_to_python
def clear_custom_microorganisms(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.clear_custom_microorganisms(*args, **kwargs)
@r_to_python
def age(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.age(x, *args, **kwargs)
@r_to_python
def age_groups(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.age_groups(x, *args, **kwargs)
@r_to_python
def all_sir(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_sir(*args, **kwargs)
@r_to_python
def all_sir_predictors(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_sir_predictors(*args, **kwargs)
@r_to_python
def all_mic(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_mic(*args, **kwargs)
@r_to_python
def all_mic_predictors(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_mic_predictors(*args, **kwargs)
@r_to_python
def all_disk(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_disk(*args, **kwargs)
@r_to_python
def all_disk_predictors(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_disk_predictors(*args, **kwargs)
@r_to_python
def step_mic_log2(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.step_mic_log2(*args, **kwargs)
@r_to_python
def step_sir_numeric(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.step_sir_numeric(*args, **kwargs)
@r_to_python
def amr_course(github_repo, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.amr_course(github_repo, *args, **kwargs)
@r_to_python
def wisca(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.wisca(*args, **kwargs)
@r_to_python
def antibiogram(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.antibiogram(*args, **kwargs)
@r_to_python
def retrieve_wisca_parameters(wisca_model, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.retrieve_wisca_parameters(wisca_model, *args, **kwargs)
@r_to_python
def wisca_plot(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.wisca_plot(*args, **kwargs)
@r_to_python
def aminoglycosides(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.aminoglycosides(*args, **kwargs)
@r_to_python
def aminopenicillins(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.aminopenicillins(only_sir_columns = False, *args, **kwargs)
@r_to_python
def antifungals(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.antifungals(only_sir_columns = False, *args, **kwargs)
@r_to_python
def antimycobacterials(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.antimycobacterials(only_sir_columns = False, *args, **kwargs)
@r_to_python
def betalactams(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.betalactams(*args, **kwargs)
@r_to_python
def betalactams_with_inhibitor(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.betalactams_with_inhibitor(only_sir_columns = False, *args, **kwargs)
@r_to_python
def carbapenems(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.carbapenems(*args, **kwargs)
@r_to_python
def cephalosporins(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.cephalosporins(*args, **kwargs)
@r_to_python
def cephalosporins_1st(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.cephalosporins_1st(only_sir_columns = False, *args, **kwargs)
@r_to_python
def cephalosporins_2nd(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.cephalosporins_2nd(only_sir_columns = False, *args, **kwargs)
@r_to_python
def cephalosporins_3rd(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.cephalosporins_3rd(*args, **kwargs)
@r_to_python
def cephalosporins_4th(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.cephalosporins_4th(only_sir_columns = False, *args, **kwargs)
@r_to_python
def cephalosporins_5th(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.cephalosporins_5th(only_sir_columns = False, *args, **kwargs)
@r_to_python
def fluoroquinolones(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.fluoroquinolones(*args, **kwargs)
@r_to_python
def glycopeptides(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.glycopeptides(only_sir_columns = False, *args, **kwargs)
@r_to_python
def ionophores(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ionophores(only_sir_columns = False, *args, **kwargs)
@r_to_python
def isoxazolylpenicillins(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.isoxazolylpenicillins(*args, **kwargs)
@r_to_python
def lincosamides(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.lincosamides(*args, **kwargs)
@r_to_python
def lipoglycopeptides(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.lipoglycopeptides(only_sir_columns = False, *args, **kwargs)
@r_to_python
def macrolides(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.macrolides(only_sir_columns = False, *args, **kwargs)
@r_to_python
def monobactams(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.monobactams(only_sir_columns = False, *args, **kwargs)
@r_to_python
def nitrofurans(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.nitrofurans(only_sir_columns = False, *args, **kwargs)
@r_to_python
def oxazolidinones(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.oxazolidinones(only_sir_columns = False, *args, **kwargs)
@r_to_python
def penicillins(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.penicillins(only_sir_columns = False, *args, **kwargs)
@r_to_python
def peptides(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.peptides(only_sir_columns = False, *args, **kwargs)
@r_to_python
def phenicols(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.phenicols(only_sir_columns = False, *args, **kwargs)
@r_to_python
def phosphonics(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.phosphonics(only_sir_columns = False, *args, **kwargs)
@r_to_python
def polymyxins(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.polymyxins(*args, **kwargs)
@r_to_python
def quinolones(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.quinolones(*args, **kwargs)
@r_to_python
def rifamycins(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.rifamycins(only_sir_columns = False, *args, **kwargs)
@r_to_python
def spiropyrimidinetriones(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.spiropyrimidinetriones(only_sir_columns = False, *args, **kwargs)
@r_to_python
def streptogramins(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.streptogramins(only_sir_columns = False, *args, **kwargs)
@r_to_python
def sulfonamides(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.sulfonamides(only_sir_columns = False, *args, **kwargs)
@r_to_python
def tetracyclines(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.tetracyclines(*args, **kwargs)
@r_to_python
def trimethoprims(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.trimethoprims(only_sir_columns = False, *args, **kwargs)
@r_to_python
def ureidopenicillins(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ureidopenicillins(only_sir_columns = False, *args, **kwargs)
@r_to_python
def amr_class(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.amr_class(*args, **kwargs)
@r_to_python
def amr_selector(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.amr_selector(*args, **kwargs)
@r_to_python
def administrable_per_os(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.administrable_per_os(only_sir_columns = False, *args, **kwargs)
@r_to_python
def administrable_iv(only_sir_columns = False, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.administrable_iv(only_sir_columns = False, *args, **kwargs)
@r_to_python
def not_intrinsic_resistant(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.not_intrinsic_resistant(*args, **kwargs)
@r_to_python
def as_ab(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.as_ab(*args, **kwargs)
@r_to_python
def is_ab(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_ab(x)
@r_to_python
def ab_reset_session(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ab_reset_session(*args, **kwargs)
@r_to_python
def as_av(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.as_av(x, *args, **kwargs)
@r_to_python
def is_av(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_av(x)
@r_to_python
def as_disk(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.as_disk(x, *args, **kwargs)
@r_to_python
def is_disk(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_disk(x)
@r_to_python
def as_mic(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.as_mic(x, *args, **kwargs)
@r_to_python
def is_mic(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_mic(x)
@r_to_python
def rescale_mic(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.rescale_mic(*args, **kwargs)
@r_to_python
def mic_p50(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mic_p50(x, *args, **kwargs)
@r_to_python
def mic_p90(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mic_p90(x, *args, **kwargs)
@r_to_python
def as_mo(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.as_mo(*args, **kwargs)
@r_to_python
def is_mo(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_mo(x)
@r_to_python
def mo_uncertainties(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_uncertainties(*args, **kwargs)
@r_to_python
def mo_renamed(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_renamed(*args, **kwargs)
@r_to_python
def mo_failures(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_failures(*args, **kwargs)
@r_to_python
def mo_reset_session(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_reset_session(*args, **kwargs)
@r_to_python
def mo_cleaning_regex(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_cleaning_regex(*args, **kwargs)
@r_to_python
def as_sir(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.as_sir(x, *args, **kwargs)
@r_to_python
def is_sir(x):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_sir(x)
@r_to_python
def is_sir_eligible(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_sir_eligible(x, *args, **kwargs)
@r_to_python
def sir_interpretation_history(clean):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.sir_interpretation_history(clean)
@r_to_python
def atc_online_property(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.atc_online_property(*args, **kwargs)
@r_to_python
def atc_online_groups(atc_code, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.atc_online_groups(atc_code, *args, **kwargs)
@r_to_python
def atc_online_ddd(atc_code, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.atc_online_ddd(atc_code, *args, **kwargs)
@r_to_python
def atc_online_ddd_units(atc_code, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.atc_online_ddd_units(atc_code, *args, **kwargs)
@r_to_python
def av_from_text(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_from_text(*args, **kwargs)
@r_to_python
def av_name(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_name(x, *args, **kwargs)
@r_to_python
def av_cid(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_cid(x, *args, **kwargs)
@r_to_python
def av_synonyms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_synonyms(x, *args, **kwargs)
@r_to_python
def av_tradenames(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_tradenames(x, *args, **kwargs)
@r_to_python
def av_group(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_group(x, *args, **kwargs)
@r_to_python
def av_atc(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_atc(x, *args, **kwargs)
@r_to_python
def av_loinc(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_loinc(x, *args, **kwargs)
@r_to_python
def av_ddd(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_ddd(x, *args, **kwargs)
@r_to_python
def av_ddd_units(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_ddd_units(x, *args, **kwargs)
@r_to_python
def av_info(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_info(x, *args, **kwargs)
@r_to_python
def av_url(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_url(x, *args, **kwargs)
@r_to_python
def av_property(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.av_property(x, *args, **kwargs)
@r_to_python
def availability(tbl, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.availability(tbl, *args, **kwargs)
@r_to_python
def bug_drug_combinations(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.bug_drug_combinations(*args, **kwargs)
@r_to_python
def count_resistant(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_resistant(*args, **kwargs)
@r_to_python
def count_susceptible(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_susceptible(*args, **kwargs)
@r_to_python
def count_S(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_S(*args, **kwargs)
@r_to_python
def count_SI(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_SI(*args, **kwargs)
@r_to_python
def count_I(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_I(*args, **kwargs)
@r_to_python
def count_IR(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_IR(*args, **kwargs)
@r_to_python
def count_R(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_R(*args, **kwargs)
@r_to_python
def count_all(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_all(*args, **kwargs)
@r_to_python
def n_sir(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.n_sir(*args, **kwargs)
@r_to_python
def count_df(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.count_df(*args, **kwargs)
@r_to_python
def custom_interpretive_rules(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.custom_interpretive_rules(*args, **kwargs)
@r_to_python
def custom_mdro_guideline(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.custom_mdro_guideline(*args, **kwargs)
@r_to_python
def export_ncbi_biosample(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.export_ncbi_biosample(*args, **kwargs)
@r_to_python
def first_isolate(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.first_isolate(*args, **kwargs)
@r_to_python
def filter_first_isolate(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.filter_first_isolate(*args, **kwargs)
@r_to_python
def g_test(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.g_test(x, *args, **kwargs)
@r_to_python
def is_new_episode(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.is_new_episode(x, *args, **kwargs)
@r_to_python
def ggplot_pca(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ggplot_pca(*args, **kwargs)
@r_to_python
def ggplot_sir(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ggplot_sir(*args, **kwargs)
@r_to_python
def geom_sir(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.geom_sir(*args, **kwargs)
@r_to_python
def guess_ab_col(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.guess_ab_col(*args, **kwargs)
@r_to_python
def interpretive_rules(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.interpretive_rules(*args, **kwargs)
@r_to_python
def eucast_rules(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.eucast_rules(*args, **kwargs)
@r_to_python
def clsi_rules(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.clsi_rules(*args, **kwargs)
@r_to_python
def eucast_dosage(ab, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.eucast_dosage(ab, *args, **kwargs)
@r_to_python
def italicise_taxonomy(string, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.italicise_taxonomy(string, *args, **kwargs)
@r_to_python
def italicize_taxonomy(string, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.italicize_taxonomy(string, *args, **kwargs)
@r_to_python
def inner_join_microorganisms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.inner_join_microorganisms(x, *args, **kwargs)
@r_to_python
def left_join_microorganisms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.left_join_microorganisms(x, *args, **kwargs)
@r_to_python
def right_join_microorganisms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.right_join_microorganisms(x, *args, **kwargs)
@r_to_python
def full_join_microorganisms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.full_join_microorganisms(x, *args, **kwargs)
@r_to_python
def semi_join_microorganisms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.semi_join_microorganisms(x, *args, **kwargs)
@r_to_python
def anti_join_microorganisms(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.anti_join_microorganisms(x, *args, **kwargs)
@r_to_python
def key_antimicrobials(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.key_antimicrobials(*args, **kwargs)
@r_to_python
def all_antimicrobials(x = None, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.all_antimicrobials(x = None, *args, **kwargs)
@r_to_python
def kurtosis(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.kurtosis(x, *args, **kwargs)
@r_to_python
def like(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.like(x, *args, **kwargs)
@r_to_python
def mdro(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mdro(*args, **kwargs)
@r_to_python
def brmo(x = None, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.brmo(x = None, *args, **kwargs)
@r_to_python
def mrgn(x = None, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mrgn(x = None, *args, **kwargs)
@r_to_python
def mdr_tb(x = None, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mdr_tb(x = None, *args, **kwargs)
@r_to_python
def mdr_cmi2012(x = None, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mdr_cmi2012(x = None, *args, **kwargs)
@r_to_python
def eucast_exceptional_phenotypes(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.eucast_exceptional_phenotypes(*args, **kwargs)
@r_to_python
def mean_amr_distance(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mean_amr_distance(x, *args, **kwargs)
@r_to_python
def amr_distance_from_row(amr_distance, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.amr_distance_from_row(amr_distance, *args, **kwargs)
@r_to_python
def mo_matching_score(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_matching_score(x, *args, **kwargs)
@r_to_python
def mo_name(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_name(*args, **kwargs)
@r_to_python
def mo_fullname(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_fullname(*args, **kwargs)
@r_to_python
def mo_shortname(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_shortname(*args, **kwargs)
@r_to_python
def mo_subspecies(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_subspecies(*args, **kwargs)
@r_to_python
def mo_species(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_species(*args, **kwargs)
@r_to_python
def mo_genus(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_genus(*args, **kwargs)
@r_to_python
def mo_family(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_family(*args, **kwargs)
@r_to_python
def mo_order(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_order(*args, **kwargs)
@r_to_python
def mo_class(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_class(*args, **kwargs)
@r_to_python
def mo_phylum(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_phylum(*args, **kwargs)
@r_to_python
def mo_kingdom(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_kingdom(*args, **kwargs)
@r_to_python
def mo_domain(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_domain(*args, **kwargs)
@r_to_python
def mo_type(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_type(*args, **kwargs)
@r_to_python
def mo_status(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_status(*args, **kwargs)
@r_to_python
def mo_pathogenicity(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_pathogenicity(*args, **kwargs)
@r_to_python
def mo_gramstain(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_gramstain(*args, **kwargs)
@r_to_python
def mo_is_gram_negative(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_is_gram_negative(*args, **kwargs)
@r_to_python
def mo_is_gram_positive(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_is_gram_positive(*args, **kwargs)
@r_to_python
def mo_is_yeast(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_is_yeast(*args, **kwargs)
@r_to_python
def mo_is_intrinsic_resistant(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_is_intrinsic_resistant(*args, **kwargs)
@r_to_python
def mo_oxygen_tolerance(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_oxygen_tolerance(*args, **kwargs)
@r_to_python
def mo_is_anaerobic(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_is_anaerobic(*args, **kwargs)
@r_to_python
def mo_morphology(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_morphology(*args, **kwargs)
@r_to_python
def mo_snomed(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_snomed(*args, **kwargs)
@r_to_python
def mo_ref(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_ref(*args, **kwargs)
@r_to_python
def mo_authors(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_authors(*args, **kwargs)
@r_to_python
def mo_year(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_year(*args, **kwargs)
@r_to_python
def mo_lpsn(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_lpsn(*args, **kwargs)
@r_to_python
def mo_mycobank(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_mycobank(*args, **kwargs)
@r_to_python
def mo_gbif(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_gbif(*args, **kwargs)
@r_to_python
def mo_rank(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_rank(*args, **kwargs)
@r_to_python
def mo_taxonomy(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_taxonomy(*args, **kwargs)
@r_to_python
def mo_synonyms(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_synonyms(*args, **kwargs)
@r_to_python
def mo_current(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_current(x, *args, **kwargs)
@r_to_python
def mo_group_members(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_group_members(*args, **kwargs)
@r_to_python
def mo_info(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_info(*args, **kwargs)
@r_to_python
def mo_url(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_url(*args, **kwargs)
@r_to_python
def mo_property(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.mo_property(*args, **kwargs)
@r_to_python
def pca(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.pca(*args, **kwargs)
@r_to_python
def theme_sir(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.theme_sir(*args, **kwargs)
@r_to_python
def labels_sir_count(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.labels_sir_count(*args, **kwargs)
@r_to_python
def resistance(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.resistance(*args, **kwargs)
@r_to_python
def susceptibility(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.susceptibility(*args, **kwargs)
@r_to_python
def sir_confidence_interval(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.sir_confidence_interval(*args, **kwargs)
@r_to_python
def proportion_R(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.proportion_R(*args, **kwargs)
@r_to_python
def proportion_IR(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.proportion_IR(*args, **kwargs)
@r_to_python
def proportion_I(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.proportion_I(*args, **kwargs)
@r_to_python
def proportion_SI(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.proportion_SI(*args, **kwargs)
@r_to_python
def proportion_S(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.proportion_S(*args, **kwargs)
@r_to_python
def proportion_df(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.proportion_df(*args, **kwargs)
@r_to_python
def sir_df(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.sir_df(*args, **kwargs)
@r_to_python
def random_mic(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.random_mic(*args, **kwargs)
@r_to_python
def random_disk(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.random_disk(*args, **kwargs)
@r_to_python
def random_sir(size = None, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.random_sir(size = None, *args, **kwargs)
@r_to_python
def resistance_predict(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.resistance_predict(*args, **kwargs)
@r_to_python
def sir_predict(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.sir_predict(*args, **kwargs)
@r_to_python
def ggplot_sir_predict(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.ggplot_sir_predict(*args, **kwargs)
@r_to_python
def skewness(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.skewness(x, *args, **kwargs)
@r_to_python
def top_n_microorganisms(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.top_n_microorganisms(*args, **kwargs)
@r_to_python
def reset_AMR_locale(*args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.reset_AMR_locale(*args, **kwargs)
@r_to_python
def translate_AMR(x, *args, **kwargs):
"""Please see our website of the R package for the full manual: https://amr-for-r.org"""
return amr_r.translate_AMR(x, *args, **kwargs)
-32
View File
@@ -1,32 +0,0 @@
Package: AMR
Version: 0.1.1
Date: 2018-02-22
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(
given = c("Matthijs", "S."),
family = "Berends",
email = "m.s.berends@umcg.nl",
role = c("aut", "cre")),
person(
given = c("Christian", "F."),
family = "Luz",
email = "c.f.luz@umcg.nl",
role = c("aut", "ctb")),
person(
given = c("Erwin", "E.A."),
family = "Hassing",
email = "e.hassing@certe.nl",
role = "ctb"))
Description: Functions to simplify the analysis of Antimicrobial Resistance (AMR)
of microbial isolates, by using new S3 classes and applying EUCAST expert rules
on antibiograms according to Leclercq (2013)
<doi:10.1111/j.1469-0691.2011.03703.x>.
Depends: R (>= 3.0)
Imports: dplyr (>= 0.7.0), reshape2 (>= 1.4.0), xml2, rvest
URL: https://github.com/msberends/AMR
BugReports: https://github.com/msberends/AMR/issues
License: GPL-2 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1.9000
-339
View File
@@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
-68
View File
@@ -1,68 +0,0 @@
# Generated by roxygen2: do not edit by hand
S3method(as.double,mic)
S3method(as.integer,mic)
S3method(as.numeric,mic)
S3method(plot,mic)
S3method(plot,rsi)
S3method(print,mic)
S3method(print,rsi)
S3method(summary,mic)
S3method(summary,rsi)
export(EUCAST_rules)
export(abname)
export(anti_join_bactlist)
export(as.mic)
export(as.rsi)
export(atc_property)
export(full_join_bactlist)
export(inner_join_bactlist)
export(interpretive_reading)
export(is.mic)
export(is.rsi)
export(key_antibiotics)
export(left_join_bactlist)
export(mo_property)
export(right_join_bactlist)
export(rsi)
export(rsi_df)
export(rsi_predict)
export(semi_join_bactlist)
exportMethods(as.double.mic)
exportMethods(as.integer.mic)
exportMethods(as.numeric.mic)
exportMethods(plot.mic)
exportMethods(plot.rsi)
exportMethods(print.mic)
exportMethods(print.rsi)
exportMethods(summary.mic)
exportMethods(summary.rsi)
importFrom(dplyr,"%>%")
importFrom(dplyr,all_vars)
importFrom(dplyr,any_vars)
importFrom(dplyr,arrange)
importFrom(dplyr,arrange_at)
importFrom(dplyr,between)
importFrom(dplyr,filter)
importFrom(dplyr,filter_at)
importFrom(dplyr,group_by)
importFrom(dplyr,group_by_at)
importFrom(dplyr,if_else)
importFrom(dplyr,lag)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,n_distinct)
importFrom(dplyr,progress_estimated)
importFrom(dplyr,pull)
importFrom(dplyr,row_number)
importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,summarise)
importFrom(dplyr,tibble)
importFrom(dplyr,vars)
importFrom(graphics,plot)
importFrom(graphics,text)
importFrom(reshape2,dcast)
importFrom(rvest,html_nodes)
importFrom(rvest,html_table)
importFrom(xml2,read_html)
-638
View File
@@ -1,638 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' EUCAST expert rules
#'
#' Apply expert rules (like intrinsic resistance), as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}.
#' @param tbl table with antibiotic columns, like e.g. \code{amox} and \code{amcl}
#' @param col_bactcode column name of the bacteria ID in \code{tbl} - should also be present in \code{bactlist$bactid}, see \code{\link{bactlist}}.
#' @param info print progress
#' @param amcl,amik,amox,ampi,azit,aztr,cefa,cfra,cfep,cfot,cfox,cfta,cftr,cfur,chlo,cipr,clar,clin,clox,coli,czol,dapt,doxy,erta,eryt,fosf,fusi,gent,imip,kana,levo,linc,line,mero,mino,moxi,nali,neom,neti,nitr,novo,norf,oflo,peni,pita,poly,qida,rifa,roxi,siso,teic,tetr,tica,tige,tobr,trim,trsu,vanc column names of antibiotics. Use \code{NA} to skip a column, like \code{tica = NA}. Non-existing column will be skipped.
#' @param ... parameters that are passed on to \code{EUCAST_rules}
#' @name EUCAST
#' @rdname EUCAST
#' @export
#' @importFrom dplyr %>% left_join select
#' @return table with edited variables of antibiotics.
#' @source
#' EUCAST Expert Rules Version 2.0: \cr
#' Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility testing.} \emph{Clin Microbiol Infect.} 2013;19(2):141-60. \cr
#' \url{https://doi.org/10.1111/j.1469-0691.2011.03703.x} \cr
#' \cr
#' EUCAST Expert Rules Version 3.1: \cr
#' \url{http://www.eucast.org/expert_rules_and_intrinsic_resistance}
#' @examples
#' \dontrun{
#' tbl <- EUCAST_rules(tbl)
#' }
EUCAST_rules <- function(tbl,
col_bactcode = 'bacteriecode',
info = TRUE,
amcl = 'amcl',
amik = 'amik',
amox = 'amox',
ampi = 'ampi',
azit = 'azit',
aztr = 'aztr',
cefa = 'cefa',
cfra = 'cfra',
cfep = 'cfep',
cfot = 'cfot',
cfox = 'cfox',
cfta = 'cfta',
cftr = 'cftr',
cfur = 'cfur',
chlo = 'chlo',
cipr = 'cipr',
clar = 'clar',
clin = 'clin',
clox = 'clox',
coli = 'coli',
czol = 'czol',
dapt = 'dapt',
doxy = 'doxy',
erta = 'erta',
eryt = 'eryt',
fosf = 'fosf',
fusi = 'fusi',
gent = 'gent',
imip = 'imip',
kana = 'kana',
levo = 'levo',
linc = 'linc',
line = 'line',
mero = 'mero',
mino = 'mino',
moxi = 'moxi',
nali = 'nali',
neom = 'neom',
neti = 'neti',
nitr = 'nitr',
novo = 'novo',
norf = 'norf',
oflo = 'oflo',
peni = 'peni',
pita = 'pita',
poly = 'poly',
qida = 'qida',
rifa = 'rifa',
roxi = 'roxi',
siso = 'siso',
teic = 'teic',
tetr = 'tetr',
tica = 'tica',
tige = 'tige',
tobr = 'tobr',
trim = 'trim',
trsu = 'trsu',
vanc = 'vanc') {
if (!col_bactcode %in% colnames(tbl)) {
stop('Column ', col_bactcode, ' not found.')
}
# kolommen controleren
col.list <- c(amcl, amik, amox, ampi, azit, aztr, cefa, cfra, cfep,
cfot, cfox, cfta, cftr, cfur, cipr, clar, clin, clox, coli, czol,
dapt, doxy, erta, eryt, fusi, gent, imip, kana, levo, linc, line,
mero, mino, moxi, nali, neom, neti, nitr, novo, norf, oflo, peni,
pita, poly, qida, rifa, roxi, siso, teic, tetr, tica, tige, tobr,
trim, trsu, vanc)
col.list <- col.list[!is.na(col.list)]
if (!all(col.list %in% colnames(tbl))) {
if (info == TRUE) {
cat('\n')
}
if (info == TRUE) {
warning('These columns do not exist and will be ignored:\n',
col.list[!(col.list %in% colnames(tbl))] %>% toString(),
immediate. = TRUE,
call. = FALSE)
}
if (!amcl %in% colnames(tbl)) { amcl <- NA }
if (!amik %in% colnames(tbl)) { amik <- NA }
if (!amox %in% colnames(tbl)) { amox <- NA }
if (!ampi %in% colnames(tbl)) { ampi <- NA }
if (!azit %in% colnames(tbl)) { azit <- NA }
if (!aztr %in% colnames(tbl)) { aztr <- NA }
if (!cefa %in% colnames(tbl)) { cefa <- NA }
if (!cfra %in% colnames(tbl)) { cfra <- NA }
if (!cfep %in% colnames(tbl)) { cfep <- NA }
if (!cfot %in% colnames(tbl)) { cfot <- NA }
if (!cfox %in% colnames(tbl)) { cfox <- NA }
if (!cfta %in% colnames(tbl)) { cfta <- NA }
if (!cftr %in% colnames(tbl)) { cftr <- NA }
if (!cfur %in% colnames(tbl)) { cfur <- NA }
if (!chlo %in% colnames(tbl)) { chlo <- NA }
if (!cipr %in% colnames(tbl)) { cipr <- NA }
if (!clar %in% colnames(tbl)) { clar <- NA }
if (!clin %in% colnames(tbl)) { clin <- NA }
if (!clox %in% colnames(tbl)) { clox <- NA }
if (!coli %in% colnames(tbl)) { coli <- NA }
if (!czol %in% colnames(tbl)) { czol <- NA }
if (!dapt %in% colnames(tbl)) { dapt <- NA }
if (!doxy %in% colnames(tbl)) { doxy <- NA }
if (!erta %in% colnames(tbl)) { erta <- NA }
if (!eryt %in% colnames(tbl)) { eryt <- NA }
if (!fosf %in% colnames(tbl)) { fosf <- NA }
if (!fusi %in% colnames(tbl)) { fusi <- NA }
if (!gent %in% colnames(tbl)) { gent <- NA }
if (!imip %in% colnames(tbl)) { imip <- NA }
if (!kana %in% colnames(tbl)) { kana <- NA }
if (!levo %in% colnames(tbl)) { levo <- NA }
if (!linc %in% colnames(tbl)) { linc <- NA }
if (!line %in% colnames(tbl)) { line <- NA }
if (!mero %in% colnames(tbl)) { mero <- NA }
if (!mino %in% colnames(tbl)) { mino <- NA }
if (!moxi %in% colnames(tbl)) { moxi <- NA }
if (!nali %in% colnames(tbl)) { nali <- NA }
if (!neom %in% colnames(tbl)) { neom <- NA }
if (!neti %in% colnames(tbl)) { neti <- NA }
if (!nitr %in% colnames(tbl)) { nitr <- NA }
if (!novo %in% colnames(tbl)) { novo <- NA }
if (!norf %in% colnames(tbl)) { norf <- NA }
if (!oflo %in% colnames(tbl)) { oflo <- NA }
if (!peni %in% colnames(tbl)) { peni <- NA }
if (!pita %in% colnames(tbl)) { pita <- NA }
if (!poly %in% colnames(tbl)) { poly <- NA }
if (!qida %in% colnames(tbl)) { qida <- NA }
if (!rifa %in% colnames(tbl)) { rifa <- NA }
if (!roxi %in% colnames(tbl)) { roxi <- NA }
if (!siso %in% colnames(tbl)) { siso <- NA }
if (!teic %in% colnames(tbl)) { teic <- NA }
if (!tetr %in% colnames(tbl)) { tetr <- NA }
if (!tica %in% colnames(tbl)) { tica <- NA }
if (!tige %in% colnames(tbl)) { tige <- NA }
if (!tobr %in% colnames(tbl)) { tobr <- NA }
if (!trim %in% colnames(tbl)) { trim <- NA }
if (!trsu %in% colnames(tbl)) { trsu <- NA }
if (!vanc %in% colnames(tbl)) { vanc <- NA }
}
total <- 0
# functie voor uitvoeren
edit_rsi <- function(to, rows, cols) {
#voortgang$tick()$print()
cols <- cols[!is.na(cols)]
if (length(rows) > 0 & length(cols) > 0) {
tbl[rows, cols] <<- to
total <<- total + (length(rows) * length(cols))
}
}
# bactlist aan vastknopen (bestaande kolommen krijgen extra suffix)
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- col_bactcode
tbl <- tbl %>% left_join(y = AMR::bactlist, by = joinby, suffix = c("_tempbactlist", ""))
# antibioticagroepen
aminoglycosiden <- c(tobr, gent, kana, neom, neti, siso)
tetracyclines <- c(doxy, mino, tetr) # sinds EUCAST v3.1 is tige(cycline) apart
polymyxines <- c(poly, coli)
macroliden <- c(eryt, azit, roxi, clar) # sinds EUCAST v3.1 is clinda apart
glycopeptiden <- c(vanc, teic)
streptogramines <- qida # eigenlijk pristinamycine en quinupristine/dalfopristine
cefalosporines <- c(cfep, cfot, cfox, cfra, cfta, cftr, cfur, czol)
carbapenems <- c(erta, imip, mero)
aminopenicillines <- c(ampi, amox)
ureidopenicillines <- pita # eigenlijk ook azlo en mezlo
fluorochinolonen <- c(oflo, cipr, norf, levo, moxi)
if (info == TRUE) {
cat('\nApplying EUCAST expert rules on',
tbl[!is.na(tbl$genus),] %>% nrow(),
'isolates according to "EUCAST Expert Rules Version 3.1"\n\n')
}
# Table 1: Intrinsic resistance in Enterobacteriaceae ----
if (info == TRUE) {
cat('...Table 1: Intrinsic resistance in Enterobacteriaceae\n')
}
#voortgang <- progress_estimated(17)
# Intrisiek R voor groep
edit_rsi(to = 'R',
rows = which(tbl$family == 'Enterobacteriaceae'),
cols = c(peni, glycopeptiden, fusi, macroliden, linc, streptogramines, rifa, dapt, line))
# Citrobacter
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Citrobacter (koseri|amalonaticus|sedlakii|farmeri|rodentium)'),
cols = c(ampi, tica))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Citrobacter (freundii|braakii|murliniae|werkmanii|youngae)'),
cols = c(ampi, amcl, czol, cfox))
# Enterobacter
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Enterobacter cloacae'),
cols = c(ampi, amcl, czol, cfox))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Enterobacter aerogenes'),
cols = c(ampi, amcl, czol, cfox))
# Escherichia
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Escherichia hermanni'),
cols = c(ampi, tica))
# Hafnia
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Hafnia alvei'),
cols = c(ampi, amcl, czol, cfox))
# Klebsiella
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Klebsiella'),
cols = c(ampi, tica))
# Morganella / Proteus
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Morganella morganii'),
cols = c(ampi, amcl, czol, tetracyclines, polymyxines, nitr))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Proteus mirabilis'),
cols = c(tetracyclines, tige, polymyxines, nitr))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Proteus penneri'),
cols = c(ampi, czol, cfur, tetracyclines, tige, polymyxines, nitr))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Proteus vulgaris'),
cols = c(ampi, czol, cfur, tetracyclines, tige, polymyxines, nitr))
# Providencia
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Providencia rettgeri'),
cols = c(ampi, amcl, czol, cfur, tetracyclines, tige, polymyxines, nitr))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Providencia stuartii'),
cols = c(ampi, amcl, czol, cfur, tetracyclines, tige, polymyxines, nitr))
# Raoultella
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Raoultella'),
cols = c(ampi, tica))
# Serratia
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Serratia marcescens'),
cols = c(ampi, amcl, czol, cfox, cfur, tetracyclines[tetracyclines != 'mino'], polymyxines, nitr))
# Yersinia
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Yersinia enterocolitica'),
cols = c(ampi, amcl, tica, czol, cfox))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Yersinia pseudotuberculosis'),
cols = c(poly, coli))
# Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria ----
if (info == TRUE) {
cat('...Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria\n')
}
#voortgang <- progress_estimated(8)
# Intrisiek R voor groep
edit_rsi(to = 'R',
rows = which(tbl$genus %in% c('Achromobacter',
'Acinetobacter',
'Alcaligenes',
'Bordatella',
'Burkholderia',
'Elizabethkingia',
'Flavobacterium',
'Ochrobactrum',
'Pseudomonas',
'Stenotrophomonas')),
cols = c(peni, cfox, cfur, glycopeptiden, fusi, macroliden, linc, streptogramines, rifa, dapt, line))
# Acinetobacter
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Acinetobacter (baumannii|pittii|nosocomialis|calcoaceticus)'),
cols = c(ampi, amcl, czol, cfot, cftr, aztr, erta, trim, fosf, tetracyclines[tetracyclines != 'mino']))
# Achromobacter
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Achromobacter (xylosoxydans|xylosoxidans)'),
cols = c(ampi, czol, cfot, cftr, erta))
# Burkholderia
edit_rsi(to = 'R',
# onder 'Burkholderia cepacia complex' vallen deze species allemaal: PMID 16217180.
rows = which(tbl$fullname %like% '^Burkholderia (cepacia|multivorans|cenocepacia|stabilis|vietnamiensis|dolosa|ambifaria|anthina|pyrrocinia|ubonensis)'),
cols = c(ampi, amcl, tica, pita, czol, cfot, cftr, aztr, erta, cipr, chlo, aminoglycosiden, trim, fosf, polymyxines))
# Elizabethkingia
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Elizabethkingia meningoseptic(a|um)'),
cols = c(ampi, amcl, tica, czol, cfot, cftr, cfta, cfep, aztr, erta, imip, mero, polymyxines))
# Ochrobactrum
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Ochrobactrum anthropi'),
cols = c(ampi, amcl, tica, pita, czol, cfot, cftr, cfta, cfep, aztr, erta))
# Pseudomonas
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Pseudomonas aeruginosa'),
cols = c(ampi, amcl, czol, cfot, cftr, erta, chlo, kana, neom, trim, trsu, tetracyclines, tige))
# Stenotrophomonas
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Stenotrophomonas maltophilia'),
cols = c(ampi, amcl, tica, pita, czol, cfot, cftr, cfta, aztr, erta, imip, mero, aminoglycosiden, trim, fosf, tetr))
# Table 3: Intrinsic resistance in other Gram-negative bacteria ----
if (info == TRUE) {
cat('...Table 3: Intrinsic resistance in other Gram-negative bacteria\n')
}
#voortgang <- progress_estimated(7)
# Intrisiek R voor groep
edit_rsi(to = 'R',
rows = which(tbl$genus %in% c('Haemophilus',
'Moraxella',
'Neisseria',
'Campylobacter')),
cols = c(glycopeptiden, linc, dapt, line))
# Haemophilus
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Haemophilus influenzae'),
cols = c(fusi, streptogramines))
# Moraxella
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Moraxella catarrhalis'),
cols = trim)
# Neisseria
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Neisseria'),
cols = trim)
# Campylobacter
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Campylobacter fetus'),
cols = c(fusi, streptogramines, trim, nali))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Campylobacter (jejuni|coli)'),
cols = c(fusi, streptogramines, trim))
# Table 4: Intrinsic resistance in Gram-positive bacteria ----
if (info == TRUE) {
cat('...Table 4: Intrinsic resistance in Gram-positive bacteria\n')
}
#voortgang <- progress_estimated(14)
# Intrisiek R voor groep
edit_rsi(to = 'R',
rows = which(tbl$gramstain %like% 'Positi(e|)(v|f)'),
cols = c(aztr, polymyxines, nali))
# Staphylococcus
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Staphylococcus saprophyticus'),
cols = c(fusi, cfta, fosf, novo))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Staphylococcus (cohnii|xylosus)'),
cols = c(cfta, novo))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Staphylococcus capitis'),
cols = c(cfta, fosf))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Staphylococcus (aureus|epidermidis|coagulase negatief|hominis|haemolyticus|intermedius|pseudointermedius)'),
cols = cfta)
# Streptococcus
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Streptococcus'),
cols = c(fusi, cfta, aminoglycosiden))
# Enterococcus
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Enterococcus faecalis'),
cols = c(fusi, cfta, cefalosporines[cefalosporines != cfta], aminoglycosiden, macroliden, clin, qida, trim, trsu))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Enterococcus (gallinarum|casseliflavus)'),
cols = c(fusi, cfta, cefalosporines[cefalosporines != cfta], aminoglycosiden, macroliden, clin, qida, vanc, trim, trsu))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Enterococcus faecium'),
cols = c(fusi, cfta, cefalosporines[cefalosporines != cfta], aminoglycosiden, macroliden, trim, trsu))
# Corynebacterium
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Corynebacterium'),
cols = fosf)
# Listeria
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Listeria monocytogenes'),
cols = c(cfta, cefalosporines[cefalosporines != cfta]))
# overig
edit_rsi(to = 'R',
rows = which(tbl$genus %in% c('Leuconostoc', 'Pediococcus')),
cols = c(vanc, teic))
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Lactobacillus'),
cols = c(vanc, teic))
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Clostridium (ramosum|innocuum)'),
cols = vanc)
# Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci ----
if (info == TRUE) {
cat('...Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci\n')
}
#voortgang <- progress_estimated(2)
# regel 8.3
if (!is.na(peni)) {
edit_rsi(to = 'S',
rows = which(tbl$fullname %like% '^Streptococcus (pyogenes|agalactiae|dysgalactiae|groep A|groep B|groep C|groep G)'
& tbl[, peni] == 'S'),
cols = c(aminopenicillines, cefalosporines, carbapenems))
}
# regel 8.6
if (!is.na(ampi)) {
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Enterococcus'
& tbl[, ampi] == 'R'),
cols = c(ureidopenicillines, carbapenems))
}
# Table 9: Interpretive rules for B-lactam agents and Gram-negative rods ----
if (info == TRUE) {
cat('...Table 9: Interpretive rules for B-lactam agents and Gram-negative rods\n')
}
#voortgang <- progress_estimated(1)
# regel 9.3
if (!is.na(tica) & !is.na(pita)) {
edit_rsi(to = 'R',
rows = which(tbl$family == 'Enterobacteriaceae'
& tbl[, tica] == 'R'
& tbl[, pita] == 'S'),
cols = pita)
}
# Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria ----
if (info == TRUE) {
cat('...Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria\n')
}
#voortgang <- progress_estimated(1)
# regel 10.2
if (!is.na(ampi)) {
# hiervoor moeten we eerst weten of ze B-lactamase-positief zijn
# edit_rsi(to = 'R',
# rows = which(tbl$fullname %like% '^Haemophilus influenza'
# & tbl[, ampi] == 'R'),
# cols = c(ampi, amox, amcl, pita, cfur))
}
# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins ----
if (info == TRUE) {
cat('...Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins\n')
}
# regel 11.1
if (!is.na(eryt)) {
if (!is.na(azit)) {
tbl[, azit] <- tbl[, eryt]
}
if (!is.na(clar)) {
tbl[, clar] <- tbl[, eryt]
}
}
# Table 12: Interpretive rules for aminoglycosides ----
if (info == TRUE) {
cat('...Table 12: Interpretive rules for aminoglycosides\n')
}
#voortgang <- progress_estimated(4)
# regel 12.2
if (!is.na(tobr)) {
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Staphylococcus'
& tbl[, tobr] == 'R'),
cols = c(kana, amik))
}
# regel 12.3
if (!is.na(gent)) {
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Staphylococcus'
& tbl[, gent] == 'R'),
cols = aminoglycosiden)
}
# regel 12.8
if (!is.na(gent) & !is.na(tobr)) {
edit_rsi(to = 'R',
rows = which(tbl$family == 'Enterobacteriaceae'
& tbl[, gent] == 'I'
& tbl[, tobr] == 'S'),
cols = gent)
}
# regel 12.9
if (!is.na(gent) & !is.na(tobr)) {
edit_rsi(to = 'R',
rows = which(tbl$family == 'Enterobacteriaceae'
& tbl[, tobr] == 'I'
& tbl[, gent] == 'R'),
cols = tobr)
}
# Table 13: Interpretive rules for quinolones ----
if (info == TRUE) {
cat('...Table 13: Interpretive rules for quinolones\n')
}
#voortgang <- progress_estimated(4)
# regel 13.2
if (!is.na(moxi)) {
edit_rsi(to = 'R',
rows = which(tbl$genus == 'Staphylococcus'
& tbl[, moxi] == 'R'),
cols = fluorochinolonen)
}
# regel 13.4
if (!is.na(moxi)) {
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Streptococcus pneumoniae'
& tbl[, moxi] == 'R'),
cols = fluorochinolonen)
}
# regel 13.5
if (!is.na(cipr)) {
edit_rsi(to = 'R',
rows = which(tbl$family == 'Enterobacteriaceae'
& tbl[, cipr] == 'R'),
cols = fluorochinolonen)
}
# regel 13.8
if (!is.na(cipr)) {
edit_rsi(to = 'R',
rows = which(tbl$fullname %like% '^Neisseria gonorrhoeae'
& tbl[, cipr] == 'R'),
cols = fluorochinolonen)
}
# Other ----
if (info == TRUE) {
cat('...Other\n')
}
#voortgang <- progress_estimated(2)
if (!is.na(amcl)) {
edit_rsi(to = 'R',
rows = which(tbl[, amcl] == 'R'),
cols = ampi)
}
if (!is.na(trsu)) {
edit_rsi(to = 'R',
rows = which(tbl[, trsu] == 'R'),
cols = trim)
}
if (!is.na(ampi) & !is.na(amox)) {
tbl[, amox] <- tbl[, ampi]
}
# Toegevoegde kolommen weer verwijderen
bactlist.ncol <- ncol(AMR::bactlist) - 2
tbl.ncol <- ncol(tbl)
tbl <- tbl %>% select(-c((tbl.ncol - bactlist.ncol):tbl.ncol))
# en eventueel toegevoegde suffix aan bestaande kolommen weer verwijderen
colnames(tbl) <- gsub("_tempbactlist", "", colnames(tbl))
if (info == TRUE) {
cat('\nDone.\nExpert rules applied to', total, 'test results.\n')
}
tbl
}
#' @rdname EUCAST
#' @export
interpretive_reading <- function(...) {
EUCAST_rules(...)
}
#' Poperties of a microorganism
#'
#' @param bactcode ID of a microorganisme, like \code{"STAAUR} and \code{"ESCCOL}
#' @param property One of the values \code{bactid}, \code{bactsys}, \code{family}, \code{genus}, \code{species}, \code{subspecies}, \code{fullname}, \code{type}, \code{gramstain}, \code{aerobic}
#' @export
#' @importFrom dplyr %>% filter select
#' @seealso \code{\link{bactlist}}
mo_property <- function(bactcode, property = 'fullname') {
mocode <- as.character(bactcode)
for (i in 1:length(mocode)) {
bug <- mocode[i]
if (!is.na(bug)) {
result = tryCatch({
mocode[i] <-
AMR::bactlist %>%
filter(bactid == bactcode) %>%
select(property) %>%
unlist() %>%
as.character()
}, error = function(error_condition) {
warning('Code ', bug, ' not found in bacteria list.')
}, finally = {
if (mocode[i] == bug & !property %in% c('bactid', 'bactsys')) {
mocode[i] <- NA
}
})
}
}
mocode
}
-226
View File
@@ -1,226 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' Properties of an ATC code
#'
#' Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic. \strong{This function requires an internet connection.}
#' @param atc_code a character or character vector with ATC code(s) of antibiotic(s)
#' @param property property of an ATC code. Valid values are \code{"ATC code"}, \code{"Name"}, \code{"DDD"}, \code{"U"} (\code{"unit"}), \code{"Adm.R"} en \code{"Note"}.
#' @param administration type of administration, see \emph{Details}
#' @param url url of website of the WHO. The sign \code{\%s} can be used as a placeholder for ATC codes.
#' @details
#' Abbreviations for the property \code{"Adm.R"} (parameter \code{administration}):
#' \itemize{
#' \item{\code{"Implant"}}{ = Implant}
#' \item{\code{"Inhal"}}{ = Inhalation}
#' \item{\code{"Instill"}}{ = Instillation}
#' \item{\code{"N"}}{ = nasal}
#' \item{\code{"O"}}{ = oral}
#' \item{\code{"P"}}{ = parenteral}
#' \item{\code{"R"}}{ = rectal}
#' \item{\code{"SL"}}{ = sublingual/buccal}
#' \item{\code{"TD"}}{ = transdermal}
#' \item{\code{"V"}}{ = vaginal}
#' }
#'
#' Abbreviations for the property \code{"U"} (unit):
#' \itemize{
#' \item{\code{"g"}}{ = gram}
#' \item{\code{"mg"}}{ = milligram}
#' \item{\code{"mcg"}}{ = microgram}
#' \item{\code{"U"}}{ = unit}
#' \item{\code{"TU"}}{ = thousand units}
#' \item{\code{"MU"}}{ = million units}
#' \item{\code{"mmol"}}{ = millimole}
#' \item{\code{"ml"}}{ = milliliter (e.g. eyedrops)}
#' }
#' @export
#' @importFrom dplyr %>% progress_estimated
#' @importFrom xml2 read_html
#' @importFrom rvest html_nodes html_table
#' @source \url{https://www.whocc.no/atc_ddd_alterations__cumulative/ddd_alterations/abbrevations/}
#' @examples
#' \donttest{
#' atc_property("J01CA04", "DDD", "O") # oral DDD of amoxicillin
#' atc_property("J01CA04", "DDD", "P") # parenteral DDD of amoxicillin
#' }
atc_property <- function(atc_code,
property,
administration = 'O',
url = 'https://www.whocc.no/atc_ddd_index/?code=%s&showdescription=no') {
# property <- property %>% tolower()
#
if (property %like% 'unit') {
property <- 'U'
}
# validation of properties
valid_properties.bak <- c("ATC code", "Name", "DDD", "U", "Adm.R", "Note")
valid_properties <- valid_properties.bak #%>% tolower()
if (!property %in% valid_properties) {
stop('Invalid `property`, use one of ', paste(valid_properties, collapse = ", "), '.')
}
returnvalue <- rep(NA_character_, length(atc_code))
if (property == 'DDD') {
returnvalue <- rep(NA_real_, length(atc_code))
}
progress <- progress_estimated(n = length(atc_code))
for (i in 1:length(atc_code)) {
progress$tick()$print()
atc_url <- sub('%s', atc_code[i], url, fixed = TRUE)
tbl <- xml2::read_html(atc_url) %>%
rvest::html_nodes('table') %>%
rvest::html_table(header = TRUE)
if (length(tbl) == 0) {
warning('ATC not found: ', atc_code[i], '. Please check ', atc_url, '.', call. = FALSE)
returnvalue[i] <- NA
next
}
tbl <- tbl[[1]]
if (property == 'Name') {
returnvalue[i] <- tbl[1, 2]
} else {
names(returnvalue)[i] <- tbl[1, 2] %>% as.character()
if (!'Adm.R' %in% colnames(tbl) | is.na(tbl[1, 'Adm.R'])) {
returnvalue[i] <- NA
next
} else {
for (j in 1:nrow(tbl)) {
if (tbl[j, 'Adm.R'] == administration) {
returnvalue[i] <- tbl[j, property]
}
}
}
}
}
cat('\n')
returnvalue
}
#' Name of an antibiotic
#'
#' Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{ablist}}.
#' @param abcode a code or name, like \code{"amox"}, \code{"cftr"} or \code{"J01CA04"}
#' @param from,to type to transform from and to. See \code{\link{ablist}} for its column names.
#' @param textbetween text to put between multiple returned texts
#' @param tolower return output as lower case with function \code{\link{tolower}}.
#' @keywords ab antibiotics
#' @source \code{\link{ablist}}
#' @export
#' @importFrom dplyr %>% filter select slice
#' @examples
#' abname("AMCL")
#' # "amoxicillin and enzyme inhibitor"
#'
#' abname("AMCL+GENT")
#' # "amoxicillin and enzyme inhibitor + gentamicin"
#'
#' abname(c("AMCL", "GENT"))
#' # "amoxicillin and enzyme inhibitor" "gentamicin"
#'
#' abname("AMCL", to = "trivial")
#' # "Amoxicilline/clavulaanzuur"
#'
#' abname("AMCL", to = "atc")
#' # "J01CR02"
#'
#' abname("J01CR02", from = "atc", to = "umcg")
#' # "AMCL"
abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', tolower = FALSE) {
ablist <- AMR::ablist
colnames(ablist) <- colnames(ablist) %>% tolower()
from <- from %>% tolower()
to <- to %>% tolower()
if (!from %in% colnames(ablist) |
!to %in% colnames(ablist)) {
stop(paste0('Invalid `from` or `to`. Choose one of ',
colnames(ablist) %>% paste(collapse = ","), '.'), call. = FALSE)
}
abcode <- as.character(abcode)
for (i in 1:length(abcode)) {
drug <- abcode[i]
if (!grepl('+', drug, fixed = TRUE) & !grepl(' en ', drug, fixed = TRUE)) {
# bestaat maar uit 1 middel
if (any(ablist[, from] == drug)) {
abcode[i] <-
ablist %>%
filter(.[, from] == drug) %>%
select(to) %>%
slice(1) %>%
as.character()
} else {
# niet gevonden
warning('Code "', drug, '" not found in antibiotics list.', call. = FALSE)
abcode[i] <- NA
}
} else {
# meerdere middelen
if (grepl('+', drug, fixed = TRUE)) {
drug.group <-
strsplit(drug, '+', fixed = TRUE) %>%
unlist() %>%
trimws('both')
} else if (grepl(' en ', drug, fixed = TRUE)) {
drug.group <-
strsplit(drug, ' en ', fixed = TRUE) %>%
unlist() %>%
trimws('both')
} else {
warning('Invalid concat.')
abcode[i] <- NA
next
}
for (j in 1:length(drug.group)) {
drug.group[j] <-
ablist %>%
filter(.[, from] == drug.group[j]) %>%
select(to) %>%
slice(1) %>%
as.character()
if (j > 1 & to %in% c('official', 'trivial')) {
drug.group[j] <- drug.group[j] %>% tolower()
}
}
abcode[i] <- paste(drug.group, collapse = textbetween)
}
}
if (tolower == TRUE) {
abcode <- abcode %>% tolower()
}
abcode
}
-375
View File
@@ -1,375 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' Class 'rsi'
#'
#' This transforms a vector to a new class \code{rsi}, which is an ordered factor with levels \code{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning.
#' @rdname as.rsi
#' @param x vector
#' @return New class \code{rsi}
#' @export
#' @importFrom dplyr %>%
#' @examples
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C"))
#' is.rsi(rsi_data)
#' plot(rsi_data)
#'
#' \donttest{
#' library(dplyr)
#' tbl %>%
#' mutate_at(vars(ends_with("_rsi")), as.rsi)
#' sapply(mic_data, is.rsi)
#' }
as.rsi <- function(x) {
if (is.rsi(x)) {
x
} else {
x <- x %>% unlist()
x.bak <- x
na_before <- x[is.na(x) | x == ''] %>% length()
x <- gsub('[^RSI]+', '', x %>% toupper())
# needed for UMCG in cases of "S;S" but also "S;I"; the latter will be NA:
x <- gsub('^S+$', 'S', x)
x <- gsub('^I+$', 'I', x)
x <- gsub('^R+$', 'R', x)
x[!x %in% c('S', 'I', 'R')] <- NA
na_after <- x[is.na(x) | x == ''] %>% length()
if (na_before != na_after) {
list_missing <- x.bak[is.na(x) & !is.na(x.bak) & x.bak != ''] %>%
unique() %>%
sort()
list_missing <- paste0('"', list_missing , '"', collapse = ", ")
warning(na_after - na_before, ' results truncated (',
round(((na_after - na_before) / length(x)) / 100),
'%) that were invalid antimicrobial interpretations: ',
list_missing, call. = FALSE)
}
x <- x %>% toupper() %>% factor(levels = c("S", "I", "R"), ordered = TRUE)
class(x) <- c('rsi', 'ordered', 'factor')
x
}
}
#' @rdname as.rsi
#' @export
#' @importFrom dplyr %>%
is.rsi <- function(x) {
class(x) %>% identical(c('rsi', 'ordered', 'factor'))
}
#' @exportMethod print.rsi
#' @export
#' @importFrom dplyr %>%
#' @noRd
print.rsi <- function(x, ...) {
n_total <- x %>% length()
x <- x[!is.na(x)]
n <- x %>% length()
S <- x[x == 'S'] %>% length()
I <- x[x == 'I'] %>% length()
R <- x[x == 'R'] %>% length()
IR <- x[x %in% c('I', 'R')] %>% length()
cat("Class 'rsi': ", n, " isolates\n", sep = '')
cat('\n')
cat('<NA>: ', n_total - n, '\n')
cat('Sum of S: ', S, '\n')
cat('Sum of IR: ', IR, '\n')
cat('- Sum of R:', R, '\n')
cat('- Sum of I:', I, '\n')
cat('\n')
print(c(
`%S` = round((S / n) * 100, 1),
`%IR` = round((IR / n) * 100, 1),
`%I` = round((I / n) * 100, 1),
`%R` = round((R / n) * 100, 1)
))
}
#' @exportMethod summary.rsi
#' @export
#' @importFrom dplyr %>%
#' @noRd
summary.rsi <- function(object, ...) {
x <- object
n_total <- x %>% length()
x <- x[!is.na(x)]
n <- x %>% length()
S <- x[x == 'S'] %>% length()
I <- x[x == 'I'] %>% length()
R <- x[x == 'R'] %>% length()
IR <- x[x %in% c('I', 'R')] %>% length()
lst <- c('rsi', n_total - n, S, IR, R, I)
names(lst) <- c("Mode", "<NA>", "Sum S", "Sum IR", "Sum R", "Sum I")
lst
}
#' @exportMethod plot.rsi
#' @export
#' @importFrom dplyr %>% group_by summarise filter mutate if_else
#' @importFrom graphics plot text
#' @noRd
plot.rsi <- function(x, ...) {
x_name <- deparse(substitute(x))
data <- data.frame(x = x,
y = 1,
stringsAsFactors = TRUE) %>%
group_by(x) %>%
summarise(n = sum(y)) %>%
filter(!is.na(x)) %>%
mutate(s = round((n / sum(n)) * 100, 1))
data$x <- factor(data$x, levels = c('S', 'I', 'R'), ordered = TRUE)
ymax <- if_else(max(data$s) > 95, 105, 100)
plot(x = data$x,
y = data$s,
lwd = 2,
col = c('green', 'orange', 'red'),
ylim = c(0, ymax),
ylab = 'Percentage',
xlab = 'Antimicrobial Interpretation',
main = paste('Susceptibilty Analysis of', x_name),
...)
text(x = data$x,
y = data$s + 5,
labels = paste0(data$s, '% (n = ', data$n, ')'))
}
#' Class 'mic'
#'
#' This transforms a vector to a new class\code{mic}, which is an ordered factor valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
#' @rdname as.mic
#' @param x vector
#' @param na.rm a logical indicating whether missing values should be removed
#' @return New class \code{mic}
#' @export
#' @importFrom dplyr %>%
#' @examples
#' mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
#' is.mic(mic_data)
#' plot(mic_data)
#'
#' \donttest{
#' library(dplyr)
#' tbl %>%
#' mutate_at(vars(ends_with("_mic")), as.mic)
#' sapply(mic_data, is.mic)
#' }
as.mic <- function(x, na.rm = FALSE) {
if (is.mic(x)) {
x
} else {
x <- x %>% unlist()
if (na.rm == TRUE) {
x <- x[!is.na(x)]
}
x.bak <- x
# comma to dot
x <- gsub(',', '.', x, fixed = TRUE)
# starting dots must start with 0
x <- gsub('^[.]', '0.', x)
# <=0.2560.512 should be 0.512
x <- gsub('.*[.].*[.]', '0.', x)
# remove ending .0
x <- gsub('[.]0$', '', x)
# remove all after last digit
x <- gsub('[^0-9]$', '', x)
# remove last zeroes
x <- gsub('[.]?0+$', '', x)
lvls <- c("<0.002", "<=0.002", "0.002", ">=0.002", ">0.002",
"<0.003", "<=0.003", "0.003", ">=0.003", ">0.003",
"<0.004", "<=0.004", "0.004", ">=0.004", ">0.004",
"<0.006", "<=0.006", "0.006", ">=0.006", ">0.006",
"<0.008", "<=0.008", "0.008", ">=0.008", ">0.008",
"<0.012", "<=0.012", "0.012", ">=0.012", ">0.012",
"<0.016", "<=0.016", "0.016", ">=0.016", ">0.016",
"<0.023", "<=0.023", "0.023", ">=0.023", ">0.023",
"<0.03", "<=0.03", "0.03", ">=0.03", ">0.03",
"<0.032", "<=0.032", "0.032", ">=0.032", ">0.032",
"<0.047", "<=0.047", "0.047", ">=0.047", ">0.047",
"<0.05", "<=0.05", "0.05", ">=0.05", ">0.05",
"<0.06", "<=0.06", "0.06", ">=0.06", ">0.06",
"<0.0625", "<=0.0625", "0.0625", ">=0.0625", ">0.0625",
"<0.064", "<=0.064", "0.064", ">=0.064", ">0.064",
"<0.09", "<=0.09", "0.09", ">=0.09", ">0.09",
"<0.094", "<=0.094", "0.094", ">=0.094", ">0.094",
"<0.12", "<=0.12", "0.12", ">=0.12", ">0.12",
"<0.125", "<=0.125", "0.125", ">=0.125", ">0.125",
"<0.128", "<=0.128", "0.128", ">=0.128", ">0.128",
"<0.19", "<=0.19", "0.19", ">=0.19", ">0.19",
"<0.25", "<=0.25", "0.25", ">=0.25", ">0.25",
"<0.256", "<=0.256", "0.256", ">=0.256", ">0.256",
"<0.38", "<=0.38", "0.38", ">=0.38", ">0.38",
"<0.5", "<=0.5", "0.5", ">=0.5", ">0.5",
"<0.512", "<=0.512", "0.512", ">=0.512", ">0.512",
"<0.75", "<=0.75", "0.75", ">=0.75", ">0.75",
"<1", "<=1", "1", ">=1", ">1",
"<1.5", "<=1.5", "1.5", ">=1.5", ">1.5",
"<2", "<=2", "2", ">=2", ">2",
"<3", "<=3", "3", ">=3", ">3",
"<4", "<=4", "4", ">=4", ">4",
"<6", "<=6", "6", ">=6", ">6",
"<8", "<=8", "8", ">=8", ">8",
"<10", "<=10", "10", ">=10", ">10",
"<12", "<=12", "12", ">=12", ">12",
"<16", "<=16", "16", ">=16", ">16",
"<20", "<=20", "20", ">=20", ">20",
"<24", "<=24", "24", ">=24", ">24",
"<32", "<=32", "32", ">=32", ">32",
"<40", "<=40", "40", ">=40", ">40",
"<48", "<=48", "48", ">=48", ">48",
"<64", "<=64", "64", ">=64", ">64",
"<80", "<=80", "80", ">=80", ">80",
"<96", "<=96", "96", ">=96", ">96",
"<128", "<=128", "128", ">=128", ">128",
"<160", "<=160", "160", ">=160", ">160",
"<256", "<=256", "256", ">=256", ">256",
"<320", "<=320", "320", ">=320", ">320",
"<512", "<=512", "512", ">=512", ">512",
"<1024", "<=1024", "1024", ">=1024", ">1024")
x <- x %>% as.character()
na_before <- x[is.na(x) | x == ''] %>% length()
x[!x %in% lvls] <- NA
na_after <- x[is.na(x) | x == ''] %>% length()
if (na_before != na_after) {
list_missing <- x.bak[is.na(x) & !is.na(x.bak) & x.bak != ''] %>%
unique() %>%
sort()
list_missing <- paste0('"', list_missing , '"', collapse = ", ")
warning(na_after - na_before, ' results truncated (',
round(((na_after - na_before) / length(x)) / 100),
'%) that were invalid MICs: ',
list_missing, call. = FALSE)
}
x <- factor(x = x,
levels = lvls,
ordered = TRUE)
class(x) <- c('mic', 'ordered', 'factor')
x
}
}
#' @rdname as.mic
#' @export
#' @importFrom dplyr %>%
is.mic <- function(x) {
class(x) %>% identical(c('mic', 'ordered', 'factor'))
}
#' @exportMethod as.double.mic
#' @export
#' @importFrom dplyr %>%
#' @noRd
as.double.mic <- function(x, ...) {
as.double(gsub('(<=)|(>=)', '', as.character(x)))
}
#' @exportMethod as.integer.mic
#' @export
#' @importFrom dplyr %>%
#' @noRd
as.integer.mic <- function(x, ...) {
as.integer(gsub('(<=)|(>=)', '', as.character(x)))
}
#' @exportMethod as.numeric.mic
#' @export
#' @importFrom dplyr %>%
#' @noRd
as.numeric.mic <- function(x, ...) {
as.numeric(gsub('(<=)|(>=)', '', as.character(x)))
}
#' @exportMethod print.mic
#' @export
#' @importFrom dplyr %>% tibble group_by summarise pull
#' @noRd
print.mic <- function(x, ...) {
n_total <- x %>% length()
x <- x[!is.na(x)]
n <- x %>% length()
cat("Class 'mic': ", n, " isolates\n", sep = '')
cat('\n')
cat('<NA> ', n_total - n, '\n')
cat('\n')
tbl <- tibble(x = x, y = 1) %>% group_by(x) %>% summarise(y = sum(y))
cnt <- tbl %>% pull(y)
names(cnt) <- tbl %>% pull(x)
print(cnt)
}
#' @exportMethod summary.mic
#' @export
#' @importFrom dplyr %>% tibble group_by summarise pull
#' @noRd
summary.mic <- function(object, ...) {
x <- object
n_total <- x %>% length()
x <- x[!is.na(x)]
n <- x %>% length()
return(c("Mode" = 'mic',
"NA" = n_total - n,
"Min." = sort(x)[1] %>% as.character(),
"Max." = sort(x)[n] %>% as.character()
))
cat("Class 'mic': ", n, " isolates\n", sep = '')
cat('\n')
cat('<NA> ', n_total - n, '\n')
cat('\n')
tbl <- tibble(x = x, y = 1) %>% group_by(x) %>% summarise(y = sum(y))
cnt <- tbl %>% pull(y)
names(cnt) <- tbl %>% pull(x)
print(cnt)
}
#' @exportMethod plot.mic
#' @export
#' @importFrom dplyr %>% group_by summarise
#' @importFrom graphics plot text
#' @noRd
plot.mic <- function(x, ...) {
x_name <- deparse(substitute(x))
data <- data.frame(mic = x, cnt = 1) %>%
group_by(mic) %>%
summarise(cnt = sum(cnt)) %>%
droplevels()
plot(x = data$mic,
y = data$cnt,
lwd = 2,
ylim = c(-0.5, max(5, max(data$cnt))),
ylab = 'Frequency',
xlab = 'MIC value',
main = paste('MIC values of', x_name),
...)
text(x = data$mic,
y = -0.5,
labels = paste('n =', data$cnt))
}
-77
View File
@@ -1,77 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' Dataset with 420 antibiotics
#'
#' A dataset containing all antibiotics with a J0 code, with their DDD's.
#' @format A data.frame with 420 observations and 12 variables:
#' \describe{
#' \item{\code{atc}}{ATC code, like \code{J01CR02}}
#' \item{\code{molis}}{MOLIS code, like \code{amcl}}
#' \item{\code{umcg}}{UMCG code, like \code{AMCL}}
#' \item{\code{official}}{Official name by the WHO, like \code{"amoxicillin and enzyme inhibitor"}}
#' \item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}}
#' \item{\code{trivial}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}}
#' \item{\code{oral_ddd}}{Daily Defined Dose (DDD) according to the WHO, oral treatment}
#' \item{\code{oral_units}}{Units of \code{ddd_units}}
#' \item{\code{iv_ddd}}{Daily Defined Dose (DDD) according to the WHO, bij parenteral treatment}
#' \item{\code{iv_units}}{Units of \code{iv_ddd}}
#' \item{\code{atc_group1}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}}
#' \item{\code{atc_group2}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}}
#' }
#' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl} \cr \cr World Health Organization - \url{https://www.whocc.no/atc_ddd_index/}
#' @seealso \code{\link{bactlist}}
# todo:
# ablist <- ablist %>% mutate(useful_gramnegative = if_else(atc_group2 == 'Tetracyclines', FALSE, TRUE))
# ablist <- ablist %>% mutate(useful_gramnegative = if_else(atc_group2 %like% 'Glycopept', FALSE, useful_gramnegative))
# Tbl1 Enterobacteriaceae are also intrinsically resistant to benzylpenicillin, glycopeptides, fusidic acid, macrolides (with some exceptions1), lincosamides, streptogramins, rifampicin, daptomycin and linezolid.
# Tbl2 Non-fermentative Gram-negative bacteria are also generally intrinsically resistant to benzylpenicillin, first and second generation cephalosporins, glycopeptides, fusidic acid, macrolides, lincosamides, streptogramins, rifampicin, daptomycin and linezolid
# Tbl3 Gram-negative bacteria other than Enterobacteriaceae and non-fermentative Gram-negative bacteria listed are also intrinsically resistant to glycopeptides, lincosamides, daptomycin and linezolid.
"ablist"
#' Dataset with ~2500 microorganisms
#'
#' A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}.
#' @format A data.frame with 2507 observations and 10 variables:
#' \describe{
#' \item{\code{bactid}}{ID of microorganism}
#' \item{\code{bactsys}}{Bactsyscode of microorganism}
#' \item{\code{family}}{Family name of microorganism}
#' \item{\code{genus}}{Genus name of microorganism, like \code{"Echerichia"}}
#' \item{\code{species}}{Species name of microorganism, like \code{"coli"}}
#' \item{\code{subspecies}}{Subspecies name of bio-/serovar of microorganism, like \code{"EHEC"}}
#' \item{\code{fullname}}{Full name, like \code{"Echerichia coli (EHEC)"}}
#' \item{\code{type}}{Type of microorganism, like \code{"Bacterie"} en \code{"Schimmel/gist"} (these are Dutch)}
#' \item{\code{gramstain}}{Gram of microorganism in Dutch, like \code{"Negatieve staven"}}
#' \item{\code{aerobic}}{Type aerobe/anaerobe of bacteria}
#' }
#' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl}
#' @seealso \code{\link{ablist}} \code{\link{bactlist.umcg}}
"bactlist"
#' Translation table for UMCG with ~1100 microorganisms
#'
#' A dataset containing all bacteria codes of UMCG MMB. These codes can be joined to data with an ID from \code{\link{bactlist}$bactid}, using \code{\link{left_join_bactlist}}.
#' @format A data.frame with 1090 observations and 2 variables:
#' \describe{
#' \item{\code{mocode}}{Code of microorganism according to UMCG MMB}
#' \item{\code{bactid}}{Code of microorganism in \code{\link{bactlist}}}
#' }
#' @source MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl}
#' @seealso \code{\link{bactlist}}
"bactlist.umcg"
-516
View File
@@ -1,516 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' Determine first (weighted) isolates
#'
#' Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type.
#' @param tbl a \code{data.frame} containing isolates.
#' @param col_date column name of the result date (or date that is was received on the lab)
#' @param col_patid column name of the unique IDs of the patients
#' @param col_genus column name of the genus of the microorganisms
#' @param col_species column name of the species of the microorganisms
#' @param col_testcode column name of the test codes, see Details
#' @param col_specimen column name of the specimen type or group
#' @param col_icu column name of the logicals (\code{TRUE}/\code{FALSE}) whether a ward or department is an Intensive Care Unit (ICU)
#' @param col_keyantibiotics column name of the key antibiotics to determine first \emph{weighted} isolates, see \code{\link{key_antibiotics}}.
#' @param episode_days episode in days after which a genus/species combination will be determined as 'first isolate' again
#' @param testcodes_exclude character vector with test codes that should be excluded (caseINsensitive)
#' @param icu_exclude logical whether ICU isolates should be excluded
#' @param filter_specimen specimen group or type that should be excluded
#' @param output_logical return output as \code{logical} (will else the values \code{0} or \code{1})
#' @param ignore_I ignore \code{"I"} as antimicrobial interpretation of key antibiotics (with \code{FALSE}, changes in antibiograms from S to I and I to R will be interpreted as difference)
#' @param info print progress
# @param ... parameters to pass through to \code{first_isolate}.
#' @rdname first_isolate
#' @details To conduct an analysis of antimicrobial resistance, you should only include the first isolate of every patient per episode. If you would not do this, you could easily get an overestimate or underestimate of the resistance of an antibiotic. Imagine that a patient was admitted with an MRSA and that is was found in 5 different blood cultures the following week. The resistance percentage of oxacillin of all \emph{S. aureus} isolates would be overestimated, because you included this MRSA more than once. It would be selection bias.
#'
#' Use \code{col_testcode = NA} to \strong{not} exclude certain test codes (like test codes for screening). In that case \code{testcodes_exclude} will be ignored.
#' @keywords isolate isolates first
#' @importFrom dplyr arrange_at lag between row_number filter mutate arrange
#' @return A vector to add to table, see Examples.
#' @examples
#' \dontrun{
#'
#' # set key antibiotics to a new variable
#' tbl$keyab <- key_antibiotics(tbl)
#'
#' tbl$first_isolate <-
#' first_isolate(tbl)
#'
#' tbl$first_isolate_weighed <-
#' first_isolate(tbl,
#' col_keyantibiotics = 'keyab')
#'
#' tbl$first_blood_isolate <-
#' first_isolate(tbl,
#' filter_specimen = 'Blood')
#'
#' tbl$first_blood_isolate_weighed <-
#' first_isolate(tbl,
#' filter_specimen = 'Blood',
#' col_keyantibiotics = 'keyab')
#'
#' tbl$first_urine_isolate <-
#' first_isolate(tbl,
#' filter_specimen = 'Urine')
#'
#' tbl$first_urine_isolate_weighed <-
#' first_isolate(tbl,
#' filter_specimen = 'Urine',
#' col_keyantibiotics = 'keyab')
#'
#' tbl$first_resp_isolate <-
#' first_isolate(tbl,
#' filter_specimen = 'Respiratory')
#'
#' tbl$first_resp_isolate_weighed <-
#' first_isolate(tbl,
#' filter_specimen = 'Respiratory',
#' col_keyantibiotics = 'keyab')
#' }
first_isolate <- function(tbl,
col_date,
col_patid,
col_genus,
col_species,
col_testcode = NA,
col_specimen,
col_icu,
col_keyantibiotics = NA,
episode_days = 365,
testcodes_exclude = '',
icu_exclude = FALSE,
filter_specimen = NA,
output_logical = TRUE,
ignore_I = TRUE,
info = TRUE) {
# controleren of kolommen wel bestaan
check_columns_existance <- function(column, tblname = tbl) {
if (NROW(tblname) <= 1 | NCOL(tblname) <= 1) {
stop('Please check tbl for existance.')
}
if (!is.na(column)) {
if (!(column %in% colnames(tblname))) {
stop('Column ', column, ' not found.')
}
}
}
check_columns_existance(col_date)
check_columns_existance(col_patid)
check_columns_existance(col_genus)
check_columns_existance(col_species)
check_columns_existance(col_testcode)
check_columns_existance(col_icu)
check_columns_existance(col_keyantibiotics)
if (is.na(col_testcode)) {
testcodes_exclude <- NA
}
# testcodes verwijderen die ingevuld zijn
if (!is.na(testcodes_exclude[1]) & testcodes_exclude[1] != '' & info == TRUE) {
cat('Isolates from these test codes will be ignored:\n', toString(testcodes_exclude), '\n')
}
if (is.na(col_icu)) {
icu_exclude <- FALSE
} else {
tbl <- tbl %>%
mutate(col_icu = tbl %>% pull(col_icu) %>% as.logical())
}
specgroup.notice <- ''
weighted.notice <- ''
# filteren op materiaalgroep en sleutelantibiotica gebruiken wanneer deze ingevuld zijn
if (!is.na(filter_specimen) & filter_specimen != '') {
check_columns_existance(col_specimen, tbl)
if (info == TRUE) {
cat('Isolates other than of specimen group \'', filter_specimen, '\' will be ignored. ', sep = '')
}
} else {
filter_specimen <- ''
}
if (col_keyantibiotics %in% c(NA, '')) {
col_keyantibiotics <- ''
} else {
tbl <- tbl %>% mutate(key_ab = tbl %>% pull(col_keyantibiotics))
}
if (is.na(testcodes_exclude[1])) {
testcodes_exclude <- ''
}
# nieuwe dataframe maken met de oorspronkelijke rij-index, 0-bepaling en juiste sortering
#cat('Sorting table...')
tbl <- tbl %>%
mutate(first_isolate_row_index = 1:nrow(tbl),
eersteisolaatbepaling = 0,
date_lab = tbl %>% pull(col_date),
species = if_else(is.na(species), '', species),
genus = if_else(is.na(genus), '', genus))
if (filter_specimen == '') {
if (icu_exclude == FALSE) {
if (info == TRUE) {
cat('Isolates from ICU will *NOT* be ignored.\n')
}
tbl <- tbl %>%
arrange_at(c(col_patid,
col_genus,
col_species,
col_date))
row.start <- 1
row.end <- nrow(tbl)
} else {
if (info == TRUE) {
cat('Isolates from ICU will be ignored.\n')
}
tbl <- tbl %>%
arrange_at(c(col_icu,
col_patid,
col_genus,
col_species,
col_date))
suppressWarnings(
row.start <- which(tbl %>% pull(col_icu) == FALSE) %>% min(na.rm = TRUE)
)
suppressWarnings(
row.end <- which(tbl %>% pull(col_icu) == FALSE) %>% max(na.rm = TRUE)
)
}
} else {
# sorteren op materiaal en alleen die rijen analyseren om tijd te besparen
if (icu_exclude == FALSE) {
if (info == TRUE) {
cat('Isolates from ICU will *NOT* be ignored.\n')
}
tbl <- tbl %>%
arrange_at(c(col_specimen,
col_patid,
col_genus,
col_species,
col_date))
suppressWarnings(
row.start <- which(tbl %>% pull(col_specimen) == filter_specimen) %>% min(na.rm = TRUE)
)
suppressWarnings(
row.end <- which(tbl %>% pull(col_specimen) == filter_specimen) %>% max(na.rm = TRUE)
)
} else {
if (info == TRUE) {
cat('Isolates from ICU will be ignored.\n')
}
tbl <- tbl %>%
arrange_at(c(col_icu,
col_specimen,
col_patid,
col_genus,
col_species,
col_date))
suppressWarnings(
row.start <- which(tbl %>% pull(col_specimen) == filter_specimen
& tbl %>% pull(col_icu) == FALSE) %>% min(na.rm = TRUE)
)
suppressWarnings(
row.end <- which(tbl %>% pull(col_specimen) == filter_specimen
& tbl %>% pull(col_icu) == FALSE) %>% max(na.rm = TRUE)
)
}
}
if (abs(row.start) == Inf | abs(row.end) == Inf) {
if (info == TRUE) {
cat('No isolates found.\n')
}
# NA's maken waar genus niet beschikbaar is
tbl <- tbl %>%
mutate(real_first_isolate = if_else(genus == '', NA, FALSE))
if (output_logical == FALSE) {
tbl$real_first_isolate <- tbl %>% pull(real_first_isolate) %>% as.integer()
}
return(tbl %>% pull(real_first_isolate))
}
scope.size <- tbl %>%
filter(row_number() %>%
between(row.start,
row.end),
genus != '') %>%
nrow()
# Analyse van eerste isolaat ----
all_first <- tbl %>%
mutate(other_pat_or_mo = if_else(patient_id == lag(patient_id)
& genus == lag(genus)
& species == lag(species),
FALSE,
TRUE),
days_diff = 0) %>%
mutate(days_diff = if_else(other_pat_or_mo == FALSE,
(date_lab - lag(date_lab)) + lag(days_diff),
0))
if (col_keyantibiotics != '') {
# dit duurt 2 min bij 120.000 isolaten
if (info == TRUE) {
cat('Comparing key antibiotics for first weighted isolates')
if (ignore_I == TRUE) {
cat(' (ignoring I)')
}
cat('...\n')
}
all_first <- all_first %>%
mutate(key_ab_lag = lag(key_ab)) %>%
mutate(key_ab_other = !key_antibiotics_equal(key_ab,
key_ab_lag,
ignore_I = ignore_I,
info = info)) %>%
mutate(
real_first_isolate =
if_else(
between(row_number(), row.start, row.end)
& genus != ''
& (other_pat_or_mo
| days_diff >= episode_days
| key_ab_other),
TRUE,
FALSE))
if (info == TRUE) {
cat('\n')
}
} else {
all_first <- all_first %>%
mutate(
real_first_isolate =
if_else(
between(row_number(), row.start, row.end)
& genus != ''
& (other_pat_or_mo
| days_diff >= episode_days),
TRUE,
FALSE))
}
# allereerst isolaat als TRUE
all_first[row.start, 'real_first_isolate'] <- TRUE
# geen testen die uitgesloten moeten worden, of ICU
if (!is.na(col_testcode)) {
all_first[which(all_first[, col_testcode] %in% tolower(testcodes_exclude)), 'real_first_isolate'] <- FALSE
}
if (icu_exclude == TRUE) {
all_first[which(all_first[, col_icu] == TRUE), 'real_first_isolate'] <- FALSE
}
# NA's maken waar genus niet beschikbaar is
all_first <- all_first %>%
mutate(real_first_isolate = if_else(genus == '', NA, real_first_isolate))
all_first <- all_first %>%
arrange(first_isolate_row_index) %>%
pull(real_first_isolate)
if (info == TRUE) {
cat(paste0('\nFound ',
all_first %>% sum(na.rm = TRUE),
' first ', weighted.notice, 'isolates (',
(all_first %>% sum(na.rm = TRUE) / scope.size) %>% percent(),
' of isolates in scope [where genus was not empty] and ',
(all_first %>% sum(na.rm = TRUE) / tbl %>% nrow()) %>% percent(),
' of total)\n'))
}
if (output_logical == FALSE) {
all_first <- all_first %>% as.integer()
}
all_first
}
#' Key antibiotics based on bacteria ID
#'
#' @param tbl table with antibiotics coloms, like \code{amox} and \code{amcl}.
#' @param col_bactcode column of bacteria IDs in \code{tbl}; these should occur in \code{bactlist$bactid}, see \code{\link{bactlist}}
#' @param info print warnings
#' @param amcl,amox,cfot,cfta,cftr,cfur,cipr,clar,clin,clox,doxy,gent,line,mero,peni,pita,rifa,teic,trsu,vanc column names of antibiotics.
#' @export
#' @importFrom dplyr %>% mutate if_else
#' @return Character of length 1.
#' @seealso \code{\link{mo_property}} \code{\link{ablist}}
#' @examples
#' \donttest{
#' #' # set key antibiotics to a new variable
#' tbl$keyab <- key_antibiotics(tbl)
#' }
key_antibiotics <- function(tbl,
col_bactcode = 'bacteriecode',
info = TRUE,
amcl = 'amcl',
amox = 'amox',
cfot = 'cfot',
cfta = 'cfta',
cftr = 'cftr',
cfur = 'cfur',
cipr = 'cipr',
clar = 'clar',
clin = 'clin',
clox = 'clox',
doxy = 'doxy',
gent = 'gent',
line = 'line',
mero = 'mero',
peni = 'peni',
pita = 'pita',
rifa = 'rifa',
teic = 'teic',
trsu = 'trsu',
vanc = 'vanc') {
keylist <- character(length = nrow(tbl))
# check columns
col.list <- c(amox, cfot, cfta, cftr, cfur, cipr, clar,
clin, clox, doxy, gent, line, mero, peni,
pita, rifa, teic, trsu, vanc)
col.list <- col.list[!is.na(col.list)]
if (!all(col.list %in% colnames(tbl))) {
if (info == TRUE) {
warning('These columns do not exist and will be ignored:\n',
col.list[!(col.list %in% colnames(tbl))] %>% toString(),
immediate. = TRUE,
call. = FALSE)
}
}
# bactlist aan vastknopen
tbl <- tbl %>% left_join_bactlist(col_bactcode)
tbl$key_ab <- NA_character_
# Staphylococcus
list_ab <- c(clox, trsu, teic, vanc, doxy, line, clar, rifa)
list_ab <- list_ab[list_ab %in% colnames(tbl)]
tbl <- tbl %>% mutate(key_ab =
if_else(genus == 'Staphylococcus',
apply(X = tbl[, list_ab],
MARGIN = 1,
FUN = function(x) paste(x, collapse = "")),
key_ab))
# Rest of Gram +
list_ab <- c(peni, amox, teic, vanc, clin, line, clar, trsu)
list_ab <- list_ab[list_ab %in% colnames(tbl)]
tbl <- tbl %>% mutate(key_ab =
if_else(gramstain %like% '^Positi[e]?ve',
apply(X = tbl[, list_ab],
MARGIN = 1,
FUN = function(x) paste(x, collapse = "")),
key_ab))
# Gram -
list_ab <- c(amox, amcl, pita, cfur, cfot, cfta, cftr, mero, cipr, trsu, gent)
list_ab <- list_ab[list_ab %in% colnames(tbl)]
tbl <- tbl %>% mutate(key_ab =
if_else(gramstain %like% '^Negati[e]?ve',
apply(X = tbl[, list_ab],
MARGIN = 1,
FUN = function(x) paste(x, collapse = "")),
key_ab))
# format
tbl <- tbl %>%
mutate(key_ab = gsub('(NA|NULL)', '-', key_ab) %>% toupper())
tbl$key_ab
}
# Compare key antibiotics
#
# Check whether two text values with key antibiotics match. Supports vectors.
# @param x,y tekst (or multiple text vectors) with antimicrobial interpretations
# @param ignore_I ignore \code{"I"} as antimicrobial interpretation of key antibiotics (with \code{FALSE}, changes in antibiograms from S to I and I to R will be interpreted as difference)
# @param info print progress
# @return logical
# @export
# @seealso \code{\link{key_antibiotics}}
# only internal use
key_antibiotics_equal <- function(x, y, ignore_I = TRUE, info = FALSE) {
if (length(x) != length(y)) {
stop('Length of `x` and `y` must be equal.')
}
result <- logical(length(x))
if (info == TRUE) {
voortgang <- dplyr::progress_estimated(length(x))
}
for (i in 1:length(x)) {
if (info == TRUE) {
voortgang$tick()$print()
}
if (is.na(x[i])) {
x[i] <- ''
}
if (is.na(y[i])) {
y[i] <- ''
}
if (nchar(x[i]) != nchar(y[i])) {
result[i] <- FALSE
} else if (x[i] == '' & y[i] == '') {
result[i] <- TRUE
} else {
x2 <- strsplit(x[i], "")[[1]]
y2 <- strsplit(y[i], "")[[1]]
if (ignore_I == TRUE) {
valid_chars <- c('S', 's', 'R', 'r')
} else {
valid_chars <- c('S', 's', 'I', 'i', 'R', 'r')
}
# Ongeldige waarden (zoals "-", NA) op beide locaties verwijderen
x2[which(!x2 %in% valid_chars)] <- '?'
x2[which(!y2 %in% valid_chars)] <- '?'
y2[which(!x2 %in% valid_chars)] <- '?'
y2[which(!y2 %in% valid_chars)] <- '?'
result[i] <- all(x2 == y2)
}
}
if (info == TRUE) {
cat('\n')
}
result
}
-37
View File
@@ -1,37 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
globalVariables(c('.',
'abname',
'bactid',
'cnt',
'date_lab',
'days_diff',
'first_isolate_row_index',
'genus',
'gramstain',
'key_ab',
'key_ab_lag',
'key_ab_other',
'mic',
'n',
'other_pat_or_mo',
'patient_id',
'real_first_isolate',
'species',
'y'))
-109
View File
@@ -1,109 +0,0 @@
#' Join a table with \code{bactlist}
#'
#' Join the list of microorganisms \code{\link{bactlist}} easily to an existing table.
#' @rdname join
#' @name join
#' @aliases join inner_join
#' @param x existing table to join
#' @param by a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})
#' @param ... other parameters to pass trhough to \code{dplyr::\link[dplyr]{join}}.
#' @details As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
#' @export
#' @examples
#' df <- data.frame(date = seq(from = as.Date("2018-01-01"),
#' to = as.Date("2018-01-07"),
#' by = 1),
#' bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR",
#' "ESCCOL", "ESCCOL", "ESCCOL"),
#' stringsAsFactors = FALSE)
#'
#' colnames(df)
#' df2 <- left_join_bactlist(df, "bacteria_id")
#' colnames(df2)
inner_join_bactlist <- function(x, by = 'bactid', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- by
} else {
joinby <- by
}
join <- dplyr::inner_join(x = x, y = AMR::bactlist, by = joinby, suffix = c("2", ""), ...)
if (nrow(join) > nrow(x)) {
warning('the newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original')
}
join
}
#' @rdname join
#' @export
left_join_bactlist <- function(x, by = 'bacteriecode', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- by
} else {
joinby <- by
}
join <- dplyr::left_join(x = x, y = AMR::bactlist, by = joinby, suffix = c("2", ""), ...)
if (nrow(join) > nrow(x)) {
warning('the newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original')
}
join
}
#' @rdname join
#' @export
right_join_bactlist <- function(x, by = 'bacteriecode', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- by
} else {
joinby <- by
}
join <- dplyr::right_join(x = x, y = AMR::bactlist, by = joinby, suffix = c("2", ""), ...)
if (nrow(join) > nrow(x)) {
warning('the newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original')
}
join
}
#' @rdname join
#' @export
full_join_bactlist <- function(x, by = 'bacteriecode', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- by
} else {
joinby <- by
}
dplyr::full_join(x = x, y = AMR::bactlist, by = joinby, suffix = c("2", ""), ...)
}
#' @rdname join
#' @export
semi_join_bactlist <- function(x, by = 'bacteriecode', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- by
} else {
joinby <- by
}
dplyr::semi_join(x = x, y = AMR::bactlist, by = joinby, ...)
}
#' @rdname join
#' @export
anti_join_bactlist <- function(x, by = 'bacteriecode', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {
joinby <- colnames(AMR::bactlist)[1]
names(joinby) <- by
} else {
joinby <- by
}
dplyr::anti_join(x = x, y = AMR::bactlist, by = joinby, ...)
}
-31
View File
@@ -1,31 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
# No export, no Rd
"%like%" <- function(vector, pattern) {
# Source: https://github.com/Rdatatable/data.table/blob/master/R/like.R
if (is.factor(vector)) {
as.integer(vector) %in% grep(pattern, levels(vector))
} else {
grepl(pattern, vector)
}
}
percent <- function(x, round = 1, ...) {
base::paste0(base::round(x * 100, digits = round), "%")
}
-386
View File
@@ -1,386 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
#' Resistance of isolates in data.frame
#'
#' \strong{NOTE: use \code{\link{rsi}} in dplyr functions like \code{\link[dplyr]{summarise}}.} \cr Calculate the percentage of S, SI, I, IR or R of a \code{data.frame} containing isolates.
#' @param tbl \code{data.frame} containing columns with antibiotic interpretations.
#' @param antibiotics character vector with 1, 2 or 3 antibiotics that occur as column names in \code{tbl}, like \code{antibiotics = c("amox", "amcl")}
#' @param interpretation antimicrobial interpretation of which the portion must be calculated. Valid values are \code{"S"}, \code{"SI"}, \code{"I"}, \code{"IR"} or \code{"R"}.
#' @param minimum minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA} with a warning (when \code{warning = TRUE}).
#' @param percent return output as percent (text), will else (at default) be a double
#' @param info calculate the amount of available isolates and print it, like \code{n = 423}
#' @param warning show a warning when the available amount of isolates is below \code{minimum}
#' @details Remember that you should filter your table to let it contain \strong{only first isolates}!
#' @keywords rsi antibiotics isolate isolates
#' @return Double or, when \code{percent = TRUE}, a character.
#' @export
#' @importFrom dplyr %>% n_distinct filter filter_at pull vars all_vars any_vars
#' @seealso \code{\link{rsi}} for the function that can be used with \code{\link[dplyr]{summarise}} directly.
#' @examples
#' \dontrun{
#' rsi_df(tbl_with_bloodcultures, 'amcl')
#'
#' rsi_df(tbl_with_bloodcultures, c('amcl', 'gent'), interpretation = 'IR')
#'
#' library(dplyr)
#' # calculate current empiric therapy of Helicobacter gastritis:
#' my_table %>%
#' filter(first_isolate == TRUE,
#' genus == "Helicobacter") %>%
#' rsi_df(antibiotics = c("amox", "metr"))
#' }
rsi_df <- function(tbl,
antibiotics,
interpretation = 'IR',
minimum = 30,
percent = FALSE,
info = TRUE,
warning = TRUE) {
# we willen niet dat tbl$interpretation toevallig ook bestaat, dus:
te_testen_uitslag_ab <- interpretation
# validatie:
if (min(grepl('^[a-z]{3,4}$', antibiotics)) == 0 &
min(grepl('^rsi[1-2]$', antibiotics)) == 0) {
for (i in 1:length(antibiotics)) {
antibiotics[i] <- paste0('rsi', i)
}
}
if (!grepl('^(S|SI|IS|I|IR|RI|R){1}$', te_testen_uitslag_ab)) {
stop('Invalid `interpretation`; must be "S", "SI", "I", "IR", or "R".')
}
if ('is_ic' %in% colnames(tbl)) {
if (n_distinct(tbl$is_ic) > 1) {
warning('Dataset contains isolates from the Intensive Care. Exclude them from proper epidemiological analysis.')
}
}
# transformeren wanneer gezocht wordt op verschillende uitslagen
if (te_testen_uitslag_ab %in% c('SI', 'IS')) {
for (i in 1:length(antibiotics)) {
lijst <- tbl[, antibiotics[i]]
if ('I' %in% lijst) {
tbl[which(tbl[antibiotics[i]] == 'I'), ][antibiotics[i]] <- 'S'
}
}
te_testen_uitslag_ab <- 'S'
}
if (te_testen_uitslag_ab %in% c('RI', 'IR')) {
for (i in 1:length(antibiotics)) {
lijst <- tbl[, antibiotics[i]]
if ('I' %in% lijst) {
tbl[which(tbl[antibiotics[i]] == 'I'), ][antibiotics[i]] <- 'R'
}
}
te_testen_uitslag_ab <- 'R'
}
# breuk samenstellen
if (length(antibiotics) == 1) {
numerator <- tbl %>%
filter(pull(., antibiotics[1]) == te_testen_uitslag_ab) %>%
nrow()
denominator <- tbl %>%
filter(pull(., antibiotics[1]) %in% c("S", "I", "R")) %>%
nrow()
} else if (length(antibiotics) == 2) {
numerator <- tbl %>%
filter_at(vars(antibiotics[1], antibiotics[2]),
any_vars(. == te_testen_uitslag_ab)) %>%
filter_at(vars(antibiotics[1], antibiotics[2]),
all_vars(. %in% c("S", "R", "I"))) %>%
nrow()
denominator <- tbl %>%
filter_at(vars(antibiotics[1], antibiotics[2]),
all_vars(. %in% c("S", "R", "I"))) %>%
nrow()
} else if (length(antibiotics) == 3) {
numerator <- tbl %>%
filter_at(vars(antibiotics[1], antibiotics[2], antibiotics[3]),
any_vars(. == te_testen_uitslag_ab)) %>%
filter_at(vars(antibiotics[1], antibiotics[2], antibiotics[3]),
all_vars(. %in% c("S", "R", "I"))) %>%
nrow()
denominator <- tbl %>%
filter_at(vars(antibiotics[1], antibiotics[2], antibiotics[3]),
all_vars(. %in% c("S", "R", "I"))) %>%
nrow()
} else {
stop('Maximum of 3 drugs allowed.')
}
# tekstdeel opbouwen
if (info == TRUE) {
cat('n =', denominator)
info.txt1 <- percent(denominator / nrow(tbl))
if (denominator == 0) {
info.txt1 <- 'none'
}
info.txt2 <- gsub(',', ' and',
antibiotics %>%
abname(to = 'trivial',
tolower = TRUE) %>%
toString(), fixed = TRUE)
info.txt2 <- gsub('rsi1 and rsi2', 'these two drugs', info.txt2, fixed = TRUE)
info.txt2 <- gsub('rsi1', 'this drug', info.txt2, fixed = TRUE)
cat(paste0(' (of ', nrow(tbl), ' in total; ', info.txt1, ' tested on ', info.txt2, ')\n'))
}
# rekenen en opmaken
y <- numerator / denominator
if (percent == TRUE) {
y <- percent(y)
}
if (denominator < minimum) {
if (warning == TRUE) {
warning(paste0('TOO FEW ISOLATES OF ', toString(antibiotics), ' (n = ', denominator, ', n < ', minimum, '); NO RESULT.'))
}
y <- NA
}
# output
y
}
#' Resistance of isolates
#'
#' This function can be used in \code{dplyr}s \code{\link[dplyr]{summarise}}, see \emph{Examples}. Calculate the percentage S, SI, I, IR or R of a vector of isolates.
#' @param ab1,ab2 list with interpretations of an antibiotic
#' @inheritParams rsi_df
#' @details This function uses the \code{\link{rsi_df}} function internally.
#' @keywords rsi antibiotics isolate isolates
#' @return Double or, when \code{percent = TRUE}, a character.
#' @export
#' @examples
#' \dontrun{
#' tbl %>%
#' group_by(hospital) %>%
#' summarise(cipr = rsi(cipr))
#'
#' tbl %>%
#' group_by(year, hospital) %>%
#' summarise(
#' isolates = n(),
#' cipro = rsi(cipr %>% as.rsi(), percent = TRUE),
#' amoxi = rsi(amox %>% as.rsi(), percent = TRUE))
#'
#' rsi(as.rsi(isolates$amox))
#'
#' rsi(as.rsi(isolates$amcl), interpretation = "S")
#' }
rsi <- function(ab1, ab2 = NA, interpretation = 'IR', minimum = 30, percent = FALSE, info = FALSE, warning = FALSE) {
functietekst <- as.character(match.call())
# param 1 = functienaam
# param 2 = ab1
# param 3 = ab2
ab1.naam <- functietekst[2]
if (!grepl('^[a-z]{3,4}$', ab1.naam)) {
ab1.naam <- 'rsi1'
}
ab2.naam <- functietekst[3]
if (!grepl('^[a-z]{3,4}$', ab2.naam)) {
ab2.naam <- 'rsi2'
}
tbl <- tibble(rsi1 = ab1, rsi2 = ab2)
colnames(tbl) <- c(ab1.naam, ab2.naam)
if (length(ab2) == 1) {
return(rsi_df(tbl = tbl,
antibiotics = ab1.naam,
interpretation = interpretation,
minimum = minimum,
percent = percent,
info = info,
warning = warning))
} else {
if (length(ab1) != length(ab2)) {
stop('`ab1` (n = ', length(ab1), ') and `ab2` (n = ', length(ab2), ') must be of same length.', call. = FALSE)
}
if (interpretation != 'S') {
warning('`interpretation` is not set to S, albeit analysing a combination therapy.')
}
return(rsi_df(tbl = tbl,
antibiotics = c(ab1.naam, ab2.naam),
interpretation = interpretation,
minimum = minimum,
percent = percent,
info = info,
warning = warning))
}
}
#' Predict antimicrobial resistance
#'
#' Create a prediction model to predict antimicrobial resistance for the next years on statistical solid ground. Standard errors (SE) will be returned as columns \code{se_min} and \code{se_max}.
#' @param tbl table that contains columns \code{col_ab} and \code{col_date}
#' @param col_ab column name of \code{tbl} with antimicrobial interpretations (\code{R}, \code{I} and \code{S})
#' @param col_date column name of the date, will be used to calculate years
#' @param year_max highest year to use in the prediction model, deafults to 15 years after today
#' @param year_every unit of sequence between lowest year found in the data and \code{year_max}
#' @param model the statistical model of choice. Valid values are \code{"binomial"} (or \code{"binom"} or \code{"logit"}) or \code{"loglin"} or \code{"linear"} (or \code{"lin"}).
#' @param I_as_R treat \code{I} as \code{R}
#' @param preserve_measurements overwrite predictions of years that are actually available in the data, with the original data. The standard errors of those years will be \code{NA}.
#' @param info print textual analysis with the name and \code{\link{summary}} of the model.
#' @return \code{data.frame} with columns \code{year}, \code{probR}, \code{se_min} and \code{se_max}.
#' @seealso \code{\link{lm}} \cr \code{\link{glm}}
#' @export
#' @importFrom dplyr %>% pull mutate group_by_at summarise filter
#' @importFrom reshape2 dcast
#' @examples
#' \dontrun{
#' # use it directly:
#' rsi_predict(tbl[which(first_isolate == TRUE & genus == "Haemophilus"),], "amcl")
#'
#' # or with dplyr so you can actually read it:
#' library(dplyr)
#' tbl %>%
#' filter(first_isolate == TRUE,
#' genus == "Haemophilus") %>%
#' rsi_predict("amcl")
#'
#' tbl %>%
#' filter(first_isolate_weighted == TRUE,
#' genus == "Haemophilus") %>%
#' rsi_predict(col_ab = "amcl",
#' year_max = 2050,
#' year_every = 5)
#'
#' }
rsi_predict <- function(tbl,
col_ab,
col_date = 'ontvangstdatum',
year_max = as.integer(format(as.Date(Sys.Date()), '%Y')) + 15,
year_every = 1,
model = 'binomial',
I_as_R = TRUE,
preserve_measurements = TRUE,
info = TRUE) {
if (I_as_R == TRUE) {
tbl[, col_ab] <- gsub('I', 'R', tbl %>% pull(col_ab))
}
year <- function(x) {
as.integer(format(as.Date(x), '%Y'))
}
years_predict <- seq(from = min(year(tbl %>% pull(col_date))), to = year_max, by = year_every)
df <- tbl %>%
mutate(year = year(tbl %>% pull(col_date))) %>%
group_by_at(c('year', col_ab)) %>%
summarise(n())
colnames(df) <- c('year', 'antibiotic', 'count')
df <- df %>%
reshape2::dcast(year ~ antibiotic, value.var = 'count')
if (model %in% c('binomial', 'binom', 'logit')) {
logitmodel <- with(df, glm(cbind(R, S) ~ year, family = binomial))
if (info == TRUE) {
cat('\nLogistic regression model (logit) with binomial distribution')
cat('\n------------------------------------------------------------\n')
print(summary(logitmodel))
}
predictmodel <- stats::predict(logitmodel, newdata = with(df, list(year = years_predict)), type = "response", se.fit = TRUE)
prediction <- predictmodel$fit
se <- predictmodel$se.fit
} else if (model == 'loglin') {
loglinmodel <- with(df, glm(R ~ year, family = poisson))
if (info == TRUE) {
cat('\nLog-linear regression model (loglin) with poisson distribution')
cat('\n--------------------------------------------------------------\n')
print(summary(loglinmodel))
}
predictmodel <- stats::predict(loglinmodel, newdata = with(df, list(year = years_predict)), type = "response", se.fit = TRUE)
prediction <- predictmodel$fit
se <- predictmodel$se.fit
} else if (model %in% c('lin', 'linear')) {
linmodel <- with(df, lm((R / (R + S)) ~ year))
if (info == TRUE) {
cat('\nLinear regression model')
cat('\n-----------------------\n')
print(summary(linmodel))
}
predictmodel <- stats::predict(linmodel, newdata = with(df, list(year = years_predict)), se.fit = TRUE)
prediction <- predictmodel$fit
se <- predictmodel$se.fit
} else {
stop('No valid model selected.')
}
# prepare the output dataframe
prediction <- data.frame(year = years_predict, probR = prediction, stringsAsFactors = FALSE)
prediction$se_min <- prediction$probR - se
prediction$se_max <- prediction$probR + se
if (model == 'loglin') {
prediction$probR <- prediction$probR %>%
format(scientific = FALSE) %>%
as.integer()
prediction$se_min <- prediction$se_min %>% as.integer()
prediction$se_max <- prediction$se_max %>% as.integer()
colnames(prediction) <- c('year', 'amountR', 'se_max', 'se_min')
} else {
prediction$se_max[which(prediction$se_max > 1)] <- 1
}
prediction$se_min[which(prediction$se_min < 0)] <- 0
total <- prediction
if (preserve_measurements == TRUE) {
# geschatte data vervangen door gemeten data
if (I_as_R == TRUE) {
if (!'I' %in% colnames(df)) {
df$I <- 0
}
df$probR <- df$R / rowSums(df[, c('R', 'S', 'I')])
} else {
df$probR <- df$R / rowSums(df[, c('R', 'S')])
}
measurements <- data.frame(year = df$year,
probR = df$probR,
se_min = NA,
se_max = NA,
stringsAsFactors = FALSE)
colnames(measurements) <- colnames(prediction)
prediction <- prediction %>% filter(!year %in% df$year)
total <- rbind(measurements, prediction)
}
total
}
Regular → Executable
+186 -107
View File
@@ -1,147 +1,226 @@
# `AMR`
This is an [R package](https://www.r-project.org) to simplify the analysis and prediction of Antimicrobial Resistance (AMR).
![logo_uni](man/figures/logo_en.png)![logo_umcg](man/figures/logo_umcg.png)
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](https://pypi.org/project/AMR/).
This R package was created for academic research by PhD students of the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl/) and the Medical Microbiology & Infection Prevention department of the University Medical Center Groningen (UMCG). They also maintain this package, see [Authors](#authors).
This Python package is a wrapper around 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.
## Why this package?
This R package contains functions to make microbiological, epidemiological data analysis easier. It allows the use of some new S3 classes to work with MIC values and antimicrobial interpretations (i.e. values S, I and R).
# Prerequisites
AMR can also be predicted for the forthcoming years with the `rsi_predict` function. For use with the `dplyr` package, the `rsi` function can be used in conjunction with `summarise` to calculate the resistance percentages of different antibiotic columns of a table.
This package was only tested with a [virtual environment (venv)](https://docs.python.org/3/library/venv.html). You can set up such an environment by running:
It also contains functions to translate antibiotic codes from the lab (like `"AMOX"`) or the [WHO](https://www.whocc.no/atc_ddd_index/?code=J01CA04&showdescription=no) (like `"J01CA04"`) to trivial names (like `"amoxicillin"`) and vice versa.
```python
# linux and macOS:
python -m venv /path/to/new/virtual/environment
## How to get it?
[![CRAN_Badge](http://www.r-pkg.org/badges/version/AMR)](http://cran.r-project.org/package=AMR)
This package is available on CRAN (latest stable version) and also here on GitHub (latest development version).
#### Latest stable version from CRAN (recommended)
RStudio:
- Click on `Tools` and then `Install Packages..`
- Type in `AMR` and press <kbd>Install</kbd>
Other:
```r
install.packages("AMR")
# Windows:
python -m venv C:\path\to\new\virtual\environment
```
#### Latest development version from GitHub
```r
devtools::install_github("msberends/AMR")
Then you can [activate the environment](https://docs.python.org/3/library/venv.html#how-venvs-work), after which the venv is ready to work with.
# Install AMR
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)
```
## How to use it?
```r
# Call it with:
library(AMR)
| 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 |
# For a list of functions:
help(package = "AMR")
### 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".
## Calculating AMR
```python
import AMR
import pandas as pd
df = AMR.example_isolates
result = AMR.resistance(df["AMX"])
print(result)
```
### Databases included in package
```r
# Dataset with ATC antibiotics codes, official names and DDD's (oral and parenteral)
ablist # A tibble: 420 x 12
# Dataset with bacteria codes and properties like gram stain and aerobic/anaerobic
bactlist # A tibble: 2,507 x 10
```
[0.59555556]
```
### New classes
This package contains two new S3 classes: `mic` for MIC values (e.g. from Vitek or Phoenix) and `rsi` for antimicrobial drug interpretations (i.e. S, I and R). Both are actually ordered factors under the hood (an MIC of `2` being higher than `<=1` but lower than `>=32`, and for class `rsi` factors are ordered as `S < I < R`).
Both classes have extensions for existing generic functions like `print`, `summary` and `plot`.
## Generating Antibiograms
```r
# Transform values to new classes
mic_data <- as.mic(c(">=32", "1.0", "8", "<=0.128", "8", "16", "16"))
rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
```
These functions also try to coerce valid values.
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:
Quick overviews when just printing objects:
```r
mic_data
# Class 'mic': 7 isolates
#
# <NA> 0
#
# <=0.128 1 8 16 >=32
# 1 1 2 2 1
rsi_data
# Class 'rsi': 880 isolates
#
# <NA>: 0
# Sum of S: 474
# Sum of IR: 406
# - Sum of R: 370
# - Sum of I: 36
#
# %S %IR %I %R
# 53.9 46.1 4.1 42.0
```python
result2a = AMR.antibiogram(df[["mo", "AMX", "CIP", "TZP"]])
print(result2a)
```
A plot of `rsi_data`:
```r
plot(rsi_data)
| 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)
```
![example](man/figures/rsi_example.png)
| 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) |
Other epidemiological functions:
```r
# Apply EUCAST Expert Rules v3.1 (latest) to antibiotic columns
EUCAST_rules(...)
In this example, we generate an antibiogram by selecting various antibiotics.
# Determine key antibiotic based on bacteria ID
key_antibiotics(...)
# Check if key antibiotics are equal
key_antibiotics_equal(...)
## Taxonomic Data Sets Now in Python!
# Selection of first isolates of any patient
first_isolate(...)
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antimicrobials`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
# Calculate resistance levels of antibiotics
rsi(...)
# Predict resistance levels of antibiotics
rsi_predict(...)
# Get name of antibiotic by ATC code
abname(...)
abname("J01CR02", from = "atc", to = "umcg") # "AMCL"
```python
AMR.microorganisms
```
## Authors
| 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 |
- [Berends MS](https://github.com/msberends)<sup>1,2</sup>, PhD Student
- [Luz CF](https://github.com/ceefluz)<sup>1</sup>, PhD Student
- [Hassing EEA](https://github.com/erwinhassing)<sup>2</sup>, Data Analyst (contributor)
```python
AMR.antimicrobials
```
<sup>1</sup> Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands
| 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 |
<sup>2</sup> Department of Medical, Market and Innovation (MMI), Certe Medische diagnostiek & advies, Groningen, the Netherlands
## Copyright
This R package is licensed under the [GNU General Public License (GPL) v2.0](https://github.com/msberends/AMR/blob/master/LICENSE). In a nutshell, this means that this package:
# Installation Channels
- May be used for commercial purposes
## Stable Release (CRAN)
- May be used for private purposes
The default `AMR` Python package uses the latest stable version of the `AMR` R package, published on CRAN. After running `pip install AMR`, import it as usual:
- May be modified, although:
```python
import AMR
- Modifications **must** be released under the same license when distributing the package
- Changes made to the code **must** be documented
AMR.example_isolates
```
- May be distributed, although:
## Development Version (GitHub)
- Source code **must** be made available when the package is distributed
- A copy of the license and copyright notice **must** be included with the package.
To use the latest development version of the `AMR` R package (sourced directly from GitHub), import the `beta` sub-package and alias it as `AMR`:
- Comes with a LIMITATION of liability
```python
import AMR.beta as AMR
- Comes with NO warranty
AMR.example_isolates
```
Aliasing with `as AMR` keeps all downstream code identical to the stable import. Switching between the stable release and the development version requires changing only the import line — nothing else in your script needs to change.
# SIR Classification with `as_sir()`
## Using `enforce_method`
The `as_sir()` function in R uses S3 method dispatch to select the correct calculation method based on the input class: `<mic>` for MIC values and `<disk>` for disk diffusion values. Because Python objects do not carry R class attributes through the `rpy2` bridge, this automatic dispatch may not resolve correctly.
To explicitly specify the input type, use the `enforce_method` argument:
```python
# Treat the column as MIC values — maps to R's as.sir.mic()
AMR.as_sir(df["MIC_col"], mo="E. coli", ab="AMX", guideline="EUCAST", enforce_method="mic")
# Treat the column as disk diffusion values — maps to R's as.sir.disk()
AMR.as_sir(df["disk_col"], mo="E. coli", ab="AMX", guideline="EUCAST", enforce_method="disk")
```
Without `enforce_method`, R falls back to class-based dispatch on the raw Python input, which may fail or return unexpected results. Always supply `enforce_method` when calling `as_sir()` from Python.
# 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
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
-57
View File
@@ -1,57 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/EUCAST.R
\name{EUCAST}
\alias{EUCAST}
\alias{EUCAST_rules}
\alias{interpretive_reading}
\title{EUCAST expert rules}
\source{
EUCAST Expert Rules Version 2.0: \cr
Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility testing.} \emph{Clin Microbiol Infect.} 2013;19(2):141-60. \cr
\url{https://doi.org/10.1111/j.1469-0691.2011.03703.x} \cr
\cr
EUCAST Expert Rules Version 3.1: \cr
\url{http://www.eucast.org/expert_rules_and_intrinsic_resistance}
}
\usage{
EUCAST_rules(tbl, col_bactcode = "bacteriecode", info = TRUE,
amcl = "amcl", amik = "amik", amox = "amox", ampi = "ampi",
azit = "azit", aztr = "aztr", cefa = "cefa", cfra = "cfra",
cfep = "cfep", cfot = "cfot", cfox = "cfox", cfta = "cfta",
cftr = "cftr", cfur = "cfur", chlo = "chlo", cipr = "cipr",
clar = "clar", clin = "clin", clox = "clox", coli = "coli",
czol = "czol", dapt = "dapt", doxy = "doxy", erta = "erta",
eryt = "eryt", fosf = "fosf", fusi = "fusi", gent = "gent",
imip = "imip", kana = "kana", levo = "levo", linc = "linc",
line = "line", mero = "mero", mino = "mino", moxi = "moxi",
nali = "nali", neom = "neom", neti = "neti", nitr = "nitr",
novo = "novo", norf = "norf", oflo = "oflo", peni = "peni",
pita = "pita", poly = "poly", qida = "qida", rifa = "rifa",
roxi = "roxi", siso = "siso", teic = "teic", tetr = "tetr",
tica = "tica", tige = "tige", tobr = "tobr", trim = "trim",
trsu = "trsu", vanc = "vanc")
interpretive_reading(...)
}
\arguments{
\item{tbl}{table with antibiotic columns, like e.g. \code{amox} and \code{amcl}}
\item{col_bactcode}{column name of the bacteria ID in \code{tbl} - should also be present in \code{bactlist$bactid}, see \code{\link{bactlist}}.}
\item{info}{print progress}
\item{amcl, amik, amox, ampi, azit, aztr, cefa, cfra, cfep, cfot, cfox, cfta, cftr, cfur, chlo, cipr, clar, clin, clox, coli, czol, dapt, doxy, erta, eryt, fosf, fusi, gent, imip, kana, levo, linc, line, mero, mino, moxi, nali, neom, neti, nitr, novo, norf, oflo, peni, pita, poly, qida, rifa, roxi, siso, teic, tetr, tica, tige, tobr, trim, trsu, vanc}{column names of antibiotics. Use \code{NA} to skip a column, like \code{tica = NA}. Non-existing column will be skipped.}
\item{...}{parameters that are passed on to \code{EUCAST_rules}}
}
\value{
table with edited variables of antibiotics.
}
\description{
Apply expert rules (like intrinsic resistance), as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}.
}
\examples{
\dontrun{
tbl <- EUCAST_rules(tbl)
}
}
-34
View File
@@ -1,34 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{ablist}
\alias{ablist}
\title{Dataset with 420 antibiotics}
\format{A data.frame with 420 observations and 12 variables:
\describe{
\item{\code{atc}}{ATC code, like \code{J01CR02}}
\item{\code{molis}}{MOLIS code, like \code{amcl}}
\item{\code{umcg}}{UMCG code, like \code{AMCL}}
\item{\code{official}}{Official name by the WHO, like \code{"amoxicillin and enzyme inhibitor"}}
\item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}}
\item{\code{trivial}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}}
\item{\code{oral_ddd}}{Daily Defined Dose (DDD) according to the WHO, oral treatment}
\item{\code{oral_units}}{Units of \code{ddd_units}}
\item{\code{iv_ddd}}{Daily Defined Dose (DDD) according to the WHO, bij parenteral treatment}
\item{\code{iv_units}}{Units of \code{iv_ddd}}
\item{\code{atc_group1}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}}
\item{\code{atc_group2}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}}
}}
\source{
MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl} \cr \cr World Health Organization - \url{https://www.whocc.no/atc_ddd_index/}
}
\usage{
ablist
}
\description{
A dataset containing all antibiotics with a J0 code, with their DDD's.
}
\seealso{
\code{\link{bactlist}}
}
\keyword{datasets}
-45
View File
@@ -1,45 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/atc.R
\name{abname}
\alias{abname}
\title{Name of an antibiotic}
\source{
\code{\link{ablist}}
}
\usage{
abname(abcode, from = "umcg", to = "official", textbetween = " + ",
tolower = FALSE)
}
\arguments{
\item{abcode}{a code or name, like \code{"amox"}, \code{"cftr"} or \code{"J01CA04"}}
\item{from, to}{type to transform from and to. See \code{\link{ablist}} for its column names.}
\item{textbetween}{text to put between multiple returned texts}
\item{tolower}{return output as lower case with function \code{\link{tolower}}.}
}
\description{
Convert antibiotic codes (from a laboratory information system like MOLIS or GLIMS) to a (trivial) antibiotic name or ATC code, or vice versa. This uses the data from \code{\link{ablist}}.
}
\examples{
abname("AMCL")
# "amoxicillin and enzyme inhibitor"
abname("AMCL+GENT")
# "amoxicillin and enzyme inhibitor + gentamicin"
abname(c("AMCL", "GENT"))
# "amoxicillin and enzyme inhibitor" "gentamicin"
abname("AMCL", to = "trivial")
# "Amoxicilline/clavulaanzuur"
abname("AMCL", to = "atc")
# "J01CR02"
abname("J01CR02", from = "atc", to = "umcg")
# "AMCL"
}
\keyword{ab}
\keyword{antibiotics}
-34
View File
@@ -1,34 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classes.R
\name{as.mic}
\alias{as.mic}
\alias{is.mic}
\title{Class 'mic'}
\usage{
as.mic(x, na.rm = FALSE)
is.mic(x)
}
\arguments{
\item{x}{vector}
\item{na.rm}{a logical indicating whether missing values should be removed}
}
\value{
New class \code{mic}
}
\description{
This transforms a vector to a new class\code{mic}, which is an ordered factor valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
}
\examples{
mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
is.mic(mic_data)
plot(mic_data)
\donttest{
library(dplyr)
tbl \%>\%
mutate_at(vars(ends_with("_mic")), as.mic)
sapply(mic_data, is.mic)
}
}
-33
View File
@@ -1,33 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classes.R
\name{as.rsi}
\alias{as.rsi}
\alias{is.rsi}
\title{Class 'rsi'}
\usage{
as.rsi(x)
is.rsi(x)
}
\arguments{
\item{x}{vector}
}
\value{
New class \code{rsi}
}
\description{
This transforms a vector to a new class \code{rsi}, which is an ordered factor with levels \code{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning.
}
\examples{
rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C"))
is.rsi(rsi_data)
plot(rsi_data)
\donttest{
library(dplyr)
tbl \%>\%
mutate_at(vars(ends_with("_rsi")), as.rsi)
sapply(mic_data, is.rsi)
}
}
-57
View File
@@ -1,57 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/atc.R
\name{atc_property}
\alias{atc_property}
\title{Properties of an ATC code}
\source{
\url{https://www.whocc.no/atc_ddd_alterations__cumulative/ddd_alterations/abbrevations/}
}
\usage{
atc_property(atc_code, property, administration = "O",
url = "https://www.whocc.no/atc_ddd_index/?code=\%s&showdescription=no")
}
\arguments{
\item{atc_code}{a character or character vector with ATC code(s) of antibiotic(s)}
\item{property}{property of an ATC code. Valid values are \code{"ATC code"}, \code{"Name"}, \code{"DDD"}, \code{"U"} (\code{"unit"}), \code{"Adm.R"} en \code{"Note"}.}
\item{administration}{type of administration, see \emph{Details}}
\item{url}{url of website of the WHO. The sign \code{\%s} can be used as a placeholder for ATC codes.}
}
\description{
Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic. \strong{This function requires an internet connection.}
}
\details{
Abbreviations for the property \code{"Adm.R"} (parameter \code{administration}):
\itemize{
\item{\code{"Implant"}}{ = Implant}
\item{\code{"Inhal"}}{ = Inhalation}
\item{\code{"Instill"}}{ = Instillation}
\item{\code{"N"}}{ = nasal}
\item{\code{"O"}}{ = oral}
\item{\code{"P"}}{ = parenteral}
\item{\code{"R"}}{ = rectal}
\item{\code{"SL"}}{ = sublingual/buccal}
\item{\code{"TD"}}{ = transdermal}
\item{\code{"V"}}{ = vaginal}
}
Abbreviations for the property \code{"U"} (unit):
\itemize{
\item{\code{"g"}}{ = gram}
\item{\code{"mg"}}{ = milligram}
\item{\code{"mcg"}}{ = microgram}
\item{\code{"U"}}{ = unit}
\item{\code{"TU"}}{ = thousand units}
\item{\code{"MU"}}{ = million units}
\item{\code{"mmol"}}{ = millimole}
\item{\code{"ml"}}{ = milliliter (e.g. eyedrops)}
}
}
\examples{
\donttest{
atc_property("J01CA04", "DDD", "O") # oral DDD of amoxicillin
atc_property("J01CA04", "DDD", "P") # parenteral DDD of amoxicillin
}
}
-32
View File
@@ -1,32 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{bactlist}
\alias{bactlist}
\title{Dataset with ~2500 microorganisms}
\format{A data.frame with 2507 observations and 10 variables:
\describe{
\item{\code{bactid}}{ID of microorganism}
\item{\code{bactsys}}{Bactsyscode of microorganism}
\item{\code{family}}{Family name of microorganism}
\item{\code{genus}}{Genus name of microorganism, like \code{"Echerichia"}}
\item{\code{species}}{Species name of microorganism, like \code{"coli"}}
\item{\code{subspecies}}{Subspecies name of bio-/serovar of microorganism, like \code{"EHEC"}}
\item{\code{fullname}}{Full name, like \code{"Echerichia coli (EHEC)"}}
\item{\code{type}}{Type of microorganism, like \code{"Bacterie"} en \code{"Schimmel/gist"} (these are Dutch)}
\item{\code{gramstain}}{Gram of microorganism in Dutch, like \code{"Negatieve staven"}}
\item{\code{aerobic}}{Type aerobe/anaerobe of bacteria}
}}
\source{
MOLIS (LIS of Certe) - \url{https://www.certe.nl}
}
\usage{
bactlist
}
\description{
A dataset containing all microorganisms of MOLIS. MO codes of the UMCG can be looked up using \code{\link{bactlist.umcg}}.
}
\seealso{
\code{\link{ablist}} \code{\link{bactlist.umcg}}
}
\keyword{datasets}
-24
View File
@@ -1,24 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{bactlist.umcg}
\alias{bactlist.umcg}
\title{Translation table for UMCG with ~1100 microorganisms}
\format{A data.frame with 1090 observations and 2 variables:
\describe{
\item{\code{mocode}}{Code of microorganism according to UMCG MMB}
\item{\code{bactid}}{Code of microorganism in \code{\link{bactlist}}}
}}
\source{
MOLIS (LIS of Certe) - \url{https://www.certe.nl} \cr \cr GLIMS (LIS of UMCG) - \url{https://www.umcg.nl}
}
\usage{
bactlist.umcg
}
\description{
A dataset containing all bacteria codes of UMCG MMB. These codes can be joined to data with an ID from \code{\link{bactlist}$bactid}, using \code{\link{left_join_bactlist}}.
}
\seealso{
\code{\link{bactlist}}
}
\keyword{datasets}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

-100
View File
@@ -1,100 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/first_isolates.R
\name{first_isolate}
\alias{first_isolate}
\title{Determine first (weighted) isolates}
\usage{
first_isolate(tbl, col_date, col_patid, col_genus, col_species,
col_testcode = NA, col_specimen, col_icu, col_keyantibiotics = NA,
episode_days = 365, testcodes_exclude = "", icu_exclude = FALSE,
filter_specimen = NA, output_logical = TRUE, ignore_I = TRUE,
info = TRUE)
}
\arguments{
\item{tbl}{a \code{data.frame} containing isolates.}
\item{col_date}{column name of the result date (or date that is was received on the lab)}
\item{col_patid}{column name of the unique IDs of the patients}
\item{col_genus}{column name of the genus of the microorganisms}
\item{col_species}{column name of the species of the microorganisms}
\item{col_testcode}{column name of the test codes, see Details}
\item{col_specimen}{column name of the specimen type or group}
\item{col_icu}{column name of the logicals (\code{TRUE}/\code{FALSE}) whether a ward or department is an Intensive Care Unit (ICU)}
\item{col_keyantibiotics}{column name of the key antibiotics to determine first \emph{weighted} isolates, see \code{\link{key_antibiotics}}.}
\item{episode_days}{episode in days after which a genus/species combination will be determined as 'first isolate' again}
\item{testcodes_exclude}{character vector with test codes that should be excluded (caseINsensitive)}
\item{icu_exclude}{logical whether ICU isolates should be excluded}
\item{filter_specimen}{specimen group or type that should be excluded}
\item{output_logical}{return output as \code{logical} (will else the values \code{0} or \code{1})}
\item{ignore_I}{ignore \code{"I"} as antimicrobial interpretation of key antibiotics (with \code{FALSE}, changes in antibiograms from S to I and I to R will be interpreted as difference)}
\item{info}{print progress}
}
\value{
A vector to add to table, see Examples.
}
\description{
Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type.
}
\details{
To conduct an analysis of antimicrobial resistance, you should only include the first isolate of every patient per episode. If you would not do this, you could easily get an overestimate or underestimate of the resistance of an antibiotic. Imagine that a patient was admitted with an MRSA and that is was found in 5 different blood cultures the following week. The resistance percentage of oxacillin of all \emph{S. aureus} isolates would be overestimated, because you included this MRSA more than once. It would be selection bias.
Use \code{col_testcode = NA} to \strong{not} exclude certain test codes (like test codes for screening). In that case \code{testcodes_exclude} will be ignored.
}
\examples{
\dontrun{
# set key antibiotics to a new variable
tbl$keyab <- key_antibiotics(tbl)
tbl$first_isolate <-
first_isolate(tbl)
tbl$first_isolate_weighed <-
first_isolate(tbl,
col_keyantibiotics = 'keyab')
tbl$first_blood_isolate <-
first_isolate(tbl,
filter_specimen = 'Blood')
tbl$first_blood_isolate_weighed <-
first_isolate(tbl,
filter_specimen = 'Blood',
col_keyantibiotics = 'keyab')
tbl$first_urine_isolate <-
first_isolate(tbl,
filter_specimen = 'Urine')
tbl$first_urine_isolate_weighed <-
first_isolate(tbl,
filter_specimen = 'Urine',
col_keyantibiotics = 'keyab')
tbl$first_resp_isolate <-
first_isolate(tbl,
filter_specimen = 'Respiratory')
tbl$first_resp_isolate_weighed <-
first_isolate(tbl,
filter_specimen = 'Respiratory',
col_keyantibiotics = 'keyab')
}
}
\keyword{first}
\keyword{isolate}
\keyword{isolates}
-50
View File
@@ -1,50 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/join.R
\name{join}
\alias{join}
\alias{inner_join_bactlist}
\alias{inner_join}
\alias{left_join_bactlist}
\alias{right_join_bactlist}
\alias{full_join_bactlist}
\alias{semi_join_bactlist}
\alias{anti_join_bactlist}
\title{Join a table with \code{bactlist}}
\usage{
inner_join_bactlist(x, by = "bactid", ...)
left_join_bactlist(x, by = "bacteriecode", ...)
right_join_bactlist(x, by = "bacteriecode", ...)
full_join_bactlist(x, by = "bacteriecode", ...)
semi_join_bactlist(x, by = "bacteriecode", ...)
anti_join_bactlist(x, by = "bacteriecode", ...)
}
\arguments{
\item{x}{existing table to join}
\item{by}{a variable to join by - could be a column name of \code{x} with values that exist in \code{bactlist$bactid} (like \code{by = "bacteria_id"}), or another column in \code{\link{bactlist}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})}
\item{...}{other parameters to pass trhough to \code{dplyr::\link[dplyr]{join}}.}
}
\description{
Join the list of microorganisms \code{\link{bactlist}} easily to an existing table.
}
\details{
As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
}
\examples{
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
to = as.Date("2018-01-07"),
by = 1),
bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR",
"ESCCOL", "ESCCOL", "ESCCOL"),
stringsAsFactors = FALSE)
colnames(df)
df2 <- left_join_bactlist(df, "bacteria_id")
colnames(df2)
}
-37
View File
@@ -1,37 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/first_isolates.R
\name{key_antibiotics}
\alias{key_antibiotics}
\title{Key antibiotics based on bacteria ID}
\usage{
key_antibiotics(tbl, col_bactcode = "bacteriecode", info = TRUE,
amcl = "amcl", amox = "amox", cfot = "cfot", cfta = "cfta",
cftr = "cftr", cfur = "cfur", cipr = "cipr", clar = "clar",
clin = "clin", clox = "clox", doxy = "doxy", gent = "gent",
line = "line", mero = "mero", peni = "peni", pita = "pita",
rifa = "rifa", teic = "teic", trsu = "trsu", vanc = "vanc")
}
\arguments{
\item{tbl}{table with antibiotics coloms, like \code{amox} and \code{amcl}.}
\item{col_bactcode}{column of bacteria IDs in \code{tbl}; these should occur in \code{bactlist$bactid}, see \code{\link{bactlist}}}
\item{info}{print warnings}
\item{amcl, amox, cfot, cfta, cftr, cfur, cipr, clar, clin, clox, doxy, gent, line, mero, peni, pita, rifa, teic, trsu, vanc}{column names of antibiotics.}
}
\value{
Character of length 1.
}
\description{
Key antibiotics based on bacteria ID
}
\examples{
\donttest{
#' # set key antibiotics to a new variable
tbl$keyab <- key_antibiotics(tbl)
}
}
\seealso{
\code{\link{mo_property}} \code{\link{ablist}}
}
-19
View File
@@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/EUCAST.R
\name{mo_property}
\alias{mo_property}
\title{Poperties of a microorganism}
\usage{
mo_property(bactcode, property = "fullname")
}
\arguments{
\item{bactcode}{ID of a microorganisme, like \code{"STAAUR} and \code{"ESCCOL}}
\item{property}{One of the values \code{bactid}, \code{bactsys}, \code{family}, \code{genus}, \code{species}, \code{subspecies}, \code{fullname}, \code{type}, \code{gramstain}, \code{aerobic}}
}
\description{
Poperties of a microorganism
}
\seealso{
\code{\link{bactlist}}
}
-53
View File
@@ -1,53 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rsi_analysis.R
\name{rsi}
\alias{rsi}
\title{Resistance of isolates}
\usage{
rsi(ab1, ab2 = NA, interpretation = "IR", minimum = 30, percent = FALSE,
info = FALSE, warning = FALSE)
}
\arguments{
\item{ab1, ab2}{list with interpretations of an antibiotic}
\item{interpretation}{antimicrobial interpretation of which the portion must be calculated. Valid values are \code{"S"}, \code{"SI"}, \code{"I"}, \code{"IR"} or \code{"R"}.}
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA} with a warning (when \code{warning = TRUE}).}
\item{percent}{return output as percent (text), will else (at default) be a double}
\item{info}{calculate the amount of available isolates and print it, like \code{n = 423}}
\item{warning}{show a warning when the available amount of isolates is below \code{minimum}}
}
\value{
Double or, when \code{percent = TRUE}, a character.
}
\description{
This function can be used in \code{dplyr}s \code{\link[dplyr]{summarise}}, see \emph{Examples}. Calculate the percentage S, SI, I, IR or R of a vector of isolates.
}
\details{
This function uses the \code{\link{rsi_df}} function internally.
}
\examples{
\dontrun{
tbl \%>\%
group_by(hospital) \%>\%
summarise(cipr = rsi(cipr))
tbl \%>\%
group_by(year, hospital) \%>\%
summarise(
isolates = n(),
cipro = rsi(cipr \%>\% as.rsi(), percent = TRUE),
amoxi = rsi(amox \%>\% as.rsi(), percent = TRUE))
rsi(as.rsi(isolates$amox))
rsi(as.rsi(isolates$amcl), interpretation = "S")
}
}
\keyword{antibiotics}
\keyword{isolate}
\keyword{isolates}
\keyword{rsi}
-54
View File
@@ -1,54 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rsi_analysis.R
\name{rsi_df}
\alias{rsi_df}
\title{Resistance of isolates in data.frame}
\usage{
rsi_df(tbl, antibiotics, interpretation = "IR", minimum = 30,
percent = FALSE, info = TRUE, warning = TRUE)
}
\arguments{
\item{tbl}{\code{data.frame} containing columns with antibiotic interpretations.}
\item{antibiotics}{character vector with 1, 2 or 3 antibiotics that occur as column names in \code{tbl}, like \code{antibiotics = c("amox", "amcl")}}
\item{interpretation}{antimicrobial interpretation of which the portion must be calculated. Valid values are \code{"S"}, \code{"SI"}, \code{"I"}, \code{"IR"} or \code{"R"}.}
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA} with a warning (when \code{warning = TRUE}).}
\item{percent}{return output as percent (text), will else (at default) be a double}
\item{info}{calculate the amount of available isolates and print it, like \code{n = 423}}
\item{warning}{show a warning when the available amount of isolates is below \code{minimum}}
}
\value{
Double or, when \code{percent = TRUE}, a character.
}
\description{
\strong{NOTE: use \code{\link{rsi}} in dplyr functions like \code{\link[dplyr]{summarise}}.} \cr Calculate the percentage of S, SI, I, IR or R of a \code{data.frame} containing isolates.
}
\details{
Remember that you should filter your table to let it contain \strong{only first isolates}!
}
\examples{
\dontrun{
rsi_df(tbl_with_bloodcultures, 'amcl')
rsi_df(tbl_with_bloodcultures, c('amcl', 'gent'), interpretation = 'IR')
library(dplyr)
# calculate current empiric therapy of Helicobacter gastritis:
my_table \%>\%
filter(first_isolate == TRUE,
genus == "Helicobacter") \%>\%
rsi_df(antibiotics = c("amox", "metr"))
}
}
\seealso{
\code{\link{rsi}} for the function that can be used with \code{\link[dplyr]{summarise}} directly.
}
\keyword{antibiotics}
\keyword{isolate}
\keyword{isolates}
\keyword{rsi}
-60
View File
@@ -1,60 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rsi_analysis.R
\name{rsi_predict}
\alias{rsi_predict}
\title{Predict antimicrobial resistance}
\usage{
rsi_predict(tbl, col_ab, col_date = "ontvangstdatum",
year_max = as.integer(format(as.Date(Sys.Date()), "\%Y")) + 15,
year_every = 1, model = "binomial", I_as_R = TRUE,
preserve_measurements = TRUE, info = TRUE)
}
\arguments{
\item{tbl}{table that contains columns \code{col_ab} and \code{col_date}}
\item{col_ab}{column name of \code{tbl} with antimicrobial interpretations (\code{R}, \code{I} and \code{S})}
\item{col_date}{column name of the date, will be used to calculate years}
\item{year_max}{highest year to use in the prediction model, deafults to 15 years after today}
\item{year_every}{unit of sequence between lowest year found in the data and \code{year_max}}
\item{model}{the statistical model of choice. Valid values are \code{"binomial"} (or \code{"binom"} or \code{"logit"}) or \code{"loglin"} or \code{"linear"} (or \code{"lin"}).}
\item{I_as_R}{treat \code{I} as \code{R}}
\item{preserve_measurements}{overwrite predictions of years that are actually available in the data, with the original data. The standard errors of those years will be \code{NA}.}
\item{info}{print textual analysis with the name and \code{\link{summary}} of the model.}
}
\value{
\code{data.frame} with columns \code{year}, \code{probR}, \code{se_min} and \code{se_max}.
}
\description{
Create a prediction model to predict antimicrobial resistance for the next years on statistical solid ground. Standard errors (SE) will be returned as columns \code{se_min} and \code{se_max}.
}
\examples{
\dontrun{
# use it directly:
rsi_predict(tbl[which(first_isolate == TRUE & genus == "Haemophilus"),], "amcl")
# or with dplyr so you can actually read it:
library(dplyr)
tbl \%>\%
filter(first_isolate == TRUE,
genus == "Haemophilus") \%>\%
rsi_predict("amcl")
tbl \%>\%
filter(first_isolate_weighted == TRUE,
genus == "Haemophilus") \%>\%
rsi_predict(col_ab = "amcl",
year_max = 2050,
year_every = 5)
}
}
\seealso{
\code{\link{lm}} \cr \code{\link{glm}}
}
+27
View File
@@ -0,0 +1,27 @@
from setuptools import setup, find_packages
setup(
name='AMR',
version='3.0.1.9091',
packages=find_packages(),
install_requires=[
'rpy2',
'numpy',
'pandas',
],
author='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',
)