API Reference

This section contains the API documentation for all modules in the Napari Chromosome Analysis project.

Main Module

Image Processor

Author: Md Abdul Kader Sagar Email: sagarm2@nih.gov Institute: National Cancer Institute/NIH

This code is designed for analyzing metaphase chromosomes using the Napari platform. It facilitates the visualization and segmentation of chromosome images, enabling users to efficiently assess chromosome structures and perform quantitative analysis. The code integrates tools for detecting centromeres and measuring CENP-A levels within metaphase chromosome regions, enhancing the accuracy of chromosome analysis.

class image_processor.ImageProcessor[source]

Bases: object

load_images(folder_path, dapi_id, dna_fish_id, cenpc_id, skip_segmentation)[source]
get_spots_in_common_regions(df_spots, common_nuclei)[source]

Filter spots to only include those in common regions.

Parameters:

df_spotspandas.DataFrame

DataFrame containing spot coordinates with columns [‘Y’, ‘X’]

common_nucleinumpy.ndarray

Label image of common regions

Returns:

pandas.DataFrame

Filtered DataFrame containing only spots in common regions

load_images1(folder_path)[source]
segment_image_BU(image)[source]
segment_image(image, save_dir=None)[source]

Segment the image using Cellpose and optionally save the results.

Parameters:
  • image – Input image to segment

  • save_dir – Optional directory to save intermediate results

Returns:

The segmented image masks

segment_image_BU_original(image)[source]
find_peaks(dataIn, n=5)[source]
detect_spots1(image, channel, threshold=0.4)[source]
detect_spots2(image, channel, threshold=0.4)[source]
detect_spots(image, channel, threshold=0.4)[source]
ndi = <module 'scipy.ndimage' from '/home/docs/checkouts/readthedocs.org/user_builds/metachrome/envs/latest/lib/python3.9/site-packages/scipy/ndimage/__init__.py'>
detect_spots_cent(image, channel_type, threshold, save_dir=None)[source]

Detect spots and save results if save_dir is provided.

Parameters:
  • image – Input image

  • channel_type – Type of channel (‘DNA-FISH’ or ‘CENPC’)

  • threshold – Detection threshold

  • save_dir – Directory to save results (optional)

Returns:

Array of centroids if spots are detected, None otherwise

Return type:

numpy.ndarray

detect_spots_cent_BU(image, channel, threshold=0.4)[source]
detect_spots_no_segmentation(image, threshold=0.4, channel=None)[source]

Detect spots in an image without segmentation.

Parameters:
  • image – Input image

  • threshold – Detection threshold (default: 0.4)

  • channel – Channel type (‘DNA-FISH’ or ‘CENPC’)

Returns:

(labeled_spots, centroids) or (None, None) if no spots detected

Return type:

tuple

detect_spots_no_segmentation_BU(image, threshold=0.4)[source]
find_common()[source]

Find Channel 1 spots in chromosomes that also contain Channel 2 spots and calculate Channel 2 intensity.

Returns:

Labeled image showing chromosomes with both types of spots None: If no spots are found or an error occurs

Return type:

numpy.ndarray

Note

  • Requires prior segmentation (self.nuclei must be set)

  • Requires prior spot detection for both channels

  • Updates self.common_nuclei with the labeled image

  • Updates self.df_centroid_dna_fish with spot locations and intensities

find_common_BU(threshold_dna_fish, threshold_cenpc)[source]
find_common2(threshold_dna_fish, threshold_cenpc)[source]
get_spot_location(normIm, threshold, labels_to_get_centroid)[source]
measure_intensity_at_spots(intensity_image, spots_df, channel_name)[source]

Measure intensity values at spot locations for a single channel.

Parameters:
  • intensity_image – Image to measure intensities from

  • spots_df – DataFrame with spot locations (must have ‘Y’ and ‘X’ columns)

  • channel_name – Name of the channel (‘Channel1’ or ‘Channel2’)

Returns:

DataFrame with spot locations and their corresponding intensities

gen_intensity_from_df(intensity_image_ch2, spots_df_ch1, intensity_image_ch1=None, spots_df_ch2=None)[source]

Generate intensity measurements for both channels at each other’s spot locations.

Parameters:
  • intensity_image_ch2 – Channel 2 intensity image

  • spots_df_ch1 – DataFrame with Channel 1 spot locations

  • intensity_image_ch1 – Channel 1 intensity image (optional)

  • spots_df_ch2 – DataFrame with Channel 2 spot locations (optional)

Returns:

DataFrame with both channels’ spot locations and their corresponding intensities

calculate_intensity_all_cenpc(intensity_image_ch1=None)[source]

Calculate Channel 1 intensity at all Channel 2 spot locations without segmentation.

Parameters:

intensity_image_ch1 – Optional Channel 1 intensity image. If not provided, uses self.img_dna_fish

Returns:

DataFrame containing spot locations and corresponding intensities,

or None if spots or intensity image are missing

Return type:

pandas.DataFrame

calculate_intensity_all_dna_fish(intensity_image_ch2=None)[source]

Calculate Channel 2 intensity at all Channel 1 spot locations without segmentation.

Parameters:

intensity_image_ch2 – Optional Channel 2 intensity image. If not provided, uses self.img_cenpc

Returns:

DataFrame containing spot locations and corresponding intensities,

or None if spots or intensity image are missing

Return type:

pandas.DataFrame

get_centroids_from_labels(labels)[source]
merge_nuclei_with_line(line_coords)[source]
remove_nuclei_with_line(line_coords)[source]
split_chromosome_with_line(line_coords)[source]
delete_dna_fish_spots_with_line(viewer)[source]

Delete DNA-FISH spots that intersect with the drawn line or points.

delete_cenpc_spots_with_line(viewer)[source]

Delete Channel 2 spots that intersect with the drawn line or points.

split_chromosome_with_line_BU(line_coords)[source]

Batch Processor

class batch_processor.BatchProcessor(processor, control_widget_dna_fish, control_widget_cenpc)[source]

Bases: object

Parameters:

processor (ImageProcessor)

batch_processing(root_folder, dapi_id, dna_fish_id, cenpc_id, skip_segmentation)[source]

Segmentation Post-processing

Author: Md Abdul Kader Sagar Email: sagarm2@nih.gov Institute: National Cancer Institute/NIH

This code is designed for analyzing metaphase chromosomes using the Napari platform. It facilitates the visualization and segmentation of chromosome images, enabling users to efficiently assess chromosome structures and perform quantitative analysis. The code integrates tools for detecting centromeres and measuring CENP-A levels within metaphase chromosome regions, enhancing the accuracy of chromosome analysis.

class segmentation_postprocessing.SegmentationPostprocessing(viewer, processor, chromosome_counter)[source]

Bases: object

set_current_folder(folder_path)[source]

Set the current folder path

save_segmentation()[source]
remove_chromosome()[source]
split_chromosome()[source]
merge_chromosomes()[source]
show_info(message)[source]

Helper method to show information messages