mirror of
https://github.com/msberends/AMR.git
synced 2025-07-21 11:33:13 +02:00
(v2.1.1.9127) unit tests
This commit is contained in:
@ -63,6 +63,9 @@ r_lib_path = os.path.join(venv_path, "R_libs")
|
||||
os.makedirs(r_lib_path, exist_ok=True)
|
||||
# Set the R library path in .libPaths
|
||||
base = importr('base')
|
||||
# Turn off warnings
|
||||
base.options(warn = -1)
|
||||
|
||||
base._libPaths(r_lib_path)
|
||||
r_amr_lib_path = base._libPaths()[0]
|
||||
|
||||
@ -90,6 +93,9 @@ if r_amr_version != python_amr_version:
|
||||
except Exception as e:
|
||||
print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True)
|
||||
|
||||
# Restore warnings to default
|
||||
base.options(warn = 0)
|
||||
|
||||
print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True)
|
||||
|
||||
# Activate the automatic conversion between R and pandas DataFrames
|
||||
|
@ -1,5 +1,5 @@
|
||||
This files contains all context you must know about the AMR package for R.
|
||||
First and foremost, you are trained on version 2.1.1.9126. Remember this whenever someone asks which AMR package version you’re at.
|
||||
First and foremost, you are trained on version 2.1.1.9127. Remember this whenever someone asks which AMR package version you’re at.
|
||||
--------------------------------
|
||||
|
||||
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'NAMESPACE':
|
||||
@ -228,7 +228,6 @@ export(g.test)
|
||||
export(geom_sir)
|
||||
export(get_AMR_locale)
|
||||
export(get_episode)
|
||||
export(get_long_numeric_format)
|
||||
export(get_mo_source)
|
||||
export(ggplot_pca)
|
||||
export(ggplot_sir)
|
||||
@ -1609,7 +1608,6 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antibiogram.Rd':
|
||||
\name{antibiogram}
|
||||
\alias{antibiogram}
|
||||
\alias{wisca}
|
||||
\alias{get_long_numeric_format}
|
||||
\alias{plot.antibiogram}
|
||||
\alias{autoplot.antibiogram}
|
||||
\alias{knit_print.antibiogram}
|
||||
@ -1641,8 +1639,6 @@ wisca(x, antibiotics = where(is.sir), mo_transform = "shortname",
|
||||
combine_SI = TRUE, sep = " + ", simulations = 1000,
|
||||
info = interactive())
|
||||
|
||||
get_long_numeric_format(antibiogram)
|
||||
|
||||
\method{plot}{antibiogram}(x, ...)
|
||||
|
||||
\method{autoplot}{antibiogram}(object, ...)
|
||||
@ -1689,8 +1685,6 @@ get_long_numeric_format(antibiogram)
|
||||
|
||||
\item{info}{a \link{logical} to indicate info should be printed - the default is \code{TRUE} only in interactive mode}
|
||||
|
||||
\item{antibiogram}{the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}}
|
||||
|
||||
\item{...}{when used in \link[knitr:kable]{R Markdown or Quarto}: arguments passed on to \code{\link[knitr:kable]{knitr::kable()}} (otherwise, has no use)}
|
||||
|
||||
\item{object}{an \code{\link[=antibiogram]{antibiogram()}} object}
|
||||
@ -1711,7 +1705,7 @@ This function returns a table with values between 0 and 100 for \emph{susceptibi
|
||||
|
||||
For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top \emph{n} species encountered in the data. You can filter on this top \emph{n} using \code{\link[=top_n_microorganisms]{top_n_microorganisms()}}. For example, use \code{top_n_microorganisms(your_data, n = 10)} as a pre-processing step to only include the top 10 species in the data.
|
||||
|
||||
Using \code{\link[=get_long_numeric_format]{get_long_numeric_format()}}, the antibiogram is converted to a long format containing numeric values. This is ideal for e.g. advanced plotting.
|
||||
The numeric values of an antibiogram are stored in a long format as the \link{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting.
|
||||
\subsection{Formatting Type}{
|
||||
|
||||
The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the susceptibility percentage (for WISCA: \code{4-6} indicates the confidence level), \code{15} the numerator, and \code{300} the denominator:
|
||||
@ -1985,7 +1979,8 @@ if (requireNamespace("knitr")) {
|
||||
|
||||
ab1 <- antibiogram(example_isolates,
|
||||
antibiotics = c("AMC", "CIP", "TZP", "TZP+TOB"),
|
||||
mo_transform = "gramstain"
|
||||
mo_transform = "gramstain",
|
||||
wisca = TRUE
|
||||
)
|
||||
ab2 <- antibiogram(example_isolates,
|
||||
antibiotics = c("AMC", "CIP", "TZP", "TZP+TOB"),
|
||||
@ -8596,48 +8591,6 @@ print(df)
|
||||
|
||||
* **ab_name**: Similarly, this function standardises antimicrobial names. The different representations of ciprofloxacin (e.g., "Cipro", "CIP", "J01MA02", and "Ciproxin") are all converted to the standard name, "Ciprofloxacin".
|
||||
|
||||
|
||||
## Taxonomic Data Sets Now in Python!
|
||||
|
||||
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antibiotics`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
|
||||
|
||||
```python
|
||||
AMR.microorganisms
|
||||
```
|
||||
|
||||
| mo | fullname | status | kingdom | gbif | gbif_parent | gbif_renamed_to | prevalence |
|
||||
|--------------|------------------------------------|----------|----------|-----------|-------------|-----------------|------------|
|
||||
| B_GRAMN | (unknown Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_GRAMP | (unknown Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_ANAER-NEG | (unknown anaerobic Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_ANAER-POS | (unknown anaerobic Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_ANAER | (unknown anaerobic bacteria) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||
| B_ZYMMN_POMC | Zymomonas pomaceae | accepted | Bacteria | 10744418 | 3221412 | None | 2.0 |
|
||||
| B_ZYMPH | Zymophilus | synonym | Bacteria | None | 9475166 | None | 2.0 |
|
||||
| B_ZYMPH_PCVR | Zymophilus paucivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||
| B_ZYMPH_RFFN | Zymophilus raffinosivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||
| F_ZYZYG | Zyzygomyces | unknown | Fungi | None | 7581 | None | 2.0 |
|
||||
|
||||
```python
|
||||
AMR.antibiotics
|
||||
```
|
||||
|
||||
| ab | cid | name | group | oral_ddd | oral_units | iv_ddd | iv_units |
|
||||
|-----|-------------|----------------------|----------------------------|----------|------------|--------|----------|
|
||||
| AMA | 4649.0 | 4-aminosalicylic acid| Antimycobacterials | 12.00 | g | NaN | None |
|
||||
| ACM | 6450012.0 | Acetylmidecamycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||
| ASP | 49787020.0 | Acetylspiramycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||
| ALS | 8954.0 | Aldesulfone sodium | Other antibacterials | 0.33 | g | NaN | None |
|
||||
| AMK | 37768.0 | Amikacin | Aminoglycosides | NaN | None | 1.0 | g |
|
||||
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||
| VIR | 11979535.0 | Virginiamycine | Other antibacterials | NaN | None | NaN | None |
|
||||
| VOR | 71616.0 | Voriconazole | Antifungals/antimycotics | 0.40 | g | 0.4 | g |
|
||||
| XBR | 72144.0 | Xibornol | Other antibacterials | NaN | None | NaN | None |
|
||||
| ZID | 77846445.0 | Zidebactam | Other antibacterials | NaN | None | NaN | None |
|
||||
| ZFD | NaN | Zoliflodacin | None | NaN | None | NaN | None |
|
||||
|
||||
|
||||
## Calculating AMR
|
||||
|
||||
```python
|
||||
@ -8688,6 +8641,47 @@ print(result2b)
|
||||
|
||||
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`, `antibiotics`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
|
||||
|
||||
```python
|
||||
AMR.microorganisms
|
||||
```
|
||||
|
||||
| mo | fullname | status | kingdom | gbif | gbif_parent | gbif_renamed_to | prevalence |
|
||||
|--------------|------------------------------------|----------|----------|-----------|-------------|-----------------|------------|
|
||||
| B_GRAMN | (unknown Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_GRAMP | (unknown Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_ANAER-NEG | (unknown anaerobic Gram-negatives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_ANAER-POS | (unknown anaerobic Gram-positives) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| B_ANAER | (unknown anaerobic bacteria) | unknown | Bacteria | None | None | None | 2.0 |
|
||||
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||
| B_ZYMMN_POMC | Zymomonas pomaceae | accepted | Bacteria | 10744418 | 3221412 | None | 2.0 |
|
||||
| B_ZYMPH | Zymophilus | synonym | Bacteria | None | 9475166 | None | 2.0 |
|
||||
| B_ZYMPH_PCVR | Zymophilus paucivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||
| B_ZYMPH_RFFN | Zymophilus raffinosivorans | synonym | Bacteria | None | None | None | 2.0 |
|
||||
| F_ZYZYG | Zyzygomyces | unknown | Fungi | None | 7581 | None | 2.0 |
|
||||
|
||||
```python
|
||||
AMR.antibiotics
|
||||
```
|
||||
|
||||
| ab | cid | name | group | oral_ddd | oral_units | iv_ddd | iv_units |
|
||||
|-----|-------------|----------------------|----------------------------|----------|------------|--------|----------|
|
||||
| AMA | 4649.0 | 4-aminosalicylic acid| Antimycobacterials | 12.00 | g | NaN | None |
|
||||
| ACM | 6450012.0 | Acetylmidecamycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||
| ASP | 49787020.0 | Acetylspiramycin | Macrolides/lincosamides | NaN | None | NaN | None |
|
||||
| ALS | 8954.0 | Aldesulfone sodium | Other antibacterials | 0.33 | g | NaN | None |
|
||||
| AMK | 37768.0 | Amikacin | Aminoglycosides | NaN | None | 1.0 | g |
|
||||
| ... | ... | ... | ... | ... | ... | ... | ... |
|
||||
| VIR | 11979535.0 | Virginiamycine | Other antibacterials | NaN | None | NaN | None |
|
||||
| VOR | 71616.0 | Voriconazole | Antifungals/antimycotics | 0.40 | g | 0.4 | g |
|
||||
| XBR | 72144.0 | Xibornol | Other antibacterials | NaN | None | NaN | None |
|
||||
| ZID | 77846445.0 | Zidebactam | Other antibacterials | NaN | None | NaN | None |
|
||||
| ZFD | NaN | Zoliflodacin | None | NaN | None | NaN | None |
|
||||
|
||||
|
||||
# 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.
|
Reference in New Issue
Block a user