twocan.IMCProcessor

class twocan.IMCProcessor(arcsinh_normalize=True, arcsinh_cofactor=5, winsorize_limits=[None, None], binarize=True, binarization_threshold=2, sigma=1)[source]

Bases: object

Preprocessing pipeline for Imaging Mass Cytometry (IMC) images.

This class provides a comprehensive preprocessing pipeline specifically designed for IMC images, including arcsinh transformation for variance stabilization, winsorization for outlier handling, normalization, Gaussian blurring, and optional binarization.

Parameters:
  • arcsinh_normalize (bool, default=True) – Whether to apply arcsinh transformation for variance stabilization.

  • arcsinh_cofactor (float, default=5) – Cofactor for arcsinh transformation. Lower values increase the transformation strength.

  • winsorize_limits (list of float, default=[None, None]) – Lower and upper percentile limits for winsorization. [0.01, 0.01] means clip bottom 1% and top 1% of values.

  • binarize (bool, default=True) – Whether to apply binarization after preprocessing.

  • binarization_threshold (float, default=2) – Threshold value for binarization.

  • sigma (float, default=1) – Standard deviation for Gaussian blur kernel.

arcsinh_normalize

Whether arcsinh transformation is enabled.

Type:

bool

arcsinh_cofactor

Current arcsinh cofactor value.

Type:

float

winsorize_limits

Current winsorization limits.

Type:

list

binarize

Whether binarization is enabled.

Type:

bool

binarization_threshold

Current binarization threshold.

Type:

float

sigma

Current Gaussian blur sigma value.

Type:

float

Notes

The arcsinh transformation is particularly useful for IMC data because it stabilizes variance across the intensity range, which is important for count-based mass spectrometry data.

configure(trial_params)[source]

Configure processor parameters from Optuna trial parameters.

This method updates the processor parameters based on values suggested by an Optuna trial. It looks for specific IMC parameter names in the trial params dictionary.

Parameters:

trial_params (dict) – Dictionary of trial parameters from Optuna optimization. Expected keys: ‘IMC_arcsinh_normalize’, ‘IMC_arcsinh_cofactor’, ‘IMC_winsorization_lower_limit’, ‘IMC_winsorization_upper_limit’, ‘IMC_binarization_threshold’, ‘IMC_gaussian_sigma’, ‘binarize_images’.

Returns:

self – Returns self for method chaining.

Return type:

IMCProcessor