pyamr.core.asai pyamr.core.asai =============== ===============

Functions

pyamr.core.asai.antimicrobial_spectrum_activity_index(dataframe, weights='uniform', threshold=0.5, tol=1e-06, verbose=0)[source]

Computes the Antimicrobial Spectrum of Activity.

Note

Since threshold and weights have a default value, the warnings below will not be displayed. However, the code is there in case the behaviour needs to be changed in the future.

Note

Another way to check that the weights are correct is just by computing ASAI with th=0 and th=1. These should result in asai=1 and asai=0 respectively. | # Compute score | score_1 = np.sum(wgn * wsp * (sari <= 0)) | score_2 = np.sum(wgn * wsp * (sari <= 1))

Warning

Should the duplicated check only for the columns GENUS and SPECIE? What if we do not group by antibiotic? It has to be unique for the antibiotic also. It is up to the user to make the right use of this?

Parameters:
  • dataframe (pd.DataFrame) – The pandas dataframe with the information. The following columns are always required [RESISTANCE, GENUS and SPECIE]. In addition, [W_GENUS and W_SPECIE] are required if weights is None. Also, if weights = ‘frequency’ the column FREQUENCY must be present.

  • weights (string, default=’uniform’) –

    The method to compute the weights. The methods supported are:

    • ‘specified’: weights must be in [W_GENUS and W_SPECIE]

    • ‘uniform’: uniform weights for genus and species within genus.

    • ‘frequency’: weights are proportional to the frequencies.

    The following rules must be fulfilled by the weight columns:

    • consistent weight for a given genus

    • all genus weights must add up to one.

    • all specie weights within a genus must add up to one.

  • threshold (float, default=0.5) – The threshold resistance value above which the antimicrobial is considered non-effective to treat the microorganism. For instance, for a resistance threshold of 0.5, if a pair <o,a> has a resistance value of 0.4, the microorganism will be considered sensitive. In order to use specific thresholds keep threshold to None and include a column ‘THRESHOLD’.ss

  • tol (float, default=1e-6) – The tolerance in order to check that all conditions (uniqueness and sums) are satisfied. Note that that float precision varies and therefore not always adds up to exactly one.

  • verbose (int, default=0) – The level of verbosity.

Returns:

The dataframe with the ASAI information and counts.

Return type:

pd.DataFrame

pyamr.core.asai.asai(*args, **kwargs)[source]

Redirects to antimicrobial_spectrum_activity_index.

Examples using pyamr.core.asai.asai

ASAI - Compute timeseries

ASAI - Compute timeseries

Classes

class pyamr.core.asai.ASAI(column_genus='GENUS', column_specie='SPECIE', column_resistance='RESISTANCE', column_threshold='THRESHOLD', column_frequency='FREQUENCY', column_wgenus='W_GENUS', column_wspecie='W_SPECIE')[source]

Antimicrobial Spectrum of Activity Index.

Methods:

compute(dataframe[, groupby, min_freq])

Computes the ASAI index (safely).

compute(dataframe, groupby=None, min_freq=None, **kwargs)[source]

Computes the ASAI index (safely).

Parameters:
  • dataframe (pd.DataFrame) – The pandas dataframe with the information. The following columns are always required [RESISTANCE, GENUS and SPECIE]. In addition, [W_GENUS and W_SPECIE] are required if weights is None. Also, if weights = ‘frequency’ the column FREQUENCY must be present.

  • groupby (list, default=None) – The elements to groupby (pd.groupby)

  • min_freq (int, default=None) – The minimum number of susceptibility tests required in order to include the species to compute ASAI. Note that to work the dataframe must include a column indicating the frequencies.

  • weights (string, default=None) –

    The method to compute the weights. The methods supported are:

    • None: weights must be specified in [W_GENUS and W_SPECIE]

    • ‘uniform’: uniform weights for genus and species within genus.

    • ‘frequency: weights are proportional to the frequencies.

    The following rules must be fulfilled by the weight columns:

    • consistent weight for a given genus

    • all genus weights must add up to one.

    • all specie weights within a genus must add up to one.

  • threshold (float, default=None) – The threshold resistance value above which the antimicrobial is considered non-effective to treat the microorganism. For instance, for a resistance threshold of 0.5, if a pair <o,a> has a resistance value of 0.4, the microorganism will be considered sensitive. In order to use specific thresholds keep threshold to None and include a column ‘THRESHOLD’.ss

  • tol (float, default=1e-6) – The tolerance in order to check that all conditions (uniqueness and sums) are satisfied. Note that that float precision varies and therefore not always adds up to exactly one.

  • verbose (int, default=0) – The level of verbosity.

Returns:

The dataframe with the ASAI information and counts.

Return type:

pd.DataFrame

Examples using pyamr.core.asai.ASAI

ASAI - Compute timeseries

ASAI - Compute timeseries
class pyamr.core.asai.ASAI_old(weights='uniform', threshold=0.5, column_genus='GENUS', column_specie='SPECIE', column_antibiotic='ANTIBIOTIC', column_resistance='RESISTANCE', column_threshold='THRESHOLD', column_frequency='FREQUENCY', column_wgenus='W_GENUS', column_wspecie='W_SPECIE')[source]

This class computes the antimicrobial spectrum of activity.

Deprecated since version 0.0.1.

Methods:

compute(dataframe, by_category)

This function computes the asai index by category.

compute(dataframe, by_category)[source]

This function computes the asai index by category.

Parameters:
  • dataframe (pandas DataFrame) – The pandas DataFrame containing the data. In particular it needs to contain the following columns: genus, specie, antibiotic and the resistance outcome within the range [0,1].

  • by_category (string) – The name of the column that will be used to group ASAI.

Returns:

the dataframe…

Return type:

pandas dataframe