ahcore.cli package#

Submodules#

ahcore.cli.data module#

Module to write copy manifests files over to SCRATCH directory

ahcore.cli.data.copy_data(args: Namespace) None[source]#
ahcore.cli.data.register_parser(parser: argparse._SubParsersAction[Any]) None[source]#

Register inspect commands to a root parser.

ahcore.cli.tiling module#

Utility to create tiles from the TCGA FFPE H&E slides.

Many models uses 0.5um/pixel at 224 x 224 size.

class ahcore.cli.tiling.DatasetConfigs(*, mpp: float, tile_size: tuple[int, int], tile_overlap: tuple[int, int], tile_mode: str, crop: bool, mask_threshold: float, grid_order: str, color_profile_applied: bool = False)[source]#

Bases: BaseModel

Configurations of the TiledWsiDataset dataset

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

color_profile_applied: bool#
crop: bool#
grid_order: str#
mask_threshold: float#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'color_profile_applied': FieldInfo(annotation=bool, required=False, default=False), 'crop': FieldInfo(annotation=bool, required=True), 'grid_order': FieldInfo(annotation=str, required=True), 'mask_threshold': FieldInfo(annotation=float, required=True), 'mpp': FieldInfo(annotation=float, required=True), 'tile_mode': FieldInfo(annotation=str, required=True), 'tile_overlap': FieldInfo(annotation=tuple[int, int], required=True), 'tile_size': FieldInfo(annotation=tuple[int, int], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mpp: float#
tile_mode: str#
tile_overlap: tuple[int, int]#
tile_size: tuple[int, int]#
class ahcore.cli.tiling.SlideImageMetaData(*, path: Path, mpp: float, aspect_ratio: float, magnification: float | None, size: tuple[int, int], vendor: str | None)[source]#

Bases: BaseModel

Metadata of a whole slide image.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

aspect_ratio: float#
classmethod from_dataset(dataset: TiledWsiDataset) SlideImageMetaData[source]#
magnification: float | None#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'aspect_ratio': FieldInfo(annotation=float, required=True), 'magnification': FieldInfo(annotation=Union[float, NoneType], required=True), 'mpp': FieldInfo(annotation=float, required=True), 'path': FieldInfo(annotation=Path, required=True), 'size': FieldInfo(annotation=tuple[int, int], required=True), 'vendor': FieldInfo(annotation=Union[str, NoneType], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

mpp: float#
path: Path#
size: tuple[int, int]#
vendor: str | None#
class ahcore.cli.tiling.Thumbnail(thumbnail: npt.NDArray[np.uint8], mask: npt.NDArray[np.uint8] | None, overlay: npt.NDArray[np.uint8] | None)[source]#

Bases: NamedTuple

Thumbnail of a slide image.

Create new instance of Thumbnail(thumbnail, mask, overlay)

mask: ndarray[Any, dtype[uint8]] | None#

Alias for field number 1

overlay: ndarray[Any, dtype[uint8]] | None#

Alias for field number 2

thumbnail: ndarray[Any, dtype[uint8]]#

Alias for field number 0

class ahcore.cli.tiling.TileMetaData(*, coordinates: tuple[int, int], region_index: int, grid_local_coordinates: tuple[int, int], grid_index: int)[source]#

Bases: BaseModel

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

coordinates: tuple[int, int]#
grid_index: int#
grid_local_coordinates: tuple[int, int]#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'coordinates': FieldInfo(annotation=tuple[int, int], required=True), 'grid_index': FieldInfo(annotation=int, required=True), 'grid_local_coordinates': FieldInfo(annotation=tuple[int, int], required=True), 'region_index': FieldInfo(annotation=int, required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

region_index: int#
ahcore.cli.tiling.create_slide_image_dataset(slide_image_path: Path, mask: SlideImage | ndarray[Any, dtype[int64]] | None, cfg: DatasetConfigs, overwrite_mpp: tuple[float, float] | None = None) TiledWsiDataset[source]#

Initializes and returns a slide image dataset.

Parameters:
slide_image_pathPath

Path to a whole slide image file.

masknp.ndarray | None

Binary mask used to filter each tile.

cfgDatasetConfigs

Dataset configurations.

overwrite_mpptuple[float, float] | None

Tuple of (mpp_x, mpp_y) used to overwrite the mpp of the loaded slide image.

Returns:
TiledROIsSlideImageDataset

Initialized slide image dataset.

ahcore.cli.tiling.read_mask(path: Path) ndarray[Any, dtype[int64]][source]#
ahcore.cli.tiling.register_parser(parser: argparse._SubParsersAction[Any]) None[source]#

Register inspect commands to a root parser.

ahcore.cli.tiling.save_tiles(dataset: TiledWsiDataset, h5_writer: H5FileImageWriter, compression: Literal['jpg', 'png', 'none'], quality: int | None = 80) None[source]#

Saves the tiles in the given image slide dataset to disk.

Parameters:
datasetTiledROIsSlideImageDataset

The image slide dataset containing tiles of a single whole slide image.

h5_writerH5FileImageWriter

The H5 writer to write the tiles to.

compressionLiteral[“jpg”, “png”, “none”]

Either “jpg”, “png” or “none”.

qualityint | None

If not None, the compression quality of the saved tiles in jpg, otherwise png

Module contents#

Ahcore Command-line interface. This is the file which builds the main parser.

ahcore.cli.dir_path(require_writable: bool = False) Callable[[str], Path][source]#
ahcore.cli.file_path(path: str) Path[source]#

Check if the path is a valid file.

Parameters:
pathstr
Returns:
pathlib.Path

The path as a pathlib.Path object.

ahcore.cli.main() None[source]#

Main entrypoint for the CLI command of ahcore.