Skip to content

PyPlaque_utils_visualise

gh_actions_runner edited this page Aug 1, 2025 · 2 revisions

PyPlaque.utils.visualise

Functions:

barplot_quants(abs_df, save_path=None, normalize=False)

barplot_quants Function This function generates a bar plot to visualize quantitative data, optionally normalized. It takes a dataframe containing the quantitative data and generates a bar plot using seaborn. The bars can be optionally normalized for better comparison across different types (specified by 'type' column). The function adjusts the width of each bar for better visual presentation and saves the plot if a save path is provided. It also sets specific labels and formatting details to enhance readability and aesthetics.

Args: abs_df (pd.DataFrame, required): A dataframe containing quantitative data to be plotted, with columns 'Quant' for quantification and optionally 'Values_scaled' if normalization is enabled.
save_path (str or None, optional): The file path where the plot will be saved if provided; otherwise, it is displayed interactively. Defaults to None. normalize (bool, optional): If set to True, scales the values for better visualization by normalizing them using MinMax scaling. Defaults to False.

Returns: None: The function generates and optionally saves a matplotlib bar plot based on the arguments provided.

Raises: TypeError: If any of the input arguments do not match their expected types as specified in the method signature.

boxplot_quants(plq_measures_df, col_name, return_stats=False, save_path=None)

boxplot_quants Function This function generates a box plot to visualize quantitative measures and provides additional statistics if specified. It takes a dataframe containing the quantitative measures and a specific column name for which the boxplot should be created. It optionally returns the statistical details of the plotted data. The function plots the boxplot using seaborn and annotates it with calculated statistics such as median, mean, lower whisker, upper whisker, etc., rounded to two decimal places. If a save path is provided, the plot will be saved at that location with specified parameters for quality and layout optimization.

Args: plq_measures_df (pd.DataFrame, required): A dataframe containing the quantitative measures to be plotted. col_name (str, required): The name of the column in plq_measures_df that contains the data to plot. return_stats (bool, optional): If set to True, returns a dataframe with statistical details about the boxplot. Defaults to False. save_path (str or None, optional): The file path where the plot will be saved if provided; otherwise, it is displayed interactively. Defaults to None.

Returns: pd.DataFrame or None: If return_stats is True, returns a dataframe with statistical details of the boxplot. Otherwise, returns None.

Raises: TypeError: If any of the input arguments do not match their expected types as specified in the method signature.

compare_plaque_detection_from_image(i, j, true_count, mask, plaques_list, mask_gadjusted, plaques_list_gadjusted, save_path=None)

compare_plaque_detection_from_image Function This function compares plaque detection results from two different images (original and gamma-adjusted) by overlaying bounding boxes. It visualizes the detected plaques on top of both the original mask image and a gamma-adjusted version of it using bounding boxes. The visualization includes title labeling with well coordinates (i, j), which are passed as arguments to the function. If a save path is provided via the save_path parameter, the plot will be saved at that location using specified parameters for quality and layout optimization.

Args: i (int, required): The x-coordinate or row index of the well being visualized.
j (int, required): The y-coordinate or column index of the well being visualized. true_count (int, required): The expected number of plaques, used for validation and comparison purposes. mask (object, required): An object representing the original mask from which plaques were detected. This is typically a numpy array with additional metadata if applicable. plaques_list (list, required): A list of objects containing plaque information including bounding box coordinates (bbox), detected from the mask. mask_gadjusted (object, required): An object representing the mask from the gamma-adjusted image, similar to mask. plaques_list_gadjusted (list, required): A list of objects containing plaque information including bounding box coordinates (bbox), detected from the mask_gadjusted. save_path (str or None, optional): The file path where the plot will be saved if provided; otherwise, it is displayed interactively. Defaults to None.

Returns: None: The function displays and optionally saves a matplotlib figure based on the arguments provided.

Raises: TypeError: If any of the input arguments do not match their expected types as specified in the method signature.

create_grouped_bar_from_df(abs_df_img, abs_df_img_cont, col_name, normalize=False, save_path=None)

create_grouped_bar_from_df Function This function creates a grouped bar plot from two dataframes based on specified column values. It combines viral and control data from two separate dataframes into one dataframe and optionally normalizes the values for better comparison. It then generates a grouped bar plot to visualize the quantitative information across different types (viral vs. control). If normalize is set to True, the values are scaled using MinMax scaling for better visual representation. The function optionally saves the generated plot if a save path is provided.

Args: abs_df_img (pd.DataFrame, required): A dataframe containing quantitative data specific to viral samples. abs_df_img_cont (pd.DataFrame, required): A dataframe containing quantitative data specific to control samples. col_name (str, required): The name of the column in both dataframes that contains the values to be plotted. normalize (bool, optional): If set to True, scales the quantitative values using MinMax scaling for better visualization. Defaults to False. save_path (str or None, optional): The file path where the plot will be saved if provided; otherwise, it is displayed interactively. Defaults to None.

Returns: None: The function generates and optionally saves a matplotlib bar plot based on the arguments provided.

Raises: TypeError: If any of the input arguments do not match their expected types as specified in the method signature.

plot_bbox_plaques_mask(i, j, mask, plaques_list, save_path=None)

plot_bbox_plaques_mask Function This function plots a masked image of plaques overlaid with bounding boxes and saves it if a save path is provided. It visualizes the plaque masks and draws bounding boxes around each plaque detected in plaques_list. The visualization includes title labeling with well coordinates (i, j), which are passed as arguments to the function. If a save path is provided via the save_path parameter, the plot will be saved at that location using specified parameters for quality and layout optimization.

Args: i (int, required): The x-coordinate or row index of the well being visualized. j (int, required): The y-coordinate or column index of the well being visualized. mask (np.ndarray, required): A 2D numpy array representing the original mask image, typically from nuclei images before plaque segmentation. plaques_list (list, required): A list of objects containing plaque information including bounding box coordinates (bbox, required), which are used to draw rectangles on top of the mask. save_path (str or None, optional): The file path where the plot will be saved if provided; otherwise, it is displayed interactively. Defaults to None.

Returns: None: The function displays and optionally saves a matplotlib figure based on the arguments provided.

Raises: TypeError: If any of the input arguments do not match their expected types as specified in the method signature.

Clone this wiki locally