tmas.analysis

Module Contents

tmas.analysis.build_drug_info_dict(plate_info)[source]

Build a dictionary containing drug information based on plate data.

This function processes the plate_info dictionary. It returns a dictionary where each drug is a key, and the corresponding value is another dictionary containing sorted lists of dilutions and concentrations.

Parameters:

plate_info (dict) – A dictionary containing the following keys: - “drug_matrix”: - “dilution_matrix”: - “conc_matrix”:

Returns:

A dictionary where each key is a drug name, and the value is another dictionary containing: - “dilutions” - “concentrations”

Return type:

dict

Raises:

KeyError – If any of the expected keys (“drug_matrix”, “dilution_matrix”, “conc_matrix”) are missing from plate_info.

tmas.analysis.visualize_growth_matrix(image_name, img, growth_matrix, drug_info, drug_results, plate_info)[source]

Visualize the growth matrix on a drug susceptibility testing plate image.

This function overlays the growth detection information on an image of a microtitre plate, highlighting wells with detected growth, and annotating the wells with the corresponding drug names and concentrations.

Parameters:
  • image_name (str) – The base name of the image.

  • img (numpy.ndarray) – The image of the plate. If the image is in BGR format, it will be converted to RGB.

  • growth_matrix (list[list[str]]) – A matrix indicating the growth status of each well.

  • drug_info (dict) – A dictionary containing drug information, including dilutions and concentrations.

  • drug_results (dict) – A dictionary containing the results of the drug susceptibility test, including MIC values.

  • plate_info (dict) – A dictionary containing plate-specific information, including drug and concentration matrices.

Returns:

None

Return type:

None

tmas.analysis.analyze_growth_matrix(image_name, image, growth_matrix, plate_design, plate_design_type)[source]

Analyze the growth matrix and determine the Minimum Inhibitory Concentration (MIC) for each drug.

This function processes the growth matrix of a microtitre plate, compares it with the plate design, and determines the MIC values for each drug tested. The function also visualizes the results by overlaying growth detection on the image of the plate.

Parameters:
  • image_name (str) – The name of the image file used for labeling and saving results.

  • image (numpy.ndarray) – The image data of the plate.

  • growth_matrix (list[list[str]]) – A matrix indicating the growth status of each well.

  • plate_design (dict) – A dictionary containing the design of the plate, including drug and dilution matrices.

  • plate_design_type (str) – A string representing the type of plate design being used.

Returns:

A dictionary containing the growth results and MIC values for each drug.

Return type:

dict

tmas.analysis.extract_image_name_from_path(image_path)[source]

Extract the image name from a file path.

This function takes a file path to an image and extracts the base name of the file

Parameters:

image_path (str) – The full file path to the image.

Returns:

The base name of the image file without the extension.

Return type:

str

tmas.analysis.extract_plate_design_type_from_image_name(image_name)[source]

Extract the plate design type from an image name.

Assumes that the plate design type is always the 6th element in a hyphen-separated image name string.

Parameters:

image_name (str) – The image name string, typically in a hyphen-separated format.

Returns:

The plate design type extracted from the image name.

Return type:

str

tmas.analysis.analyze_and_extract_mic(image_path, image, detections, plate_design)[source]

Analyze growth matrix and extract Minimum Inhibitory Concentration (MIC) results.

This function takes an image path, image data, detection results, and a dictionary containing plate designs. It extracts the image name and plate design type from the image path, and then uses these to analyze the growth matrix and determine MIC values.

Parameters:
  • image_path (str) – The full file path to the image.

  • image (numpy.ndarray) – The image data, typically as a numpy array.

  • detections (Any) – Detection results for the growth matrix.

  • plate_design (dict) – A dictionary containing different plate designs indexed by plate design type.

Returns:

A dictionary containing drug results, including MIC values.

Return type:

dict