sarcasm.structure_modules.loi_detection

Lines of Interest (LOI) Detection Module

This module provides functions for detecting, filtering, clustering, and analyzing lines of interest (LOIs) in sarcomere structures. LOIs are linear or curved paths along myofibrils used for tracking sarcomere motion in high-speed microscopy movies.

Functions

filter_lois : Filter LOIs based on geometric and morphological criteria hausdorff_distance_lois : Compute Hausdorff distances between LOIs cluster_lois : Perform agglomerative clustering of LOIs fit_straight_line_to_clusters : Fit linear lines to clustered LOI points select_longest_in_cluster : Select the longest LOI from each cluster select_random_from_cluster : Select a random LOI from each cluster select_random_lois : Select random LOIs without clustering

Attributes

logger

Functions

filter_lois(, length_lims, float] =, ...)

Filter Lines of Interest (LOIs) based on various geometric and morphological criteria.

hausdorff_distance_lois(→ numpy.ndarray)

Compute Hausdorff distances between all LOIs.

cluster_lois(→ Tuple[numpy.ndarray, int])

Perform agglomerative clustering of LOIs using Hausdorff distance matrix.

fit_straight_line_to_clusters(...)

Fit linear lines to clustered LOI points.

select_longest_in_cluster(→ Tuple[List[numpy.ndarray], ...)

Select the longest LOI from each cluster.

select_random_from_cluster(...)

Select a random LOI from each cluster.

select_random_lois(→ Tuple[List[numpy.ndarray], List[int]])

Select random LOIs without clustering.

Module Contents

sarcasm.structure_modules.loi_detection.logger
sarcasm.structure_modules.loi_detection.filter_lois(lois: List[numpy.ndarray], loi_features: Dict[str, List], lois_vectors: List[numpy.ndarray], number_lims: Tuple[int, int] = (10, 100), length_lims: Tuple[float, float] = (0, 200), sarcomere_mean_length_lims: Tuple[float, float] = (1, 3), sarcomere_std_length_lims: Tuple[float, float] = (0, 1), midline_mean_length_lims: Tuple[float, float] = (0, 50), midline_std_length_lims: Tuple[float, float] = (0, 50), midline_min_length_lims: Tuple[float, float] = (0, 50)) Tuple[List[numpy.ndarray], List[numpy.ndarray], Dict[str, List]][source]

Filter Lines of Interest (LOIs) based on various geometric and morphological criteria.

Parameters:
  • lois (list of np.ndarray) – List of LOI indices into sarcomere vectors

  • loi_features (dict) – Dictionary containing LOI features (n_vectors, length, sarcomere stats, etc.)

  • lois_vectors (list of np.ndarray) – List of actual position vectors for each LOI

  • number_lims (tuple of int, optional) – Limits of sarcomere numbers in LOI (min, max). Defaults to (10, 100).

  • length_lims (tuple of float, optional) – Limits for LOI lengths (in µm) (min, max). Defaults to (0, 200).

  • sarcomere_mean_length_lims (tuple of float, optional) – Limits for mean length of sarcomeres in LOI (min, max). Defaults to (1, 3).

  • sarcomere_std_length_lims (tuple of float, optional) – Limits for standard deviation of sarcomere lengths in LOI (min, max). Defaults to (0, 1).

  • midline_mean_length_lims (tuple of float, optional) – Limits for mean length of the midline in LOI (min, max). Defaults to (0, 50).

  • midline_std_length_lims (tuple of float, optional) – Limits for standard deviation of the midline length in LOI (min, max). Defaults to (0, 50).

  • midline_min_length_lims (tuple of float, optional) – Limits for minimum length of the midline in LOI (min, max). Defaults to (0, 50).

Returns:

  • filtered_lois (list of np.ndarray) – Filtered LOI indices

  • filtered_lois_vectors (list of np.ndarray) – Filtered position vectors

  • filtered_features (dict) – Filtered features dictionary

sarcasm.structure_modules.loi_detection.hausdorff_distance_lois(lines_vectors: List[numpy.ndarray], symmetry_mode: str = 'max') numpy.ndarray[source]

Compute Hausdorff distances between all LOIs.

The Hausdorff distance measures how far two sets of points are from each other. It’s used to quantify similarity between LOI trajectories.

Parameters:
  • lines_vectors (list of np.ndarray) – List of position vectors for each LOI

  • symmetry_mode ({'min', 'max'}, optional) – Whether to use min or max of H(loi_i, loi_j) and H(loi_j, loi_i). Defaults to ‘max’.

Returns:

hausdorff_dist_matrix – Symmetric matrix of pairwise Hausdorff distances

Return type:

np.ndarray

sarcasm.structure_modules.loi_detection.cluster_lois(hausdorff_dist_matrix: numpy.ndarray, distance_threshold: float = 40, linkage: str = 'single') Tuple[numpy.ndarray, int][source]

Perform agglomerative clustering of LOIs using Hausdorff distance matrix.

Parameters:
  • hausdorff_dist_matrix (np.ndarray) – Precomputed pairwise distance matrix

  • distance_threshold (float, optional) – The linkage distance threshold above which clusters will not be merged. Defaults to 40.

  • linkage ({'complete', 'average', 'single'}, optional) – Which linkage criterion to use: - ‘single’ uses the minimum of distances between all observations of the two sets - ‘average’ uses the average of the distances of each observation of the two sets - ‘complete’ uses the maximum distances between all observations of the two sets Defaults to ‘single’.

Returns:

  • cluster_labels (np.ndarray) – Cluster label for each LOI

  • n_clusters (int) – Number of unique clusters

sarcasm.structure_modules.loi_detection.fit_straight_line_to_clusters(lines_vectors: List[numpy.ndarray], cluster_labels: numpy.ndarray, n_clusters: int, pixelsize: float, add_length: float = 1.0, n_lois: int = None) Tuple[List[numpy.ndarray], List[float]][source]

Fit linear lines to clustered LOI points.

For each cluster, fits a linear regression to all points and creates a line that spans the extent of the cluster with optional extension.

Parameters:
  • lines_vectors (list of np.ndarray) – List of position vectors for each LOI

  • cluster_labels (np.ndarray) – Cluster label for each LOI

  • n_clusters (int) – Number of clusters

  • pixelsize (float) – Pixel size in micrometers

  • add_length (float, optional) – Length to extend line at each end (in micrometers). Defaults to 1.0.

  • n_lois (int, optional) – If specified, only the n longest LOIs are returned. If None, all are returned.

Returns:

  • loi_lines (list of np.ndarray) – List of fitted line coordinates [(y0, x0), (y1, x1)]

  • len_loi_lines (list of float) – Length of each fitted line in pixels

sarcasm.structure_modules.loi_detection.select_longest_in_cluster(lines: List[numpy.ndarray], pos_vectors: numpy.ndarray, cluster_labels: numpy.ndarray, n_clusters: int, n_lois: int) Tuple[List[numpy.ndarray], List[int]][source]

Select the longest LOI from each cluster.

Parameters:
  • lines (list of np.ndarray) – List of LOI indices

  • pos_vectors (np.ndarray) – Position vectors array

  • cluster_labels (np.ndarray) – Cluster label for each LOI

  • n_clusters (int) – Number of clusters

  • n_lois (int) – Maximum number of LOIs to return

Returns:

  • loi_lines (list of np.ndarray) – Selected LOI position vectors

  • len_loi_lines (list of int) – Length (number of points) of each LOI

sarcasm.structure_modules.loi_detection.select_random_from_cluster(lines: List[numpy.ndarray], pos_vectors: numpy.ndarray, cluster_labels: numpy.ndarray, n_clusters: int, n_lois: int) Tuple[List[numpy.ndarray], List[int]][source]

Select a random LOI from each cluster.

Parameters:
  • lines (list of np.ndarray) – List of LOI indices

  • pos_vectors (np.ndarray) – Position vectors array

  • cluster_labels (np.ndarray) – Cluster label for each LOI

  • n_clusters (int) – Number of clusters

  • n_lois (int) – Number of LOIs to randomly select from available clusters

Returns:

  • loi_lines (list of np.ndarray) – Selected LOI position vectors

  • len_loi_lines (list of int) – Length (number of points) of each LOI

sarcasm.structure_modules.loi_detection.select_random_lois(lines: List[numpy.ndarray], pos_vectors: numpy.ndarray, n_lois: int) Tuple[List[numpy.ndarray], List[int]][source]

Select random LOIs without clustering.

Parameters:
  • lines (list of np.ndarray) – List of LOI indices

  • pos_vectors (np.ndarray) – Position vectors array

  • n_lois (int) – Number of LOIs to randomly select

Returns:

  • loi_lines (list of np.ndarray) – Selected LOI position vectors

  • len_loi_lines (list of int) – Length (number of points) of each LOI