StructuredQuery#

class astropathdb.db_io._sample_utils.StructuredQuery(*args, input_kwargs, kind, **kwargs)#

Bases: BasicSampleQueries

Create a structured query for elements.

Parameters:
  • input_kwargs (str)

  • kind (str)

StructuredQuery Attributes#

StructuredQuery Properties#

query_string

Returns the query string for the element query.

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.

StructuredQuery 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.

StructuredQuery References#

Attribute Reference#

attribute kind#
attribute kwargs#
attribute astrodb#

Property Reference#

property query_string#
Type:

str

Return type:

str

Returns the query string for the element query.

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 Method Reference#

method _validate_input_kwargs(*, input_kwargs)#

Validates the input kwargs for the element query.

If the input_kwargs is a bool or str, it will be converted to an empty dict. If it is a Mapping, it will be returned as a dict. If it is not one of these types, a TypeError will be raised.

Parameters:

input_kwargs (bool | str | Mapping[str, Any])

Return type:

None

method _parse_element_column_input(_input_kwargs)#
Parameters:

_input_kwargs (dict[str, Any])

Return type:

tuple[list, dict, dict]

method _parse_input_kwargs(*, input_kwargs)#

Parse the input kwargs for the query.

Parameters:

input_kwargs (bool | str | Mapping[str, Any])

Return type:

tuple