BasicSampleQueries#

class astropathdb.db_io._sample_utils.BasicSampleQueries(astrodb, sampleid)#

Basic queries for samples in the AstroPath databases.

Parameters:

BasicSampleQueries Attributes#

BasicSampleQueries Properties#

samples

Returns the sampleids to query.

cell_range_query

Returns a list of one query for the max and min cellid in a sample.

image_dims_query

Returns a list of two queries for the image dimensions for a sample.

BasicSampleQueries Methods#

query_by_cell_ranges(base_query[, min_cellid, ...])

Parse the cell boundaries queries into 20 separate queries for speed.

create_cells_parquet(directory[, slideids, ...])

Create parquet files for the cells in the samples.

create_cells_geoms_parquet(directory[, slideids, btype])

Create parquet files for the cells geometries in the samples.

create_cells_positions_parquet(directory[, slideids])

Create parquet files for the cells positions in the samples.

BasicSampleQueries References#

Attribute Reference#

attribute astrodb#

Property Reference#

property samples#
Type:

str | int | list[int]

Return type:

str | int | list[int]

Returns the sampleids to query.

If the element is ‘cells’, it returns the sampleids for all cell elements; otherwise it returns the sampleids for the specified element.

property cell_range_query#
Type:

list

Return type:

list

Returns a list of one query for the max and min cellid in a sample.

Note

Returns the strings for the query not the results.

property image_dims_query#
Type:

list

Return type:

list

Returns a list of two queries for the image dimensions for a sample.

The first query is for the unique (x, y, level) combinations, the second is for the unique ztype layers.

Note

Returns the strings for the queries not the results.

Method Reference#

method query_by_cell_ranges(base_query, min_cellid=None, max_cellid=None, cell_ranges=None, sample=None, *, is_and=True)#

Parse the cell boundaries queries into 20 separate queries for speed.

The cell boundaries take longer to query. To improve the speed we parse the cell boundaries into 20 queries based on the cellid range for the sample and pass those in parallel.

Parameters:
Return type:

list

method create_cells_parquet(directory, slideids=None, base_query='SELECT * FROM CELLTAG', *, is_and=False, file_spec='cells')#

Create parquet files for the cells in the samples.

Parameters:
  • directory (str) – The directory to save the parquet files. Each sample will be saved in a subdirectory under “slide ID / wsi”.

  • slideids (list | DataFrame) – A list of slide IDs to use for the samples. If None, the sample name will be used as the slide ID.

  • base_query (str) – The base query to use for the cells.

  • is_and (bool) – Whether to use ‘and’ or ‘where’ in the query.

  • file_spec (str) – The file specification to use for the parquet files. Defaults to ‘cells’ (i.e. creates ‘cells.parquet’).

Return type:

None

method create_cells_geoms_parquet(directory, slideids=None, btype=0)#

Create parquet files for the cells geometries in the samples.

Parameters:
  • directory (str) – The directory to save the parquet files. Each sample will be saved in a subdirectory under “slide ID / wsi”.

  • slideids (list | DataFrame) – A list of slide IDs to use for the samples. If None, the sample name will be used as the slide ID.

  • btype (int) – The boundary type to use for the cells. 0 for boundaries, 1 for nuclei. Defaults to 0.

Return type:

None

method create_cells_positions_parquet(directory, slideids=None)#

Create parquet files for the cells positions in the samples.

Parameters:
  • directory (str) – The directory to save the parquet files. Each sample will be saved in a subdirectory under “slide ID / wsi”.

  • slideids (list | DataFrame) – A list of slide IDs to use for the samples. If None, the sample name will be used as the slide ID.

Return type:

None

Private Attribute Reference#

attribute __samples#

Private Method Reference#

method _sample_cell_range(cell_ranges, sample)#

Get the min and max cellid for the sample.

Parameters:
  • cell_ranges (DataFrame) – A DataFrame with the min and max cellid for a sample.

  • sample (int) – The sample for which to get the cell range.

Returns:

A tuple with the min and max cellid for the sample.

Return type:

tuple[int, int]

method _check_slideids_input(slideids)#
Parameters:

slideids (list | DataFrame)

Return type:

None

method _lookup_slideid(slideids, sample, idx)#
Parameters:
Return type:

int

method _write_cells_parquet(directory, slideid, file_spec, df)#

Write the DataFrame to a parquet file in the specified directory.

Parameters:
  • directory (str) – The directory to save the parquet file.

  • slideid (int) – The slide ID.

  • file_spec (str) – The file specification for the parquet file.

  • df (DataFrame) – The DataFrame to save.

Return type:

None