parse#

Contains functions to parse imaging data aquired on an OperaPhenix or Operetta into usable formats for downstream pipelines.

class scportrait.tools.parse.PhenixParser(experiment_dir: str | PosixPath, flatfield_exported: bool = True, use_symlinks: bool = True, compress_rows: bool = False, compress_cols: bool = False, overwrite: bool = False)#

Parse and manage image data exported from Phenix experiments.

Parameters:
  • experiment_dir – Directory containing the exported Phenix experiment.

  • flatfield_exported – Whether flatfield corrected images were exported.

  • use_symlinks – Whether to use symbolic links for parsed images.

  • compress_rows – Whether to merge all plate rows into a single parsed row.

  • compress_cols – Whether to merge all wells into a single parsed column.

  • overwrite – Whether to overwrite existing files during the parsing process.

generate_metadata() DataFrame#

Generate metadata for the Phenix experiment, including parsed file names.

check_for_missing_files(metadata: DataFrame = None, return_values: bool = False) list | None#

Check for missing images in the experiment.

Stitching requires a full rectangular tile grid, so missing images are identified and can later be replaced with black images.

Parameters:
  • metadata – Metadata for the experiment. If omitted, cached or freshly generated metadata is used.

  • return_values – Whether to return the list of missing images instead of only storing it on self.missing_images.

Returns:

A list of missing images if return_values is True, otherwise None.

replace_missing_images() None#

Replace missing images with black images of the same size.

parse(check_missing_tiles: bool = True) None#

Complete parsing of the Phenix experiment.

Parameters:

check_missing_tiles – Whether to check for and generate missing tiles.

sort_wells(sort_tiles: bool = False) None#

Sort parsed images by well.

Generates a folder tree where each well has its own folder containing all images from that well. If sort_tiles is True, an additional layer is added where all images from the same FOV are sorted into a dedicated subfolder.

Parameters:

sort_tiles – Whether to sort images into per-tile directories within each well.

sort_timepoints(sort_wells: bool = False) None#

Sort parsed images by timepoint.

Generates a folder tree where each timepoint has its own folder containing all images captured at that timepoint. If sort_wells is True, an additional layer is added where images from the same well are grouped within each timepoint.

Parameters:

sort_wells – Whether to sort images into per-well directories within each timepoint.

class scportrait.tools.parse.CombinedPhenixParser(experiment_dir: str, flatfield_exported: bool = True, use_symlinks: bool = True, compress_rows: bool = False, compress_cols: bool = False, overwrite: bool = False)#

Parse Phenix experiments where multiple exports should be combined into one dataset.

This is typically used when individual tiles were not imaged during acquisition, for example because of a focus failure. Instead of repeating the entire measurement, the missing tiles can be acquired in a separate experiment and combined with the original dataset.

This class inherits from the PhenixParser class and extends it by adding the functionality to combine multiple experiments into one dataset. These individual experiments need to be placed together in the following structure:

<experiment_name>/
└── experiments_to_combine/
    ├── experiment_1/
    ├── experiment_2/
    ├── experiment_3/
    └── ...
  • <experiment_name> can be chosen freely.

  • experiments_to_combine is a folder containing all experiments that should be combined. This folder should be placed in the main experiment directory.

  • experiment_n always refers to the complete folder as generated by Harmony when exporting Phenix data without any further modifications.

The experiments will be combined in the order of their creation date and time. If two experiments contain images in the same position, the parser will keep the images from the first experiment.

Parameters:
  • experiment_dir – Directory containing the exported Phenix experiment.

  • flatfield_exported – Whether flatfield corrected images were exported.

  • use_symlinks – Whether to use symbolic links for parsed images.

  • compress_rows – Whether to merge all plate rows into a single parsed row.

  • compress_cols – Whether to merge all wells into a single parsed column.

  • overwrite – Whether to overwrite existing files during the parsing process.

get_datasets_to_combine() None#

Get all Phenix experiments from subdirectories that should be combined.