Note
Go to the end to download the full example code
Single Antimicrobial Resistance (SARI
)
The Single Antimicrobial Resistance Index or SARI
describes the proportion
of resistant isolates for a given set of susceptibility tests. It provides a
value within the range [0, 1] where values close to one indicate high resistance.
It is agnostic to pathogen, antibiotic and/or time. The variables R
, I
and
S
represent the number of susceptibility tests with Resistant, Intermediate and
Susceptible outcomes respectively. The definition might vary slightly since the
intermediate category is not always considered.
For more information see: pyamr.core.sari.SARI
16 # Libraries
17 import pandas as pd
18 import matplotlib as mpl
19 import matplotlib.pyplot as plt
20
21 # Specific
22 from pyamr.core.sari import SARI
23 from pyamr.datasets.load import fixture
24
25 # Set matplotlib
26 mpl.rcParams['xtick.labelsize'] = 9
27 mpl.rcParams['ytick.labelsize'] = 9
28 mpl.rcParams['axes.titlesize'] = 11
29 mpl.rcParams['legend.fontsize'] = 9
30
31 # ----------------------------------
32 # Methods
33 # ----------------------------------
34 def own(aux, offset):
35 """Add offset to hard"""
36 # Extract vectors
37 r = aux.resistant
38 i = aux.intermediate
39 s = aux.sensitive
40 # Compute
41 return ((r+i) / (r+i+s)) + offset
42
43 # ----------------------------------
44 # Create data
45 # ----------------------------------
46 # Load data
47 data = fixture(name='fixture_07.csv')
48
49 # ---------------------------------
50 # Compute SARI
51 # ---------------------------------
52 # Create SARI instance
53 sari = SARI(groupby=['SPECIMEN',
54 'MICROORGANISM',
55 'ANTIMICROBIAL',
56 'SENSITIVITY'])
57
58 # Compute SARI overall (hard)
59 sari_overall = sari.compute(data,
60 return_frequencies=False)
61
62 # Compute SARI overall (soft)
63 sari_overall_soft = sari.compute(data,
64 return_frequencies=False,
65 strategy='soft')
66
67 # Compute SARI overall (own)
68 sari_overall_own = sari.compute(data,
69 return_frequencies=False,
70 strategy=own,
71 offset=5)
72
73 # Compute SARI temporal (ITI)
74 sari_iti = sari.compute(data, shift='1D',
75 period='1D', cdate='DATE')
76
77 # Compute SARI temporal (OTI)
78 sari_oti = sari.compute(data, shift='1D',
79 period='2D', cdate='DATE')
80
81 # Show
82 print("\nSARI (overall):")
83 print(sari_overall)
84 print("\nSARI (iti):")
85 print(sari_iti)
86 print("\nSARI (oti):")
87 print(sari_oti)
SARI (overall):
SPECIMEN MICROORGANISM ANTIMICROBIAL
BLDCUL ECOL AAUG 0.4000
ACIP 0.6000
SAUR ACIP 0.6111
URICUL SAUR ACIP 0.7000
Name: sari, dtype: float64
SARI (iti):
intermediate resistant sensitive freq sari
SPECIMEN MICROORGANISM ANTIMICROBIAL DATE
BLDCUL ECOL AAUG 2021-01-01 0.0 1.0 3.0 4.0 0.2500
2021-01-02 0.0 1.0 2.0 3.0 0.3333
2021-01-03 0.0 1.0 1.0 2.0 0.5000
2021-01-04 0.0 1.0 0.0 1.0 1.0000
ACIP 2021-01-01 0.0 3.0 1.0 4.0 0.7500
2021-01-02 0.0 2.0 1.0 3.0 0.6667
2021-01-03 0.0 1.0 1.0 2.0 0.5000
2021-01-04 0.0 0.0 1.0 1.0 0.0000
SAUR ACIP 2021-01-01 0.0 4.0 0.0 4.0 1.0000
2021-01-02 0.0 1.0 2.0 3.0 0.3333
2021-01-08 0.0 5.0 1.0 6.0 0.8333
2021-01-09 0.0 1.0 4.0 5.0 0.2000
URICUL SAUR ACIP 2021-01-12 1.0 1.0 0.0 2.0 1.0000
2021-01-13 0.0 1.0 1.0 2.0 0.5000
2021-01-14 0.0 2.0 0.0 2.0 1.0000
2021-01-15 0.0 0.0 2.0 2.0 0.0000
2021-01-16 2.0 0.0 0.0 2.0 1.0000
SARI (oti):
intermediate resistant sensitive freq sari
SPECIMEN MICROORGANISM ANTIMICROBIAL DATE
BLDCUL ECOL AAUG 2021-01-01 0.0 1.0 3.0 4.0 0.2500
2021-01-02 0.0 2.0 5.0 7.0 0.2857
2021-01-03 0.0 2.0 3.0 5.0 0.4000
2021-01-04 0.0 2.0 1.0 3.0 0.6667
ACIP 2021-01-01 0.0 3.0 1.0 4.0 0.7500
2021-01-02 0.0 5.0 2.0 7.0 0.7143
2021-01-03 0.0 3.0 2.0 5.0 0.6000
2021-01-04 0.0 1.0 2.0 3.0 0.3333
SAUR ACIP 2021-01-01 0.0 4.0 0.0 4.0 1.0000
2021-01-02 0.0 5.0 2.0 7.0 0.7143
2021-01-08 0.0 5.0 1.0 6.0 0.8333
2021-01-09 0.0 6.0 5.0 11.0 0.5455
URICUL SAUR ACIP 2021-01-12 1.0 1.0 0.0 2.0 1.0000
2021-01-13 1.0 2.0 1.0 4.0 0.7500
2021-01-14 0.0 3.0 1.0 4.0 0.7500
2021-01-15 0.0 2.0 2.0 4.0 0.5000
2021-01-16 2.0 0.0 2.0 4.0 0.5000
Lets see the susceptibility test records.
91 data.head(15)
Let’s display the overall_hard
resistance.
96 sari_overall.to_frame()
Let’s compare with the overall_soft
resistance.
101 sari_overall_soft.to_frame()
Let’s compare with the overall_own
resistance.
106 sari_overall_own.to_frame()
Let’s display the resistance time-series using independent
time intervals (ITI)
111 sari_iti
Let’s display the resistance time-series using overlapping
time intervals (OTI)
117 sari_oti
Note
On a side note, the variable sari_overall returned is a pd.Series
.
However, it has been converted to a pd.DataFrame
for display purposes.
The sphinx
library used to create the documentation uses the method
_repr_html_
from the latter to display it nicely in the docs.
Let’s display the information graphically
Total running time of the script: ( 0 minutes 0.063 seconds)