AMR 2.1.1.9095__py3-none-any.whl → 2.1.1.9103__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
AMR/datasets.py CHANGED
@@ -8,14 +8,31 @@ from rpy2 import robjects
8
8
  from rpy2.robjects import pandas2ri
9
9
  from rpy2.robjects.packages import importr, isinstalled
10
10
  import pandas as pd
11
+ # import importlib.metadata as metadata
11
12
 
12
- # Check if the R package is installed
13
+ # Check if AMR package is installed in R
13
14
  if not isinstalled('AMR'):
14
15
  utils = importr('utils')
15
- utils.install_packages('AMR')
16
+ utils.install_packages('AMR', repos='https://msberends.r-universe.dev')
17
+
18
+ # Python package version of AMR
19
+ python_amr_version = metadata.version('AMR')
20
+ # R package version of AMR
21
+ # r_amr_version = robjects.r('packageVersion("AMR")')[0]
22
+
23
+ # Compare R and Python package versions
24
+ # if r_amr_version != python_amr_version:
25
+ # print(f"{BLUE}AMR:{RESET} Version mismatch detected. Updating AMR R package version to {python_amr_version}...", flush=True)
26
+ # try:
27
+ # # Re-install the specific version of AMR in R
28
+ # utils = importr('utils')
29
+ # utils.install_packages('AMR', repos='https://msberends.r-universe.dev')
30
+ # except Exception as e:
31
+ # print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True)
16
32
 
17
33
  # Activate the automatic conversion between R and pandas DataFrames
18
34
  pandas2ri.activate()
35
+
19
36
  # example_isolates
20
37
  example_isolates = pandas2ri.rpy2py(robjects.r('''
21
38
  df <- AMR::example_isolates
@@ -26,6 +43,7 @@ df[] <- lapply(df, function(x) {
26
43
  x
27
44
  }
28
45
  })
46
+ df <- df[, !sapply(df, is.list)]
29
47
  df
30
48
  '''))
31
49
  example_isolates['date'] = pd.to_datetime(example_isolates['date'])
@@ -33,6 +51,6 @@ example_isolates['date'] = pd.to_datetime(example_isolates['date'])
33
51
  # microorganisms
34
52
  microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR::microorganisms, is.list)]'))
35
53
  antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]'))
36
- clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints'))
54
+ clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]'))
37
55
 
38
56
  print(f"{BLUE}AMR:{RESET} {GREEN}Done.{RESET}", flush=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: AMR
3
- Version: 2.1.1.9095
3
+ Version: 2.1.1.9103
4
4
  Summary: A Python wrapper for the AMR R package
5
5
  Home-page: https://github.com/msberends/AMR
6
6
  Author: Dr. Matthijs Berends
@@ -16,43 +16,43 @@ Requires-Dist: rpy2
16
16
  Requires-Dist: numpy
17
17
  Requires-Dist: pandas
18
18
 
19
- ---
20
- title: "AMR for Python"
21
- output:
22
- rmarkdown::html_vignette:
23
- toc: true
24
- toc_depth: 3
25
- vignette: >
26
- %\VignetteIndexEntry{AMR for Python}
27
- %\VignetteEncoding{UTF-8}
28
- %\VignetteEngine{knitr::rmarkdown}
29
- editor_options:
30
- chunk_output_type: console
31
- ---
32
-
33
- ```{r setup, include = FALSE, results = 'markup'}
34
- knitr::opts_chunk$set(
35
- warning = FALSE,
36
- collapse = TRUE,
37
- comment = "#>",
38
- fig.width = 7.5,
39
- fig.height = 5
40
- )
41
- ```
42
19
 
43
- # Introduction
20
+ The `AMR` package for R is a powerful tool for antimicrobial resistance (AMR) analysis. It provides extensive features for handling microbial and antimicrobial data. However, for those who work primarily in Python, we now have a more intuitive option available: the [`AMR` Python Package Index](https://pypi.org/project/AMR/).
21
+
22
+ This Python package is a wrapper round the `AMR` R package. It uses the `rpy2` package internally. Despite the need to have R installed, Python users can now easily work with AMR data directly through Python code.
23
+
24
+ # Install
44
25
 
45
- 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, which uses `rpy2` internally. This package allows Python users to access all the functions from the R `AMR` package without the need to set up `rpy2` themselves. Since this Python package is not a true 'port' (which would require all R functions to be rewritten into Python), R and the AMR R package are still required to be installed. Yet, Python users can now easily work with AMR data directly through Python code.
26
+ 1. Since the Python package is available on the official [Python Package Index](https://pypi.org/project/AMR/), you can just run:
46
27
 
47
- In this document, we explain how this works and provide simple examples of using the `AMR` Python package.
28
+ ```bash
29
+ pip install AMR
30
+ ```
48
31
 
49
- ## How It Works
32
+ 2. Make sure you have R installed. There is **no need to install the `AMR` R package**, as it will be installed automatically.
50
33
 
51
- The `AMR` Python package acts as a wrapper around the functions in the `AMR` R package. The package simplifies the process of calling R functions in Python, eliminating the need to manually manage the `rpy2` setup, which Python uses internally to be able to work with the R package. By just using `import AMR`, Python users can directly use the functions from the `AMR` R package as if they were native Python functions.
34
+ For Linux:
52
35
 
53
- Internally, `rpy2` is still being used, but all complexity is hidden from the user. This approach keeps the Python code clean and Pythonic, while still leveraging the full power of the R `AMR` package.
36
+ ```bash
37
+ # Ubuntu / Debian
38
+ sudo apt install r-base
39
+ # Fedora:
40
+ sudo dnf install R
41
+ # CentOS/RHEL
42
+ sudo yum install R
43
+ ```
44
+
45
+ For macOS (using [Homebrew](https://brew.sh)):
46
+
47
+ ```bash
48
+ brew install r
49
+ ```
50
+
51
+ For Windows, visit the [CRAN download page](https://cran.r-project.org) to download and install R.
54
52
 
55
- ## Example of Usage
53
+ # Examples of Usage
54
+
55
+ ## Cleaning Taxonomy
56
56
 
57
57
  Here’s an example that demonstrates how to clean microorganism and drug names using the `AMR` Python package:
58
58
 
@@ -88,7 +88,8 @@ print(df)
88
88
 
89
89
  * **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".
90
90
 
91
- ### Taxonomic Data Sets Now in Python!
91
+
92
+ ## Taxonomic Data Sets Now in Python!
92
93
 
93
94
  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:
94
95
 
@@ -129,42 +130,7 @@ AMR.antibiotics
129
130
  | ZFD | NaN | Zoliflodacin | None | NaN | None | NaN | None |
130
131
 
131
132
 
132
- # Installation
133
-
134
- To be able to use the `AMR` Python package, it is required to install both R and the `AMR` R package.
135
-
136
- ### Preparation: Install R and `AMR` R package
137
-
138
- For Linux and macOS, this is just:
139
-
140
- ```bash
141
- # Ubuntu / Debian
142
- sudo apt install r-base && Rscript -e 'install.packages("AMR")'
143
- # Fedora:
144
- sudo dnf install R && Rscript -e 'install.packages("AMR")'
145
- # CentOS/RHEL
146
- sudo yum install R && Rscript -e 'install.packages("AMR")'
147
- # Arch Linux
148
- sudo pacman -S r && Rscript -e 'install.packages("AMR")'
149
- # macOS
150
- brew install r && Rscript -e 'install.packages("AMR")'
151
- ```
152
-
153
- For Windows, visit the [CRAN download page](https://cran.r-project.org) in install R, then afterwards install the 'AMR' package manually.
154
-
155
- ### Install `AMR` Python Package
156
-
157
- Since the Python package is available on the official [Python Package Index](https://pypi.org/project/AMR/), you can just run:
158
-
159
- ```bash
160
- pip install AMR
161
- ```
162
-
163
- # Working with `AMR` in Python
164
-
165
- Now that we have everything set up, let’s walk through some practical examples of using the `AMR` package within Python.
166
-
167
- ## Example 1: Calculating AMR
133
+ ## Calculating AMR
168
134
 
169
135
  ```python
170
136
  import AMR
@@ -179,7 +145,7 @@ print(result)
179
145
  [0.59555556]
180
146
  ```
181
147
 
182
- ## Example 2: Generating Antibiograms
148
+ ## Generating Antibiograms
183
149
 
184
150
  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:
185
151
 
@@ -218,6 +184,8 @@ In this example, we generate an antibiogram by selecting various antibiotics.
218
184
 
219
185
  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.
220
186
 
221
- By using `import AMR`, you can seamlessly integrate the robust features of the R `AMR` package into your 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.
187
+ By just running `import AMR`, users can seamlessly integrate the robust features of the R `AMR` package into Python workflows.
188
+
189
+ Whether you're cleaning data or analysing resistance patterns, the `AMR` Python package makes it easy to work with AMR data in Python.
222
190
 
223
191
 
@@ -0,0 +1,7 @@
1
+ AMR/__init__.py,sha256=Jzrh0SVD8tXP1_sJAnElOPAJcvMgtleTzdSnY3RI3HY,7315
2
+ AMR/datasets.py,sha256=rZyCubWpEMEHoY0Wmh7HHHo4Exsys8Cq8JobVl5YgHg,2022
3
+ AMR/functions.py,sha256=XDN7fo0N3gGnZHYL0pdkG_9jwlsrvj0fo5IqLS7gWBM,43615
4
+ AMR-2.1.1.9103.dist-info/METADATA,sha256=6NamjGS5HgvSg_1uDTSXndnwi7H9Vh7qb1XH4FMnWWw,9414
5
+ AMR-2.1.1.9103.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
6
+ AMR-2.1.1.9103.dist-info/top_level.txt,sha256=7K6Mq_X_OHdXOzQM5y06VUadXjYkze6yzufL1d7_6xc,4
7
+ AMR-2.1.1.9103.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- AMR/__init__.py,sha256=Jzrh0SVD8tXP1_sJAnElOPAJcvMgtleTzdSnY3RI3HY,7315
2
- AMR/datasets.py,sha256=_TgR3aHvBVw2-hw3hhcVsY_FiTgCDLFQaNt8ChDuM48,1188
3
- AMR/functions.py,sha256=XDN7fo0N3gGnZHYL0pdkG_9jwlsrvj0fo5IqLS7gWBM,43615
4
- AMR-2.1.1.9095.dist-info/METADATA,sha256=Zk7uK8KtHNb7DikoFr0_rskjdnmAQwfb9hSFBiDRd9c,11148
5
- AMR-2.1.1.9095.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
6
- AMR-2.1.1.9095.dist-info/top_level.txt,sha256=7K6Mq_X_OHdXOzQM5y06VUadXjYkze6yzufL1d7_6xc,4
7
- AMR-2.1.1.9095.dist-info/RECORD,,